Skip to content

Commit

Permalink
working tenant dev cluster deploy code
Browse files Browse the repository at this point in the history
  • Loading branch information
usrbinkat authored Sep 2, 2024
1 parent f42993a commit 8d689f5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
9 changes: 6 additions & 3 deletions docs/metal/optiplexprime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pulumi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
53 changes: 47 additions & 6 deletions pulumi/src/vm/talos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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,
Expand All @@ -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": {
Expand All @@ -67,7 +108,7 @@ def generate_talos_vm_pool_spec(
}
},
"spec": {
"running": True,
"running": running,
"template": {
"metadata": {
"labels": {
Expand Down Expand Up @@ -148,7 +189,7 @@ def generate_talos_vm_pool_spec(
},
"source": {
"registry": {
"url": image_name
"url": docker_image_address,
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion pulumi/stacks/Pulumi.optiplexprime.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8d689f5

Please sign in to comment.