-
Notifications
You must be signed in to change notification settings - Fork 265
Decouple release reconciliation from chart source sync #99
Conversation
47a1230
to
f9f02d7
Compare
// indicates whether the repo was already present (`true` if so, | ||
// `false` otherwise). | ||
func (c *GitChartSync) maybeMirror(mirrorName string, remote string) bool { | ||
ok := c.mirrors.Mirror( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this isn't a new problem but, I only see a StopOne()
counterpart to this Mirror()
call in Delete()
which seems to only be invoked when a HelmRelease()
is deleted.
Doesn't this mean that there will be a mirror leak if the git
entry of a HelmRelease
is changed (or removed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, Delete()
doesn't help once the git
field is modified, since it uses helmReleasesForMirror()
which relies in live data, and not the mirrors created by the HelmRelease()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want to track changes on thegit
field explicitly, I think this can be fixed by periodically comparing the output of helmReleasesForMirror()
on c.mirrors
. I don't think it's ideal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see that forHelmRelease()
is used in get()
to take into account that the repo of HelmRelease
s can change with respect to what's book-kept in GitChartSync
, but I don't think we do anything to correct divergences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this isn't a new problem but, I only see a
StopOne()
counterpart to thisMirror()
call inDelete()
which seems to only be invoked when aHelmRelease()
is deleted.
The current master
version does not stop any mirrors, they continue to live forever. I will let your comments simmer in my head for a while.
// record). In case of failure it returns an error. | ||
func (c *GitChartSync) sync(hr *v1.HelmRelease, mirrorName string, repo *git.Repo) (sourceRef, bool, error) { | ||
source := hr.Spec.GitChartSource | ||
if source == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange that the method needs to check for the GitChartSource
and also provide a mirrorName
, which should be a subproduct of the former).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the interface to sync(hrID resource.ID, mirrorName string, repo *git.Repo)
But, that's not currently possible, because sync
also consistency-checks that the mirror we have for the Helm release (in get()
s invocation to forHelmRelease()
).
However, I don't think that consistency-checking is the direct responsibility of sync()
(or at least it makes it harder to understand what's going on since it's buried when invoking get()
).
I think that we should take car of divergences explicitly, while also garbage collecting orphan mirrors (i.e. https://github.com/fluxcd/helm-operator/pull/99/files#r347533178 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another reason this is not possible, without the v1.HelmRelease
or a copy of the v1.GitChartSource
, it is not possible to detect changes as done on L286, nor is it possible to construct a new sourceRef
as done on L265.
I think that the implementation has been drastically improved and looks much cleaner 🏅 , particularly when it comes to concurrency However, this has allowed me to focus on other parts, particularly the consistency of |
5c00f3e
to
8d3cab5
Compare
@fons I would like to propose to merge this as is, and tweak the bits around garbage collection and/or the imperfect clean up of mirrors at a later stage. This PR is holding back the developments around Helm v3 - which I would like to focus on the rest of this week, and the current state of the PR is arguably already ten times better as what it was. We can work out the missing piece of the puzzle in an issue, as we both do not seem to have a direct answer to the question what the best way forward is for this given the triangular relationship of |
To make Helm v3 a first class citizen, it would be better to mimic the `--atomic` behaviour from Helm v3 in the v2 client code, so that the release is removed automagically if the installation fails. This is however outside the scope of the PR this commit is part of.
The previous metric kept track of the time it would take to perform a Helm action, and some other actions around the synchronization of the `HelmRelease` resource to the cluster, but would not give a real insight in the total amount of time it would take to process a `HelmRelease` resource. This commit slightly tweaks the metric, so that it now measures the total amount of time it takes to synchronize a single `HelmRelease` resource to the cluster, and drops labels that due to this change have become irrelevant.
* remove obsolete `runtime.HandleCrash()` which was still included because of historical reasons * remove unnecessary mutex initialization * flatten return into something more Golang idiomatic
Plus various alignments around naming things.
If the atomic option is set during upgrades, Helm v3 will automatically rollback the release if it fails, which is not something we are after as this can be dangerous for e.g. charts that make use of `StatefulSet` resources. During installation however we _do_ want to use this flag, as this automatically removes a failed release for us, so that we do not have to perform or implement this logic ourselves.
Plus remove the explicit structure and instead return the `*git.Export` and HEAD reference string explicitly.
8d3cab5
to
d890b9d
Compare
Sounds good! Can you create a ticket for it? |
This commit brings the leakage of mirrors close to zero, as the mirroring will be stopped if there are no references to it from `HelmRelease` resources on the first signal received.
d890b9d
to
13a2e77
Compare
This PR decouples the synchronization of charts from git sources from the synchronization of
HelmRelease
resources to Helm releases and/or cluster resources.The synchronization of charts from Git sources has been rewritten so that we only do bookkeeping of git references for
HelmRelease
resources, but no longer maintain a working directory, this copy is instead made on request based on the references we have in our books at that moment.The release synchronization is moved to the
release
package, and has been rewritten so that implementers no longer have to decide what actions they want to perform, they can simply callSync
(install or upgrade on creation and/or update ofHelmRelease
resource) orUninstall
(uninstall on delete ofHelmRelease
resource).Fixes #98