feat(init): add init agent for the agent to only mutate labeled resources#4937
feat(init): add init agent for the agent to only mutate labeled resources#4937AustinAbro321 wants to merge 29 commits into
Conversation
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
✅ Deploy Preview for zarf-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
soltysh
left a comment
There was a problem hiding this comment.
Dropping the double umarshaling and the flag validating would be my two blockers. The rest is just nice to have, or can be addressed in followup (especially that context one).
| } | ||
|
|
||
| func getNamespaceLabels(ctx context.Context, c *cluster.Cluster, name string) (map[string]string, error) { | ||
| ns, err := c.Clientset.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{}) |
There was a problem hiding this comment.
Potential improvement, have you considered caching the labels here? For example up to a minute or so, the labels rarely change that fast, so 1min delay could buy us some time, and increase the throughput on subsequent requests.
There was a problem hiding this comment.
One thing we might be able to do if I understand the package correctly is to setup a shared informer which would cache the item in memory and automatically update it for us
| return nil | ||
| } | ||
|
|
||
| type mutationPolicyFlag state.MutationPolicy |
There was a problem hiding this comment.
Wouldn't just using a simple string flag and validating inside validateinitFlags be simpler than this?
There was a problem hiding this comment.
Yeah, I liked the idea of using the pflag construct, but I suppose it is more code, and adds a type to the help docs that users don't care about.
| mode state.MutationPolicy, | ||
| fn func(ctx context.Context, r *admission.AdmissionRequest, obj PT) (*operations.Result, error), | ||
| ) operations.AdmitFunc { | ||
| return func(r *admission.AdmissionRequest) (*operations.Result, error) { |
There was a problem hiding this comment.
It seems you're passing ctx twice here:
- when you're invoking
withMutationGuardwhich means you're getting the early context into this function - inside this function again to pass to
fn, that one is fine.
I think, the right way would be to pass per-request context, thus expanding the AdminFunc signature with context like so:
type AdmitFunc func(ctx context.Context, request *admission.AdmissionRequest) (*Result, error)
especially that you already wrap each execution, so you could guard each request separately.
Although the more I dig into it, it'll likely require a bigger rewrite, to ensure the admission handler from
properly passes a request-scope context.There was a problem hiding this comment.
I'd suggest to fix that as followup, or I can pick that up.
There was a problem hiding this comment.
Makes sense, I was able to write the complete fix, I'll submit a quick follow up after this PR is in
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Description
This introduces a new flag to init
--agent-mutation-policywith valuesallandlabeled. The default value isallbut we will likely change it tolabledin v1.0. New namespaces created by Zarf during package deploy are labeled withzarf.dev/agent: mutate, so resources are still automaticaly pointed to the zarf agent.Resource labels always take priority so if the resource has
zarf.dev/agent: mutateand the namespace haszarf.dev/agent: ignorethe resource will be mutated. If the resource haszarf.dev/agent: ignoreand the namespace haszarf.dev/agent: mutatethe resource will not be mutatedTo my surprise the podinfo-flux example works even when the agent is in labeled mode. The reason for this is that even though Zarf doesn't deploy any resources to the intended deploy namespace (the flux resources are deployed to
flux-system) themanifests.namespacefield is declared topodinfo-gitand so the mutate label is addedChecklist before merging