Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Allow customisation of healthcheck. (#23)
Browse files Browse the repository at this point in the history
- Update default healthCheck value in tests
- Add test for disabling healthCheck
- Add autospec=true to all cluster tests to improve matching.
- Change helm values dict comparison to assertDictEqual for better output.
  • Loading branch information
dalees authored Nov 23, 2023
1 parent b0765ea commit 66e7806
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 140 deletions.
33 changes: 26 additions & 7 deletions magnum_capi_helm/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ def _label(self, cluster, key, default):
# NOTE(johngarbutt): filtering untrusted user input
return re.sub(r"[^a-zA-Z0-9\.\-\/ ]+", "", raw)

def _get_label_bool(self, cluster, label, default):
cluster_label = self._label(cluster, label, "")
if not cluster_label:
return default
if default:
# Default is on, so return for any value except "false"
return cluster_label != "false"
# Default is False, so only "true" responds with True
return cluster_label == "true"

def _get_chart_version(self, cluster):
version = cluster.cluster_template.labels.get(
"capi_helm_chart_version",
Expand Down Expand Up @@ -540,15 +550,16 @@ def _get_dns_nameservers(self, cluster):
return None

def _get_monitoring_enabled(self, cluster):
mon_label = self._label(cluster, "monitoring_enabled", "")
# NOTE(mkjpryor) default of, like heat driver,
# as requires cinder and takes a while
return mon_label == "true"
# NOTE(mkjpryor) default off, like heat driver,
# as requires cinder and takes a while
return self._get_label_bool(cluster, "monitoring_enabled", False)

def _get_kube_dash_enabled(self, cluster):
kube_dash_label = self._label(cluster, "kube_dashboard_enabled", "")
# NOTE(mkjpryor) default on, like the heat driver
return kube_dash_label != "false"
# NOTE(mkjpryor) default on, like the heat driver
return self._get_label_bool(cluster, "kube_dashboard_enabled", True)

def _get_autoheal_enabled(self, cluster):
return self._get_label_bool(cluster, "auto_healing_enabled", True)

def _get_fixed_network_id(self, context, cluster):
network = cluster.fixed_network
Expand Down Expand Up @@ -603,6 +614,14 @@ def _update_helm_release(self, context, cluster, nodegroups=None):
"controlPlane": {
"machineFlavor": cluster.master_flavor_id,
"machineCount": cluster.master_count,
"healthCheck": {
"enabled": self._get_autoheal_enabled(cluster),
},
},
"nodeGroupDefaults": {
"healthCheck": {
"enabled": self._get_autoheal_enabled(cluster),
},
},
"nodeGroups": [
{
Expand Down
Loading

0 comments on commit 66e7806

Please sign in to comment.