# airwallex/k8s-pod-restart-info-collector architecture

> Architecture diagram of the GitHub repository airwallex/k8s-pod-restart-info-collector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/airwallex/k8s-pod-restart-info-collector
- Repository: https://github.com/airwallex/k8s-pod-restart-info-collector

## Overview

##### Main Components
- Controller (Go Binary): This is the heart of the system. Key files such as main.go, controller.go, slack.go, and helpers.go indicate that the controller watches Kubernetes pods and processes their events.
- Kubernetes Cluster: Represent the Kubernetes API server, which feeds pod events to the controller. Include typical components like Pod objects, Deployments, and the custom resource access (if any).
- Slack Integration: This component is external to the cluster. The controller utilizes a Slack webhook (configured via environment variables/Helm values) to send pod restart messages and detailed notifications.
- Helm Deployment: The helm directory and shell-version-for-poc folder contain Helm charts and templates for deploying the controller, managing RBAC, secrets, and configmaps. This should be noted as the packaging/deployment mechanism.

##### Relationships and Data Flow
- The Kubernetes API Server notifies the custom controller about pod events/changes.
- The Controller processes pod restart events and collects data (logs, events, statuses).
- After processing, the controller sends a request (using HTTP/S) to the Slack webhook URL.
- Deployment and configuration management is handled via Helm templates that define Kubernetes resources like Deployments, RBAC, ConfigMaps, and Secrets.
- Optionally, show the build and Docker container image (indicated by Dockerfile and build.sh) that encapsulates the controller.

##### Architectural Patterns and Design Principles
- Event-Driven Architecture: The controller listens to events from the K8s API and then reacts on pod status changes.
- Separation of Concerns: The code is divided between event collection, data processing, and notification (Slack) logic.
- Containerization & Helm: The Dockerfile and Helm charts indicate standard container orchestration with deployment configuration separated from business logic.

##### Technologies & Frameworks to Mention
- Go Language – the core implementation.
- Kubernetes – for pod management and event watching.
- Helm – for packaging and deploying the application into the cluster.
- Slack Webhook – for alerting users.
- Docker – for containerizing the application.
- GitHub Actions/CI configuration folder (.github) hints at continuous integration practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kubernetes Cluster
    subgraph "Kubernetes Cluster"
        API["Kubernetes API Server"]:::internal
        POD["Pod Events"]:::internal
    end

    %% Deployment & Build
    subgraph "Deployment & Build"
        CI[".github CI/CD"]:::deployment
        DFILE["Dockerfile"]:::code
        BLSH["build.sh"]:::code
        HELM1["Helm Deployment (helm)"]:::deployment
        HELM2["Helm Deployment (shell-version-for-poc)"]:::deployment
    end

    %% Application Layer
    subgraph "Application"
        CTRL["Custom Controller (Go Binary)"]:::internal
        subgraph "Controller Source Code"
            MAIN["main.go"]:::code
            CTRLR["controller.go"]:::code
            SLK["slack.go"]:::code
            HELP["helpers.go"]:::code
        end
    end

    %% External Services
    subgraph "External Services"
        SLK_EXT["Slack Notification Webhook"]:::external
    end

    %% Data Flow
    API -->|"sends events"|CTRL
    POD -->|"triggers events"|CTRL

    MAIN -->|"compiled_to"|CTRL
    CTRLR -->|"compiled_to"|CTRL
    SLK -->|"compiled_to"|CTRL
    HELP -->|"compiled_to"|CTRL

    CTRL -->|"notifies"|SLK_EXT

    CI -->|"triggers_build"|DFILE
    CI -->|"triggers_build"|BLSH
    DFILE -->|"builds_image_for"|HELM1
    BLSH -->|"builds_image_for"|HELM1
    DFILE -->|"builds_image_for"|HELM2
    BLSH -->|"builds_image_for"|HELM2
    HELM1 -->|"deploys"|CTRL
    HELM2 -->|"deploys"|CTRL

    %% Click Events
    click MAIN "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/main.go"
    click CTRLR "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/controller.go"
    click SLK "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/slack.go"
    click HELP "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/helpers.go"
    click HELM1 "https://github.com/airwallex/k8s-pod-restart-info-collector/tree/master/helm/"
    click HELM2 "https://github.com/airwallex/k8s-pod-restart-info-collector/tree/master/shell-version-for-poc/"
    click DFILE "https://github.com/airwallex/k8s-pod-restart-info-collector/tree/master/Dockerfile"
    click BLSH "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/build.sh"
    click CI "https://github.com/airwallex/k8s-pod-restart-info-collector/blob/master/.github"

    %% Styles
    classDef internal fill:#f9f,stroke:#333,stroke-width:2px;
    classDef external fill:#bbf,stroke:#333,stroke-width:2px;
    classDef deployment fill:#cff,stroke:#333,stroke-width:2px;
    classDef code fill:#fcf,stroke:#333,stroke-width:2px;
```
