Skip to content

Commit

Permalink
fix: move mhc to clusterclass
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaser committed Nov 10, 2022
1 parent 79869c8 commit c43ae93
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 119 deletions.
6 changes: 3 additions & 3 deletions magnum_cluster_api/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import keystoneauth1
from magnum import objects as magnum_objects
from magnum.drivers.common import driver
from magnum.drivers.common import driver, k8s_monitor

from magnum_cluster_api import clients, monitor, objects, resources, utils
from magnum_cluster_api import clients, objects, resources, utils


class BaseDriver(driver.Driver):
Expand Down Expand Up @@ -244,7 +244,7 @@ def delete_nodegroup(self, context, cluster, nodegroup):
)

def get_monitor(self, context, cluster):
return monitor.ClusterApiMonitor(context, cluster)
return k8s_monitor.K8sMonitor(context, cluster)

# def rotate_ca_certificate(self, context, cluster):
# raise exception.NotSupported(
Expand Down
61 changes: 0 additions & 61 deletions magnum_cluster_api/monitor.py

This file was deleted.

6 changes: 0 additions & 6 deletions magnum_cluster_api/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class Machine(pykube.objects.NamespacedAPIObject):
kind = "Machine"


class MachineHealthCheck(pykube.objects.NamespacedAPIObject):
version = "cluster.x-k8s.io/v1beta1"
endpoint = "machinehealthchecks"
kind = "MachineHealthCheck"


class OpenStackClusterTemplate(pykube.objects.NamespacedAPIObject):
version = "infrastructure.cluster.x-k8s.io/v1alpha6"
endpoint = "openstackclustertemplates"
Expand Down
89 changes: 40 additions & 49 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,49 +329,6 @@ def get_object(self) -> pykube.Secret:
)


class MachineHealthCheck(ClusterBase):
def get_object(self) -> objects.MachineHealthCheck:
return objects.MachineHealthCheck(
self.api,
{
"apiVersion": objects.MachineHealthCheck.version,
"kind": objects.MachineHealthCheck.kind,
"metadata": {
"name": utils.get_or_generate_cluster_api_name(
self.api, self.cluster
),
"namespace": "magnum-system",
"labels": self.labels,
},
"spec": {
"clusterName": utils.get_or_generate_cluster_api_name(
self.api, self.cluster
),
"maxUnhealthy": "40%",
"selector": {
"matchLabels": {
"cluster.x-k8s.io/cluster-name": utils.get_or_generate_cluster_api_name(
self.api, self.cluster
),
}
},
"unhealthyConditions": [
{
"type": "Ready",
"status": "False",
"timeout": "300s",
},
{
"type": "Ready",
"status": "Unknown",
"timeout": "300s",
},
],
},
},
)


class KubeadmControlPlaneTemplate(Base):
def get_object(self) -> objects.KubeadmControlPlaneTemplate:
manifests_path = pkg_resources.resource_filename(
Expand Down Expand Up @@ -535,6 +492,21 @@ def get_object(self) -> objects.ClusterClass:
"name": CLUSTER_CLASS_NAME,
},
},
"machineHealthCheck": {
"maxUnhealthy": "33%",
"unhealthyConditions": [
{
"type": "Ready",
"status": "False",
"timeout": "5m",
},
{
"type": "Ready",
"status": "Unknown",
"timeout": "5m",
},
],
},
},
"infrastructure": {
"ref": {
Expand Down Expand Up @@ -563,6 +535,21 @@ def get_object(self) -> objects.ClusterClass:
}
},
},
"machineHealthCheck": {
"maxUnhealthy": "33%",
"unhealthyConditions": [
{
"type": "Ready",
"status": "False",
"timeout": "5m",
},
{
"type": "Ready",
"status": "Unknown",
"timeout": "5m",
},
],
},
}
],
},
Expand Down Expand Up @@ -1115,6 +1102,11 @@ def get_object(self) -> objects.Cluster:
),
"controlPlane": {
"replicas": self.cluster.master_count,
"machineHealthCheck": {
"enable": utils.get_cluster_label_as_bool(
self.cluster, "auto_healing_enabled", True
)
},
},
"workers": {
"machineDeployments": [
Expand All @@ -1125,6 +1117,11 @@ def get_object(self) -> objects.Cluster:
"failureDomain": utils.get_cluster_label(
self.cluster, "availability_zone", ""
),
"machineHealthCheck": {
"enable": utils.get_cluster_label_as_bool(
self.cluster, "auto_healing_enabled", True
)
},
"variables": {
"overrides": [
{
Expand Down Expand Up @@ -1317,12 +1314,6 @@ def apply_cluster_from_magnum_cluster(
ClusterResourceSet(api, cluster).apply()
Cluster(context, api, cluster).apply()

# TODO: refactor into Cluster topology
if utils.get_cluster_label_as_bool(cluster, "auto_healing_enabled", True):
MachineHealthCheck(api, cluster).apply()
else:
MachineHealthCheck(api, cluster).delete()


def get_kubeadm_control_plane(
api: pykube.HTTPClient, cluster: magnum_objects.Cluster
Expand Down

0 comments on commit c43ae93

Please sign in to comment.