When setting the kustomize.toolkit.fluxcd.io/force: enabled label for statefulsets, flux will delete the statefulset if it detects an immutable field error. This will delete all the statefulset's pods as a result due to kubernetes garbage collection.
As a workaround, an admission webhook can mutate pods' metadata.ownerReferences to be empty during pod creation, but admission webhooks are risky: if they fail (service is down, or throwing unhandled exceptions) they block the creation of pods, and if set to be ignored upon failure then we would risk flux deleting a statefulset and its pods all at once.
I think that a proper solution would be to add support to set the propagationPolicy of the deleteOptions in the delete request that flux makes. This can be set for example through an annotation like kustomize.toolkit.fluxcd.io/propagationPolicy: orphan in the same resource that has kustomize.toolkit.fluxcd.io/force: enabled:
- if the label
kustomize.toolkit.fluxcd.io/force: enabled is set, then the annotation kustomize.toolkit.fluxcd.io/propagationPolicy is checked
- if the annotation
kustomize.toolkit.fluxcd.io/propagationPolicy does not exist, the default policy is used, which is background
- if the annotation
kustomize.toolkit.fluxcd.io/propagationPolicy is set to background, foreground or orphan then this value will be used in the delete request
- if the annotation
kustomize.toolkit.fluxcd.io/propagationPolicy is set to anything other than those values, the controller can throw an error during reconciliation dry-run.
what do you think about this feature?
When setting the
kustomize.toolkit.fluxcd.io/force: enabledlabel for statefulsets, flux will delete the statefulset if it detects an immutable field error. This will delete all the statefulset's pods as a result due to kubernetes garbage collection.As a workaround, an admission webhook can mutate pods'
metadata.ownerReferencesto be empty during pod creation, but admission webhooks are risky: if they fail (service is down, or throwing unhandled exceptions) they block the creation of pods, and if set to be ignored upon failure then we would risk flux deleting a statefulset and its pods all at once.I think that a proper solution would be to add support to set the
propagationPolicyof thedeleteOptionsin the delete request that flux makes. This can be set for example through an annotation likekustomize.toolkit.fluxcd.io/propagationPolicy: orphanin the same resource that haskustomize.toolkit.fluxcd.io/force: enabled:kustomize.toolkit.fluxcd.io/force: enabledis set, then the annotationkustomize.toolkit.fluxcd.io/propagationPolicyis checkedkustomize.toolkit.fluxcd.io/propagationPolicydoes not exist, the default policy is used, which isbackgroundkustomize.toolkit.fluxcd.io/propagationPolicyis set tobackground,foregroundororphanthen this value will be used in the delete requestkustomize.toolkit.fluxcd.io/propagationPolicyis set to anything other than those values, the controller can throw an error during reconciliation dry-run.what do you think about this feature?