Skip to content
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

[Net-5510][Net-5455]: CRD controller should only patch the finalizer in the metadata of a CRD, rather than the whole object #3362

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

ndhanushkodi
Copy link
Contributor

@ndhanushkodi ndhanushkodi commented Dec 12, 2023

Changes proposed in this PR

Issue: ArgoCD will flap when configured with replace mode, which causes zero values to get defaulted and the applied config to differ from the state in K8s.

This is how the ArgoCD flapping problem happens:

  1. Argo triggers a replace
  2. A replace operation will remove all finalizers, including the one that we add to all config entries in the config entry controller
  3. This triggers our config entry controller to run a reconcile to add the finalizer
  4. When our controller adds the finalizer, it updates the whole object, causing the zero values to get defaulted. (json omit empty does not kick in because the object is not being serialized/deserialized like it does when you first apply the config).

This PR:

  • Only patches finalizers in the metadata of the CRD, rather than updating the entire entry, which had caused 0 values to be defaulted when using kubectl with replace.

Added @hashi-derek as a coauthor for his work on a finalizer patcher POC that I used for this.

How I've tested this PR

From this repo https://github.com/ndhanushkodi/argocd-example-apps/tree/nd/debug-consul-config/consul-counting

Lightweight test steps with kubectl replace:
kubectl apply -f counting.yaml -f dashboard.yaml -f splitter.yaml

Test steps with Argo CD:

  1. Followed these instructions to setup argoCD, pointing to the consul-counting directory, set up the sync in manual mode with the "replace" setting.
  2. Hit the sync button in argoCD a few times.
  3. Before this PR, there would always be a diff that showed up in argoCD when using the "replace" setting with the config, because of the omitted values getting a default 0 value set.
  4. After this PR, there is no longer a diff in argoCD.

How I expect reviewers to test this PR

👀

Checklist

RemoveFinalizersPatch(obj client.Object, finalizers ...string) *FinalizerPatch
// Patch patches the object. This should only ever be used for updating the metadata of an object, and not object
// spec or status. Updating the spec could have unintended consequences like defaulting zero values.
Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hashi-derek does this interface look ok? I tried keeping it as AddFinalizers and RemoveFinalizers, implemented by the FinalizerPatcher in finalizer_patch.go but if I do the patching within those functions, I'd need to pass in the k8s client to to the FinalizerPatcher. Keeping Patch as a function on the controller allows the FinalizerPatcher to not need another k8s client that's already being embedded in the controller implementations.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is fine. It's simpler than having the client passed in on each function call.

RemoveFinalizersPatch(obj client.Object, finalizers ...string) *FinalizerPatch
// Patch patches the object. This should only ever be used for updating the metadata of an object, and not object
// spec or status. Updating the spec could have unintended consequences like defaulting zero values.
Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is fine. It's simpler than having the client passed in on each function call.

@ndhanushkodi ndhanushkodi added the backport/1.3.x This release branch is no longer active. label Dec 18, 2023
@ndhanushkodi ndhanushkodi force-pushed the nd/net-5510-net-5455-patch-config-entries branch from 42e231c to 33effff Compare December 19, 2023 21:55
Co-authored-by: Derek Menteer <[email protected]>
@ndhanushkodi ndhanushkodi force-pushed the nd/net-5510-net-5455-patch-config-entries branch from 33effff to 962f047 Compare December 19, 2023 22:04
@ndhanushkodi ndhanushkodi changed the title Finalizer patcher [Net-5510][Net-5455]: CRD controller should only patch the finalizer in the metadata of a CRD, rather than the whole object Dec 19, 2023
@ndhanushkodi ndhanushkodi added backport/1.2.x This release branch is no longer active. backport/1.1.x Backport to release/1.1.x branch labels Dec 19, 2023
@ndhanushkodi ndhanushkodi merged commit 3047e16 into main Dec 20, 2023
@ndhanushkodi ndhanushkodi deleted the nd/net-5510-net-5455-patch-config-entries branch December 20, 2023 01:12
ndhanushkodi added a commit that referenced this pull request Dec 20, 2023
…in the metadata of a CRD, rather than the whole object (#3362)

Finalizer patcher

Co-authored-by: Derek Menteer <[email protected]>
ndhanushkodi added a commit that referenced this pull request Dec 20, 2023
…in the metadata of a CRD, rather than the whole object (#3362)

Finalizer patcher

Co-authored-by: Derek Menteer <[email protected]>
ndhanushkodi added a commit that referenced this pull request Dec 21, 2023
…atch the finalizer in the metadata of a CRD, rather than the whole object into release/1.2.x (#3414)

* [Net-5510][Net-5455]: CRD controller should only patch the finalizer in the metadata of a CRD, rather than the whole object (#3362)

Finalizer patcher

Co-authored-by: Derek Menteer <[email protected]>
ndhanushkodi added a commit that referenced this pull request Dec 21, 2023
…atch the finalizer in the metadata of a CRD, rather than the whole object into release/1.1.x (#3415)

* [Net-5510][Net-5455]: CRD controller should only patch the finalizer in the metadata of a CRD, rather than the whole object (#3362)

Finalizer patcher

Co-authored-by: Derek Menteer <[email protected]>
sarahalsmiller pushed a commit that referenced this pull request Jan 5, 2024
…in the metadata of a CRD, rather than the whole object (#3362)

Finalizer patcher

Co-authored-by: Derek Menteer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.1.x Backport to release/1.1.x branch backport/1.2.x This release branch is no longer active. backport/1.3.x This release branch is no longer active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants