Skip to content

Move the GC checksum from labels to annotations#362

Merged
stefanprodan merged 1 commit intofluxcd:mainfrom
JaneLiuL:main
Jun 14, 2021
Merged

Move the GC checksum from labels to annotations#362
stefanprodan merged 1 commit intofluxcd:mainfrom
JaneLiuL:main

Conversation

@JaneLiuL
Copy link
Copy Markdown
Contributor

@JaneLiuL JaneLiuL commented Jun 9, 2021

This PR moves the kustomize.toolkit.fluxcd.io/checksum from labels to annotations. This should fix any conflicts with 3rd party controllers like Stash (fix: #315) that are copying the labels from their custom resources to generated objects.

@JaneLiuL JaneLiuL changed the title detect changes base on diff and move checksum into annotation Draft: detect changes base on diff and move checksum into annotation Jun 9, 2021
Comment thread controllers/utils.go Outdated
Comment thread controllers/kustomization_gc.go
@stefanprodan
Copy link
Copy Markdown
Member

@JaneLiuL I found some serious issues with diff, for example, if a user adds namespaces and other objects in those namespaces, then the diff fails while the apply works. I see no way around this limitation but to detect diff failures, ignore them and switch back to the old way of detecting changes.

@JaneLiuL JaneLiuL changed the title Draft: detect changes base on diff and move checksum into annotation Move the GC checksum from labels to annotations Jun 11, 2021
Comment thread controllers/utils.go Outdated
// --- /tmp/LIVE-656588208/kustomize.toolkit.fluxcd.io.v1beta1.Kustomization.namespace.name 2021-06-07 12:58:20.738794982 +0200
// +++ /tmp/MERGED-532750671/kustomize.toolkit.fluxcd.io.v1beta1.Kustomization.namespace.name 2021-06-07 12:58:20.798795908 +0200
// @@ -0,0 +1,36 @@
func parseDiffOutput(in []byte) map[string]string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this as it's unrelated to this PR.

Comment thread controllers/kustomization_generator.go Outdated
"crypto/sha1"
"encoding/json"
"fmt"
"github.com/fluxcd/pkg/apis/kustomize"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to be added further down, the first import section is for Go std lib.

Comment thread controllers/kustomization_generator.go Outdated
}
}
if !exists {
//kus.Transformers = append(kus.Transformers, transformerFileName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove these commented lines.

Comment thread controllers/kustomization_controller.go Outdated
}
}

changeSet := ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change is unrelated to this PR please undo it.

Copy link
Copy Markdown
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

Comment thread controllers/kustomization_gc.go Outdated
return changeSet, true
}

// We can't drop the label check in this version.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please replace this with:

Check both labels and annotations for the checksum to preserve backwards compatibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fix done~

func (kg *KustomizeGenerator) generateLabelTransformer(checksum, dirPath string) error {
labels := selectorLabels(kg.kustomization.GetName(), kg.kustomization.GetNamespace())

// add checksum label only if GC is enabled
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has been lost, please restore it for the annotions

Comment thread controllers/kustomization_generator.go Outdated
return err
}

labelsFile := filepath.Join(dirPath, transformerAnnotationFileName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
labelsFile := filepath.Join(dirPath, transformerAnnotationFileName)
annotationsFile := filepath.Join(dirPath, transformerAnnotationFileName)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fix done~

Comment thread controllers/kustomization_generator.go Outdated
const (
transformerFileName = "kustomization-gc-labels.yaml"
transformerFileName = "kustomization-gc-labels.yaml"
transformerAnnotationFileName = "kustomization-annotation-labels.yaml"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
transformerAnnotationFileName = "kustomization-annotation-labels.yaml"
transformerAnnotationFileName = "kustomization-gc-annotations.yaml"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fix done~

Signed-off-by: Jane Liu L <jane.l.liu@ericsson.com>
Copy link
Copy Markdown
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @JaneLiuL 🌷

PS. I'll merge this and do a followup PR to update the GC documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kustomize Kustomize related issues and pull requests enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Garbage collection conflicts with Stash controller

2 participants