# libopenstorage/operator architecture

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

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

## Overview

##### Main Components
- Operator Core: Illustrate the “operator” itself (from cmd/operator, pkg/controller, and pkg/apis) that runs inside the Kubernetes cluster. This includes:
- The controller manager and its multiple controllers (storagecluster, storagenode, CSR and Portworx diagnostic controllers).
- Client informers and listers that watch for changes in custom resources.
- Storage Drivers: Outline the storage driver layer (notably the drivers/storage/portworx folder) that implements the logic to interact with Portworx storage – including abstractions for cloud storage, CSI components, and various storage operations.
- Deployment & Automation: Include details about the deployment configurations. This covers deployment manifests in the deploy/ directory (for the operator, plugins, Grafana dashboards, etc.) and the CI/CD pipelines (GitHub workflows, Jenkinsfile, Travis configuration) which automate building, testing, and container deployment.
- Preflight and Migration: Represent helper modules from pkg/dryrun, pkg/preflight, and pkg/migration that handle validations and resource migrations.
- External Services/Dependencies: Optionally, you may show external dependencies such as cloud provider integrations (see pkg/cloudprovider for AWS, Azure, etc.) and monitoring/telemetry components (Grafana dashboards; Prometheus integration in drivers and controllers).

##### Relationships and Data Flow
- Interaction between the Operator and the storage driver layer. Make it clear that the operator uses the driver APIs (from drivers/storage/portworx) to carry out operations on the underlying storage clusters.
- How the CI/CD pipeline (as seen in Jenkinsfile, .github/workflows, and Makefile) leads to building and deploying the operator container into the Kubernetes cluster.
- If relevant, show interactions between the operator and external cloud provider APIs (from pkg/cloudprovider).

##### Architectural Patterns and Principles
- Operator Pattern: Use a dedicated block for the Kubernetes Operator and annotate that it uses controller-runtime patterns, client-informers, and watchers.
- Modular Design: Emphasize the separation between business logic (controllers), API definitions (pkg/apis), driver implementations (drivers/storage/portworx), and supporting infrastructure (preflight, migration, tests).
- Continuous Integration/Continuous Deployment (CI/CD): Note the inclusion of pipelines (Jenkins, Travis, GitHub workflows) that enforce code quality and automated deployment.
- Extensibility and Testing: Identify that the architecture supports heavy integration and unit tests (as evidenced by the integration_test and pkg/mock directories).

##### Specific Technologies and Frameworks
- Golang for the operator logic.
- Kubernetes APIs and CRDs for managing storage clusters.
- Operator SDK patterns and Kubernetes client libraries.
- CI/CD and deployment automation tools (Jenkins, Travis, GitHub workflows, and Docker).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Trigger
    CICD["CI/CD Pipeline"]:::external

    subgraph "Deployment & Automation"
        DManifests["Deployment Manifests"]:::deployment
        GHWorkflows["GitHub Workflows"]:::deployment
        JenkinsCI["Jenkins CI"]:::deployment
        TravisCI["Travis CI"]:::deployment
        BuildAuto["Build Automation"]:::deployment
    end

    %% Kubernetes Cluster Environment
    subgraph "Kubernetes Cluster"
        subgraph "Operator Core"
            Controller["Controller Manager"]:::operator
            APIDefs["API Definitions"]:::operator
        end
        CRDs["Custom Resource Definitions (CRDs)"]:::crd
        StorageDriver["Portworx Driver Module"]:::storage
        PreMig["Preflight & Migration Utilities"]:::preflight
        ExtDeps["External Dependencies"]:::external
    end

    %% CI/CD to Deployment & Automation
    CICD --> DManifests
    CICD --> GHWorkflows
    CICD --> JenkinsCI
    CICD --> TravisCI
    CICD --> BuildAuto

    %% Deployment to Cluster
    DManifests -->|"Deploys Operator"| Controller

    %% Operator Core components relationships
    Controller -->|"Uses APIs"| APIDefs
    Controller -->|"Watches and Reconciles"| CRDs
    Controller -->|"Invokes"| StorageDriver
    Controller -->|"Executes validations"| PreMig
    Controller -->|"Calls cloud/monitoring APIs"| ExtDeps

    %% Additional relationship: API Definitions also interact with CRDs
    APIDefs -->|"Defines CRDs"| CRDs

    %% Click Events for Operator Core
    click Controller "https://github.com/libopenstorage/operator/blob/master/cmd/operator/operator.go"
    click APIDefs "https://github.com/libopenstorage/operator/tree/master/pkg/apis"

    %% Click Events for CRDs
    click CRDs "https://github.com/libopenstorage/operator/tree/master/deploy/crds"

    %% Click Events for Storage Drivers
    click StorageDriver "https://github.com/libopenstorage/operator/tree/master/drivers/storage/portworx"

    %% Click Events for Preflight & Migration
    click PreMig "https://github.com/libopenstorage/operator/tree/master/pkg/preflight"

    %% Click Event for External Dependencies
    click ExtDeps "https://github.com/libopenstorage/operator/tree/master/pkg/cloudprovider"

    %% Click Events for Deployment & Automation
    click DManifests "https://github.com/libopenstorage/operator/tree/master/deploy/"
    click GHWorkflows "https://github.com/libopenstorage/operator/tree/master/.github/workflows"
    click JenkinsCI "https://github.com/libopenstorage/operator/tree/master/Jenkinsfile"
    click TravisCI "https://github.com/libopenstorage/operator/blob/master/.travis.yml"
    click BuildAuto "https://github.com/libopenstorage/operator/tree/master/Makefile"

    %% Styling
    classDef operator fill:#F6D186,stroke:#B37E2C,stroke-width:2px;
    classDef crd fill:#D0E6A5,stroke:#7BA05B,stroke-width:2px;
    classDef storage fill:#A7C7E7,stroke:#517FA4,stroke-width:2px;
    classDef deployment fill:#F7A072,stroke:#D75D41,stroke-width:2px;
    classDef preflight fill:#C9BBCF,stroke:#8E7CA0,stroke-width:2px;
    classDef external fill:#A1E3D8,stroke:#57B7A1,stroke-width:2px;
```
