Skip to content
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

Refactor garbage collection #210

Merged
merged 3 commits into from
Dec 16, 2020
Merged

Refactor garbage collection #210

merged 3 commits into from
Dec 16, 2020

Conversation

stefanprodan
Copy link
Member

@stefanprodan stefanprodan commented Dec 16, 2020

Delete stale objects if their checksum doesn't match the last applied revision. This accounts for controller restarts during reconciliation, previously, if GC was killed while running, stale objects would never be removed.

Pin controller-runtime to v0.6.3 (mitigation until we upgrade to v0.7.0), ref: #214, fix: #209

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
func (kgc *KustomizeGarbageCollector) matchingLabels(name, namespace, checksum string) client.MatchingLabels {
return gcLabels(name, namespace, checksum)
func (kgc *KustomizeGarbageCollector) isStale(obj unstructured.Unstructured) bool {
itemChecksum := obj.GetLabels()[fmt.Sprintf("%s/checksum", kustomizev1.GroupVersion.Group)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the fmt.Sprintf to a dedicated function as it is also used in the gcLabels function, or move the various label names to constants, and create something like:

const gcNameLabel = "name"

func gcLabelName(name string) string {
	return fmt.Sprintf("%s/%s", kustomizev1.GroupVersion.Group, name)
}

Avoid v0.6.4 bug where custom resources can't be converted to v1.ListOptions

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
@stefanprodan stefanprodan added the enhancement New feature or request label Dec 16, 2020
@stefanprodan stefanprodan merged commit 8be1e16 into main Dec 16, 2020
@stefanprodan stefanprodan deleted the gc-prune branch December 16, 2020 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GC seems to abandon objects
2 participants