apiVersion: v1
kind: ConfigMap
metadata:
  name: self-sign-files
  namespace: infra
  labels:
    name: self-sign-files
    namespace: infra
data:
  create-cert.sh: "#!/bin/ash\n\nopenssl req -x509 \\\n  -nodes \\\n  -days 365 \\\n  -newkey rsa:2048 \\\n  -keyout ./self-signed.key \\\n  -out ./self-signed.crt \\\n  -subj \"/C=$COUNTRY/ST=$STATE/L=$LOCAL/O=$ORGANIZATION/OU=$UNIT/CN=$FQN/emailAddress=$EMAIL\"\n\ncat ./self-signed.crt ./self-signed.key > ./self-signed.pem\n\ncat ./secret-template.json | \\\n\tsed \"s/NAMESPACE/${NAMESPACE}/\" | \\\n\tsed \"s/NAME/${SECRET}/\" | \\\n\tsed \"s/TLSCERT/$(cat ./self-signed.crt | base64 | tr -d '\\n')/\" | \\\n\tsed \"s/TLSKEY/$(cat ./self-signed.key |  base64 | tr -d '\\n')/\" | \\\n\tsed \"s/TLSPEM/$(cat ./self-signed.pem |  base64 | tr -d '\\n')/\" \\\n\t> ./secret.json\n\n# /var/run/secrets/kubernetes.io/serviceaccount/token\ncurl -v --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \\\n  -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" \\\n  -H \"Accept: application/json, */*\" \\\n  -H \"Content-Type: application/json\" \\\n  -k -v -X POST \\\n  -d @./secret.json \\\n  https://kubernetes/api/v1/namespaces/${NAMESPACE}/secrets/${SECRET}\n"
  secret-template.json: |
    {
        "kind": "Secret",
        "apiVersion": "v1",
        "metadata": {
            "name": "NAME",
            "namespace": "NAMESPACE"
        },
        "data": {
           "cert.crt": "TLSCERT",
           "cert.key": "TLSKEY",
           "cert.pem": "TLSPEM"
        },
        "type": "Opaque"
    }
