provs config now is done by domain object
This commit is contained in:
parent
643602e5b7
commit
fc58f2e807
8 changed files with 53 additions and 48 deletions
|
@ -72,8 +72,8 @@ classDiagram
|
||||||
tag_and_push_release()
|
tag_and_push_release()
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProvsK3sMixin {
|
class ProvsK3sBuild {
|
||||||
// ProvsK3sMixin -> ProvsK3sBuild
|
// ProvsK3sBuild -> ProvsK3sBuild
|
||||||
def update_runtime_config(fqdn, ipv4, ipv6=None)
|
def update_runtime_config(fqdn, ipv4, ipv6=None)
|
||||||
write_provs_config()
|
write_provs_config()
|
||||||
provs_apply(dry_run=False)
|
provs_apply(dry_run=False)
|
||||||
|
@ -95,7 +95,7 @@ classDiagram
|
||||||
DevopsTerraformBuild <|-- DigitaloceanTerraformBuild
|
DevopsTerraformBuild <|-- DigitaloceanTerraformBuild
|
||||||
DevopsTerraformBuild <|--ExoscaleMixin
|
DevopsTerraformBuild <|--ExoscaleMixin
|
||||||
DevopsTerraformBuild <|--HetznerMixin
|
DevopsTerraformBuild <|--HetznerMixin
|
||||||
DevopsBuild <|-- ProvsK3sMixin
|
DevopsBuild <|-- ProvsK3sBuild
|
||||||
DigitaloceanTerraformBuild <|-- DigitaloceanBackendPropertiesMixin
|
DigitaloceanTerraformBuild <|-- DigitaloceanBackendPropertiesMixin
|
||||||
AwsBackendPropertiesMixin <|-- AwsMfaMixin
|
AwsBackendPropertiesMixin <|-- AwsMfaMixin
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ terraform, dda-pallet, aws & hetzner-cloud.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .python_util import execute
|
from .python_util import execute
|
||||||
from .provs_k3s_mixin import ProvsK3sMixin, add_provs_k3s_mixin_config
|
from .provs_k3s_build import ProvsK3sBuild, add_provs_k3s_mixin_config
|
||||||
from .aws_mfa_mixin import AwsMfaMixin, add_aws_mfa_mixin_config
|
from .aws_mfa_mixin import AwsMfaMixin, add_aws_mfa_mixin_config
|
||||||
from .aws_backend_properties_mixin import AwsBackendPropertiesMixin, add_aws_backend_properties_mixin_config
|
from .aws_backend_properties_mixin import AwsBackendPropertiesMixin, add_aws_backend_properties_mixin_config
|
||||||
from .c4k_build import C4kBuild, add_c4k_mixin_config
|
from .c4k_build import C4kBuild, add_c4k_mixin_config
|
||||||
|
|
|
@ -21,9 +21,9 @@ class C4k(Validateable):
|
||||||
self.c4k_grafana_cloud_password = inp.get('c4k_grafana_cloud_password')
|
self.c4k_grafana_cloud_password = inp.get('c4k_grafana_cloud_password')
|
||||||
self.dns_record: Optional[DnsRecord] = None
|
self.dns_record: Optional[DnsRecord] = None
|
||||||
|
|
||||||
# TODO: these functions should be located at TerraformBuild later on.
|
|
||||||
def update_runtime_config(self, dns_record: DnsRecord):
|
def update_runtime_config(self, dns_record: DnsRecord):
|
||||||
self.dns_record = dns_record
|
self.dns_record = dns_record
|
||||||
|
self.throw_if_invalid()
|
||||||
|
|
||||||
def validate(self) -> List[str]:
|
def validate(self) -> List[str]:
|
||||||
result = []
|
result = []
|
||||||
|
|
|
@ -21,18 +21,16 @@ CONFIG_CERTMANAGER = """certmanager:
|
||||||
CONFIG_ECHO = """echo: $echo
|
CONFIG_ECHO = """echo: $echo
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class K3s(Validateable):
|
class K3s(Validateable):
|
||||||
def __init__(self, inp: dict):
|
def __init__(self, inp: dict):
|
||||||
self.k3s_provision_user = inp.get("k3s_provision_user")
|
self.k3s_provision_user = inp.get("k3s_provision_user")
|
||||||
self.k3s_letsencrypt_email = inp.get("k3s_letsencrypt_email")
|
self.k3s_letsencrypt_email = inp.get("k3s_letsencrypt_email")
|
||||||
self.k3s_letsencrypt_endpoint = inp.get("k3s_letsencrypt_endpoint")
|
self.k3s_letsencrypt_endpoint = inp.get("k3s_letsencrypt_endpoint")
|
||||||
self.k3s_app_filename_to_provision = inp.get("k3s_app_filename_to_provision", "provs")
|
self.k3s_app_filename_to_provision = inp.get("k3s_app_filename_to_provision")
|
||||||
fqdn = inp.get("k3_fqdn")
|
self.k3s_enable_echo = inp.get("k3s_enable_echo", "false")
|
||||||
ipv4 = inp.get("k3_ipv4")
|
|
||||||
ipv6 = inp.get("k3_ipv6")
|
|
||||||
self.provision_dns = DnsRecord(fqdn, ipv4=ipv4, ipv6=ipv6)
|
|
||||||
self.k3s_enable_echo = inp.get("k3s_enable_echo", False)
|
|
||||||
self.k3s_provs_template = inp.get("k3s_provs_template", None)
|
self.k3s_provs_template = inp.get("k3s_provs_template", None)
|
||||||
|
self.provision_dns: Optional[DnsRecord] = None
|
||||||
|
|
||||||
def validate(self) -> List[str]:
|
def validate(self) -> List[str]:
|
||||||
result = []
|
result = []
|
||||||
|
@ -44,7 +42,29 @@ class K3s(Validateable):
|
||||||
result += self.provision_dns.validate()
|
result += self.provision_dns.validate()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def config_template(self) -> str:
|
def update_runtime_config(self, dns_record: DnsRecord):
|
||||||
|
self.provision_dns = dns_record
|
||||||
|
self.throw_if_invalid()
|
||||||
|
|
||||||
|
def provs_config(self) -> str:
|
||||||
|
if not self.provision_dns:
|
||||||
|
raise ValueError("provision_dns was not set.")
|
||||||
|
substitutes = {
|
||||||
|
"fqdn": self.provision_dns.fqdn,
|
||||||
|
}
|
||||||
|
if self.provision_dns.ipv4 is not None:
|
||||||
|
substitutes["ipv4"] = self.provision_dns.ipv4
|
||||||
|
if self.provision_dns.ipv6 is not None:
|
||||||
|
substitutes["ipv6"] = self.provision_dns.ipv6
|
||||||
|
if self.k3s_letsencrypt_email is not None:
|
||||||
|
substitutes["letsencrypt_email"] = self.k3s_letsencrypt_email
|
||||||
|
if self.k3s_letsencrypt_endpoint is not None:
|
||||||
|
substitutes["letsencrypt_endpoint"] = self.k3s_letsencrypt_endpoint
|
||||||
|
if self.k3s_enable_echo is not None:
|
||||||
|
substitutes["echo"] = self.k3s_enable_echo
|
||||||
|
return self.__config_template__().substitute(substitutes)
|
||||||
|
|
||||||
|
def __config_template__(self) -> Template:
|
||||||
template_text = self.k3s_provs_template
|
template_text = self.k3s_provs_template
|
||||||
if template_text is None:
|
if template_text is None:
|
||||||
template_text = CONFIG_BASE
|
template_text = CONFIG_BASE
|
||||||
|
@ -56,5 +76,4 @@ class K3s(Validateable):
|
||||||
template_text += CONFIG_IPV4
|
template_text += CONFIG_IPV4
|
||||||
if self.provision_dns.ipv6 is not None:
|
if self.provision_dns.ipv6 is not None:
|
||||||
template_text += CONFIG_IPV6
|
template_text += CONFIG_IPV6
|
||||||
return template_text
|
return Template(template_text)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
from string import Template
|
from string import Template
|
||||||
import deprecation
|
import deprecation
|
||||||
from .python_util import execute_live
|
from .python_util import execute_live
|
||||||
|
from .domain import DnsRecord
|
||||||
from .devops_build import DevopsBuild
|
from .devops_build import DevopsBuild
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_BASE = """
|
CONFIG_BASE = """
|
||||||
fqdn: $fqdn
|
fqdn: $fqdn
|
||||||
"""
|
"""
|
||||||
|
@ -42,7 +44,7 @@ def add_provs_k3s_mixin_config(config,
|
||||||
if ipv6 is not None:
|
if ipv6 is not None:
|
||||||
template_text += CONFIG_IPV6
|
template_text += CONFIG_IPV6
|
||||||
|
|
||||||
config.update({'ProvsK3sMixin':
|
config.update({'ProvsK3sBuild':
|
||||||
{'fqdn': fqdn,
|
{'fqdn': fqdn,
|
||||||
'provision_user': provision_user,
|
'provision_user': provision_user,
|
||||||
'ipv4': ipv4,
|
'ipv4': ipv4,
|
||||||
|
@ -55,7 +57,7 @@ def add_provs_k3s_mixin_config(config,
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
class ProvsK3sMixin(DevopsBuild):
|
class ProvsK3sBuild(DevopsBuild):
|
||||||
|
|
||||||
def __init__(self, project, config):
|
def __init__(self, project, config):
|
||||||
inp = config.copy()
|
inp = config.copy()
|
||||||
|
@ -70,33 +72,16 @@ class ProvsK3sMixin(DevopsBuild):
|
||||||
if BuildType.K3S not in devops.specialized_builds:
|
if BuildType.K3S not in devops.specialized_builds:
|
||||||
raise ValueError("K3SBuild requires BuildType.K3S")
|
raise ValueError("K3SBuild requires BuildType.K3S")
|
||||||
|
|
||||||
def update_runtime_config(self, fqdn, ipv4, ipv6=None):
|
def update_runtime_config(self, dns_record: DnsRecord):
|
||||||
self.fqdn = fqdn
|
devops = self.devops_repo.get_devops(self.project)
|
||||||
self.put('fqdn', fqdn)
|
devops.specialized_builds[BuildType.K3S].update_runtime_config(dns_record)
|
||||||
self.ipv4 = ipv4
|
self.devops_repo.set_devops(self.project, devops)
|
||||||
self.put('ipv4', ipv4)
|
|
||||||
self.ipv6 = ipv6
|
|
||||||
self.put('ipv6', ipv6)
|
|
||||||
template_text = self.k3s_config_template_text
|
|
||||||
if ipv4 is not None:
|
|
||||||
template_text += CONFIG_IPV4
|
|
||||||
if ipv6 is not None:
|
|
||||||
template_text += CONFIG_IPV6
|
|
||||||
self.k3s_config_template_text = template_text
|
|
||||||
self.put('k3s_config_template_text', template_text)
|
|
||||||
template = Template(template_text)
|
|
||||||
self.k3s_config_template = template
|
|
||||||
self.put('k3s_config_template', template)
|
|
||||||
|
|
||||||
def write_provs_config(self):
|
def write_provs_config(self):
|
||||||
substitutes = self.get_keys(['fqdn', 'ipv4', 'ipv6', 'letsencrypt_email',
|
devops = self.devops_repo.get_devops(self.project)
|
||||||
'letsencrypt_endpoint', 'echo'])
|
k3s = devops.specialized_builds[BuildType.K3S]
|
||||||
with open(self.build_path() + '/out_k3sServerConfig.yaml', "w", encoding="utf-8") as output_file:
|
with open(self.build_path() + '/out_k3sServerConfig.yaml', "w", encoding="utf-8") as output_file:
|
||||||
output_file.write(self.k3s_config_template.substitute(substitutes))
|
output_file.write(k3s.provs_config())
|
||||||
|
|
||||||
@deprecation.deprecated(deprecated_in="3.1")
|
|
||||||
def provs_server(self, dry_run=False):
|
|
||||||
self.provs_apply(dry_run)
|
|
||||||
|
|
||||||
def provs_apply(self, dry_run=False):
|
def provs_apply(self, dry_run=False):
|
||||||
cmd = ['provs-server.jar', 'k3s', self.provision_user + '@' + self.fqdn, '-c',
|
cmd = ['provs-server.jar', 'k3s', self.provision_user + '@' + self.fqdn, '-c',
|
|
@ -24,9 +24,6 @@ def devops_config(overrides: dict) -> dict:
|
||||||
"k3s_letsencrypt_endpoint": "k3s_letsencrypt_endpoint",
|
"k3s_letsencrypt_endpoint": "k3s_letsencrypt_endpoint",
|
||||||
"k3s_enable_echo": False,
|
"k3s_enable_echo": False,
|
||||||
"k3s_app_filename_to_provision": "provs",
|
"k3s_app_filename_to_provision": "provs",
|
||||||
"k3_fqdn": "example.org",
|
|
||||||
"k3_ipv4": "1.2.3.4",
|
|
||||||
"k3_ipv6": "::1",
|
|
||||||
"release_type": "NONE",
|
"release_type": "NONE",
|
||||||
"release_main_branch": "main",
|
"release_main_branch": "main",
|
||||||
"release_current_branch": "my_feature",
|
"release_current_branch": "my_feature",
|
||||||
|
|
|
@ -20,7 +20,7 @@ def test_c4k_should_calculate_config():
|
||||||
|
|
||||||
sut = build_devops({})
|
sut = build_devops({})
|
||||||
c4k = sut.specialized_builds[BuildType.C4K]
|
c4k = sut.specialized_builds[BuildType.C4K]
|
||||||
c4k.update_runtime_config(DnsRecord("fqdn"))
|
c4k.update_runtime_config(DnsRecord("fqdn", ipv6="::1"))
|
||||||
assert {
|
assert {
|
||||||
"fqdn": "fqdn",
|
"fqdn": "fqdn",
|
||||||
"mon-cfg": {
|
"mon-cfg": {
|
||||||
|
@ -36,7 +36,7 @@ def test_c4k_should_calculate_config():
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
c4k = sut.specialized_builds[BuildType.C4K]
|
c4k = sut.specialized_builds[BuildType.C4K]
|
||||||
c4k.update_runtime_config(DnsRecord("fqdn"))
|
c4k.update_runtime_config(DnsRecord("fqdn", ipv6="::1"))
|
||||||
assert {
|
assert {
|
||||||
"test": "test",
|
"test": "test",
|
||||||
"fqdn": "fqdn",
|
"fqdn": "fqdn",
|
||||||
|
|
|
@ -13,6 +13,10 @@ def test_creation():
|
||||||
assert BuildType.K3S in sut.specialized_builds
|
assert BuildType.K3S in sut.specialized_builds
|
||||||
assert sut.specialized_builds[BuildType.K3S]
|
assert sut.specialized_builds[BuildType.K3S]
|
||||||
|
|
||||||
def test_should_calculate_template():
|
def test_should_calculate_provs_config():
|
||||||
sut = build_devops({}).specialized_builds[BuildType.K3S]
|
sut = build_devops({}).specialized_builds[BuildType.K3S]
|
||||||
assert "fqdn:" in sut.config_template()
|
sut.update_runtime_config(
|
||||||
|
DnsRecord("example.org", ipv6="::1")
|
||||||
|
)
|
||||||
|
assert "fqdn:" in sut.provs_config()
|
||||||
|
assert not "$" in sut.provs_config()
|
||||||
|
|
Loading…
Reference in a new issue