Process feedback; make it possible to install monitoring

This commit is contained in:
Maarten de Waard 2022-09-23 17:10:31 +02:00
parent 6529636b3d
commit 4c57f92c8a
No known key found for this signature in database
GPG key ID: 1D3E893A657CC8DA
4 changed files with 84 additions and 59 deletions

View file

@ -110,8 +110,7 @@ def store_kustomization(kustomization_template_filepath, app_slug):
"""Add a kustomization that installs app {app_slug} to the cluster"""
kustomization_dict = read_template_to_dict(kustomization_template_filepath,
{"app": app_slug})
api_client_instance = api_client.ApiClient()
custom_objects_api = client.CustomObjectsApi(api_client_instance)
custom_objects_api = client.CustomObjectsApi()
try:
api_response = custom_objects_api.create_namespaced_custom_object(
group="kustomize.toolkit.fluxcd.io",
@ -128,8 +127,7 @@ def delete_kustomization(kustomization_name):
"""Deletes kustomization for an app_slug. Should also result in the
deletion of the app's HelmReleases, PVCs, OAuth2Client, etc. Nothing will
remain"""
api_client_instance = api_client.ApiClient()
custom_objects_api = client.CustomObjectsApi(api_client_instance)
custom_objects_api = client.CustomObjectsApi()
body = client.V1DeleteOptions()
try:
api_response = custom_objects_api.delete_namespaced_custom_object(
@ -143,6 +141,7 @@ def delete_kustomization(kustomization_name):
print(f"Could not delete {kustomization_name} Kustomization because of exception {ex}")
return False
print(f"Kustomization deleted with api response: {api_response}")
return api_response
def read_template_to_dict(template_filepath, template_globals):
@ -292,6 +291,28 @@ def get_helmrelease(name, namespace='stackspin-apps'):
return resource
def list_helmreleases(namespace='stackspin-apps', label_selector=""):
"""
Lists all helmreleases in a certain namespace (stackspin-apps by default)
Optionally takes a label selector to limit the list.
"""
api_instance = client.CustomObjectsApi()
try:
api_response = api_instance.list_namespaced_custom_object(
group="helm.toolkit.fluxcd.io",
version="v2beta1",
namespace=namespace,
plural="helmreleases",
label_selector=label_selector)
except ApiException as error:
if error.status == 404:
return None
# Raise all non-404 errors
raise error
return api_response
def get_readiness(app_status):
"""