Skip to content

Yorkerrr/dynamo-ctr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tenant Controller

A Kubernetes controller that manages tenant resources based on DynamoDB records.

Overview

The Tenant Controller watches a DynamoDB table for tenant configurations and automatically creates/updates/deletes the corresponding Kubernetes resources (Deployments and ConfigMaps) based on the table records.

Prerequisites

  • Kubernetes cluster
  • AWS credentials with access to DynamoDB
  • Docker

DynamoDB Table Structure

The DynamoDB table should have the following attributes:

  • name (String) - Tenant name
  • spec (String) - JSON string containing the Deployment manifest
  • customizations (String) - JSON string containing an array of ConfigMap manifests
  • deleted (Boolean) - Flag indicating if the tenant resources should be deleted

Building

docker build -t tenant-controller:latest .

Deployment

  1. Create the necessary RBAC resources and deploy the controller:
kubectl apply -f k8s/deployment.yaml
  1. Make sure to set up AWS credentials. You can do this by:
    • Using AWS IAM roles for service accounts (IRSA)
    • Using environment variables
    • Using AWS credentials mounted as a secret

Configuration

The following environment variables are available:

  • DYNAMODB_TABLE (required) - Name of the DynamoDB table to watch

How it Works

  1. The controller watches the specified DynamoDB table for changes
  2. When a new tenant is added or updated:
    • Creates/updates the Deployment from the spec field
    • Creates/updates ConfigMaps from the customizations field
  3. When a tenant is marked as deleted:
    • Deletes the corresponding Deployment and ConfigMaps
  4. Periodically reconciles the state to ensure Kubernetes resources match the DynamoDB records

Example DynamoDB Record

{
  "name": "tenant-1",
  "spec": {
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
      "name": "tenant-1-app",
      "namespace": "default"
    },
    "spec": {
      "replicas": 1,
      "selector": {
        "matchLabels": {
          "app": "tenant-1"
        }
      },
      "template": {
        "metadata": {
          "labels": {
            "app": "tenant-1"
          }
        },
        "spec": {
          "containers": [
            {
              "name": "app",
              "image": "nginx:latest"
            }
          ]
        }
      }
    }
  },
  "customizations": [
    {
      "apiVersion": "v1",
      "kind": "ConfigMap",
      "metadata": {
        "name": "tenant-1-config",
        "namespace": "default"
      },
      "data": {
        "config.json": "{\"key\": \"value\"}"
      }
    }
  ],
  "deleted": false
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published