-
Notifications
You must be signed in to change notification settings - Fork 187
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
Detect changes/drift through a filtered diff of the apply #379
Conversation
We need a test that proves that we ignore objects that are changed only due to the checksum annotation. We also need to test diff failures, for example a namespace and configmap will error out on create, but will succeed on update. |
Get ~ I will add it now~ |
I think that as a future optimization it would also be an idea to create some type of wrapper around the working directory and/or commands we run so that we can omit the |
Signed-off-by: Jane Liu L <jane.l.liu@ericsson.com>
7c53b7d
to
ab3f40f
Compare
controllers/utils.go
Outdated
|
||
func containsChangeInSlice(tmpslice []string) bool { | ||
for _, s := range tmpslice { | ||
if strings.HasPrefix(s, "+ kustomize.toolkit.fluxcd.io/checksum:") || strings.HasPrefix(s, "- kustomize.toolkit.fluxcd.io/checksum:") || strings.HasPrefix(s, "--- /tmp") || strings.HasPrefix(s, "+++ /tmp") { |
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.
Please declare a var above like checksumAnnotation := fmt.Sprintf("%s/checksum", kustomizev1.GroupVersion.Group)
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.
Fix done
Some things to note about this PR:
|
return "", fmt.Errorf("apply failed: %s", applyErr) | ||
} | ||
|
||
resources := parseApplyOutput(output) | ||
log.Info( |
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.
We shouldn't log that we applied something on the cluster if we didn't, please move the log below inside else if differr.ExitCode() == 1
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.
Fix done
// Kubectl or diff failed with an error. | ||
if differr, ok := err.(*exec.ExitError); ok { | ||
if differr.ExitCode() > 1 { | ||
log.Info("Kubectl or diff failed with an error, will execute apply soon") |
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.
Make this a debug log please.
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.
Fix done~
} else if differr.ExitCode() == 1 { | ||
resources = parseDiffOutput(diffoutput) | ||
// Since we found difference in "diff" command, so we need to execute apply | ||
log.Info("Differences found, will execute apply soon") |
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.
Make this a debug log please.
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.
Fix done
One unfortunate outcome of skipping the apply when the diff returns no changes is that enabling pruning will not be possible, as the the annotations will never be added. |
8b9d7bf
to
5b7d918
Compare
…cksum annotation and test diff failures Signed-off-by: Jane Liu L <jane.l.liu@ericsson.com>
Any update for this PR? Should I still keep this PR or not? @stefanprodan |
👋 We have not forgotten about this PR, but are currently in the process of a bigger refactor which will drastically change the structure of all controller's reconcilers (see fluxcd/flux2#1601 for details), and improve the test coverage of the individual operations a controller performs. Given one of the goals of this PR is to hypothetically improve performance, we think it is better for the refactor to land first, so that we are properly able to benchmark your proposal against the current way the controller does things. Well aware this may be a bummer to you, and I am really sorry about that. 🌻 |
Close this PR since already have stefanprodan/kustomizer#17 to cove |
This PR including below contents:
Detail could be check on: #352