Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify undefined values for plugin.install #307

Merged
merged 4 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions kubemarine/core/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"kubemarine.packages.enrich_inventory_associations",
"kubemarine.system.enrich_upgrade_inventory",
"kubemarine.core.defaults.compile_inventory",
"kubemarine.core.defaults.manage_true_false_values",
"kubemarine.admission.manage_enrichment",
"kubemarine.thirdparties.enrich_inventory_apply_upgrade_defaults",
"kubemarine.procedures.migrate_cri.enrich_inventory",
Expand Down Expand Up @@ -545,3 +546,15 @@ def prepare_for_dump(inventory, copy=True):

return dump_inventory


def manage_true_false_values(inventory, cluster):
# Check undefined values for plugin.name.install and convert it to bool
for plugin_name, plugin_item in inventory["plugins"].items():
# Check install value
if 'install' not in plugin_item:
continue
value = utils.true_or_false(plugin_item.get('install', False))
if value == 'undefined':
raise ValueError(f"Found unsupported value for plugin.{plugin_name}.install: {plugin_item['install']}")
plugin_item['install'] = value == 'true'
return inventory
2 changes: 1 addition & 1 deletion kubemarine/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def make_ansible_inventory(location, cluster):
if inventory.get(group) is not None:
for service_name, service_configs in inventory[group].items():
# write to inventory only plugins, which will be installed
if group != 'plugins' or true_or_false(service_configs.get('install', False)) == 'true':
if group != 'plugins' or service_configs.get('install', False):

config['cluster:vars'].append('\n# %s.%s' % (group, service_name))

Expand Down
3 changes: 1 addition & 2 deletions kubemarine/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def install(cluster, plugins=None):
plugins_queue = []
max_priority = 0
for plugin_name, plugin_item in plugins.items():
if utils.true_or_false(plugin_item.get("install", False)) == 'true' and \
plugin_item.get("installation", {}).get('procedures') is not None:
if plugin_item.get("install", False) and plugin_item.get("installation", {}).get('procedures') is not None:
plugin_item['plugin_name'] = plugin_name
plugins_queue.append(plugin_item)
if plugin_item.get("installation", {}).get('priority') is not None \
Expand Down
6 changes: 3 additions & 3 deletions kubemarine/plugins/calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def enrich_inventory(inventory, cluster):
# By default installation parameter is unset, means user did not made any decision
if inventory["plugins"]["calico"].get("install") is None:
# Is user defined Flannel plugin and set it to install?
flannel_required = utils.true_or_false(inventory["plugins"].get("flannel", {}).get("install", False)) == 'true'
flannel_required = inventory["plugins"].get("flannel", {}).get("install", False)
# Is user defined Canal plugin and set it to install?
canal_required = utils.true_or_false(inventory["plugins"].get("canal", {}).get("install", False)) == 'true'
canal_required = inventory["plugins"].get("canal", {}).get("install", False)
# If Flannel and Canal is unset or not required to install, then install Calico
if not flannel_required and not canal_required:
inventory["plugins"]["calico"]["install"] = True

if utils.true_or_false(inventory["plugins"]["calico"]["install"]) == 'true':
if inventory["plugins"]["calico"]["install"]:
# Check if original YAML and final YAML have different paths (applicable for non Jinja2 template)
items = inventory['plugins']['calico']['installation']['procedures']
for item in items:
Expand Down
6 changes: 3 additions & 3 deletions kubemarine/plugins/nginx_ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def verify_inventory(inventory, _):
if utils.true_or_false(inventory["plugins"]["nginx-ingress-controller"]["install"]) != "true":
if not inventory["plugins"]["nginx-ingress-controller"]["install"]:
return inventory

nginx_plugin = inventory["plugins"]["nginx-ingress-controller"]
Expand All @@ -43,7 +43,7 @@ def verify_inventory(inventory, _):


def enrich_inventory(inventory, _):
if utils.true_or_false(inventory["plugins"]["nginx-ingress-controller"]["install"]) != "true":
if not inventory["plugins"]["nginx-ingress-controller"]["install"]:
return inventory

if inventory["plugins"]["nginx-ingress-controller"].get('custom_headers'):
Expand All @@ -63,7 +63,7 @@ def cert_renew_enrichment(inventory, cluster):
nginx_plugin = inventory["plugins"]["nginx-ingress-controller"]

# check that renewal is possible
if utils.true_or_false(nginx_plugin["install"]) != 'true':
if not nginx_plugin["install"]:
raise Exception("Certificates can not be renewed for nginx plugin since it is not installed")

# update certificates in inventory, other check will be performed in "verify_inventory" function
Expand Down
8 changes: 3 additions & 5 deletions kubemarine/procedures/check_paas.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def kubernetes_dashboard_status(cluster):
i = 0
while not test_succeeded and i < retries:
i += 1
if utils.true_or_false(cluster.inventory['plugins']['kubernetes-dashboard']['install']) == 'true':
if cluster.inventory['plugins']['kubernetes-dashboard']['install']:
results = cluster.nodes['control-plane'].get_first_member().sudo("kubectl get svc -n kubernetes-dashboard kubernetes-dashboard -o=jsonpath=\"{['spec.clusterIP']}\"", warn=True)
for control_plane, result in results.items():
if result.failed:
Expand Down Expand Up @@ -982,8 +982,7 @@ def default_services_configuration_status(cluster):
for service in services:
for service_name, properties in service.items():
if service_name == "ingress-nginx-controller":
if utils.true_or_false(
cluster.inventory['plugins']['nginx-ingress-controller']['install']) != 'true':
if not cluster.inventory['plugins']['nginx-ingress-controller']['install']:
break
content = first_control_plane.sudo(f"kubectl get {type} {service_name} -n {namespace} -oyaml").get_simple_out()
content = yaml.safe_load(content)
Expand Down Expand Up @@ -1020,8 +1019,7 @@ def default_services_health_status(cluster):
if type == 'DaemonSet':
for service in services:
if service == "ingress-nginx-controller":
if utils.true_or_false(
cluster.inventory['plugins']['nginx-ingress-controller']['install']) != 'true':
if not cluster.inventory['plugins']['nginx-ingress-controller']['install']:
break
daemon_set = DaemonSet(cluster, name=service, namespace=namespace)
ready = daemon_set.reload(control_plane=first_control_plane, suppress_exceptions=True).is_actual_and_ready()
Expand Down