create secret programatically
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tobias Trabelsi 2022-09-10 19:34:07 +02:00
parent 600de43344
commit 592a6d5e1a
Signed by: lerentis
GPG Key ID: FF0C2839718CAF2E
3 changed files with 25 additions and 12 deletions

View File

@ -16,20 +16,33 @@ def create_fn(spec, name, namespace, logger, **kwargs):
api = kubernetes.client.CoreV1Api()
# TODO: this should better be a os lookup
with open('/home/bw-operator/templates/username-password.yaml.j2') as file_:
template = Template(file_.read())
#with open('/home/bw-operator/templates/username-password.yaml.j2') as file_:
# template = Template(file_.read())
data = template.render(
original_crd=name,
secret_name=secret_name,
namespace=secret_namespace,
username=str(base64.b64encode("test".encode("utf-8")), "utf-8"),
password=str(base64.b64encode("test".encode("utf-8")), "utf-8")
)
#data = template.render(
# original_crd=name,
# secret_name=secret_name,
# namespace=secret_namespace,
# username=str(base64.b64encode("test".encode("utf-8")), "utf-8"),
# password=str(base64.b64encode("test".encode("utf-8")), "utf-8")
#)
metadata = {
'name': secret_name,
'namespace': secret_namespace
}
data = {
'username': str(base64.b64encode("test".encode("utf-8")), "utf-8"),
'password': str(base64.b64encode("test".encode("utf-8")), "utf-8")
}
api_version = 'v1'
kind = 'Secret'
body = kubernetes.client.V1Secret(api_version, data , kind, metadata,
type='Opaque')
obj = api.create_namespaced_secret(
namespace=secret_namespace,
body=data
body=body
)
logger.info(f"Secret {name} is created: {obj}")

View File

@ -6,7 +6,7 @@ rules:
- apiGroups: ["lerentis.uploadfilter24.eu"]
resources: ["bitwarden-secrets"]
verbs: ["get", "watch", "list", "create", "delete", "patch", "update"]
- apiGroups: ["v1"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list", "create", "delete", "patch", "update"]
- apiGroups: [""]

View File

@ -8,7 +8,7 @@ image:
repository: lerentis/bitwarden-crd-operator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "97fced6969e32d0c7e0975865f26ebbc43f1cd8a"
tag: "600de4334491e51e1412f80231d3fcf0db765214"
imagePullSecrets: []
nameOverride: ""