# cert-manager/cmctl architecture

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

- Interactive diagram: https://gitdiagram.com/cert-manager/cmctl
- Repository: https://github.com/cert-manager/cmctl

## Overview

##### Project Type and Purpose
- cmctl is a Go-based command-line interface (CLI) tool for managing cert-manager resources on a Kubernetes cluster.
- It provides multiple subcommands (convert, create, install, renew, status, etc.) which drive interactions with the Kubernetes API server and cert-manager CRDs.

##### File Structure Analysis
- Top-level
- cmd/ & main.go: entry point and command‐dispatcher wiring
- pkg/: implementation of each subcommand (approve, build, check, completion, convert, create, deny, inspect, install, renew, status, uninstall, upgrade, version)
- internal/: shared utilities (signal handling, exit codes, version checking)
- Makefile & make/: build/test/release automation
- .github/: CI workflows (govulncheck, self-upgrade, release)
- Patterns & Dependencies
- Subcommands follow Cobra or similar CLI framework conventions
- pkg/convert/internal/apis: generated conversion code for cert-manager APIs (multiple versions/v1alpha2/v1beta1)
- Extensive integration tests under test/integration drive end-to-end scenarios with a fake API server.

##### Architecture Overview
- Main Components
a. CLI Binary (cmctl)
b. Command Dispatcher (cmd/cmd.go)
c. Subcommand Modules (pkg/*)
d. Shared Utilities (internal/util, internal/versionchecker)
e. Kubernetes API Server (external)
f. cert-manager CustomResourceDefinitions (CRDs) (external)
- Data Flows & Interactions
- User invokes `cmctl <subcommand> [flags]` → cmd layer parses and dispatches
- Subcommand handler loads kubeconfig → creates client-go REST client
- Handler queries/updates Kubernetes API server (CRUD operations on cert-manager CRs)
- convert subcommand can operate entirely client-side: reads YAML, applies conversion library → emits new API version
- internal/versionchecker optionally fetches deployed cert-manager version via Kubernetes API
- Results are printed to stdout/stderr or exit with status codes.
- Architectural Patterns
- Modular CLI: each subcommand encapsulated in its own package
- Shared library code in internal/ for non-exported utilities
- Code-generation for Kubernetes API conversions under pkg/convert/internal/apis
- Test harness uses an in-memory or local control-plane for integration tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["cmctl CLI Binary"]:::cli
        Dispatcher["Command Dispatcher & Flag Parser"]:::cli
    end

    %% Subcommands Layer
    subgraph "Subcommand Modules"
        Convert["convert"]:::cli
        Create["create"]:::cli
        Install["install"]:::cli
        Renew["renew"]:::cli
        Status["status"]:::cli
        Uninstall["uninstall"]:::cli
        Upgrade["upgrade"]:::cli
        Check["check"]:::cli
        Inspect["inspect"]:::cli
        Approve["approve"]:::cli
        Deny["deny"]:::cli
        BuildCmd["build"]:::cli
        Completion["completion"]:::cli
        VersionCmd["version"]:::cli
        Experimental["experimental"]:::cli
        Factory["factory"]:::cli
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        Util["generic helpers"]:::shared
        VersionChecker["version checker"]:::shared
    end

    %% Code Generation Library
    Codegen["API Conversion Code"]:::shared

    %% External Systems
    subgraph "External Systems"
        K8sAPI["Kubernetes API Server"]:::external
        CRD["cert-manager CRDs"]:::external
    end

    %% Test Framework
    subgraph "Test Framework"
        IntegrationTests["Integration Test Framework"]:::test
        TestHelpers["Integration Test Helpers"]:::test
    end

    %% DevOps / CI-CD
    subgraph "DevOps & CI/CD"
        MakefileNode["Makefile"]:::devops
        BuildScripts["build scripts"]:::devops
        CI["CI Workflows"]:::devops
        ReleaseCfg["Release Configuration"]:::devops
    end

    %% Connections
    CLI --> Dispatcher
    Dispatcher --> Convert
    Dispatcher --> Create
    Dispatcher --> Install
    Dispatcher --> Renew
    Dispatcher --> Status
    Dispatcher --> Uninstall
    Dispatcher --> Upgrade
    Dispatcher --> Check
    Dispatcher --> Inspect
    Dispatcher --> Approve
    Dispatcher --> Deny
    Dispatcher --> BuildCmd
    Dispatcher --> Completion
    Dispatcher --> VersionCmd
    Dispatcher --> Experimental
    Dispatcher --> Factory

    %% Subcommands to Shared Utilities
    Convert <--> Util
    Create <--> Util
    Install <--> Util
    Renew <--> Util
    Status <--> Util
    Uninstall <--> Util
    Upgrade <--> Util
    Check <--> Util
    Inspect <--> Util
    Approve <--> Util
    Deny <--> Util
    BuildCmd <--> Util
    Completion <--> Util
    VersionCmd <--> Util
    Experimental <--> Util
    Factory <--> Util

    %% Version Checker usage
    Dispatcher --> VersionChecker
    VersionChecker --> K8sAPI

    %% Subcommands to External API
    Create -->|"CRUD operations"| K8sAPI
    Install -->|"CRUD operations"| K8sAPI
    Renew -->|"CRUD operations"| K8sAPI
    Status -->|"CRUD operations"| K8sAPI
    Uninstall -->|"CRUD operations"| K8sAPI
    Upgrade -->|"CRUD operations"| K8sAPI
    Check -->|"CRUD operations"| K8sAPI
    Inspect -->|"CRUD operations"| K8sAPI
    Approve -->|"CRUD operations"| K8sAPI
    Deny -->|"CRUD operations"| K8sAPI

    %% convert specific
    Convert -->|"codegen pipeline"| Codegen
    Convert -->|"reads YAML"| Util
    Convert -->|"writes YAML"| Util

    %% External CRDs
    K8sAPI --> CRD

    %% Test connections
    IntegrationTests --> CLI
    IntegrationTests --> K8sAPI
    IntegrationTests --> TestHelpers

    %% DevOps connections
    MakefileNode --> CLI
    MakefileNode --> BuildScripts
    CI --> MakefileNode
    CI --> ReleaseCfg

    %% Click Events
    click CLI "https://github.com/cert-manager/cmctl/blob/main/main.go"
    click Dispatcher "https://github.com/cert-manager/cmctl/blob/main/cmd/cmd.go"
    click Convert "https://github.com/cert-manager/cmctl/tree/main/pkg/convert"
    click Create "https://github.com/cert-manager/cmctl/tree/main/pkg/create"
    click Install "https://github.com/cert-manager/cmctl/tree/main/pkg/install"
    click Renew "https://github.com/cert-manager/cmctl/tree/main/pkg/renew"
    click Status "https://github.com/cert-manager/cmctl/tree/main/pkg/status"
    click Uninstall "https://github.com/cert-manager/cmctl/tree/main/pkg/uninstall"
    click Upgrade "https://github.com/cert-manager/cmctl/tree/main/pkg/upgrade"
    click Check "https://github.com/cert-manager/cmctl/tree/main/pkg/check"
    click Inspect "https://github.com/cert-manager/cmctl/tree/main/pkg/inspect"
    click Approve "https://github.com/cert-manager/cmctl/tree/main/pkg/approve"
    click Deny "https://github.com/cert-manager/cmctl/tree/main/pkg/deny"
    click BuildCmd "https://github.com/cert-manager/cmctl/tree/main/pkg/build"
    click Completion "https://github.com/cert-manager/cmctl/tree/main/pkg/completion"
    click VersionCmd "https://github.com/cert-manager/cmctl/tree/main/pkg/version"
    click Experimental "https://github.com/cert-manager/cmctl/tree/main/pkg/experimental"
    click Factory "https://github.com/cert-manager/cmctl/tree/main/pkg/factory"
    click Util "https://github.com/cert-manager/cmctl/tree/main/internal/util"
    click VersionChecker "https://github.com/cert-manager/cmctl/tree/main/internal/versionchecker"
    click Codegen "https://github.com/cert-manager/cmctl/tree/main/pkg/convert/internal/apis"
    click IntegrationTests "https://github.com/cert-manager/cmctl/tree/main/test/integration"
    click TestHelpers "https://github.com/cert-manager/cmctl/tree/main/test/integration/framework"
    click MakefileNode "https://github.com/cert-manager/cmctl/tree/main/Makefile"
    click BuildScripts "https://github.com/cert-manager/cmctl/tree/main/make/"
    click CI "https://github.com/cert-manager/cmctl/tree/main/.github/workflows"
    click ReleaseCfg "https://github.com/cert-manager/cmctl/blob/main/.goreleaser.yml"

    %% Styles
    classDef cli fill:#DDEEFF,stroke:#000
    classDef shared fill:#DDFFDD,stroke:#000
    classDef external fill:#FFDDAA,stroke:#000
    classDef test fill:#EEDDFF,stroke:#000
    classDef devops fill:#EEEEEE,stroke:#000
```
