Skip to content
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
138 changes: 55 additions & 83 deletions src/mas/devops/tekton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
"""
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/mas/devops/templates/pipelinerun-install.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -------------------------------------------------------------------------
Expand All @@ -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
# -------------------------------------------------------------------------
Expand Down