empath-nirvana / magic-happens

A kubernetes operator you should never run under any circumstances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Readme written by chatgpt, because of course it is:

MagicHappens Kubernetes Operator

Welcome to the MagicHappens Kubernetes Operator project! This is a proof-of-concept (PoC) operator, built using Kopf, that leverages OpenAI's GPT-powered generation capabilities to create a Kubernetes spec from a simple, human-readable description. Please note that this project is just for fun and should NOT be deployed to a real Kubernetes cluster under any circumstances.

Overview

The MagicHappens operator takes the following YAML as input:

kind: MagicHappens
apiVersion: gptmagic.io/v1
metadata:
  name: redis
spec:
  description: "create a redis namespace, and inside the namespace, create a redis cluster, backed by a stateful set, along with a service"

Upon receiving the YAML, the operator sends the description to OpenAI, which then generates a Kubernetes spec. The operator applies the returned YAML, attempting to correct any errors and maintain consistency across updates.

Prerequisites

  • A Kubernetes cluster (for testing purposes only).
  • kubectl installed and configured to interact with your cluster.
  • Python 3.7+ installed.
  • an openai api key (you can use gpt-3.5 if you don't have access to gpt-4, but the results aren't as reliable

Installation

git clone https://github.com/empath-nirvana/magic-happens.git
cd magic-happens

Install the required Python packages:

pip install -r requirements.txt

Deploy the Custom Resource Definition (CRD) to your cluster:

kubectl apply -f crd.yaml

Set up your OpenAI API key as an environment variable:

export OPENAI_API_KEY=your_openai_api_key

Usage

Start the operator locally:

kopf run handler.py --verbose

In another terminal, create a new MagicHappens custom resource:

kubectl apply -f test.yaml

This will trigger the MagicHappens operator to generate and apply the Kubernetes spec based on the description provided in the YAML.

Monitor the operator logs for the generated YAML and any errors or corrections.

To clean up the resources created by the operator, delete the MagicHappens custom resource:


kubectl delete -f example.yaml

Limitations

This PoC operator is meant for fun and experimentation only. It is not production-ready, and should not be deployed to real Kubernetes clusters. The generated specs may not always be accurate or secure, and the operator may not handle all edge cases or errors gracefully.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to open issues, submit pull requests, or provide feedback to help improve this proof-of-concept project. Remember, this is just for fun and learning!

About

A kubernetes operator you should never run under any circumstances


Languages

Language:Python 98.6%Language:Dockerfile 1.4%