# krkn-chaos/krkn architecture

> Architecture diagram of the GitHub repository krkn-chaos/krkn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krkn-chaos/krkn
- Repository: https://github.com/krkn-chaos/krkn

## Overview

#### Purpose and Entry Points
Krkn (Kraken) is a Python chaos/resiliency test runner for Kubernetes, OpenShift, Kind, and KubeVirt clusters. It deliberately injects infrastructure and workload failures, then evaluates cluster/application health. Primary launch surfaces are `run_kraken.py`, the optional HTTP service `server.py`, and container startup `containers/entrypoint.sh`.

#### Configuration-to-Execution Orchestration
A run combines a global configuration with one or more scenario YAML files. Environment-specific defaults and metric/alert definitions reside in `config/config.yaml`, `config/config_kubernetes.yaml`, and `config/config_kind.yaml`; executable examples are under `scenarios/openshift/`, `scenarios/kube/`, and `scenarios/kind/`. The runner parses selected scenarios, creates plugins through the central factory, executes them, and collects failures/results.

#### Scenario Plugin Boundary
`krkn/scenario_plugins/scenario_plugin_factory.py` is the extension and dispatch boundary, backed by `krkn/scenario_plugins/abstract_scenario_plugin.py`. Each plugin encapsulates a chaos operation and its lifecycle against the target cluster. Major plugin families include workload/pod disruption (`krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py`), cloud or physical node actions (`krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py`), and application/service disruptions (`krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py`).

#### Fault Injection Implementations
Plugins act through Kubernetes APIs, rendered workload/job manifests, host/cloud controls, or shell commands. Network chaos has both template-driven and modular implementations: `krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py` and `krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py`; the latter selects specialized node, pod, and VMI modules. Node-action adapters isolate provider-specific behavior for AWS, Azure, GCP, OpenStack, VMware, IBM Cloud, Alibaba, Docker, and bare metal under `krkn/scenario_plugins/node_actions/`.

#### Health, Metrics, and Resiliency Assessment
Health checking is plugin-based: `krkn/health_checks/health_check_factory.py` selects simple, HTTP, or virtual-machine checks defined by the abstract contract in `krkn/health_checks/abstract_health_check_plugin.py`. Prometheus integration (`krkn/prometheus/client.py`, `krkn/prometheus/collector.py`) queries and records telemetry. Resiliency evaluation and scoring are separated in `krkn/resiliency/resiliency.py` and `krkn/resiliency/score.py`; alert and metric definitions are supplied through files such as `config/alerts.yaml` and `config/metrics.yaml`.

#### Safety, Rollback, and Triggers
Rollback is a first-class recovery boundary: `krkn/rollback/handler.py` coordinates serialized rollback commands/configuration from `krkn/rollback/command.py` and `krkn/rollback/config.py`, including signal-related handling. Scenario execution can be gated or augmented by command triggers via `krkn/scenario_plugins/triggers/trigger_manager.py`. This separates fault initiation from compensating actions and failure accumulation.

#### Deployment and External Dependencies
Krkn runs as a local Python process or container image, with image assembly under `containers/Dockerfile.template`. It requires credentials/RBAC to modify cluster resources; privileged and non-privileged deployment roles are in `rbac/privileged-clusterrole.yaml` and `rbac/non-privileged-role.yaml`. External control planes can include Kubernetes/OpenShift APIs, supported cloud-provider APIs, Prometheus, and optionally Cerberus (`krkn/cerberus/setup.py`) for cluster health validation. Ansible deployment assets are provided in `ansible/kraken.yml`.

