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

fix(rollout-restart): adding field manager vault-secrets-operator to the restartAt annotation #1016

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BradErz
Copy link

@BradErz BradErz commented Feb 20, 2025

Should fix #921

Copy link

hashicorp-cla-app bot commented Feb 20, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@benashz benashz self-assigned this Feb 20, 2025
Copy link
Collaborator

@benashz benashz left a comment

Choose a reason for hiding this comment

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

This PR is looking good. I made an initial pass at it.

We will have to do a bit more testing before we can merge it, however.

case *appsv1.DaemonSet:
restartAt = o.Spec.Template.ObjectMeta.Annotations[AnnotationRestartedAt]
assertFieldManagerSet(t, obj, FieldManagerName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For completeness, I wonder if we should assert that the field manager was not added in the ArgoRollout case below?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the initial pass @benashz. Actually i discovered the test itself is not testing anything regarding the field manager. Because its passed in as an option to the client.Patch function.

Im not super familiar with the kubernetes client; it seems to be a fake implementation of the actual Kubernetes client. Do you have an example of how to inspect the request potentially to make sure the options are really added to the request? I guess in other apps i would use a mock of the client and expect

As for the test for making sure its not applied to the argo rollout, makes complete sense. Will do it when i figure out how to actually inspect the options ahaha.

Copy link
Author

Choose a reason for hiding this comment

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

I think i found an example using the interceptor functions. Will be able to look at implementing in the morning.

Is this kind of what you would expect?
https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/fieldowner_test.go#L78

default:
return fmt.Errorf("unsupported type %T for rollout-restart patching", t)
}

return client.Patch(ctx, obj, patch, patchOptions...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Previously, we were returning from each case. I am not opposed to this refactoring but we should guard against a nil patch here.

@@ -185,3 +188,14 @@ func assertPatchedRolloutRestartObj(t *testing.T, ctx context.Context, obj ctrlc
"restartAt should be after beforeRolloutRestart",
attr, restartAtTime, "beforeRolloutRestart", beforeRolloutRestart)
}

func assertFieldManagerSet(t *testing.T, obj ctrlclient.Object, manager string) {
found := false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
found := false
t.Helper()
found := false

@benashz benashz added this to the v0.10.0 milestone Feb 20, 2025
@BradErz
Copy link
Author

BradErz commented Feb 21, 2025

After double-checking the installation of VSO in our development environment (0.7.1). It seems it's already adding the FieldManager for the restartedAt annotation.

kubectl get deployment -n deseb --show-managed-fields -o json my-test-app | jq '.metadata.managedFields[] | select(.manager == "vault-secrets-operator")'
{
  "apiVersion": "apps/v1",
  "fieldsType": "FieldsV1",
  "fieldsV1": {
    "f:spec": {
      "f:template": {
        "f:metadata": {
          "f:annotations": {
            ".": {},
            "f:vso.secrets.hashicorp.com/restartedAt": {}
          }
        }
      }
    }
  },
  "manager": "vault-secrets-operator",
  "operation": "Update",
  "time": "2025-02-21T11:47:17Z"
}

Would you be able to double-check on your side @benashz if you already see the field, too? From my limited experience with the controller-runtime client, I thought the only way to add that was using the thectrlclient.FieldOwner(FieldManagerName) like I did in this PR or using the wrapper client client = ctrlclient.WithFieldOwner(client, FieldManagerName). But maybe it's simply added automatically somewhere in the controller-runtime initialisation.

So potentially, this PR this can just be closed alongside with #921.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rollouts trigger a double rollout for Flux managed workloads
2 participants