Skip to content

Commit

Permalink
Remove microk8s from sunbeam
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesJP committed Dec 10, 2024
1 parent 358d374 commit 4c42656
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 1,098 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/test-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ on:
- single
- multi
k8s-provider:
description: Select k8s provider
description: Specify k8s provider
required: true
default: microk8s
type: choice
options:
- microk8s
- k8s
default: k8s
type: string

jobs:
functional-test:
Expand Down Expand Up @@ -133,7 +130,7 @@ jobs:
if: always()
run: |
mkdir -p logs
if [ ${{ inputs.k8s-provider }} == "k8s" ]; then kubectl="k8s kubectl"; else kubectl="microk8s.kubectl"; fi
kubectl="k8s kubectl"
cp -rf $HOME/snap/openstack/common/logs/*.log logs/
models=$(juju models --format json | jq -r .models[].name)
for model in $models;
Expand Down
54 changes: 0 additions & 54 deletions cloud/etc/deploy-microk8s/main.tf

This file was deleted.

64 changes: 0 additions & 64 deletions cloud/etc/deploy-microk8s/variables.tf

This file was deleted.

28 changes: 5 additions & 23 deletions sunbeam-python/sunbeam/core/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@
from lightkube.models.meta_v1 import ObjectMeta
from lightkube.resources.core_v1 import Node, PersistentVolumeClaim, Pod
from lightkube.types import CascadeType
from snaphelpers import Snap
from snaphelpers import Snap # noqa: F401 - required for test mocks

from sunbeam.core.common import SunbeamException

LOG = logging.getLogger(__name__)

# --- Microk8s specific
MICROK8S_KUBECONFIG_KEY = "Microk8sConfig"
MICROK8S_DEFAULT_STORAGECLASS = "microk8s-hostpath"

# --- K8s specific
METALLB_ANNOTATION = "metallb.universe.tf/loadBalancerIPs"
K8S_DEFAULT_STORAGECLASS = "csi-rawfile-default"
K8S_KUBECONFIG_KEY = "K8SKubeConfig"
SERVICE_LB_ANNOTATION = "io.cilium/lb-ipam-ips"
Expand All @@ -44,7 +41,6 @@
METALLB_ADDRESS_POOL_ANNOTATION = "metallb.universe.tf/address-pool"
METALLB_ALLOCATED_POOL_ANNOTATION = "metallb.universe.tf/ip-allocated-from-pool"

SUPPORTED_K8S_PROVIDERS = ["k8s", "microk8s"]
CREDENTIAL_SUFFIX = "-creds"
K8S_CLOUD_SUFFIX = "-k8s"
LOADBALANCER_QUESTION_DESCRIPTION = """\
Expand All @@ -70,13 +66,7 @@ class K8SHelper:
@classmethod
def get_provider(cls) -> str:
"""Return k8s provider from snap settings."""
provider = Snap().config.get("k8s.provider")
if provider not in SUPPORTED_K8S_PROVIDERS:
raise SunbeamException(
f"k8s provider should be one of {SUPPORTED_K8S_PROVIDERS}"
)

return provider
return "k8s"

@classmethod
def get_cloud(cls, deployment_name: str) -> str:
Expand All @@ -86,20 +76,12 @@ def get_cloud(cls, deployment_name: str) -> str:
@classmethod
def get_default_storageclass(cls) -> str:
"""Return storageclass matching provider."""
match cls.get_provider():
case "k8s":
return K8S_DEFAULT_STORAGECLASS
case _:
return MICROK8S_DEFAULT_STORAGECLASS
return K8S_DEFAULT_STORAGECLASS

@classmethod
def get_kubeconfig_key(cls) -> str:
"""Return kubeconfig key matching provider."""
match cls.get_provider():
case "k8s":
return K8S_KUBECONFIG_KEY
case _:
return MICROK8S_KUBECONFIG_KEY
return K8S_KUBECONFIG_KEY

@classmethod
def get_loadbalancer_ip_annotation(cls) -> str:
Expand Down
110 changes: 26 additions & 84 deletions sunbeam-python/sunbeam/provider/local/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@
DeployMicrocephApplicationStep,
RemoveMicrocephUnitsStep,
)
from sunbeam.steps.microk8s import (
AddMicrok8sCloudStep,
AddMicrok8sCredentialStep,
AddMicrok8sUnitsStep,
DeployMicrok8sApplicationStep,
RemoveMicrok8sUnitsStep,
StoreMicrok8sConfigStep,
)
from sunbeam.steps.openstack import (
DeployControlPlaneStep,
OpenStackPatchLoadBalancerServicesIPStep,
Expand Down Expand Up @@ -294,7 +286,6 @@ def bootstrap(
pretty_roles = ", ".join(role.name.lower() for role in roles)
LOG.debug(f"Bootstrap node: roles {roles_str}")

k8s_provider = snap.config.get("k8s.provider")
juju_bootstrap_args = manifest.core.software.juju.bootstrap_args
data_location = snap.paths.user_data

Expand Down Expand Up @@ -539,52 +530,26 @@ def bootstrap(
)
)

if k8s_provider == "k8s":
k8s_tfhelper = deployment.get_tfhelper("k8s-plan")
plan4.append(TerraformInitStep(k8s_tfhelper))
plan4.append(
DeployK8SApplicationStep(
deployment,
client,
k8s_tfhelper,
jhelper,
manifest,
deployment.openstack_machines_model,
accept_defaults=accept_defaults,
)
)
plan4.append(
AddK8SUnitsStep(client, fqdn, jhelper, deployment.openstack_machines_model)
)
plan4.append(
StoreK8SKubeConfigStep(client, jhelper, deployment.openstack_machines_model)
)
plan4.append(AddK8SCloudStep(deployment, jhelper))
else:
k8s_tfhelper = deployment.get_tfhelper("microk8s-plan")
plan4.append(TerraformInitStep(k8s_tfhelper))
plan4.append(
DeployMicrok8sApplicationStep(
deployment,
client,
k8s_tfhelper,
jhelper,
manifest,
deployment.openstack_machines_model,
accept_defaults=accept_defaults,
)
)
plan4.append(
AddMicrok8sUnitsStep(
client, fqdn, jhelper, deployment.openstack_machines_model
)
)
plan4.append(
StoreMicrok8sConfigStep(
client, jhelper, deployment.openstack_machines_model
)
k8s_tfhelper = deployment.get_tfhelper("k8s-plan")
plan4.append(TerraformInitStep(k8s_tfhelper))
plan4.append(
DeployK8SApplicationStep(
deployment,
client,
k8s_tfhelper,
jhelper,
manifest,
deployment.openstack_machines_model,
accept_defaults=accept_defaults,
)
plan4.append(AddMicrok8sCloudStep(deployment, jhelper))
)
plan4.append(
AddK8SUnitsStep(client, fqdn, jhelper, deployment.openstack_machines_model)
)
plan4.append(
StoreK8SKubeConfigStep(client, jhelper, deployment.openstack_machines_model)
)
plan4.append(AddK8SCloudStep(deployment, jhelper))

# Deploy Microceph application during bootstrap irrespective of node role.
microceph_tfhelper = deployment.get_tfhelper("microceph-plan")
Expand Down Expand Up @@ -820,8 +785,6 @@ def join(
pretty_roles = ", ".join(role_.name.lower() for role_ in roles)
LOG.debug(f"Node joining the cluster with roles: {pretty_roles}")

k8s_provider = Snap().config.get("k8s.provider")

preflight_checks: list[Check] = []
preflight_checks.append(SystemRequirementsCheck())
preflight_checks.append(JujuSnapCheck())
Expand Down Expand Up @@ -906,20 +869,10 @@ def join(
)

if is_control_node:
if k8s_provider == "k8s":
plan4.append(
AddK8SUnitsStep(
client, name, jhelper, deployment.openstack_machines_model
)
)
plan4.append(AddK8SCredentialStep(deployment, jhelper))
else:
plan4.append(
AddMicrok8sUnitsStep(
client, name, jhelper, deployment.openstack_machines_model
)
)
plan4.append(AddMicrok8sCredentialStep(deployment, jhelper))
plan4.append(
AddK8SUnitsStep(client, name, jhelper, deployment.openstack_machines_model)
)
plan4.append(AddK8SCredentialStep(deployment, jhelper))

if is_storage_node:
plan4.append(
Expand Down Expand Up @@ -1004,8 +957,6 @@ def remove(ctx: click.Context, name: str, force: bool, show_hints: bool) -> None
client = deployment.get_client()
jhelper = JujuHelper(deployment.get_connected_controller())

k8s_provider = Snap().config.get("k8s.provider")

preflight_checks = [DaemonGroupCheck()]
run_preflight_checks(preflight_checks, console)

Expand All @@ -1016,18 +967,9 @@ def remove(ctx: click.Context, name: str, force: bool, show_hints: bool) -> None
),
]

if k8s_provider == "k8s":
plan.append(
RemoveK8SUnitsStep(
client, name, jhelper, deployment.openstack_machines_model
)
)
else:
plan.append(
RemoveMicrok8sUnitsStep(
client, name, jhelper, deployment.openstack_machines_model
)
)
plan.append(
RemoveK8SUnitsStep(client, name, jhelper, deployment.openstack_machines_model)
)

plan.extend(
[
Expand Down
Loading

0 comments on commit 4c42656

Please sign in to comment.