Set last-applied-label during create or replace operation atomically #972
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaces #971
For resources that are BOTH
create
and/orreplace
krane
currently first issues thecreate/replace
command, then subsequently callsapply
. This is done to ensure ongoing cleanup of resources like DB-Migrate pods that would otherwise just hang around.Unfortunately, this subsequent
apply
breaks if a mutating admission controller modified an otherwise immutable field. The document presented bykrane
now conflicts with the API server and the deploy fails.Thankfully,
kubectl
supports adding thelast-applied-configuration
annotation (which is the signal used by k8s to marks resources as prunable). Using the exact same logic we were using to add individual resources to theapplyables
list, we can just conditionally set the--save-config
flag onkubectl create/replace
EDIT: I had to bend over backwards a bit further than I first thought to get this working. The intent with this behaviour is to clean up
created/replaced
resources from the LAST deployment that has occurred. After fighting trying to get no-op server-side applies to work (the documentation does not match the behaviour), I've been forced to conditionally setlast-applied-configuration
annotations on created resources in theDeploy all Resources
phase. This entails adding a conditional parameter for whether or not to annotate individual resources, since this code path is used by both thePredeploy Priority Resources
andDeploy all Resources
stepsThis does introduce a subtle failure mode. If the
apply_all
succeeds butannotate_individuals
fails, the individual resources will never be tagged and thus not subject to pruning on the subsequent deploy.