# ocervell/slo-generator-gke architecture

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

- Interactive diagram: https://gitdiagram.com/ocervell/slo-generator-gke
- Repository: https://github.com/ocervell/slo-generator-gke

## Overview

The project is a deployment example for the SLO Generator on GKE. Its purpose is to run the slo-generator on a schedule (via a Kubernetes CronJob) to report Service Level Objectives (SLOs) using configurations that are provided via ConfigMaps. In this context, the project facilitates the integration of SLO reporting into a GKE environment, with additional support for alternative environments such as Cloud Run.

##### Core Components
- SLO Generator Container: Represent the container that runs the slo-generator tool. This is built via the provided Dockerfile instructions and is executed as part of a Kubernetes CronJob (defined in app.yaml).
- ConfigMap Resources: Include components for the SLO configurations (“slos” directory) and the error-budget policy configuration (error_budget_policy.yaml). These are mounted into the pod so that the generator reads its instructions.
- CRD (Custom Resource Definition): There is a CRD file for service level objectives (crd/service_level_objective.yaml) that indicates possible use of custom resources to manage SLO definitions.
- External Services & Permissions: Illustrate integrations with external systems:
- Cloud Monitoring (Stackdriver): Roles and permissions to view metrics and write metrics.
- BigQuery: Data export roles.
- PubSub: Messaging publisher roles.
These external services are connected to the SLO generator to report and export SLO metrics.

##### Relationships and Data Flow
- Container to ConfigMap components (both for SLO configs and error-budget policy) indicating that the container mounts these configurations as volumes on startup.
- Deployment pipelines connecting the GitHub workflows and deployment scripts to the Kubernetes cluster (and possibly to Cloud Run), highlighting the automation that manages resource deployment and updates.

##### Architectural Patterns and Strategies
- Separation of Concerns: The design clearly separates configuration (via ConfigMaps) from the application logic inside the container.
- Containerization & Orchestration: Emphasize that the basis is a containerized application deployed on a Kubernetes cluster as a CronJob.
- Infrastructure as Code: The repository includes YAML files (app.yaml, CRD YAMLs, configuration files) that explicitly define the deployment setup.
- CI/CD Integration: GitHub workflows and deploy scripts imply an automated deployment pipeline.

##### Specific Technical Elements to Capture
- The Docker image build and deployment instructions – note that the image is built using either gcloud builds (for GKE) or Docker commands (for local testing).
- The mounting of SLO configurations (from the “slos/” directory) into the container.
- The integration of service account IAM roles, which is crucial for secure access to the external services required by the SLO generator.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Automation Section
    subgraph "Deployment Automation"
        DA1("Deploy CloudRun Service (Script)"):::cd
        DA2("Deploy CloudRun SLOs (Script)"):::cd
        DA3("Deploy K8s Service (Script)"):::cd
        DA4("Deploy K8s SLOs (Script)"):::cd
        DA5("GitHub Workflow CloudRun Service"):::cd
        DA6("GitHub Workflow CloudRun SLOs"):::cd
        DA7("GitHub Workflow GKE Service"):::cd
        DA8("GitHub Workflow GKE SLOs"):::cd
    end

    %% Kubernetes Cluster Section
    subgraph "Kubernetes Cluster"
        K1("Kubernetes CronJob for SLO Generator"):::kube
        K2("SLO Generator Container"):::kube
        K3("ConfigMap – SLO Configs"):::kube
        K4("ConfigMap – Error Budget Policy"):::kube
        K5("CRD – Service Level Objective"):::kube
    end

    %% External Services Section
    subgraph "External Services"
        E1("Cloud Monitoring"):::external
        E2("BigQuery"):::external
        E3("PubSub"):::external
    end

    %% Relationships
    %% Deployment Automation triggers the deployment to the Kubernetes cluster
    DA1 -->|"deploys"| K1
    DA2 -->|"deploys"| K1
    DA3 -->|"deploys"| K1
    DA4 -->|"deploys"| K1
    DA5 -->|"triggers"| K1
    DA6 -->|"triggers"| K1
    DA7 -->|"triggers"| K1
    DA8 -->|"triggers"| K1

    %% CronJob schedules the SLO Generator Container
    K1 -->|"schedules"| K2

    %% SLO Generator Container mounts ConfigMaps
    K2 -->|"mounts"| K3
    K2 -->|"mounts"| K4

    %% SLO Generator Container relies on CRD definitions
    K2 -->|"uses"| K5

    %% SLO Generator Container reports to External Services
    K2 -->|"reports"| E1
    K2 -->|"exports"| E2
    K2 -->|"publishes"| E3

    %% Styling definitions
    classDef kube fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef cd fill:#d4edda,stroke:#155724,stroke-width:2px;

    %% Click Events for Component Mapping
    click K2 "https://github.com/ocervell/slo-generator-gke/blob/master/app.yaml"
    click K1 "https://github.com/ocervell/slo-generator-gke/blob/master/app.yaml"
    click K3 "https://github.com/ocervell/slo-generator-gke/tree/master/slos/"
    click K5 "https://github.com/ocervell/slo-generator-gke/blob/master/crd/service_level_objective.yaml"
    click DA1 "https://github.com/ocervell/slo-generator-gke/blob/master/deploy_cloudrun_service.sh"
    click DA2 "https://github.com/ocervell/slo-generator-gke/blob/master/deploy_cloudrun_slos.sh"
    click DA3 "https://github.com/ocervell/slo-generator-gke/blob/master/deploy_k8s_service.sh"
    click DA4 "https://github.com/ocervell/slo-generator-gke/blob/master/deploy_k8s_slos.sh"
    click DA5 "https://github.com/ocervell/slo-generator-gke/blob/master/.github/workflows/cloudrun_service.yml"
    click DA6 "https://github.com/ocervell/slo-generator-gke/blob/master/.github/workflows/cloudrun_slos.yml"
    click DA7 "https://github.com/ocervell/slo-generator-gke/blob/master/.github/workflows/gke_service.yml"
    click DA8 "https://github.com/ocervell/slo-generator-gke/blob/master/.github/workflows/gke_slos.yml"
```
