Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Detect changes made to git source in HelmRelease
Browse files Browse the repository at this point in the history
Before this change changes made to the git chart source in a
`HelmRelease` did go unnoticed. Now, in case the URL or ref in the
`HelmRelease` changes, the clone is removed so a new one can be made
that matches the updated URL and ref.

As a bonus, in case a `HelmRelease` is removed, the clone will now be
removed too.
  • Loading branch information
hiddeco committed Apr 4, 2019
1 parent 4fa5fd4 commit c485ca5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion integrations/helm/chartsync/chartsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (c Config) WithDefaults() Config {
// revision), so we can keep track of when it needs to be updated.
type clone struct {
export *git.Export
remote string
ref string
head string
}

Expand Down Expand Up @@ -230,7 +232,7 @@ func (chs *ChartChangeSync) Run(stopCh <-chan struct{}, errc chan error, wg *syn
chs.logger.Log("warning", "could not clone from mirror while checking for changes", "repo", repoURL, "ref", ref, "err", err)
continue
}
newCloneForChart := clone{head: refHead, export: newClone}
newCloneForChart := clone{remote: repoURL, ref: ref, head: refHead, export: newClone}
chs.clonesMu.Lock()
chs.clones[releaseName] = newCloneForChart
chs.clonesMu.Unlock()
Expand Down Expand Up @@ -305,6 +307,17 @@ func (chs *ChartChangeSync) reconcileReleaseDef(fhr fluxv1beta1.HelmRelease) {
chs.clonesMu.Lock()
defer chs.clonesMu.Unlock()
chartClone, ok := chs.clones[releaseName]
// Validate the clone we have for the release is the same as
// is being referenced in the chart source.
if ok {
ok = chartClone.remote == chartSource.GitURL && chartClone.ref == chartSource.RefOrDefault()
if !ok {
if chartClone.export != nil {
chartClone.export.Clean()
}
delete(chs.clones, releaseName)
}
}
// FIXME(michael): if it's not cloned, and it's not going to
// be, we might not want to wait around until the next tick
// before reporting what's wrong with it. But if we just use
Expand Down Expand Up @@ -409,6 +422,17 @@ func (chs *ChartChangeSync) DeleteRelease(fhr fluxv1beta1.HelmRelease) {
if err != nil {
chs.logger.Log("warning", "Chart release not deleted", "release", name, "error", err)
}

// Remove the clone we may have for this HelmRelease
chs.clonesMu.Lock()
cloneForChart, ok := chs.clones[name]
if ok {
if cloneForChart.export != nil {
cloneForChart.export.Clean()
}
delete(chs.clones, name)
}
chs.clonesMu.Unlock()
}

// SyncMirrors instructs all mirrors to refresh from their upstream.
Expand Down

0 comments on commit c485ca5

Please sign in to comment.