From 8d689f584e701c8e136950621a70319d897b2aa0 Mon Sep 17 00:00:00 2001 From: Kat Morgan Date: Mon, 2 Sep 2024 15:32:43 +0000 Subject: [PATCH] working tenant dev cluster deploy code --- docs/metal/optiplexprime/README.md | 9 +++-- pulumi/__main__.py | 9 +++-- pulumi/src/vm/talos.py | 53 ++++++++++++++++++++++--- pulumi/stacks/Pulumi.optiplexprime.yaml | 8 +++- 4 files changed, 65 insertions(+), 14 deletions(-) diff --git a/docs/metal/optiplexprime/README.md b/docs/metal/optiplexprime/README.md index 559c5f6..b53b8e3 100644 --- a/docs/metal/optiplexprime/README.md +++ b/docs/metal/optiplexprime/README.md @@ -34,11 +34,14 @@ d. Verify connection to Omni Console > Machines # Login pulumi login -# Select the correct organization and project stack -pulumi stack select --create usrbinkat/kargo/optiplexprime - # Init Pulumi ESC Emvironment for local config and env eval $(pulumi env open --format=shell optiplexprime) + +# create the organization and project stack +pulumi stack select --create usrbinkat/kargo/optiplexprime + +# or select the stack +pulumi stack select usrbinkat/kargo/optiplexprime ``` 2. Omni CLI Login diff --git a/pulumi/__main__.py b/pulumi/__main__.py index 42238b9..636e837 100644 --- a/pulumi/__main__.py +++ b/pulumi/__main__.py @@ -75,7 +75,7 @@ def get_module_config(module_name): config_kubernetes_dashboard, kubernetes_dashboard_enabled = get_module_config('kubernetes_dashboard') config_kubevirt_manager, kubevirt_manager_enabled = get_module_config('kubevirt_manager') config_vm, vm_enabled = get_module_config('vm') -config_talos_controlplane, talos_controlplane_enabled = get_module_config('talos_controlplane') +config_talos_controlplane, talos_controlplane_enabled = get_module_config('talos') ################################################################################## ## Get the Kubernetes API endpoint IP @@ -521,9 +521,9 @@ def run_talos_controlplane(): if talos_controlplane_enabled: # Set the number of replicas based on Pulumi config values either "ha" or "single" - if config_talos_controlplane.get('replicas') == "ha": + if config_talos_controlplane.get('controlplane') == "ha": config_talos_controlplane_replicas = 3 - elif config_talos_controlplane.get('replicas') == "single": + elif config_talos_controlplane.get('controlplane') == "single": config_talos_controlplane_replicas = 1 else: config_talos_controlplane_replicas = 1 @@ -538,7 +538,8 @@ def run_talos_controlplane(): "empty_disk_size": "4Gi", "image_name": "docker.io/containercraft/talos:1.7.6", "network_name": "br0", - "vm_pool_name": "talos-controlplane", + "vm_pool_name": "kargo-dev", + "workers": 0, } # Merge the default values with the existing config_talos_controlplane values diff --git a/pulumi/src/vm/talos.py b/pulumi/src/vm/talos.py index 0683071..50efa7e 100644 --- a/pulumi/src/vm/talos.py +++ b/pulumi/src/vm/talos.py @@ -6,7 +6,44 @@ def deploy_talos_controlplane( k8s_provider: k8s.Provider, depends_on: list = [] ): + # Generate the VirtualMachinePool spec using the provided config + vm_pool_spec = generate_talos_vm_pool_spec( + vm_pool_name=config_vm["vm_pool_name"], + namespace=config_vm["namespace"], + replicas=config_vm["replicas"], + cpu_cores=config_vm["cpu_cores"], + memory_size=config_vm["memory_size"], + root_disk_size=config_vm["root_disk_size"], + empty_disk_size=config_vm["empty_disk_size"], + image_name=config_vm["image_name"], + network_name=config_vm["network_name"], + running=config_vm["running"] + ) + # Create the VirtualMachinePool resource + vm_pool_name=f"""{config_vm["vm_pool_name"]}-controlplane""" + vm_pool = k8s.apiextensions.CustomResource( + vm_pool_name, + api_version="pool.kubevirt.io/v1alpha1", + kind="VirtualMachinePool", + metadata=k8s.meta.v1.ObjectMetaArgs( + name=vm_pool_name, + namespace=config_vm["namespace"], + ), + spec=vm_pool_spec, + opts=pulumi.ResourceOptions( + provider=k8s_provider, + depends_on=depends_on + ) + ) + + return vm_pool + +def deploy_talos_workers( + config_vm, + k8s_provider: k8s.Provider, + depends_on: list = [] + ): # Generate the VirtualMachinePool spec using the provided config vm_pool_spec = generate_talos_vm_pool_spec( vm_pool_name=config_vm["vm_pool_name"], @@ -17,16 +54,18 @@ def deploy_talos_controlplane( root_disk_size=config_vm["root_disk_size"], empty_disk_size=config_vm["empty_disk_size"], image_name=config_vm["image_name"], - network_name=config_vm["network_name"] + network_name=config_vm["network_name"], + running=config_vm["running"] ) # Create the VirtualMachinePool resource + vm_pool_name=f"""{config_vm["vm_pool_name"]}-workers""" vm_pool = k8s.apiextensions.CustomResource( - config_vm["vm_pool_name"], + vm_pool_name, api_version="pool.kubevirt.io/v1alpha1", kind="VirtualMachinePool", metadata=k8s.meta.v1.ObjectMetaArgs( - name=config_vm["vm_pool_name"], + name=vm_pool_name, namespace=config_vm["namespace"], ), spec=vm_pool_spec, @@ -47,12 +86,14 @@ def generate_talos_vm_pool_spec( root_disk_size: str, empty_disk_size: str, image_name: str, - network_name: str + network_name: str, + running: bool ) -> dict: """ Generate the VirtualMachinePool spec for Talos VMs. This function can be used for both control plane and worker node VM pools. """ + docker_image_address = f"docker://{image_name}" return { "replicas": replicas, "selector": { @@ -67,7 +108,7 @@ def generate_talos_vm_pool_spec( } }, "spec": { - "running": True, + "running": running, "template": { "metadata": { "labels": { @@ -148,7 +189,7 @@ def generate_talos_vm_pool_spec( }, "source": { "registry": { - "url": image_name + "url": docker_image_address, } } } diff --git a/pulumi/stacks/Pulumi.optiplexprime.yaml b/pulumi/stacks/Pulumi.optiplexprime.yaml index dcdad5d..4d023fe 100644 --- a/pulumi/stacks/Pulumi.optiplexprime.yaml +++ b/pulumi/stacks/Pulumi.optiplexprime.yaml @@ -1,5 +1,11 @@ config: kargo:kubernetes: context: usrbinkat-optiplexprime - kargo:vm: + kargo:talos: + controlplane: ha enabled: true + image: docker.io/containercraft/omni + running: true + workers: 1 + kargo:vm: + enabled: false