From e6f39eab217b78904536e4eff8742353dd08a697 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 10 May 2024 15:24:29 +0200 Subject: [PATCH] Add support for hetzner csi --- doc/ProvsK3sBuild.md | 19 ++++++++++------- src/main/python/ddadevops/domain/provs_k3s.py | 21 ++++++++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/doc/ProvsK3sBuild.md b/doc/ProvsK3sBuild.md index 95aa5b8..b959dcc 100644 --- a/doc/ProvsK3sBuild.md +++ b/doc/ProvsK3sBuild.md @@ -13,14 +13,17 @@ classDiagram ## Input -| name | description | default | -| ----------------------------- | ----------------------------------------------------------------- | --------- | -| k3s_provision_user | the user used to provision k3s | "root" | -| k3s_letsencrypt_email | email address used for letsencrypt | | -| k3s_letsencrypt_endpoint | letsencrypt endpoint. Valid values are staging, prod | "staging" | -| k3s_app_filename_to_provision | an k8s manifest to apply imediately after k3s setup was sucessful | | -| k3s_enable_echo | provision the echo app on k3s. Valid values are true, false | "false" | -| k3s_provs_template | use a individual template for provs config | None | +| name | description | default | +| --------------------------------- | ----------------------------------------------------------------- | --------- | +| k3s_provision_user | the user used to provision k3s | "root" | +| k3s_letsencrypt_email | email address used for letsencrypt | | +| k3s_letsencrypt_endpoint | letsencrypt endpoint. Valid values are staging, prod | "staging" | +| k3s_app_filename_to_provision | an k8s manifest to apply imediately after k3s setup was sucessful | | +| k3s_enable_echo | provision the echo app on k3s. Valid values are true, false | "false" | +| k3s_provs_template | use a individual template for provs config | None | +| k3s_enable_hetzner_csi | enable hetzner csi | False | +| k3s_hetzner_api_token | hetzner_api_token | None | +| k3s_hetzner_encryption_passphrase | encryption passphrase for volumes | None | ### Credentials Mapping defaults diff --git a/src/main/python/ddadevops/domain/provs_k3s.py b/src/main/python/ddadevops/domain/provs_k3s.py index 4c95d38..5ecc0e6 100644 --- a/src/main/python/ddadevops/domain/provs_k3s.py +++ b/src/main/python/ddadevops/domain/provs_k3s.py @@ -20,6 +20,14 @@ CONFIG_CERTMANAGER = """certmanager: """ CONFIG_ECHO = """echo: $echo """ +CONFIG_HETZNER_CSI = """hetzner: + hcloudApiToken: + source: "PLAIN" # PLAIN, GOPASS or PROMPT + parameter: $hcloud_api # the api key for the hetzner cloud + encryptionPassphrase: + source: "PLAIN" # PLAIN, GOPASS or PROMPT + parameter: $encryption # the encryption passphrase for created volumes +""" class K3s(Validateable): @@ -28,8 +36,11 @@ class K3s(Validateable): self.k3s_letsencrypt_email = inp.get("k3s_letsencrypt_email") self.k3s_letsencrypt_endpoint = inp.get("k3s_letsencrypt_endpoint", "staging") self.k3s_app_filename_to_provision = inp.get("k3s_app_filename_to_provision") - self.k3s_enable_echo = inp.get("k3s_enable_echo", "false") + self.k3s_enable_echo = inp.get("k3s_enable_echo", None) self.k3s_provs_template = inp.get("k3s_provs_template", None) + self.k3s_enable_hetzner_csi = inp.get("k3s_enable_hetzner_csi", False) + self.k3s_hetzner_api_token = inp.get("k3s_hetzner_api_token", None) + self.k3s_hetzner_encryption_passphrase = inp.get("k3s_hetzner_encryption_passphrase", None) self.provision_dns: Optional[DnsRecord] = None def validate(self) -> List[str]: @@ -37,6 +48,9 @@ class K3s(Validateable): result += self.__validate_is_not_empty__("k3s_letsencrypt_email") result += self.__validate_is_not_empty__("k3s_letsencrypt_endpoint") result += self.__validate_is_not_empty__("k3s_app_filename_to_provision") + if self.k3s_enable_hetzner_csi: + result += self.__validate_is_not_empty__("k3s_hetzner_api_token") + result += self.__validate_is_not_empty__("k3s_hetzner_encryption_passphrase") if self.provision_dns: result += self.provision_dns.validate() return result @@ -61,6 +75,9 @@ class K3s(Validateable): substitutes["letsencrypt_endpoint"] = self.k3s_letsencrypt_endpoint if self.k3s_enable_echo is not None: substitutes["echo"] = self.k3s_enable_echo + if self.k3s_enable_hetzner_csi: + substitutes["hcloud_api"] = self.k3s_hetzner_api_token + substitutes["encryption"] = self.k3s_hetzner_encryption_passphrase return self.__config_template__().substitute(substitutes) def command(self, devops: Devops): @@ -89,4 +106,6 @@ class K3s(Validateable): template_text += CONFIG_IPV4 if self.provision_dns.ipv6 is not None: template_text += CONFIG_IPV6 + if self.k3s_enable_hetzner_csi: + template_text += CONFIG_HETZNER_CSI return Template(template_text)