# operator-framework/operator-sdk architecture

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

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

## Overview

##### Main Components
- CLI/Command Interface: Represent the primary command-line tools (e.g., the binaries produced in cmd/helm-operator and cmd/operator-sdk, as well as the internal/cli packages) that users invoke.
- Code Generation and Scaffolding Engine: Highlight the modules under internal/generate, hack/generate, and internal/plugins. This engine is responsible for creating boilerplate, generating manifests, CRDs, kustomize files, packagemanifests, and bundle configurations.
- Core Runtime Library: Include the integration with controller-runtime (reference internal/util, internal/flags, and internal/pkg functionalities) which is used by generated operators to interact with the Kubernetes API Server.
- OLM and Bundle Components: Display the components related to Operator Lifecycle Manager (OLM) integration present under internal/olm and the related bundle generation functionality in internal/cmd/operator-sdk/bundle and internal/cmd/operator-sdk/pkgmantobundle.
- Testing and Scorecard: There are dedicated submodules (e.g., internal/scorecard, test/e2e, test/integration) that ensure operators built with the SDK meet quality, integration, and scorecard (validation) criteria.
- Build, Image, and CI/CD Pipelines: Include how Makefile, goreleaser, GitHub workflows, and Dockerfiles under images/ are used for continuous integration, building platform-specific binaries and container images.

##### Relationships and Data Flows
- The scaffolding process utilizes code generators and templates (from internal/generate and internal/plugins) to generate the operator’s source, manifests, and configuration files.
- At runtime, the operator (which now integrates with controller-runtime) communicates with the Kubernetes API server, leveraging manager configuration, custom resource definitions (CRDs), and controller logic.
- OLM components and bundle generators prepare the operator to be packaged, validated (via the scorecard tests), and eventually deployed using Kubernetes-native mechanisms.
- CI/CD pipelines continually build, test, and deploy new versions of these components via GitHub Actions (see .github/workflows) and the release tooling (goreleaser).

