Skip to content

Commit a0724aa

Browse files
[patch] add prepareUpdateSlackSecrets
1 parent 8a54b66 commit a0724aa

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

src/mas/devops/tekton.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,69 @@ def prepareInstallSecrets(dynClient: DynamicClient, namespace: str, slsLicenseFi
615615
secretsAPI.create(body=podTemplates, namespace=namespace)
616616

617617

618+
def prepareUpdateSlackSecrets(dynClient: DynamicClient, slack_token: str = None, slack_channel: str = None) -> None:
619+
"""
620+
Create or update mas-devops-slack secret in mas-pipelines namespace for update pipeline.
621+
622+
Creates the slack secret in mas-pipelines namespace if it exists and slack credentials are provided.
623+
624+
Parameters:
625+
dynClient (DynamicClient): OpenShift Dynamic Client
626+
slack_token (str, optional): Slack bot token for notifications. Defaults to None.
627+
slack_channel (str, optional): Slack channel ID for notifications. Defaults to None.
628+
629+
Returns:
630+
None
631+
632+
Raises:
633+
NotFoundError: If namespace doesn't exist (will be caught and logged)
634+
"""
635+
namespace = "mas-pipelines"
636+
637+
# Check if namespace exists
638+
try:
639+
namespaceAPI = dynClient.resources.get(api_version="v1", kind="Namespace")
640+
namespaceAPI.get(name=namespace)
641+
except NotFoundError:
642+
logger.warning(f"Namespace {namespace} does not exist, skipping slack secret creation")
643+
return
644+
645+
# Only create secret if both slack_token and slack_channel are provided
646+
if not slack_token or not slack_channel:
647+
logger.debug("Slack token or channel not provided, skipping slack secret creation")
648+
return
649+
650+
secretsAPI = dynClient.resources.get(api_version="v1", kind="Secret")
651+
652+
# Delete existing secret if it exists
653+
try:
654+
secretsAPI.delete(name="mas-devops-slack", namespace=namespace)
655+
except NotFoundError:
656+
pass
657+
658+
# Create the secret with SLACK_TOKEN and SLACK_CHANNEL
659+
secret_data = {}
660+
661+
if slack_token:
662+
secret_data["SLACK_TOKEN"] = base64.b64encode(slack_token.encode()).decode()
663+
664+
if slack_channel:
665+
secret_data["SLACK_CHANNEL"] = base64.b64encode(slack_channel.encode()).decode()
666+
667+
mas_devops_secret = {
668+
"apiVersion": "v1",
669+
"kind": "Secret",
670+
"type": "Opaque",
671+
"metadata": {
672+
"name": "mas-devops-slack"
673+
},
674+
"data": secret_data
675+
}
676+
677+
secretsAPI.create(body=mas_devops_secret, namespace=namespace)
678+
logger.info(f"Created mas-devops-slack secret in namespace {namespace}")
679+
680+
618681
def testCLI() -> None:
619682
pass
620683
# echo -n "Testing availability of $CLI_IMAGE in cluster ..."

0 commit comments

Comments
 (0)