# kartverket/skiperator architecture

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

- Interactive diagram: https://gitdiagram.com/kartverket/skiperator
- Repository: https://github.com/kartverket/skiperator

## Overview

##### Main Components

a. Core Operator Components:
- Controller Manager (central component)
- Custom Resource Definitions (CRDs)
- Application
- SKIPJob
- Routing

b. Resource Generators:
- Deployment Generator
- Service Generator
- Network Policy Generator
- Certificate Generator
- Istio Resources Generator
- GCP Integration Components
- Monitoring Components

c. External Integration Points:
- Kubernetes API Server
- Istio Service Mesh
- GCP Services
- Prometheus Monitoring
- Identity Providers (IDPorten/Maskinporten)

**┌─ Kubernetes Cluster ──────────────────────────────────────────┐**

- ┌─ Skiperator Operator ─────────────────────────────┐      │

- Controllers                Resource Generators    │      │
- Application             - Deployment           │      │
- SKIPJob                - Service              │      │
- Routing                - Network Policy        │      │
- Namespace              - Certificates          │      │
- Istio Resources       │      │

- Generated Resources                                        │
- Deployments                                             │
- Services                                                │
- Network Policies                                        │
- Certificates                                            │
- Istio Configurations                                    │
- ┘

##### Flow Directions

Key interactions:
- Custom Resource → Controller Manager
- Controller Manager → Resource Generators
- Resource Generators → Kubernetes API
- External Service Connections

##### Important Details

a. Resource Processing Pipeline:
**CR Definition → Validation → Generation → Reconciliation → Status Update**

b. Security Flow:
- Authentication paths
- Authorization policies
- Network policies

c. Monitoring Flow:
- Prometheus metrics
- Service monitoring
- Pod monitoring

##### Specific Implementation Notes

- Relationship between the three main CRDs (Application, SKIPJob, Routing)
- Resource generation pattern using the pkg/resourcegenerator structure
- Reconciliation loop pattern from pkg/reconciliation
- How the controller handles different resource types

##### Implementation Details

**Controllers (internal/controllers/)**
**↓**
**Reconciliation (pkg/reconciliation/)**
**↓**
**Resource Generation (pkg/resourcegenerator/)**
**↓**
**Resource Processing (pkg/resourceprocessor/)**

Remember to:
- Clear boundaries between components
- Operator pattern and Kubernetes native integration
- Major integration points visible in the code structure

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Kubernetes["Kubernetes Cluster"]
        subgraph Operator["Skiperator Operator"]
            CM["Controller Manager"]:::controller
            
            subgraph CRDs["Custom Resource Definitions"]
                APP["Application CRD"]:::crd
                SKIP["SKIPJob CRD"]:::crd
                ROUTE["Routing CRD"]:::crd
            end
            
            subgraph Generators["Resource Generators"]
                DG["Deployment Generator"]:::generator
                SG["Service Generator"]:::generator
                NPG["Network Policy Generator"]:::generator
                CG["Certificate Generator"]:::generator
                IG["Istio Resources Generator"]:::generator
                GCPG["GCP Integration"]:::generator
                PMG["Prometheus Monitoring"]:::generator
                IDPG["Identity Provider Integration"]:::generator
            end
            
            subgraph Core["Core Processing"]
                RP["Resource Processor"]:::core
                RL["Reconciliation Logic"]:::core
            end
        end
        
        subgraph Resources["Generated Resources"]
            DEPLOY["Deployments"]:::resource
            SVC["Services"]:::resource
            NP["Network Policies"]:::resource
            CERT["Certificates"]:::resource
            ISTIO["Istio Configurations"]:::resource
        end
    end
    
    subgraph External["External Systems"]
        K8S["Kubernetes API"]:::external
        ISTIOM["Istio Service Mesh"]:::external
        GCP["GCP Services"]:::external
        PROM["Prometheus"]:::external
        IDP["Identity Providers"]:::external
    end
    
    %% Relationships
    APP & SKIP & ROUTE --> CM
    CM --> RP
    RP --> RL
    RL --> Generators
    
    DG --> DEPLOY
    SG --> SVC
    NPG --> NP
    CG --> CERT
    IG --> ISTIO
    
    Resources --> K8S
    ISTIO --> ISTIOM
    GCPG --> GCP
    PMG --> PROM
    IDPG --> IDP
    
    %% Click Events
    click CM "https://github.com/kartverket/skiperator/tree/main/internal/controllers/"
    click APP "https://github.com/kartverket/skiperator/blob/main/api/v1alpha1/application_types.go"
    click SKIP "https://github.com/kartverket/skiperator/blob/main/api/v1alpha1/skipjob_types.go"
    click ROUTE "https://github.com/kartverket/skiperator/blob/main/api/v1alpha1/routing_types.go"
    click DG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/deployment/"
    click SG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/service/"
    click NPG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/networkpolicy/"
    click CG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/certificate/"
    click IG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/istio/"
    click GCPG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/gcp/"
    click PMG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/podmonitor/"
    click IDPG "https://github.com/kartverket/skiperator/tree/main/pkg/resourcegenerator/idporten/"
    click RP "https://github.com/kartverket/skiperator/tree/main/pkg/resourceprocessor/"
    click RL "https://github.com/kartverket/skiperator/tree/main/pkg/reconciliation/"
    
    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef crd fill:#4CAF50,stroke:#2E7D32,color:white
    classDef generator fill:#FF9800,stroke:#EF6C00,color:white
    classDef core fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef resource fill:#00BCD4,stroke:#00838F,color:white
    classDef external fill:#757575,stroke:#424242,color:white
    
    %% Legend
    subgraph Legend
        L1["Controller"]:::controller
        L2["CRD"]:::crd
        L3["Generator"]:::generator
        L4["Core Processing"]:::core
        L5["Resource"]:::resource
        L6["External System"]:::external
    end
```
