Skip to content

Kubernetes operator to automatically manage namespaces for Argo CD applications

Notifications You must be signed in to change notification settings

topicusonderwijs/argocd-namespace-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

⚠️ OBSOLETE ⚠️

Argo CD Namespace Operator

The Argo CD namespace operator helps creating the namespace for an Argo CD Application CR.

Annotations on the Application CR allow defining labels and annotations for the Namespace CR. Special support is included for the Rancher field.cattle.io/projectId label and annotation to define a namespace as part of a Rancher project.

Examples

Define a label on the Namespace CR

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: cert-manager
  annotations:
    argocd-namespace.topicus.nl/label: "certmanager.k8s.io/disable-validation: true"
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: cert-manager
    server: https://kubernetes.default.svc
  ...

This Application CR automatically created the following namespace:

apiVersion: v1
kind: Namespace
metadata:
  name: cert-manager
  labels:
    certmanager.k8s.io/disable-validation: "true"

Combine with the Namespace Configuration Operator

The Namespace Configuration Operator uses a (label)selector to select namespaces to which to apply its configuration. These labels can be supplied with the Argo CD namespace operator from the Application CR. See the T-shirt sized quotas example of the Namespace Configuration Operator.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-large-project
  annotations:
    argocd-namespace.topicus.nl/label: "size: large"
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: large-project
    server: https://kubernetes.default.svc
  ...

Rancher integration

The field.cattle.io/projectId label and annotation binds a namespace to a Rancher project. The full Rancher project ID (including the cluster ID) can be supplied with the cattle.topicus.nl/projectId annotation.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-project
  annotations:
    cattle.topicus.nl/projectId: c-xxxxx:p-yyyyy
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: rancher-project-namespace
    server: https://kubernetes.default.svc
  ...

This creates the required Rancher label and annotation as follows:

apiVersion: v1
kind: Namespace
metadata:
  name: rancher-project-namespace
  annotations:
    field.cattle.io/projectId: c-xxxxx:p-yyyyy
  labels:
    field.cattle.io/projectId: p-yyyyy

Links

About

Kubernetes operator to automatically manage namespaces for Argo CD applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published