How argoproj-labs/argocd-rbac-operator works
Project type and purpose
• This is a Kubernetes Operator (an open-source tool) written in Go, built with controller-runtime.
• It defines two Custom Resource Definitions (CRDs): ArgoCDRole and ArgoCDRoleBinding.
• Purpose: watch those CRs, generate an RBAC policy string, and patch it into the Argo CD RBAC ConfigMap.
File structure
• Top-level “cmd/main.go”: entry point that starts the controller-runtime manager.
• “api/v1alpha1”: Go types for CRDs, plus generated deepcopy code.
• “internal/controller”: Reconciler implementations for ArgoCDRole and ArgoCDRoleBinding.
• “config/…”: Kustomize manifests for CRDs, RBAC, manager deployment, metrics, samples.
• “helm/argocd-rbac-operator”: Helm chart to package and install the operator.
• “test/e2e”: End-to-end tests for the operator.
• Build/CI: Dockerfile, Makefile, GitHub workflows, golangci-lint.
Key insights from README
• The operator runs a control loop: takes CR instances as source of truth, converts to policy.csv lines, patches the Argo CD ConfigMap.
• Supports installation via Kustomize or Helm.
• Default namespace for Argo CD is configurable; single-instance only today.
Main components and how to represent them
a. Custom Resources (ArgoCDRole, ArgoCDRoleBinding)
b. Kubernetes API Server
c. Operator Manager Pod
• Internal sub-components:
• controller-runtime Manager
• Scheme registration (api/v1alpha1)
• Reconcilers (ArgocdRoleReconciler, ArgocdRoleBindingReconciler)
• Common logic (internal/controller/common)
• Control loops: watch events → enqueue reconcile → business logic.
d. Argo CD RBAC ConfigMap (argocd/argocd-rbac-cm)
• Operator patches this ConfigMap.
e. Argo CD Server
• Reads the ConfigMap to enforce policies.
f. Supporting tools
• Kustomize manifests and Helm chart for packaging/deployment.
• CI pipelines that build/test/publish the chart.
Relationships and interactions
• CR YAML → Kubernetes API → Operator watches → Reconciler generates policy CSV → Kubernetes API → Operator PATCHes ConfigMap → Argo CD server picks up new policy.
• Deployment flow: Helm/Kustomize → create CRDs, RBAC, ServiceAccount, Manager Deployment → Operator Pod.
• Test flow: test/e2e uses kubectl to apply samples → validates resulting ConfigMap.
Architectural patterns and design principles
• Kubernetes Operator pattern (reconciliation loop).
• Separation of concerns: API definitions (api/), controller logic (internal/controller/), configuration (config/, helm/).
• idempotent patches: always reconcile to desired state.
• Use of controller-runtime framework for metrics, leader election, health probes.
Technologies, frameworks, libraries
• Go (go.mod), controller-runtime, client-go.
• Kustomize (config/).
• Helm (helm/argocd-rbac-operator).
• GitHub Actions for CI, golangci-lint.
Detailed component breakdown
• CRD Definitions (api/v1alpha1).
• Manager Deployment (config/manager/manager.yaml).
• RBAC and ServiceAccount (config/rbac).
• Reconcilers (internal/controller/argocdrole_controller.go, argocdrolebinding_controller.go).
• Common utility code (internal/controller/common).
• Generated deepcopy code (zz_generated.deepcopy.go).
• Sample YAML (config/samples).
• End-to-end tests (test/e2e).
• Versioning (version/version.go).
• Helm chart structure (helm/argocd-rbac-operator/templates).