##### Architectural Patterns and Design Principles
- Modular Plugin Architecture: A detailed separation between CLI, code generators, runtime integration, and testing frameworks, which allows each part channel’s responsibility to remain isolated and extendable.
- Separation of Concerns: Clear division between scaffolding (build-time) versus runtime functionality, where generated code leverages common libraries and then interacts with external systems (Kubernetes API Server).
- DevOps & CI/CD Support: The repository includes comprehensive CI scripts, Dockerfiles, and release processes, which should be highlighted as part of the overall lifecycle management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Dev("Developer"):::external
    Kube("Kubernetes API Server"):::external

    %% Main Generated Operator Node
    OP("Operator Project"):::project

    %% CLI & Scaffolding Subgraph
    subgraph "CLI & Scaffolding"
        CLI1["Operator SDK CLI"]:::cli
        CLI2["Helm Operator CLI"]:::cli
        CLI3["Internal CLI"]:::cli
        CG1["CodeGen: internal/generate"]:::codegen
        CG2["CodeGen: hack/generate"]:::codegen
        CG3["CodeGen: internal/plugins"]:::codegen
    end

    %% Core Runtime Library Subgraph
    subgraph "Core Runtime Library"
        RT1["Util Library (internal/util)"]:::runtime
        RT2["Flags Parser (internal/flags)"]:::runtime
        RT3["K8sUtil (internal/util/k8sutil)"]:::runtime
    end

    %% OLM & Bundle Components Subgraph
    subgraph "OLM & Bundle Components"
        OLM1["OLM CLI (internal/cmd/operator-sdk/olm)"]:::olm
        OLM2["Bundle Generator (internal/cmd/operator-sdk/pkgmantobundle)"]:::olm
        OLM3["OLM Core (internal/olm)"]:::olm
    end

    %% Testing & Scorecard Subgraph
    subgraph "Testing & Scorecard"
        TS1["Scorecard (internal/scorecard)"]:::test
        TS2["E2E Tests (test/e2e)"]:::test
        TS3["Integration Tests (test/integration)"]:::test
    end

    %% Build, Image & CI/CD Pipelines Subgraph
    subgraph "Build, Image & CI/CD"
        CI1["Makefile"]:::ci
        CI2["GitHub Workflows (.github/workflows)"]:::ci
        CI3[".ci Scripts (.ci)"]:::ci
        CI4["Images Directory (images)"]:::ci
        CI5["Goreleaser Config (.goreleaser.yml)"]:::ci
    end

    %% Connections between Groups
    Dev -->|"invokes"| CLI1
    CLI1 -->|"triggers scaffolding"| OP
    CLI2 --> OP
    CLI3 --> OP
    CG1 --> CG2
    CG2 --> CG3
    CG3 --> OP

    OP -->|"integrates with"| RT1
    OP --> RT2
    OP --> RT3

    RT1 -->|"communicates with"| Kube

    OP -->|"packaged by"| OLM1
    OLM1 --> OLM2
    OLM2 --> OLM3

    OP -->|"validated by"| TS1
    TS1 --> TS2
    TS1 --> TS3

    OP -->|"built/deployed via"| CI1
    CI1 --> CI2
    CI2 --> CI3
    CI3 --> CI4
    CI4 --> CI5
    CI5 --> Kube

    %% Classes and Styles
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef codegen fill:#B0E0E6,stroke:#000,stroke-width:1px;
    classDef runtime fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef olm fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef test fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef ci fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef project fill:#E6E6FA,stroke:#000,stroke-width:1px;

    %% Click Events for CLI & Scaffolding
    click CLI1 "https://github.com/operator-framework/operator-sdk/tree/master/cmd/operator-sdk"
    click CLI2 "https://github.com/operator-framework/operator-sdk/tree/master/cmd/helm-operator"
    click CLI3 "https://github.com/operator-framework/operator-sdk/tree/master/internal/cmd/operator-sdk/cli"
    click CG1 "https://github.com/operator-framework/operator-sdk/tree/master/internal/generate"
    click CG2 "https://github.com/operator-framework/operator-sdk/tree/master/hack/generate"
    click CG3 "https://github.com/operator-framework/operator-sdk/tree/master/internal/plugins"

    %% Click Events for Core Runtime Library
    click RT1 "https://github.com/operator-framework/operator-sdk/tree/master/internal/util"
    click RT2 "https://github.com/operator-framework/operator-sdk/tree/master/internal/flags"
    click RT3 "https://github.com/operator-framework/operator-sdk/tree/master/internal/util/k8sutil"

    %% Click Events for OLM & Bundle Components
    click OLM1 "https://github.com/operator-framework/operator-sdk/tree/master/internal/cmd/operator-sdk/olm"
    click OLM2 "https://github.com/operator-framework/operator-sdk/tree/master/internal/cmd/operator-sdk/pkgmantobundle"
    click OLM3 "https://github.com/operator-framework/operator-sdk/tree/master/internal/olm"

    %% Click Events for Testing & Scorecard
    click TS1 "https://github.com/operator-framework/operator-sdk/tree/master/internal/scorecard"
    click TS2 "https://github.com/operator-framework/operator-sdk/tree/master/test/e2e"
    click TS3 "https://github.com/operator-framework/operator-sdk/tree/master/test/integration"

    %% Click Events for Build, Image & CI/CD Pipelines
    click CI1 "https://github.com/operator-framework/operator-sdk/tree/master/Makefile"
    click CI2 "https://github.com/operator-framework/operator-sdk/tree/master/.github/workflows"
    click CI3 "https://github.com/operator-framework/operator-sdk/blob/master/.ci"
    click CI4 "https://github.com/operator-framework/operator-sdk/tree/master/images"
    click CI5 "https://github.com/operator-framework/operator-sdk/blob/master/.goreleaser.yml"
```
