provs_k3s now migth work
This commit is contained in:
parent
fc58f2e807
commit
0e28cbd52d
5 changed files with 51 additions and 83 deletions
|
@ -5,14 +5,14 @@ terraform, dda-pallet, aws & hetzner-cloud.
|
|||
"""
|
||||
|
||||
from .python_util import execute
|
||||
from .provs_k3s_build import ProvsK3sBuild, add_provs_k3s_mixin_config
|
||||
from .provs_k3s_build import ProvsK3sBuild
|
||||
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 .c4k_build import C4kBuild, add_c4k_mixin_config
|
||||
from .c4k_build import C4kBuild
|
||||
from .digitalocean_backend_properties_mixin import DigitaloceanBackendPropertiesMixin, add_digitalocean_backend_properties_mixin_config
|
||||
from .digitalocean_terraform_build import DigitaloceanTerraformBuild, create_digitalocean_terraform_build_config
|
||||
from .hetzner_mixin import HetznerMixin, add_hetzner_mixin_config
|
||||
from .devops_image_build import DevopsImageBuild, create_devops_docker_build_config
|
||||
from .devops_image_build import DevopsImageBuild
|
||||
from .devops_terraform_build import DevopsTerraformBuild, create_devops_terraform_build_config
|
||||
from .devops_build import DevopsBuild, create_devops_build_config, get_devops_build
|
||||
from .credential import gopass_password_from_path, gopass_field_from_path
|
||||
|
|
|
@ -64,6 +64,20 @@ class K3s(Validateable):
|
|||
substitutes["echo"] = self.k3s_enable_echo
|
||||
return self.__config_template__().substitute(substitutes)
|
||||
|
||||
def command(self, devops: Devops):
|
||||
if not self.provision_dns:
|
||||
raise ValueError("provision_dns was not set.")
|
||||
cmd = [
|
||||
"provs-server.jar",
|
||||
"k3s",
|
||||
f"{self.k3s_provision_user}@{self.provision_dns.fqdn}",
|
||||
"-c",
|
||||
f"{devops.build_path()}/out_k3sServerConfig.yaml",
|
||||
"-a",
|
||||
f"{devops.build_path()}/{self.k3s_app_filename_to_provision}",
|
||||
]
|
||||
return " ".join(cmd)
|
||||
|
||||
def __config_template__(self) -> Template:
|
||||
template_text = self.k3s_provs_template
|
||||
if template_text is None:
|
||||
|
|
|
@ -1,73 +1,18 @@
|
|||
from string import Template
|
||||
import deprecation
|
||||
from .python_util import execute_live
|
||||
from .domain import DnsRecord
|
||||
from .infrastructure import ExecutionApi
|
||||
from .devops_build import DevopsBuild
|
||||
|
||||
|
||||
|
||||
CONFIG_BASE = """
|
||||
fqdn: $fqdn
|
||||
"""
|
||||
CONFIG_IPV4 = """node:
|
||||
ipv4: $ipv4
|
||||
"""
|
||||
CONFIG_IPV6 = """ ipv6: $ipv6
|
||||
"""
|
||||
CONFIG_CERTMANAGER = """certmanager:
|
||||
email: $letsencrypt_email
|
||||
letsencryptEndpoint: $letsencrypt_endpoint
|
||||
"""
|
||||
CONFIG_ECHO = """echo: $echo
|
||||
"""
|
||||
|
||||
|
||||
def add_provs_k3s_mixin_config(config,
|
||||
provision_user='root',
|
||||
echo=None,
|
||||
k3s_config_template=None,
|
||||
letsencrypt_email=None,
|
||||
letsencrypt_endpoint=None,
|
||||
fqdn=None,
|
||||
ipv4=None,
|
||||
ipv6=None,
|
||||
app_filename_to_provision=None):
|
||||
template_text = k3s_config_template
|
||||
if template_text is None:
|
||||
template_text = CONFIG_BASE
|
||||
if letsencrypt_endpoint is not None:
|
||||
template_text += CONFIG_CERTMANAGER
|
||||
if echo is not None:
|
||||
template_text += CONFIG_ECHO
|
||||
if ipv4 is not None:
|
||||
template_text += CONFIG_IPV4
|
||||
if ipv6 is not None:
|
||||
template_text += CONFIG_IPV6
|
||||
|
||||
config.update({'ProvsK3sBuild':
|
||||
{'fqdn': fqdn,
|
||||
'provision_user': provision_user,
|
||||
'ipv4': ipv4,
|
||||
'ipv6': ipv6,
|
||||
'letsencrypt_email': letsencrypt_email,
|
||||
'letsencrypt_endpoint': letsencrypt_endpoint,
|
||||
'echo': echo,
|
||||
'k3s_config_template': template_text,
|
||||
'app_filename_to_provision': app_filename_to_provision}})
|
||||
return config
|
||||
|
||||
|
||||
class ProvsK3sBuild(DevopsBuild):
|
||||
|
||||
def __init__(self, project, config):
|
||||
inp = config.copy()
|
||||
inp["name"]=project.name
|
||||
inp["module"]=config.get("module")
|
||||
inp["stage"]=config.get("stage")
|
||||
inp["project_root_path"]=config.get("project_root_path")
|
||||
inp["build_types"]=config.get("build_types", [])
|
||||
inp["mixin_types"]=config.get("mixin_types", [])
|
||||
inp["name"] = project.name
|
||||
inp["module"] = config.get("module")
|
||||
inp["stage"] = config.get("stage")
|
||||
inp["project_root_path"] = config.get("project_root_path")
|
||||
inp["build_types"] = config.get("build_types", [])
|
||||
inp["mixin_types"] = config.get("mixin_types", [])
|
||||
super().__init__(project, inp)
|
||||
self.execution_api = ExecutionApi()
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
if BuildType.K3S not in devops.specialized_builds:
|
||||
raise ValueError("K3SBuild requires BuildType.K3S")
|
||||
|
@ -80,14 +25,12 @@ class ProvsK3sBuild(DevopsBuild):
|
|||
def write_provs_config(self):
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
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(k3s.provs_config())
|
||||
|
||||
def provs_apply(self, dry_run=False):
|
||||
cmd = ['provs-server.jar', 'k3s', self.provision_user + '@' + self.fqdn, '-c',
|
||||
self.build_path() + '/out_k3sServerConfig.yaml',
|
||||
'-a', self.build_path() + '/' + self.app_filename_to_provision]
|
||||
if dry_run:
|
||||
print(" ".join(cmd))
|
||||
else:
|
||||
execute_live(cmd)
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
k3s = devops.specialized_builds[BuildType.K3S]
|
||||
self.execution_api.execute_live(k3s.command(devops), dry_run=dry_run)
|
||||
|
|
|
@ -23,7 +23,7 @@ def devops_config(overrides: dict) -> dict:
|
|||
"k3s_letsencrypt_email": "k3s_letsencrypt_email",
|
||||
"k3s_letsencrypt_endpoint": "k3s_letsencrypt_endpoint",
|
||||
"k3s_enable_echo": False,
|
||||
"k3s_app_filename_to_provision": "provs",
|
||||
"k3s_app_filename_to_provision": "k3s_app.yaml",
|
||||
"release_type": "NONE",
|
||||
"release_main_branch": "main",
|
||||
"release_current_branch": "my_feature",
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import pytest
|
||||
from pathlib import Path
|
||||
from src.main.python.ddadevops.domain import (
|
||||
DnsRecord,
|
||||
BuildType,
|
||||
K3s
|
||||
)
|
||||
from src.main.python.ddadevops.domain import DnsRecord, BuildType, K3s
|
||||
from .helper import build_devops
|
||||
|
||||
|
||||
|
@ -13,10 +9,25 @@ def test_creation():
|
|||
assert BuildType.K3S in sut.specialized_builds
|
||||
assert sut.specialized_builds[BuildType.K3S]
|
||||
|
||||
|
||||
def test_should_calculate_provs_config():
|
||||
sut = build_devops({}).specialized_builds[BuildType.K3S]
|
||||
sut.update_runtime_config(
|
||||
DnsRecord("example.org", ipv6="::1")
|
||||
)
|
||||
sut.update_runtime_config(DnsRecord("example.org", ipv6="::1"))
|
||||
assert "fqdn:" in sut.provs_config()
|
||||
assert not "$" in sut.provs_config()
|
||||
|
||||
|
||||
def test_should_calculate_command():
|
||||
devops = build_devops({})
|
||||
sut = devops.specialized_builds[BuildType.K3S]
|
||||
sut.update_runtime_config(DnsRecord("example.org", ipv6="::1"))
|
||||
assert (
|
||||
"provs-server.jar "
|
||||
+ "k3s "
|
||||
+ "k3s_provision_user@example.org "
|
||||
+ "-c "
|
||||
+ "root_path/target/name/module/out_k3sServerConfig.yaml "
|
||||
+ "-a "
|
||||
+ "root_path/target/name/module/k3s_app.yaml"
|
||||
== sut.command(devops)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue