Skip to content

Commit 68eddf3

Browse files
authored
[patch] Improved Exception handling & dev-mode fixes (#6)
1 parent 2420b52 commit 68eddf3

2 files changed

Lines changed: 57 additions & 85 deletions

File tree

src/mas/devops/tekton.py

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -249,28 +249,18 @@ def launchUpgradePipeline(dynClient: DynamicClient,
249249
namespace = f"mas-{instanceId}-pipelines"
250250
timestamp = datetime.now().strftime("%y%m%d-%H%M")
251251
# Create the PipelineRun
252-
try:
253-
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
254-
env = Environment(
255-
loader=FileSystemLoader(searchpath=templateDir)
256-
)
257-
try:
258-
template = env.get_template("pipelinerun-upgrade.yml.j2")
259-
except TemplateNotFound as e:
260-
logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}")
261-
return None
262-
renderedTemplate = template.render(
263-
timestamp=timestamp,
264-
mas_instance_id=instanceId,
265-
mas_channel=masChannel
266-
)
267-
pipelineRun = yaml.safe_load(renderedTemplate)
268-
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
269-
270-
except Exception as e:
271-
logger.warning(f"Error: An unexpected error occured: {e}")
272-
logger.debug(renderedTemplate)
273-
return None
252+
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
253+
env = Environment(
254+
loader=FileSystemLoader(searchpath=templateDir)
255+
)
256+
template = env.get_template("pipelinerun-upgrade.yml.j2")
257+
renderedTemplate = template.render(
258+
timestamp=timestamp,
259+
mas_instance_id=instanceId,
260+
mas_channel=masChannel
261+
)
262+
pipelineRun = yaml.safe_load(renderedTemplate)
263+
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
274264

275265
pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-upgrade-{timestamp}"
276266
return pipelineURL
@@ -292,49 +282,40 @@ def launchUninstallPipeline(dynClient: DynamicClient,
292282
namespace = f"mas-{instanceId}-pipelines"
293283
timestamp = datetime.now().strftime("%y%m%d-%H%M")
294284
# Create the PipelineRun
295-
try:
296-
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
297-
env = Environment(
298-
loader=FileSystemLoader(searchpath=templateDir)
299-
)
300-
try:
301-
template = env.get_template("pipelinerun-uninstall.yml.j2")
302-
except TemplateNotFound as e:
303-
logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}")
304-
return None
305-
306-
grafanaAction = "uninstall" if uninstallGrafana else "none"
307-
certManagerAction = "uninstall" if uninstallCertManager else "none"
308-
commonServicesAction = "uninstall" if uninstallCommonServices else "none"
309-
ibmCatalogAction = "uninstall" if uninstallCatalog else "none"
310-
mongoDbAction = "uninstall" if uninstallMongoDb else "none"
311-
slsAction = "uninstall" if uninstallSLS else "none"
312-
udsAction = "uninstall" if uninstallUDS else "none"
313-
314-
# Render the pipelineRun
315-
renderedTemplate = template.render(
316-
timestamp=timestamp,
317-
mas_instance_id=instanceId,
318-
grafana_action=grafanaAction,
319-
cert_manager_provider=certManagerProvider,
320-
cert_manager_action=certManagerAction,
321-
common_services_action=commonServicesAction,
322-
ibm_catalogs_action=ibmCatalogAction,
323-
mongodb_action=mongoDbAction,
324-
sls_action=slsAction,
325-
uds_action=udsAction
326-
)
327-
pipelineRun = yaml.safe_load(renderedTemplate)
328-
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
329-
330-
except Exception as e:
331-
logger.warning(f"Error: An unexpected error occured: {e}")
332-
logger.debug(renderedTemplate)
333-
return None
285+
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
286+
env = Environment(
287+
loader=FileSystemLoader(searchpath=templateDir)
288+
)
289+
template = env.get_template("pipelinerun-uninstall.yml.j2")
290+
291+
grafanaAction = "uninstall" if uninstallGrafana else "none"
292+
certManagerAction = "uninstall" if uninstallCertManager else "none"
293+
commonServicesAction = "uninstall" if uninstallCommonServices else "none"
294+
ibmCatalogAction = "uninstall" if uninstallCatalog else "none"
295+
mongoDbAction = "uninstall" if uninstallMongoDb else "none"
296+
slsAction = "uninstall" if uninstallSLS else "none"
297+
udsAction = "uninstall" if uninstallUDS else "none"
298+
299+
# Render the pipelineRun
300+
renderedTemplate = template.render(
301+
timestamp=timestamp,
302+
mas_instance_id=instanceId,
303+
grafana_action=grafanaAction,
304+
cert_manager_provider=certManagerProvider,
305+
cert_manager_action=certManagerAction,
306+
common_services_action=commonServicesAction,
307+
ibm_catalogs_action=ibmCatalogAction,
308+
mongodb_action=mongoDbAction,
309+
sls_action=slsAction,
310+
uds_action=udsAction
311+
)
312+
pipelineRun = yaml.safe_load(renderedTemplate)
313+
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
334314

335315
pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-uninstall-{timestamp}"
336316
return pipelineURL
337317

318+
338319
def launchInstallPipeline(dynClient: DynamicClient,
339320
params: dict) -> str:
340321
"""
@@ -347,29 +328,20 @@ def launchInstallPipeline(dynClient: DynamicClient,
347328
namespace = f"mas-{instanceId}-pipelines"
348329
timestamp = datetime.now().strftime("%y%m%d-%H%M")
349330
# Create the PipelineRun
350-
try:
351-
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
352-
env = Environment(
353-
loader=FileSystemLoader(searchpath=templateDir)
354-
)
355-
try:
356-
template = env.get_template("pipelinerun-install.yml.j2")
357-
except TemplateNotFound as e:
358-
logger.warning(f"Could not find pipelinerun template in {templateDir}: {e}")
359-
return None
360-
361-
# Render the pipelineRun
362-
renderedTemplate = template.render(
363-
timestamp=timestamp,
364-
**params
365-
)
366-
logger.debug(renderedTemplate)
367-
pipelineRun = yaml.safe_load(renderedTemplate)
368-
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
331+
templateDir = path.join(path.abspath(path.dirname(__file__)), "templates")
332+
env = Environment(
333+
loader=FileSystemLoader(searchpath=templateDir)
334+
)
335+
template = env.get_template("pipelinerun-install.yml.j2")
369336

370-
except Exception as e:
371-
logger.warning(f"Error: An unexpected error occured: {e}")
372-
return None
337+
# Render the pipelineRun
338+
renderedTemplate = template.render(
339+
timestamp=timestamp,
340+
**params
341+
)
342+
logger.debug(renderedTemplate)
343+
pipelineRun = yaml.safe_load(renderedTemplate)
344+
pipelineRunsAPI.apply(body=pipelineRun, namespace=namespace)
373345

374346
pipelineURL = f"{getConsoleURL(dynClient)}/k8s/ns/mas-{instanceId}-pipelines/tekton.dev~v1beta1~PipelineRun/{instanceId}-install-{timestamp}"
375347
return pipelineURL

src/mas/devops/templates/pipelinerun-install.yml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
- name: ocp_ingress_tls_secret_name
3333
value: "{{ ocp_ingress_tls_secret_name }}"
3434
{%- endif %}
35-
{%- if artifactory_username is defined and artifactory_token is not None %}
35+
{%- if artifactory_username is defined and artifactory_token != "" %}
3636

3737
# Enable development catalogs
3838
# -------------------------------------------------------------------------
@@ -41,7 +41,7 @@ spec:
4141
- name: artifactory_token
4242
value: "{{ artifactory_token }}"
4343
{%- endif %}
44-
{%- if ibmcloud_apikey is defined and ibmcloud_resourcegroup is not None %}
44+
{%- if ibmcloud_apikey is defined and ibmcloud_resourcegroup != "" %}
4545

4646
# IBM Cloud
4747
# -------------------------------------------------------------------------

0 commit comments

Comments
 (0)