# argoproj-labs/argocd-rbac-operator architecture

> Architecture diagram of the GitHub repository argoproj-labs/argocd-rbac-operator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/argoproj-labs/argocd-rbac-operator
- Repository: https://github.com/argoproj-labs/argocd-rbac-operator

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Kubernetes Cluster
    subgraph "Kubernetes Cluster"
        direction TB
        CRDDefs["CRD Definitions (api/v1alpha1)"]:::k8s
        CRInstances["CR Instances (config/samples)"]:::k8s
        APIServer["Kubernetes API Server"]:::k8s
        OperatorPod["Operator Manager Pod"]:::operator
        ArgoCDConfigMap["Argocd RBAC ConfigMap"]:::k8s
        ArgoCDServer["Argo CD Server"]:::argo
    end

    %% Operator Pod internals
    subgraph "Operator Manager Pod"
        direction TB
        Manager["controller-runtime Manager (cmd/main.go)"]:::operator
        SchemeReg["Scheme Registration (groupversion_info.go)"]:::operator
        subgraph Reconcilers
            direction TB
            ARReconciler["ArgocdRoleReconciler"]:::operator
            ARBReconciler["ArgocdRoleBindingReconciler"]:::operator
        end
        CommonLogic["Common Utility Logic"]:::operator
    end

    %% Packaging and Deployment
    subgraph Packaging
        direction TB
        Kustomize["Kustomize Manifests (config/)"]:::tooling
        HelmChart["Helm Chart (helm/argocd-rbac-operator)"]:::tooling
    end

    %% Testing & Versioning
    subgraph "Testing & Versioning"
        direction TB
        E2ETests["End-to-End Tests (test/e2e)"]:::tooling
        VersionInfo["Version Info (version/version.go)"]:::tooling
    end

    %% Control Loop
    CRInstances -->|"create/update"| APIServer
    APIServer -->|"watch"| Manager
    Manager -->|"invoke"| SchemeReg
    Manager -->|"enqueue events"| ARReconciler
    Manager -->|"enqueue events"| ARBReconciler
    ARReconciler -->|"use logic"| CommonLogic
    ARBReconciler -->|"use logic"| CommonLogic
    ARReconciler -->|"generate policy CSV"| APIServer
    ARBReconciler -->|"generate policy CSV"| APIServer
    Manager -->|"patch"| ArgoCDConfigMap
    ArgoCDConfigMap -->|"read policies"| ArgoCDServer

    %% Deployment flow
    Kustomize -->|"apply"| CRDDefs
    Kustomize -->|"apply"| OperatorPod
    HelmChart -->|"install"| CRDDefs
    HelmChart -->|"install"| OperatorPod

    %% Testing flow
    E2ETests -->|"apply samples"| CRInstances
    E2ETests -->|"validate patch"| ArgoCDConfigMap

    %% Click Events
    click CRDDefs "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/api/v1alpha1/argocdrole_types.go"
    click CRDDefs "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/api/v1alpha1/argocdrolebinding_types.go"
    click CRDDefs "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/api/v1alpha1/groupversion_info.go"
    click CRDDefs "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/api/v1alpha1/zz_generated.deepcopy.go"
    click CRInstances "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/samples/argocdrole.yaml"
    click CRInstances "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/samples/argocdrolebinding.yaml"
    click Manager "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/cmd/main.go"
    click SchemeReg "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/api/v1alpha1/groupversion_info.go"
    click ARReconciler "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/argocdrole_controller.go"
    click ARBReconciler "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/argocdrolebinding_controller.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/common/defaults.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/common/keys.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/common/values.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/configmap.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/testing.go"
    click CommonLogic "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/internal/controller/argocdrbac_operator_finalizer.go"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/manager/manager.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/service_account.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/role_binding.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/argocdrole_editor_role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/argocdrole_viewer_role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/argocdrolebinding_editor_role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/argocdrolebinding_viewer_role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/leader_election_role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/leader_election_role_binding.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/rbac/kustomization.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/cm-role/role.yaml"
    click Kustomize "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/config/cm-role/role_binding.yaml"
    click HelmChart "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/helm/argocd-rbac-operator/Chart.yaml"
    click HelmChart "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/helm/argocd-rbac-operator/values.yaml"
    click HelmChart "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/helm/argocd-rbac-operator/templates/cm_role.yaml"
    click HelmChart "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/helm/argocd-rbac-operator/templates/cm_role_binding.yaml"
    click E2ETests "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/test/e2e/e2e_suite_test.go"
    click E2ETests "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/test/e2e/e2e_test.go"
    click VersionInfo "https://github.com/argoproj-labs/argocd-rbac-operator/blob/main/version/version.go"

    %% Styles
    classDef k8s fill:#D0E8FF,stroke:#0366D6;
    classDef operator fill:#DFFFD0,stroke:#228B22;
    classDef argo fill:#FFE5B4,stroke:#FF8C00;
    classDef tooling fill:#F0F0F0,stroke:#666;
```
