# shkatara/kubernetes-ec2-operator architecture

> Architecture diagram of the GitHub repository shkatara/kubernetes-ec2-operator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shkatara/kubernetes-ec2-operator
- Repository: https://github.com/shkatara/kubernetes-ec2-operator

## Overview

ec2operator is a Kubernetes operator that provisions and terminates AWS EC2 instances from Ec2Instance custom resources. A user applies a resource, the controller reconciles it, creates an EC2 instance and records its observed details in status; deletion triggers termination before the finalizer is removed. The API schema and controller lifecycle are supported by excerpts. The README documents applying sample resources, and the controller excerpt documents Kubernetes watch-driven reconciliation. The manager entry point and deployment configuration are present in the tree but were not sampled, so their wiring is not asserted.

Main entry points: [`internal/controller/ec2instance_controller.go`](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/ec2instance_controller.go) (EC2 reconciler), [`internal/controller/createInstance.go`](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/createInstance.go) (Create instance), [`internal/controller/deleteInstance.go`](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/deleteInstance.go) (Delete instance), [`internal/controller/aws_client.go`](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/aws_client.go) (AWS client setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Kubernetes API"]
  node_kube[("Kubernetes API")]
  node_resource["Instance resource"]
end

subgraph group_reconcile["Reconciliation"]
  node_controller["EC2 reconciler"]
end

subgraph group_cloud["AWS EC2"]
  node_create["Create instance<br/>[createInstance.go]"]
  node_delete["Delete instance<br/>[deleteInstance.go]"]
  node_check["Instance check<br/>[checkInstance.go]"]
  node_awsclient["AWS client setup<br/>[aws_client.go]"]
end

node_user(("Cluster user"))
node_aws["AWS EC2"]

node_user -->|"applies resource"| node_kube
node_kube -->|"dispatches changes"| node_controller
node_controller -->|"reads and updates"| node_kube
node_controller -->|"creates instance"| node_create
node_controller -->|"terminates instance"| node_delete
node_create -->|"configures client"| node_awsclient
node_delete -->|"configures client"| node_awsclient
node_check -->|"configures client"| node_awsclient
node_create -->|"launches and describes"| node_aws
node_delete -->|"terminates instance"| node_aws
node_check -->|"checks instance"| node_aws

click node_resource "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/api/v1/ec2instance_types.go"
click node_controller "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/ec2instance_controller.go"
click node_create "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/createInstance.go"
click node_delete "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/deleteInstance.go"
click node_check "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/checkInstance.go"
click node_awsclient "https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/aws_client.go"

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_kube,node_resource,node_user toneBlue
class node_controller toneAmber
class node_create,node_delete,node_check,node_awsclient toneMint
class node_aws toneIndigo
```

## Components

### Kubernetes API

- **Kubernetes API**
- [Instance resource](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/api/v1/ec2instance_types.go): `api/v1/ec2instance_types.go`

### Reconciliation

- [EC2 reconciler](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/ec2instance_controller.go): `internal/controller/ec2instance_controller.go`

### AWS EC2

- [Create instance](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/createInstance.go): `internal/controller/createInstance.go`
- [Delete instance](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/deleteInstance.go): `internal/controller/deleteInstance.go`
- [Instance check](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/checkInstance.go): `internal/controller/checkInstance.go`
- [AWS client setup](https://github.com/shkatara/kubernetes-ec2-operator/blob/main/internal/controller/aws_client.go): `internal/controller/aws_client.go`

### Other components

- **Cluster user**
- **AWS EC2**

## Connections

- Cluster user → Kubernetes API: applies resource (evidence: `README.md`)
- Kubernetes API → EC2 reconciler: dispatches changes (evidence: `internal/controller/ec2instance_controller.go`)
- EC2 reconciler → Kubernetes API: reads and updates (evidence: `internal/controller/ec2instance_controller.go`)
- EC2 reconciler → Create instance: creates instance (evidence: `internal/controller/ec2instance_controller.go`)
- EC2 reconciler → Delete instance: terminates instance (evidence: `internal/controller/ec2instance_controller.go`)
- Create instance → AWS client setup: configures client (evidence: `internal/controller/createInstance.go`)
- Delete instance → AWS client setup: configures client (evidence: `internal/controller/deleteInstance.go`)
- Instance check → AWS client setup: configures client (evidence: `internal/controller/checkInstance.go`)
- Create instance → AWS EC2: launches and describes (evidence: `internal/controller/createInstance.go`)
- Delete instance → AWS EC2: terminates instance (evidence: `internal/controller/deleteInstance.go`)
- Instance check → AWS EC2: checks instance (evidence: `internal/controller/checkInstance.go`)
