-
Notifications
You must be signed in to change notification settings - Fork 181
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
Orphan fields after kubectl replacements #558
Comments
I couldn't reproduce this bug in on a cluster running Kubernetes version
But it was present in
I will continue to test with other versions |
My repro was on K8s
This must take place before the next Kustomization sync. If the Kustomization syncs first, after kubectl applies the change adding a rule for a host, and before the git change arrives through Kustomization controller, the repro will not be effective because the window for orphaning the resource has passed once the kubectl manager is replaced by Flux. (The Also, I don't think you should remove the There is a similar issue in any resource with optional fields. We discovered this issue through |
Hey @kingdonb , |
Thanks @somtochiama – is there any way you can point me at the branch where I can build this from? My test machines are arm64 linux now, so the single arch image gives me an exec format error. |
I was able to get It looks like you have done it, 🎉 I don't see the issue reproduced anymore on your rc @somtochiama Have a great weekend! |
I'm not sure whether my situation matches what this issue intended to address, but we've suffered a regression in how Flux cooperates with other managers. We have a manifest for a ConfigMap that looks like this: apiVersion: v1
kind: ConfigMap
metadata:
name: gotk-sync-overrides
namespace: flux-system
annotations:
kustomize.toolkit.fluxcd.io/prune: disabled Flux reconciles this manifest in a Kustomization named "flux-system." Using kubectl patch or even kubectl edit, we come along and change this ConfigMap, adding fields under a new top-level "data" field: kubectl --namespace=flux-system patch configmap gotk-sync-overrides --patch='
data:
APPS_GIT_REPOSITORY_TAG: flux/production' That yields a ConfgMap like the following, per kubectl --namespace=flux-system get configmap gotk-sync-overrides --show-managed-fields --output=yaml: apiVersion: v1
data:
APPS_GIT_REPOSITORY_TAG: flux/production
kind: ConfigMap
metadata:
annotations:
kustomize.toolkit.fluxcd.io/prune: disabled
creationTimestamp: "2021-07-19T20:22:38Z"
labels:
kustomize.toolkit.fluxcd.io/name: flux-system
kustomize.toolkit.fluxcd.io/namespace: flux-system
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
f:kustomize.toolkit.fluxcd.io/prune: {}
f:labels:
f:kustomize.toolkit.fluxcd.io/name: {}
f:kustomize.toolkit.fluxcd.io/namespace: {}
manager: kustomize-controller
operation: Apply
time: "2022-02-07T19:23:59Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
f:APPS_GIT_REPOSITORY_TAG: {}
manager: kubectl-patch
operation: Update
time: "2022-02-07T19:33:00Z"
name: gotk-sync-overrides
namespace: flux-system
resourceVersion: "1092750058"
selfLink: /api/v1/namespaces/flux-system/configmaps/gotk-sync-overrides
uid: f20404d5-1a69-4f35-8683-8b6581684a00 Shortly after we patch the ConfigMap, Flux now comes along and removes that top-level "data" field. It didn't used to do this before version 0.26.2. |
Thanks for the report @seh I tried the process that you described, and it clearly removes the new data field. I tried the same thing with a server-side apply instead of a patch, and I got the same results. I'm going back to the previous version just to confirm this is definitely a regression, but this looks like a regression to me. We have had a lot of edge cases to cover in order to resolve these issues patching, so that users can still remove optional sections which were present in manifests applied by older versions of Flux that pre-dated server side apply. Unfortunately I'm not surprised to hear that wasn't the final weird edge case. 😞 I think the maintainers will want to track this information in a separate issue. |
I see some effort to remove changes made by field managers named "kubectl" in kustomization-controller here. In my case in #558 (comment), the manager name was "kubectl-patch," so I think I'd be clear of that interference. [More reading ....] Oh, we use these names as a prefix, so "kubect" is indeed a prefix of "kubectl-patch." |
If I include the command-line flag |
We have to remove all fields added by other managers as objects managed by Flux shouldn’t be altered outside Git. Right now we only target |
This is change in behavior, but I don't know if it's a change in your intentions for how Flux should work. I thought that the recent move to using SSA was intended to allow Flux to work with other managers more easily and properly: namely, that Flux would enforce that what it reads from manifests gets applied (as Flux owns all the fields in the manifests), and that it would leave fields owned by other managers alone. Your proposal to require defining a tolerable set of other managers would accommodate known, popular managers like kube-controller-manager, but will require users to learn the manager names of and configure Flux to tolerate other controllers that they will use. I anticipate this is going to cause a support burden and frustrate users. That said, I respect your command of the project. I'd like to understand how to proceed here. Please entertain a few questions:
|
@seh I think you should decide on a manager name (other than The main challenge we are facing now, is being able to undo manual changes made with |
It's really a struggle to find the perfect solution, on one hand users expect for Flux to override and undo changes made outside Git, on the other hand, Flux needs to tolerate other controllers such as HPA or Flagger, so they can perform their function even if it means altering objects defined in Git. Given that Kubernetes records the manager name and the operation type ( |
I think that's a fine compromise for now. It's inconvenient to need to use the It sounds like we shouldn't count on "any field manager with a name that doesn't start with 'kubectl' is tolerated" being true for long, and should instead expect that we'll need to tell Flux which manager names (or name prefixes?) it should tolerate. |
I decided to remove the aforementioned ConfigMap from Flux's coverage, so that we create it imperatively when first bootstrapping Flux into our clusters (we have a shell program that arranges for this). This leaves us with the liability that someone might delete this ConfigMap accidentally, which will cause Flux to fail on its next reconciliation attempt. Have we ever considered—as I suggested earlier—making ConfigMaps and Secrets referenced for post-build substitution optional? |
@seh please open an issue for the optional substitutions. |
Please see #565. |
Fields that are removed from a manifest, then applied with kubectl, then applied by the controller end up without a manager and are left in spec.
How to reproduce
2 . Add a
host
and removetls
and apply it with kubectl:tls
field is left on the cluster instead of being removed:The text was updated successfully, but these errors were encountered: