# ravindar55/gitops-operator architecture

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

- Interactive diagram: https://gitdiagram.com/ravindar55/gitops-operator
- Repository: https://github.com/ravindar55/gitops-operator

## Overview

##### Project type and purpose
- This is a Kubernetes Operator (written in Go) designed for OpenShift. It installs and manages a cluster-wide Argo CD (and associated GitOps components) via CustomResourceDefinitions (CRDs).
- It integrates with Operator Lifecycle Manager (OLM), provides OLM bundle/manifests, and supports OpenShift-specific features (Console plugin, Prometheus metrics, Redis HA for caching, Dex/RHSSO SSO, Argo Rollouts).

##### File structure
- Top-level:
- api/v1alpha1 – Go types for custom resources (GitOpsService, AnalysisRun, RolloutManager, etc.)
- controllers/ – Reconcile loops for each CRD: argocd, gitopsservice, notifications, rollout managers, metrics, consoleplugin
- config/ – Kustomize-based Kubernetes manifests (CRDs, RBAC, manager deployment, webhook, Prometheus, samples)
- bundle/ – OLM bundle Dockerfile and manifests (ClusterServiceVersion, CRD definitions, ServiceAccount, Roles, etc.)
- build/ – Templates and scripts to deploy Redis HA (config, liveness/readiness probes, HAProxy, Sentinel)
- main.go – Operator manager entrypoint (sets up manager, controllers, webhooks)
- hack/, scripts/ – helper scripts for development and CI (installing SDK, running tests)
- test/ – e2e and unit tests, KUTTL fixtures, sample app CRs and YAMLs
- Notice the MVC-style pattern:
- Model: api/v1alpha1 types
- Controller: reconcile logic in controllers/
- Views: resulting Kubernetes resources (Deployments, StatefulSets, Services, Routes, ConfigMaps, Secrets)

##### Key insights from README
- The operator:
- Installs CRDs and watches GitOpsService custom resources
- Deploys Argo CD cluster instance with default settings in namespace “openshift-gitops”
- Manages Redis HA cluster as backing store
- Integrates with OpenShift Console, Prometheus, OLM
- Supports progressive delivery via RolloutManager CRDs

a. Kubernetes cluster core
- API Server (CRDs registered)
- etcd
b. OLM / OperatorHub
- CatalogSource → Operatorsource → CSV
c. GitOps Operator (manager)
- Deployment “openshift-gitops-operator-controller-manager”
- Containers: manager (runs all controllers), webhook server
d. CRDs & Custom Resources
- GitOpsService (defines Argo CD installation)
- AnalysisRun/AnalysisTemplate, RolloutManager, NotificationsConfiguration
e. Controllers (inside manager)
- GitOpsServiceController → creates Argo CD resources + Redis cluster
- ArgoCDController → manages Argo CD cluster‐scoped instances
- ArgoCDMetricsController → configures ServiceMonitor for Prometheus
- NotificationsController → sets up NotificationConfig
- RolloutManagerController → deploys Argo Rollouts support
- ConsolePluginController → registers UI extension in OpenShift console
f. Operand components deployed by the operator
- Argo CD core: server, repo, dex, UI, metrics
- Redis HA cluster: StatefulSet, HAProxy, Sentinel, ConfigMaps
- Services, Routes, Ingress, ConfigMaps, Secrets
- Prometheus ServiceMonitor
g. External services
- Quay.io (pull operator + backend images)
- RHSSO / Dex identity providers
- Git repos (Argo CD sync targets)

##### Relationships & data flow
1. OLM installs the Operator (CSV → Deployment → ServiceAccount, Roles, RoleBindings).
2. Operator registers CRDs with API Server.
3. User or OLM creates GitOpsService CR in “openshift-gitops-operator” namespace.
4. GitOpsServiceController watches CR → reconcile loop triggers.
5. Operator creates:
- Namespace “openshift-gitops”
- Argo CD cluster instance (Deployment, StatefulSets, Services, Routes)
- Redis HA cluster (StatefulSet, HAProxy sidecar, Sentinel)
- ConfigMaps for Dex, RBAC, console plugin assets
- ServiceMonitor & Roles for Prometheus
- Additional CRDs (RolloutManager, NotificationConfiguration) if specified
6. Argo CD components serve HTTP/gRPC, sync Git repos, store state in Redis.
7. Dex/RHSSO handle authentication for Argo CD UI/API.
8. Prometheus scrapes metrics via ServiceMonitor.
9. Console Plugin adds UIs to OpenShift console.

##### Architectural patterns & design principles
- Kubernetes Operator pattern: Reconcile‐driven, declarative.
- MVC within operator: api/types (model), controllers (controller), YAML manifests / CRs (view).
- Separation of concerns: each controller handles a CRD.
- Use of Kustomize for multi‐environment overlays (config/default, manager, webhook, samples).
- OLM bundle design for packaging and distribution.
- Template‐based Redis HA build using Go‐text templates.

##### Essential elements
- Controller loops for each CRD (GitOpsServiceController, ArgoCDController, etc.)
- Operator manager container hosting controllers
- Resulting Kubernetes resources: Argo CD Deployment & StatefulSets, Redis HA cluster, ConfigMaps, Secrets, ServiceMonitors
- External dependencies: Quay.io (image registry), Git repos (Argo sync targets), Identity provider
- OLM objects: CatalogSource, CSV, Subscription

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Layer 1: OLM / OperatorHub
  subgraph "Layer 1: OLM / OperatorHub"
    direction TB
    CatalogSource["CatalogSource"]:::external
    Subscription["Subscription"]:::external
    CSV["ClusterServiceVersion"]:::external
  end
  CatalogSource -->|"provides"| Subscription
  Subscription -->|"installs"| CSV
  CSV -->|"creates"| OperatorDeployment

  %% Layer 2: Operator Manager
  subgraph "Layer 2: Operator Manager (openshift-gitops-operator namespace)"
    direction TB
    OperatorDeployment["Deployment: openshift-gitops-operator-controller-manager"]:::operator
    subgraph "Controller Manager Pod"
      direction TB
      ManagerContainer["Container: manager"]:::operator
      WebhookContainer["Container: webhook-server"]:::operator
      subgraph Controllers["Controllers"]
        direction TB
        GSCtrl["GitOpsServiceController"]:::operator
        ADCtrl["ArgoCDController"]:::operator
        ADM["ArgoCDMetricsController"]:::operator
        NPCtrl["NotificationsController"]:::operator
        RMCtrl["RolloutManagerController"]:::operator
        CPCtrl["ConsolePluginController"]:::operator
        Util["Common Utilities"]:::operator
      end
    end
  end
  OperatorDeployment -->|“runs”| ManagerContainer
  ManagerContainer -->|“hosts”| Controllers
  ManagerContainer -->|“hosts”| WebhookContainer

  %% Layer 3: API Server + CRDs + Custom Resources
  subgraph "Layer 3: Kubernetes API Server"
    direction TB
    APIServer["API Server"]:::k8s
    etcd[(etcd)]:::datastore
    CRDs["CRDs"]:::crd
    CRs["Custom Resources"]:::crd
  end
  CSV -->|“registers CRDs”| CRDs
  CRDs -->|“available in”| APIServer
  APIServer -->|“stores state in”| etcd
  CRs -->|“created by User/OLM”| APIServer
  APIServer -->|“Watch GitOpsService CR”| GSCtrl

  %% Layer 4: Operand Deployments (openshift-gitops namespace)
  subgraph "Layer 4: Operand Deployments"
    direction TB
    ArgoCD["Argo CD Cluster\n(Deployments, Services, Routes)"]:::operand
    RedisHA[(Redis HA Cluster)]:::datastore
    Dex["Dex / RHSSO"]:::operand
    PromSM["Prometheus ServiceMonitor"]:::operand
    ConsoleUI["Console Plugin Assets"]:::operand
  end
  GSCtrl -->|“reconcile → create”| ArgoCD
  GSCtrl -->|“reconcile → create”| RedisHA
  ADCtrl -->|“manage Argo CD instance”| ArgoCD
  ADM -->|“configure”| PromSM
  NPCtrl -->|“configure”| ConsoleUI
  RMCtrl -->|“deploy Argo Rollouts support”| ArgoCD
  CPCtrl -->|“register UI extension”| ConsoleUI
  ArgoCD -->|“sync Git repos”| GitRepos
  ArgoCD -->|“auth via”| Dex
  PromSM -->|“scrape metrics”| Prometheus

  %% Layer 5: External Systems
  subgraph "Layer 5: External Systems"
    direction TB
    GitRepos["Git Repositories"]:::external
    Quay["Quay.io Image Registry"]:::external
    RHSSO["RHSSO / Dex Identity Provider"]:::external
    Prometheus["Prometheus Server"]:::external
  end
  OperatorDeployment -->|“pull images”| Quay
  GitRepos -->|“sources for Argo CD”| ArgoCD
  RHSSO -->|“auth back-end”| Dex
  Prometheus -->|“scrapes”| PromSM

  %% Click Events
  click GSCtrl "https://github.com/ravindar55/gitops-operator/blob/master/controllers/gitopsservice_controller.go"
  click ADCtrl "https://github.com/ravindar55/gitops-operator/blob/master/controllers/argocd_controller.go"
  click ADM "https://github.com/ravindar55/gitops-operator/blob/master/controllers/argocd_metrics_controller.go"
  click CPCtrl "https://github.com/ravindar55/gitops-operator/blob/master/controllers/consoleplugin.go"
  click Util "https://github.com/ravindar55/gitops-operator/blob/master/controllers/util/util.go"
  click ArgoCDMetricsConfig "https://github.com/ravindar55/gitops-operator/blob/master/config/webhook/service.yaml"
  click API_Types "https://github.com/ravindar55/gitops-operator/blob/master/api/v1alpha1/gitopsservice_types.go"
  click GroupInfo "https://github.com/ravindar55/gitops-operator/blob/master/api/v1alpha1/groupversion_info.go"
  click Main "https://github.com/ravindar55/gitops-operator/blob/master/main.go"
  click ManagerConfig "https://github.com/ravindar55/gitops-operator/blob/master/config/manager/manager.yaml"
  click CRDRegistry "https://github.com/ravindar55/gitops-operator/tree/master/config/crd/bases/"
  click RedisTemplates "https://github.com/ravindar55/gitops-operator/tree/master/build/redis/"
  click BundleDocker "https://github.com/ravindar55/gitops-operator/blob/master/bundle/bundle.Dockerfile"
  click BundleManifests "https://github.com/ravindar55/gitops-operator/tree/master/bundle/manifests/"
  click CSVBase "https://github.com/ravindar55/gitops-operator/blob/master/config/manifests/bases/gitops-operator.clusterserviceversion.yaml"
  click DefaultKustomize "https://github.com/ravindar55/gitops-operator/blob/master/config/default/kustomization.yaml"
  click AuthProxyPatch "https://github.com/ravindar55/gitops-operator/blob/master/config/default/manager_auth_proxy_patch.yaml"
  click SampleCR "https://github.com/ravindar55/gitops-operator/blob/master/config/samples/pipelines_v1alpha1_gitopsservice.yaml"
  click ControllerTests "https://github.com/ravindar55/gitops-operator/blob/master/controllers/*_test.go"
  click E2ETests "https://github.com/ravindar55/gitops-operator/tree/master/test/e2e"
  click NonDefaultE2E "https://github.com/ravindar55/gitops-operator/tree/master/test/nondefaulte2e"

  %% Styles
  classDef operator fill:#cce5ff,stroke:#004085;
  classDef operand fill:#d4edda,stroke:#155724;
  classDef datastore fill:#fff3cd,stroke:#856404;
  classDef crd fill:#e2dbee,stroke:#5f4b8b,shape:parallelogram;
  classDef k8s fill:#f0f0f0,stroke:#6c757d;
  classDef external fill:#e2e3e5,stroke:#6c757d,stroke-dasharray: 5 5;
  class ArgoCDMetricsConfig,k8s external
```