Main entry points: [`run_kraken.py`](https://github.com/krkn-chaos/krkn/blob/main/run_kraken.py) (CLI runner), [`krkn/scenario_plugins/scenario_plugin_factory.py`](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/scenario_plugin_factory.py) (Scenario factory), [`krkn/health_checks/health_check_factory.py`](https://github.com/krkn-chaos/krkn/blob/main/krkn/health_checks/health_check_factory.py) (Health check factory), [`krkn/prometheus/collector.py`](https://github.com/krkn-chaos/krkn/blob/main/krkn/prometheus/collector.py) (Prometheus collector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Launch &amp; config"]
  node_runner["CLI runner<br/>Python entry point<br/>[run_kraken.py]"]
  node_http_server["HTTP service<br/>optional service<br/>[server.py]"]
  node_container_entrypoint["Container startup<br/>shell entry point<br/>[entrypoint.sh]"]
  node_scenario_config["Global &amp; scenario YAML<br/>configuration<br/>[config.yaml]"]
end

subgraph group_execution["Scenario execution"]
  node_scenario_factory{{"Scenario factory<br/>plugin dispatch"}}
  node_scenario_contract["Scenario plugin contract<br/>abstract plugin"]
  node_disruption_plugins["Workload &amp; app disruption<br/>scenario plugins"]
  node_node_actions["Node action adapters<br/>provider adapters"]
  node_network_chaos["Network chaos<br/>scenario plugins"]
  node_triggers["Trigger manager<br/>execution hooks<br/>[trigger_manager.py]"]
end

subgraph group_assessment["Health &amp; assessment"]
  node_health_factory{{"Health check factory<br/>plugin dispatch"}}
  node_health_contract["Health check contract<br/>abstract plugin"]
  node_prometheus["Prometheus collector<br/>telemetry integration<br/>[collector.py]"]
  node_resiliency["Resiliency scoring<br/>evaluation<br/>[resiliency.py]"]
end

subgraph group_recovery["Recovery"]
  node_rollback_handler["Rollback handler<br/>recovery coordinator<br/>[handler.py]"]
  node_rollback_commands["Rollback commands<br/>recovery model<br/>[command.py]"]
end

subgraph group_external["Target environment"]
  node_cluster_apis(("Cluster APIs<br/>external control plane"))
  node_cloud_apis(("Cloud &amp; host controls<br/>external control plane"))
  node_prometheus_service(("Prometheus<br/>external telemetry"))
  node_cerberus(("Cerberus<br/>optional validator<br/>[setup.py]"))
end

node_container_entrypoint -->|"starts"| node_runner
node_http_server -->|"invokes runs"| node_runner
node_scenario_config -->|"configures"| node_runner
node_runner -->|"creates scenarios"| node_scenario_factory
node_scenario_factory -->|"implements"| node_scenario_contract
node_scenario_factory -->|"selects"| node_disruption_plugins
node_scenario_factory -->|"selects"| node_node_actions
node_scenario_factory -->|"selects"| node_network_chaos
node_triggers -.->|"gates or augments"| node_disruption_plugins
node_disruption_plugins -->|"injects faults"| node_cluster_apis
node_network_chaos -->|"injects faults"| node_cluster_apis
node_node_actions -->|"controls nodes"| node_cloud_apis
node_runner -->|"runs checks"| node_health_factory
node_health_factory -->|"implements"| node_health_contract
node_health_factory -->|"validates"| node_cluster_apis
node_runner -->|"collects metrics"| node_prometheus
node_prometheus -->|"queries"| node_prometheus_service
node_prometheus -->|"provides telemetry"| node_resiliency
node_health_factory -->|"provides health results"| node_resiliency
node_runner -->|"recovers on failure"| node_rollback_handler
node_rollback_handler -->|"executes"| node_rollback_commands
node_rollback_handler -->|"compensates"| node_cluster_apis
node_health_factory -.->|"optional validation"| node_cerberus

click node_runner "https://github.com/krkn-chaos/krkn/blob/main/run_kraken.py"
click node_http_server "https://github.com/krkn-chaos/krkn/blob/main/server.py"
click node_container_entrypoint "https://github.com/krkn-chaos/krkn/blob/main/containers/entrypoint.sh"
click node_scenario_config "https://github.com/krkn-chaos/krkn/blob/main/config/config.yaml"
click node_scenario_factory "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/scenario_plugin_factory.py"
click node_scenario_contract "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/abstract_scenario_plugin.py"
click node_disruption_plugins "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py"
click node_node_actions "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py"
click node_network_chaos "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py"
click node_triggers "https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/triggers/trigger_manager.py"
click node_health_factory "https://github.com/krkn-chaos/krkn/blob/main/krkn/health_checks/health_check_factory.py"
click node_health_contract "https://github.com/krkn-chaos/krkn/blob/main/krkn/health_checks/abstract_health_check_plugin.py"
click node_prometheus "https://github.com/krkn-chaos/krkn/blob/main/krkn/prometheus/collector.py"
click node_resiliency "https://github.com/krkn-chaos/krkn/blob/main/krkn/resiliency/resiliency.py"
click node_rollback_handler "https://github.com/krkn-chaos/krkn/blob/main/krkn/rollback/handler.py"
click node_rollback_commands "https://github.com/krkn-chaos/krkn/blob/main/krkn/rollback/command.py"
click node_cerberus "https://github.com/krkn-chaos/krkn/blob/main/krkn/cerberus/setup.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_http_server,node_container_entrypoint,node_scenario_config toneBlue
class node_scenario_factory,node_scenario_contract,node_disruption_plugins,node_node_actions,node_network_chaos,node_triggers toneAmber
class node_health_factory,node_health_contract,node_prometheus,node_resiliency toneMint
class node_rollback_handler,node_rollback_commands toneRose
class node_cluster_apis,node_cloud_apis,node_prometheus_service,node_cerberus toneIndigo
```

## Components

### Launch & config

- [CLI runner](https://github.com/krkn-chaos/krkn/blob/main/run_kraken.py): Python entry point · Builds and runs selected chaos scenarios. · `run_kraken.py`
- [HTTP service](https://github.com/krkn-chaos/krkn/blob/main/server.py): optional service · `server.py`
- [Container startup](https://github.com/krkn-chaos/krkn/blob/main/containers/entrypoint.sh): shell entry point · `containers/entrypoint.sh`
- [Global & scenario YAML](https://github.com/krkn-chaos/krkn/blob/main/config/config.yaml): configuration · Supplies defaults, metrics, alerts, and executable scenarios. · `config/config.yaml`

### Scenario execution

- [Scenario factory](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/scenario_plugin_factory.py): plugin dispatch · Creates scenario plugins from parsed configuration. · `krkn/scenario_plugins/scenario_plugin_factory.py`
- [Scenario plugin contract](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/abstract_scenario_plugin.py): abstract plugin · `krkn/scenario_plugins/abstract_scenario_plugin.py`
- [Workload & app disruption](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py): scenario plugins · Pod disruption and application outage lifecycles. · `krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py`
- [Node action adapters](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py): provider adapters · Isolates cloud, physical-host, Docker, and bare-metal actions. · `krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py`
- [Network chaos](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py): scenario plugins · Template-driven and modular node, pod, and VMI network faults. · `krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py`
- [Trigger manager](https://github.com/krkn-chaos/krkn/blob/main/krkn/scenario_plugins/triggers/trigger_manager.py): execution hooks · `krkn/scenario_plugins/triggers/trigger_manager.py`

### Health & assessment

- [Health check factory](https://github.com/krkn-chaos/krkn/blob/main/krkn/health_checks/health_check_factory.py): plugin dispatch · Selects simple, HTTP, or virtual-machine checks. · `krkn/health_checks/health_check_factory.py`
- [Health check contract](https://github.com/krkn-chaos/krkn/blob/main/krkn/health_checks/abstract_health_check_plugin.py): abstract plugin · `krkn/health_checks/abstract_health_check_plugin.py`
- [Prometheus collector](https://github.com/krkn-chaos/krkn/blob/main/krkn/prometheus/collector.py): telemetry integration · Queries and records cluster telemetry. · `krkn/prometheus/collector.py`
- [Resiliency scoring](https://github.com/krkn-chaos/krkn/blob/main/krkn/resiliency/resiliency.py): evaluation · Evaluates results and computes resiliency scores. · `krkn/resiliency/resiliency.py`

### Recovery

- [Rollback handler](https://github.com/krkn-chaos/krkn/blob/main/krkn/rollback/handler.py): recovery coordinator · Coordinates serialized compensating actions and signal handling. · `krkn/rollback/handler.py`
- [Rollback commands](https://github.com/krkn-chaos/krkn/blob/main/krkn/rollback/command.py): recovery model · `krkn/rollback/command.py`

### Target environment

- **Cluster APIs**: external control plane · Kubernetes or OpenShift resources require credentials and RBAC.
- **Cloud & host controls**: external control plane · Provider APIs and host controls perform node actions.
- **Prometheus**: external telemetry
- [Cerberus](https://github.com/krkn-chaos/krkn/blob/main/krkn/cerberus/setup.py): optional validator · Optional cluster health validation. · `krkn/cerberus/setup.py`

## Connections

- Container startup → CLI runner: starts
- HTTP service → CLI runner: invokes runs
- Global & scenario YAML → CLI runner: configures
- CLI runner → Scenario factory: creates scenarios
- Scenario factory → Scenario plugin contract: implements
- Scenario factory → Workload & app disruption: selects
- Scenario factory → Node action adapters: selects
- Scenario factory → Network chaos: selects
- Trigger manager → Workload & app disruption: gates or augments
- Workload & app disruption → Cluster APIs: injects faults
- Network chaos → Cluster APIs: injects faults
- Node action adapters → Cloud & host controls: controls nodes
- CLI runner → Health check factory: runs checks
- Health check factory → Health check contract: implements
- Health check factory → Cluster APIs: validates
- CLI runner → Prometheus collector: collects metrics
- Prometheus collector → Prometheus: queries
- Prometheus collector → Resiliency scoring: provides telemetry
- Health check factory → Resiliency scoring: provides health results
- CLI runner → Rollback handler: recovers on failure
- Rollback handler → Rollback commands: executes
- Rollback handler → Cluster APIs: compensates
- Health check factory → Cerberus: optional validation
