-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add default ArgoCD label to auto created namespaces #6215
Comments
Hi! I'd be interested in taking a shot at this |
Hey @Tpx01 do you mind sharing some use cases where argo-cd creates its own namespaces? Might help with testing etc |
Sure thing! One of the easiest things to do is use the helm example: https://github.com/argoproj/argocd-example-apps/tree/master/helm-guestbook Next, when creating the application you can enable the checkbox in ArgoCD (upon creation of the application) to auto-create namespaces as depicted in the printscreen. By enabling this checkbox ✅ the routine/go-code, responsible for the creation of namespaces, will be called. The namespace that will be created is the same as referenced in the destination namespace of your newly Application CRD. Does this help? |
Sure does, thanks! |
This was discussed in today's contributors meeting. Some points:
|
Having the ability to add labels/annotations to namespaces created with createNamespace is something we're definitely looking for 🙏 - currently running into some issues with this because we need to add labels to namespaces created implicitly with createNamespace. |
In our App of Apps, Multi-Cluster model, where we use namespaces to segregate our application stacks into dev|stag|prod environments, we currently are just adding another App that only creates the namespace with istio-injection labels, which is our use case. This solution clutters the Argo UI and isn't very DRY, but works. The multicluster part makes the App required, because it's the only way we can control namespaces being deployed into remote clusters along with our selection of applications that define our application stack. This feature would be a great way to simplify what is otherwise a very automated, easy to use setup for creating ephemeral application environments (Thanks ArgoCD). If it helps to bring this feature to life, I would be more than happy to describe this use case in more detail, but we too would find it very useful. |
+1 Completely agree! Special if we are working with Istio, for example. |
I'm also looking ad labelled namespaces for NetworkPolicies. |
We too are looking for labelled namespaces. It is required to enable automatic pod readiness gates for AWS LoadBalancer Controller - https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.1/deploy/pod_readiness_gate/. |
Another use case for namespace labels : Pod Security Standards. apiVersion: v1
kind: Namespace
metadata:
name: ns-created-by-argocd
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/audit: restricted This feature replaces PodSecurityPolicies (deprecated) and requires namespace labels to be set |
This would also help assigning namespaces to projects in rancher which uses annotations # Create Namespace
apiVersion: v1
kind: Namespace
metadata:
name: <namespace>
annotations:
field.cattle.io/projectId: <project-id> So a way to connect argocd projects to rancher projects without managing them separately would be very helpful |
In our environment, we use multiple argocd applications inside the same namespace and we also need custom labels to be attached on namespaces. However, I think that adding labels together with namespace auto-creation could cause significant headaches in edge cases:
And different combinations of all the above. At the moment, I tend to think that if we need specific labels - it is better to track them as a separate namespace object with a separate lifecycle from the Application itself. |
Hello @v1r7u . Good questions. But some use cases look weird, specific, or complicated to me.
Simple answer : if one of the has the
If you have 1 App per namespace, this should not happen. If 2 Apps deploy to the same namespace with different namespace labels, then merge. If namespace labels conflict (same label with different values), then there will be a synchronization loop, and the user will need to find out the conflicting label, and fix it.
Then change/delete the namespace labels when next sync, as expected. |
Hello, @ledroide! Most of our problems will arise when we will need to understand how the namespace was created. We have multiple relatively big repositories that are used and maintained by several independent teams. And all the time we have several Applications deployed to the same namespace. With the proposed model we increase the cognitive load on a human. I might have several Applications deployed to the same namespace, but each of these Applications might have different namespace-related parameters: some say I believe, that impact of this proposal could be controlled by raising correct engineering culture: contributing guides, PR reviews and validation, knowledge-sharing, etc. But I think the best way to avoid issues is to limit ways how you might end up in a trouble. As an example, you can constantly educate your users to set resources requests/limits, but in my opinion, it's better to accompany the guide with a validation webhook that forbids creating pods without resources. The same with this proposal: we might write a guide on how to use |
@v1r7u : There will always exist tricky use cases like yours. It should not prevent however from offering simple solutions that satisfy most use cases. About managing resources.requests/limits, the solution is to set Limit Ranges for your pods in the namespace, combined with Resource Quotas |
This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
* namespace labels Signed-off-by: pashavictorovich <pavel@codefresh.io> * create namespace should support annotations Signed-off-by: pashavictorovich <pavel@codefresh.io> * handle also modification hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * regenerate entity on modify hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * manifests Signed-off-by: pashavictorovich <pavel@codefresh.io> * feat: enable metadata to be set on namespaces This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: don't always track namespaces For now, only allow namespaces managed with `managedNamespaceMetadata` to have tracking set by Argo. Ideally we'd like new namespaces to also be tracked by Argo, but there's currently an issue with a failing integration test. Also wrap error message if setting the app instance errors on the namespace. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: always return true with `hasManagedMetadata` If `hasManagedMetadata` is set, `true` should always be returned. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * docs: add clarifying docs on resource tracking Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * style: pr tweaks Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: re-add label unsetting Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * Update gitops-engine to current master Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: pashavictorovich <pavel@codefresh.io> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>
* namespace labels Signed-off-by: pashavictorovich <pavel@codefresh.io> * create namespace should support annotations Signed-off-by: pashavictorovich <pavel@codefresh.io> * handle also modification hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * regenerate entity on modify hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * manifests Signed-off-by: pashavictorovich <pavel@codefresh.io> * feat: enable metadata to be set on namespaces This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: don't always track namespaces For now, only allow namespaces managed with `managedNamespaceMetadata` to have tracking set by Argo. Ideally we'd like new namespaces to also be tracked by Argo, but there's currently an issue with a failing integration test. Also wrap error message if setting the app instance errors on the namespace. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: always return true with `hasManagedMetadata` If `hasManagedMetadata` is set, `true` should always be returned. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * docs: add clarifying docs on resource tracking Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * style: pr tweaks Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: re-add label unsetting Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * Update gitops-engine to current master Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: pashavictorovich <pavel@codefresh.io> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: emirot <emirot.nolan@gmail.com>
Summary
Currently there is no way to see which namespaces were automatically created by ArgoCD. Goal is to add a default label like
argocd.argoproj.io/namespace: production
.Motivation
There are a couple of reasons I can honesyly think of:
Proposal
Add a default label like
argocd.argoproj.io/namespace: production
whereproduction
here would be the actual name of namespace off course.The text was updated successfully, but these errors were encountered: