-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for flux plugin: clean up old charts from chart cache after repo update #4115 #5644
Changes from all commits
12d2b51
7b0a251
1d27a8b
40d4016
d5748d4
329ea25
ad2717c
0a9384b
a315f21
0ec7bee
536ed29
9c433fe
6bd5255
30036e1
9ae5311
285c621
a42ee29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,11 @@ func (c *ChartCache) SyncCharts(charts []models.Chart, downloadFn DownloadChartF | |
log.Warningf("Skipping chart [%s] due to empty version array", chart.ID) | ||
continue | ||
} else if len(chart.ChartVersions[0].URLs) == 0 { | ||
log.Warningf("Chart: [%s], version: [%s] has no URLs", chart.ID, chart.ChartVersions[0].Version) | ||
log.Warningf("Skipping chart [%s], version: [%s] has no URLs", chart.ID, chart.ChartVersions[0].Version) | ||
continue | ||
} else if chart.Repo == nil { | ||
// shouldn't happen | ||
log.Warningf("Skipping chart [%s] as it is not associated with any repo", chart.ID) | ||
continue | ||
} | ||
|
||
|
@@ -259,10 +263,9 @@ func (c *ChartCache) processNextWorkItem(workerName string) bool { | |
return true | ||
} | ||
|
||
func (c *ChartCache) DeleteChartsForRepo(repo *types.NamespacedName) error { | ||
log.Infof("+DeleteChartsForRepo(%s)", repo) | ||
defer log.Infof("-DeleteChartsForRepo(%s)", repo) | ||
|
||
// will clear out the cache of charts for a given repo except the charts specified by | ||
// keepThese argument, which may be nil. | ||
func (c *ChartCache) deleteChartsHelper(repo *types.NamespacedName, keepThese sets.String) error { | ||
// need to get a list of all charts/versions for this repo that are either: | ||
// a. already in the cache OR | ||
// b. being processed | ||
|
@@ -287,6 +290,7 @@ func (c *ChartCache) DeleteChartsForRepo(repo *types.NamespacedName) error { | |
if err != nil { | ||
return err | ||
} | ||
log.Infof("Redis [SCAN %d %s]: %d keys", cursor, match, len(keys)) | ||
for _, k := range keys { | ||
redisKeysToDelete.Insert(k) | ||
} | ||
|
@@ -308,7 +312,7 @@ func (c *ChartCache) DeleteChartsForRepo(repo *types.NamespacedName) error { | |
} | ||
} | ||
|
||
for k := range redisKeysToDelete { | ||
for k := range redisKeysToDelete.Difference(keepThese) { | ||
if namespace, chartID, chartVersion, err := c.fromKey(k); err != nil { | ||
log.Errorf("%+v", err) | ||
} else { | ||
|
@@ -329,6 +333,52 @@ func (c *ChartCache) DeleteChartsForRepo(repo *types.NamespacedName) error { | |
return nil | ||
} | ||
|
||
func (c *ChartCache) DeleteChartsForRepo(repo *types.NamespacedName) error { | ||
log.Infof("+DeleteChartsForRepo(%s)", repo) | ||
defer log.Infof("-DeleteChartsForRepo(%s)", repo) | ||
|
||
return c.deleteChartsHelper(repo, sets.String{}) | ||
} | ||
|
||
// this function is called when re-importing charts after an update to the repo, | ||
// so keepThese is actually populated from the new data, meaning that if the new | ||
// data no longer includes a certain version, it'll get purged here | ||
func (c *ChartCache) PurgeObsoleteChartVersions(keepThese []models.Chart) error { | ||
log.Infof("+PurgeObsoleteChartVersions()") | ||
defer log.Infof("-PurgeObsoleteChartVersions") | ||
|
||
repos := map[types.NamespacedName]sets.String{} | ||
for _, ch := range keepThese { | ||
if ch.Repo == nil { | ||
// shouldn't happen | ||
log.Warningf("Skipping chart [%s] as it is not associated with any repo", ch.ID) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should that be an error if this function is called with a chart with a nil repo? Or at least, logging the issue? Wondering why we'd not want to report that somehow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't ever happen, but you're right. Let me at least log it |
||
} | ||
n := types.NamespacedName{ | ||
Name: ch.Repo.Name, | ||
Namespace: ch.Repo.Namespace, | ||
} | ||
a, ok := repos[n] | ||
if a == nil || !ok { | ||
a = sets.String{} | ||
} | ||
for _, cv := range ch.ChartVersions { | ||
if key, err := c.KeyFor(ch.Repo.Namespace, ch.ID, cv.Version); err != nil { | ||
return err | ||
} else { | ||
repos[n] = a.Insert(key) | ||
} | ||
} | ||
} | ||
|
||
for repo, keep := range repos { | ||
if err := c.deleteChartsHelper(&repo, keep); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *ChartCache) OnResync() error { | ||
log.Infof("+OnResync(), queue: [%s], size: [%d]", c.queue.Name(), c.queue.Len()) | ||
c.resyncCond.L.Lock() | ||
|
@@ -620,7 +670,7 @@ func ChartCacheComputeValue(chartID, chartUrl, chartVersion string, downloadFn D | |
return nil, err | ||
} | ||
|
||
log.Infof("Successfully fetched details for chart: [%s], version: [%s], url: [%s], details: [%d] bytes", | ||
log.V(4).Infof("Successfully fetched details for chart: [%s], version: [%s], url: [%s], details: [%d] bytes", | ||
chartID, chartVersion, chartUrl, len(chartTgz)) | ||
|
||
cacheEntryValue := chartCacheEntryValue{ | ||
|
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.
Just reading the code below, I think
keepThese
is the slice of charts for which you're wanting to keep all versions? (as in, below, each chart is iterated with the redis key for each version added to the set of keys to keep for that repo, which is then passed askeep
todeleteChartsHelper
).I must be missing something here, because it looks like it only ever calls
deleteChartsHelper
with repos of charts that were in thekeepThese
slice? I expected to find a function that purges all other repositories, other than the ones you wanted to keep (maybe it does and I'm just mis-reading).EDIT: Oh - reading further down, I think I understand: this function is called when re-importing charts after an update to the repo, for example, so
keepThese
is actually populated from the new data, meaning that if the new data no longer includes a certain version, it'll get purged here. OK, I think I was confused initially because it wasn't clear to me thatkeepThese
was the new data that hadn't been synced yet. (?)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.
yes, you got it