bitwarden-crd-operator/bitwarden-crd-operator.py

43 lines
1.1 KiB
Python
Raw Normal View History

2022-09-04 21:21:33 +00:00
#!/usr/bin/env python3
import kopf
import kubernetes
2022-09-10 13:07:34 +00:00
from jinja2 import Template
2022-09-04 21:21:33 +00:00
2022-09-09 21:41:06 +00:00
@kopf.on.create('bitwarden-secrets.lerentis.uploadfilter24.eu')
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()
2022-09-10 13:18:47 +00:00
# TODO: this should better be a os lookup
with open('/home/bw-operator/templates/username-password.yaml.j2') as file_:
2022-09-10 13:07:34 +00:00
template = Template(file_.read())
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
@kopf.on.update('bitwarden-secrets.lerentis.uploadfilter24.eu')
def my_handler(spec, old, new, diff, **_):
pass
2022-09-04 21:21:33 +00:00
@kopf.on.delete('bitwarden-secrets.lerentis.uploadfilter24.eu')
def my_handler(spec, **_):
pass