# vin65/cert-secret-syncer architecture

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

- Interactive diagram: https://gitdiagram.com/vin65/cert-secret-syncer
- Repository: https://github.com/vin65/cert-secret-syncer

## Overview

- Kubernetes Cluster – Represent the cluster environment where all operations occur.
- cert-secret-syncer Controller – This is your core controller (the Go code under cmd and util) which:
– Monitors secrets with special annotations.
– Extracts certificates.
– Pushes certificates into AWS Certificate Manager.
– Pulls back the generated ARN and annotates the secret.
– Updates any Ingress resources that match provided label selectors.
- AWS Infrastructure – Represent AWS Certificate Manager (ACM) and the IAM Role (created via Terraform and integrated with EKS using IRSA) that permits the controller to perform ACM operations.
- Ingress / ALB – Everything that involves communication with Application Load Balancers where the certificate ARN is applied via annotations so that TLS termination happens correctly.

##### Relationships and Data Flow
- IRSA/IAM role integration providing secure credentials for cert-secret-syncer to communicate with AWS ACM.

##### Architectural Patterns and Design Principles
- Event-driven: The controller uses Kubernetes events to trigger certificate synchronization.
- Separation of Concerns: Highlight that the controller is separate from certificate creation (handled by cert-manager) and from the deployment configuration (given by the Helm charts).
- Infrastructure as Code: Emphasize that the project provides Helm charts (in charts) and Terraform examples (documented in the README) for managing deployments and permissions.

##### Technologies/Frameworks
- Go (with main command logic in cmd/main.go and utilities in util)
- Kubernetes (resource watching, Custom Resource Definitions if any, ServiceAccount with annotations)
- Helm (for packaging and deployment of the controller)
- AWS Certificate Manager and IAM (integrated via IRSA)
- Possibly Docker (docker files available for image building)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Kubernetes Cluster"
        CertManager["cert-manager"]:::kube
        K8sSecret["Kubernetes Secret"]:::kube
        subgraph "cert-secret-syncer Controller"
            ControllerMain["main.go"]:::controller
            ControllerUtil["util.go"]:::controller
            ControllerUtilFiles["util (ctx, log)"]:::controller
        end
        Ingress["Ingress/ALB"]:::ingress
        HelmDeployment["Helm Deployment (cert-secret-syncer)"]:::helm
        K8sConfig["Kubernetes Config (preview)"]:::config
    end
    ACM["AWS ACM"]:::aws
    IAMRole["IAM Role (IRSA)"]:::aws
    ServiceAccount["ServiceAccount (IRSA)"]:::aws

    CertManager -->|"creates_secret"| K8sSecret
    K8sSecret -->|"triggers_sync"| ControllerMain
    ControllerMain -->|"syncs_with_ACM"| ACM
    ACM -->|"returns_ARN"| ControllerMain
    ControllerMain -->|"updates_secret"| K8sSecret
    K8sSecret -->|"applies_ARN"| Ingress

    IAMRole -.->|"IRSA"| ControllerMain
    ServiceAccount -.->|"IRSA"| ControllerMain

    HelmDeployment -.->|"deploys_controller"| ControllerMain
    K8sConfig -.->|"configures_deployment"| HelmDeployment

    click ControllerMain "https://github.com/vin65/cert-secret-syncer/blob/main/cmd/main.go"
    click ControllerUtil "https://github.com/vin65/cert-secret-syncer/blob/main/cmd/util.go"
    click ControllerUtilFiles "https://github.com/vin65/cert-secret-syncer/tree/main/util"
    click HelmDeployment "https://github.com/vin65/cert-secret-syncer/tree/main/charts/cert-secret-syncer"
    click IAMRole "https://github.com/vin65/cert-secret-syncer/blob/main/charts/cert-secret-syncer/templates/role.yaml"
    click ServiceAccount "https://github.com/vin65/cert-secret-syncer/blob/main/charts/cert-secret-syncer/templates/serviceaccount.yaml"
    click K8sConfig "https://github.com/vin65/cert-secret-syncer/tree/main/preview"

    classDef kube fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef controller fill:#e6ffe6,stroke:#009933,stroke-width:2px;
    classDef ingress fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef aws fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
    classDef helm fill:#f9e79f,stroke:#af7ac5,stroke-width:2px;
    classDef config fill:#d5f5e3,stroke:#196F3D,stroke-width:2px;
```
