-
Notifications
You must be signed in to change notification settings - Fork 72
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
ImageUpdateAutomation in different namespace than ImagePolicy #85
Comments
I do think we should use make use of PS. This is my personal view, I think @squaremo would disagree. |
Can you explain why this is less than ideal? Are your sync definitions ( You may end up duplicating image repository credentials, if you're using imagePullSecrets for your deployments. On the other hand, this could be a convenience, if you want to define one set of credentials that can scan all image repos, but keep the credentials in "user" namespaces specific to those namespaces.
I am reconciled (ha) to cross-namespace refs, in light of the model proposed in fluxcd/flux2#582 which at least puts some restriction on them by default. But I don't think they are the right way to arrange things, if the automation can just go alongside the git repository object. |
Yes, I could have used a bit more words to explain my point, sorry about that :) From a functional perspective, I fully get what you mean. The problem for me is when you look at this from a Infrastructure as Code perspective. To give an example: In
To extend on the above example, this will be done in the This distance between defining two things that are related to Prometheus, is what I consider not ideal. Distance in code mostly results in problems, sooner or later :) I rather have things defined closely together, especially as they both have to reference the same image-name. I know how developers are .. they change 1 reference, forget to grep for another, and before you know it you have an But to put this in slightly different words: basically, I am pivoting the code around Prometheus, where I put Prometheus central and want everything related to it as closely as I can to it. You pivot around flux, where you put Flux central and want everything related to it as closely as you can :) I am not sure one is better than the other .. mostly just different :) |
I see -- thank you for taking the time to follow up here, it's really helpful to get people's thought-through perspectives. I'll attempt to paraphrase your position: a. you would like to define ImagePolicy for a workload alongside that workload I think that last is a good principle. I sometimes call this situation a "trapeze act" -- when two strings far apart have to meet, for the system to work correctly. In this case, it's the namespace of the policy and the namespace mentioned in the marker in the workload file. It is necessary to fully qualify the markers so that updates are unambiguous, so there will always be some element of trapeze act. Having the code close doesn't mean that the objects have to be co-located at runtime. It's b.) (and a reluctance to add another layer of kustomization), that entails the latter. For example, you could group together the workloads and give them a namespace all at once with one kustomization, then include the automation objects as well in a kustomization that doesn't patch the namespace. There are other arguments that don't depend on the quirks of kustomize though: perhaps you want automation to be accessible to users, so they can define their own policies, but not the git repository (or the secret that the git repository refers to). The easiest way to arrange that is to put the git repository and its secret in another namespace -- but then how do you use it from the automation? There's alternatives to the current design that are less drastic. What if automations could give the namespace in which they operated, for example. Then you would house the policies with the workloads, and the automation with the git repository. That might bring up other dangers of course, so would need plenty of thinking through. |
I did consider this solution; the problem is, we use namespace to have different identical copies of the same thing running in the same cluster (for example, we have Traefik running twice in the cluster, ones for traffic on 1 VLAN, once for traffic of another VLAN; they are both created from exactly the same base Kustomize template). So this approach means you need two overlays to make that happen, which turns out to works very clumsy. But yeah, it is a possibility for sure :) Honestly, it feels like we are more battling Kustomize here than
Honestly, I initially assumed it worked like this :) I assumed it worked something like a Prometheus controller, that uses the annotation tags over all (defined) namespaces to find what to scrape. Initially I assumed I did something wrong and I wasn't passing along the After some more thinking about this, and something that might help you out understanding where I am coming from: Anyway, thank you for thinking along with me, and being interested in my use-case; that is really much appreciated :) And I fully understand (and support) your stance on not allowing cross-namespace references without good (security) restrictions in place :) |
I'm coming from a somewhat similar situation. I'd like to keep update-stuff (i.e. ImageRepository+ImagePolicy in same ns as workload to keep them logically. Flux/sourcecontroller would |
I encounter the same need here. We have a repository describing all our infrastructure, call it In I provide the tool for GitOps in my namespace, The ownership is defined by namespace, and in Git, by folder. We don't want to create objects in a git folder into another namespace in Kubernetes. We have a tool that check that, we have CODEOWNERS of GitHub that requests reviews for appropriate people, etc. Also, I don't want to replicate a GitRepository (with ssh-credentials) in each namespace. With In the |
I have encountered the same problem and wondering if it would perhaps be a good idea to have a scanning namespace option for That way all individual payloads will continue to live in their own namespaces with everything required for it, but one |
I've been preparing a recommendation for image API v1beta1, and as part of thinking that through, I took the solutions proposed above and tried to match them with the requirements people have expressed: Let the gitRepositoryRef (/sourceRef) refer to other namespaces This has been the solution for similar inconveniences in other GOTK APIs. Its main downside is that it breaks namespacing. In effect anyone would be able to run automation on any git repository defined in the cluster (provided you know about it). There is less danger than it might seem, since policy markers are namespaced. However, anything that sidesteps namespacing should be very carefully considered, and while automation does not account for RBAC, doubly so. This is mitigated by the proposal in fluxcd/flux2#582, which at least makes cross-namespace references subject to RBAC control (assuming impersonation were extended to automation objects).
Give a target namespace in the image automation object This is a tempting proposal because it makes it possible to put the automation object alongside the git repository (and secret), while keeping policy objects next to the workloads. The justification is this: if you can create an image automation object in the same namespace as the git repository, you have demonstrated that you have permission to access that git repository. This still triggers the "cross-namespace" concern as above, though slightly differently: since you are targeting a namespace, it is like granting a capability that is yours to give, rather than claiming a capability.
|
I think some clarification on the second solution of @squaremo "Give a target namespace in the image automation object" is required. I have explained my current problem in fluxcd/flux2#1017 (reply in thread). I think for the With the path feature of the image automation it should be easy to restrict image automation based on repository structures instead of namespaces. So the Image automation controller would lookup This way also the error handling can be improved if the I maintain a fairly simple cluster with many namespaces and it would be unnecessary work to create multiple |
@stefanprodan excuse me, do you have any best practices how to do it all? Thanks! |
We stumbled upon this issue today as well. We have the following layout:
Each app*.yaml contains a bunch of different resources and we use When introducing After some experimentation, we found out that the following in kustomization.yaml does what we want:
patchesJson6902:
- target:
kind: .*
name: .*
patch: |-
- op: replace
path: /metadata/namespace
value: apps
- target:
kind: ImageRepository
name: .*
patch: |-
- op: replace
path: /metadata/namespace
value: flux-system
- target:
kind: ImagePolicy
name: .*
patch: |-
- op: replace
path: /metadata/namespace
value: flux-system We tried to do the same thing in patches as well, but this only worked with patchesJson6902 |
@espizo looks like it's solution, but feels like a crutch 😄 |
Came across this issue today as well. For me, it was natural to put the image repository and policy objects next to the workloads, because: a) image pull secrets are namespace scoped We are still thinking about what tenancy model we should choose (repo per tenant, repo per app), but whatever we end up with there will be multiple policies (eg. different policies for different app environments or different applications), potentially in separate namespaces, but applying to the same repository. This leads to either having to add app/env specific automations along with the policies OR having to move policies closer to the automation (but that crosses namespace and repo boundaries). None of those options seem ideal to me. As far as I can tell, automations are closer to repositories, while policies are closer to workloads. |
We do support cross-namespace refs from ImagePolicies to ImageRepositories, so you can place the ImageRepository where the workloads are to reuse the image pull secret. The ImagePolicies and ImageUpdateAutomation can be placed where the GitRepository is, to reuse the SSH secret. Docs here: https://fluxcd.io/docs/components/image/imagerepositories/#allow-cross-namespace-references |
@stefanprodan That's what I figured and did eventually, but apparently intuition tells people to pair policies with image repositories, not automations (maybe because there is an actual reference in policies to image repositories or because cross-namespace references are relatively rare in the Kubernetes world). Maybe this is just a documentation issue, not an architectural one. |
@sagikazarmark I got the same intuition as you and I think a lot of people do, yes. |
Further thinking about this:
This isn't necessarily enough or practical. Let's say I have a main git repository (managed by an ops team) for flux-system and centrally managed stuff and separate repos for each team. Team A creates an image repository in their git repo and do what? Send a PR to the main git repo for the policy? The above solution works great as long as there is a single repo or everything is managed by the same team. As soon as there are multiple teams involved, resource placement matters even more. |
Flux multi-tenancy implies that the tenant’s GitRepository is defined in their namespace, so all image update objects will be in the tenant’s namespace. Also for multi-tenancy, cross-refs must be disable to ensure isolation, docs here: https://github.com/fluxcd/flux2-multi-tenancy |
What about if the tenant has several namespaces (test, staging, production)? Sets of GitRepository-ImageUpdateAutomation-ImageRepository-ImagePolicy shall be defined for each single one? |
Yes, that's the premise here. |
We have a similar situation where we isolate tenants to their own namespace and do not allow cross namespace refs. If we give them access to their GitRepository (which we currently have in flux-system), then the tenant would be able to basically reach across to other folders (i.e. namespaces). |
Each tenant should have their own Git repository. Case closed. |
I have the following setup:
Flux2 is running in namespace
flux-system
.Prometheus is running in namespace
monitoring
.I am trying to get image automation to work with as little duplication as possible.
So, I defined
ImagePolicy
(andImageRepository
) close to Prometheus. This means, because I use kustomize, that it is forced in themonitoring
namespace.Next, I defined
ImageUpdateAutomation
in theflux-system
namespace, as it wants access to theGitRepository
which is already defined there.Now my problem: this setup doesn't work when I try
# {"$imagepolicy": "monitoring:prometheus:tag"}
.From what I understand, and what does work:
ImagePolicy
needs to be in theflux-system
namespace (which is far from ideal from a Infrastructure-as-Code point of view)ImageUpdateAutomation
intomonitoring
namespace. I don't really have an issue with that, except for the minor code duplication, but thegitRepositoryRef
doesn't acceptnamespace
. That would mean I also have to duplicateGitRepository
, which would be very prune to errors.Now I am not sure that what I am trying here is how this is meant to be used, or that I am overlooking some setting somewhere. So if you have any pointers for me how I should be doing this, or if there is an option I can use to make this work, that would be very welcome :)
Thank you!
The text was updated successfully, but these errors were encountered: