diff --git a/src/mas/devops/tekton.py b/src/mas/devops/tekton.py index cc703961..832a4eb9 100644 --- a/src/mas/devops/tekton.py +++ b/src/mas/devops/tekton.py @@ -249,28 +249,18 @@ def launchUpgradePipeline(dynClient: DynamicClient, namespace = f"mas-{instanceId}-pipelines" timestamp = datetime.now().strftime("%y%m%d-%H%M") # Create the PipelineRun - try: - templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") - env = Environment( - loader=FileSystemLoader(searchpath=templateDir) - ) - try: - template = env.get_template("pipelinerun-upgrade.yml.j2") - except TemplateNotFound as e: - logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}") - return None - renderedTemplate = template.render( - timestamp=timestamp, - mas_instance_id=instanceId, - mas_channel=masChannel - ) - pipelineRun = yaml.safe_load(renderedTemplate) - pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) - - except Exception as e: - logger.warning(f"Error: An unexpected error occured: {e}") - logger.debug(renderedTemplate) - return None + templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") + env = Environment( + loader=FileSystemLoader(searchpath=templateDir) + ) + template = env.get_template("pipelinerun-upgrade.yml.j2") + renderedTemplate = template.render( + timestamp=timestamp, + mas_instance_id=instanceId, + mas_channel=masChannel + ) + pipelineRun = yaml.safe_load(renderedTemplate) + pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-upgrade-{timestamp}" return pipelineURL @@ -292,49 +282,40 @@ def launchUninstallPipeline(dynClient: DynamicClient, namespace = f"mas-{instanceId}-pipelines" timestamp = datetime.now().strftime("%y%m%d-%H%M") # Create the PipelineRun - try: - templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") - env = Environment( - loader=FileSystemLoader(searchpath=templateDir) - ) - try: - template = env.get_template("pipelinerun-uninstall.yml.j2") - except TemplateNotFound as e: - logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}") - return None - - grafanaAction = "uninstall" if uninstallGrafana else "none" - certManagerAction = "uninstall" if uninstallCertManager else "none" - commonServicesAction = "uninstall" if uninstallCommonServices else "none" - ibmCatalogAction = "uninstall" if uninstallCatalog else "none" - mongoDbAction = "uninstall" if uninstallMongoDb else "none" - slsAction = "uninstall" if uninstallSLS else "none" - udsAction = "uninstall" if uninstallUDS else "none" - - # Render the pipelineRun - renderedTemplate = template.render( - timestamp=timestamp, - mas_instance_id=instanceId, - grafana_action=grafanaAction, - cert_manager_provider=certManagerProvider, - cert_manager_action=certManagerAction, - common_services_action=commonServicesAction, - ibm_catalogs_action=ibmCatalogAction, - mongodb_action=mongoDbAction, - sls_action=slsAction, - uds_action=udsAction - ) - pipelineRun = yaml.safe_load(renderedTemplate) - pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) - - except Exception as e: - logger.warning(f"Error: An unexpected error occured: {e}") - logger.debug(renderedTemplate) - return None + templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") + env = Environment( + loader=FileSystemLoader(searchpath=templateDir) + ) + template = env.get_template("pipelinerun-uninstall.yml.j2") + + grafanaAction = "uninstall" if uninstallGrafana else "none" + certManagerAction = "uninstall" if uninstallCertManager else "none" + commonServicesAction = "uninstall" if uninstallCommonServices else "none" + ibmCatalogAction = "uninstall" if uninstallCatalog else "none" + mongoDbAction = "uninstall" if uninstallMongoDb else "none" + slsAction = "uninstall" if uninstallSLS else "none" + udsAction = "uninstall" if uninstallUDS else "none" + + # Render the pipelineRun + renderedTemplate = template.render( + timestamp=timestamp, + mas_instance_id=instanceId, + grafana_action=grafanaAction, + cert_manager_provider=certManagerProvider, + cert_manager_action=certManagerAction, + common_services_action=commonServicesAction, + ibm_catalogs_action=ibmCatalogAction, + mongodb_action=mongoDbAction, + sls_action=slsAction, + uds_action=udsAction + ) + pipelineRun = yaml.safe_load(renderedTemplate) + pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-uninstall-{timestamp}" return pipelineURL + def launchInstallPipeline(dynClient: DynamicClient, params: dict) -> str: """ @@ -347,29 +328,20 @@ def launchInstallPipeline(dynClient: DynamicClient, namespace = f"mas-{instanceId}-pipelines" timestamp = datetime.now().strftime("%y%m%d-%H%M") # Create the PipelineRun - try: - templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") - env = Environment( - loader=FileSystemLoader(searchpath=templateDir) - ) - try: - template = env.get_template("pipelinerun-install.yml.j2") - except TemplateNotFound as e: - logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}") - return None - - # Render the pipelineRun - renderedTemplate = template.render( - timestamp=timestamp, - **params - ) - logger.debug(renderedTemplate) - pipelineRun = yaml.safe_load(renderedTemplate) - pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) + templateDir = path.join(path.abspath(path.dirname(__file__)), "templates") + env = Environment( + loader=FileSystemLoader(searchpath=templateDir) + ) + template = env.get_template("pipelinerun-install.yml.j2") - except Exception as e: - logger.warning(f"Error: An unexpected error occured: {e}") - return None + # Render the pipelineRun + renderedTemplate = template.render( + timestamp=timestamp, + **params + ) + logger.debug(renderedTemplate) + pipelineRun = yaml.safe_load(renderedTemplate) + pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace) pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-install-{timestamp}" return pipelineURL diff --git a/src/mas/devops/templates/pipelinerun-install.yml.j2 b/src/mas/devops/templates/pipelinerun-install.yml.j2 index 7199afe4..9cfa0c88 100644 --- a/src/mas/devops/templates/pipelinerun-install.yml.j2 +++ b/src/mas/devops/templates/pipelinerun-install.yml.j2 @@ -32,7 +32,7 @@ spec: - name: ocp_ingress_tls_secret_name value: "{{ ocp_ingress_tls_secret_name }}" {%- endif %} -{%- if artifactory_username is defined and artifactory_token is not None %} +{%- if artifactory_username is defined and artifactory_token != "" %} # Enable development catalogs # ------------------------------------------------------------------------- @@ -41,7 +41,7 @@ spec: - name: artifactory_token value: "{{ artifactory_token }}" {%- endif %} -{%- if ibmcloud_apikey is defined and ibmcloud_resourcegroup is not None %} +{%- if ibmcloud_apikey is defined and ibmcloud_resourcegroup != "" %} # IBM Cloud # -------------------------------------------------------------------------