2022-09-04 21:21:33 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-09-10 12:55:53 +00:00
|
|
|
import os
|
2022-09-04 21:21:33 +00:00
|
|
|
import kopf
|
2022-09-10 12:55:53 +00:00
|
|
|
import kubernetes
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
2022-09-04 21:21:33 +00:00
|
|
|
|
2022-09-09 21:41:06 +00:00
|
|
|
@kopf.on.create('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
2022-09-10 12:55:53 +00:00
|
|
|
def create_fn(spec, name, namespace, logger, **kwargs):
|
|
|
|
|
|
|
|
type = spec.get('type')
|
|
|
|
id = spec.get('id')
|
|
|
|
secret_name = spec.get('name')
|
|
|
|
secret_namespace = spec.get('namespace')
|
|
|
|
|
|
|
|
api = kubernetes.client.CoreV1Api()
|
|
|
|
|
|
|
|
environment = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), '/templates')))
|
|
|
|
|
|
|
|
template = environment.get_template('username-password.yaml.j2')
|
|
|
|
data = template.render(
|
|
|
|
original_crd=name,
|
|
|
|
secret_name=secret_name,
|
|
|
|
namespace=secret_namespace,
|
|
|
|
username="test",
|
|
|
|
password="test"
|
|
|
|
)
|
|
|
|
|
|
|
|
obj = api.create_namespaced_secret(
|
|
|
|
namespace=secret_namespace,
|
|
|
|
body=data
|
|
|
|
)
|
|
|
|
|
|
|
|
logger.info(f"Secret {name} is created: {obj}")
|
2022-09-04 21:21:33 +00:00
|
|
|
|
|
|
|
|
2022-09-10 12:55:53 +00:00
|
|
|
@kopf.on.update('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
|
|
|
def my_handler(spec, old, new, diff, **_):
|
|
|
|
pass
|
2022-09-04 21:21:33 +00:00
|
|
|
|
2022-09-10 12:55:53 +00:00
|
|
|
@kopf.on.delete('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
|
|
|
def my_handler(spec, **_):
|
|
|
|
pass
|