Skip to content

Commit ac3649b

Browse files
[patch] add prepareAIServiceInstallSecrets
1 parent edb1e99 commit ac3649b

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

src/mas/devops/tekton.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,74 @@ def prepareUpdateSlackSecrets(dynClient: DynamicClient, slack_token: str = None,
678678
logger.info(f"Created mas-devops-slack secret in namespace {namespace}")
679679

680680

681+
def prepareAIServiceInstallSecrets(dynClient: DynamicClient, instanceId: str, slack_token: str = None, slack_channel: str = None) -> None:
682+
"""
683+
Create or update mas-devops-slack secret in aiservice-{instanceId}-pipelines namespace for AI Service install pipeline.
684+
685+
Creates the slack secret in aiservice-{instanceId}-pipelines namespace if it exists and slack credentials are provided.
686+
This function is specifically for AI Service installations which use a different namespace pattern than MAS installations.
687+
688+
Parameters:
689+
dynClient (DynamicClient): OpenShift Dynamic Client
690+
instanceId (str): AI Service instance ID
691+
slack_token (str, optional): Slack bot token for notifications. Defaults to None.
692+
slack_channel (str, optional): Slack channel ID for notifications. Defaults to None.
693+
694+
Returns:
695+
None
696+
697+
Raises:
698+
NotFoundError: If namespace doesn't exist (will be caught and logged)
699+
"""
700+
namespace = f"aiservice-{instanceId}-pipelines"
701+
702+
# Check if namespace exists
703+
try:
704+
namespaceAPI = dynClient.resources.get(api_version="v1", kind="Namespace")
705+
namespaceAPI.get(name=namespace)
706+
except NotFoundError:
707+
logger.warning(f"Namespace {namespace} does not exist, skipping slack secret creation")
708+
return
709+
710+
# Only create secret if both slack_token and slack_channel are provided
711+
if not slack_token or not slack_channel:
712+
logger.debug("Slack token or channel not provided, skipping slack secret creation")
713+
return
714+
715+
secretsAPI = dynClient.resources.get(api_version="v1", kind="Secret")
716+
717+
# Delete existing secret if it exists
718+
try:
719+
secretsAPI.delete(name="mas-devops-slack", namespace=namespace)
720+
except NotFoundError:
721+
pass
722+
723+
# Create the secret with MAS_INSTANCE_ID, SLACK_TOKEN and SLACK_CHANNEL
724+
# Note: We use MAS_INSTANCE_ID (not AISERVICE_INSTANCE_ID) to maintain consistency with MAS install secrets
725+
secret_data = {
726+
"MAS_INSTANCE_ID": base64.b64encode(instanceId.encode()).decode()
727+
}
728+
729+
if slack_token:
730+
secret_data["SLACK_TOKEN"] = base64.b64encode(slack_token.encode()).decode()
731+
732+
if slack_channel:
733+
secret_data["SLACK_CHANNEL"] = base64.b64encode(slack_channel.encode()).decode()
734+
735+
mas_devops_secret = {
736+
"apiVersion": "v1",
737+
"kind": "Secret",
738+
"type": "Opaque",
739+
"metadata": {
740+
"name": "mas-devops-slack"
741+
},
742+
"data": secret_data
743+
}
744+
745+
secretsAPI.create(body=mas_devops_secret, namespace=namespace)
746+
logger.info(f"Created mas-devops-slack secret with MAS_INSTANCE_ID={instanceId} in namespace {namespace}")
747+
748+
681749
def testCLI() -> None:
682750
pass
683751
# echo -n "Testing availability of $CLI_IMAGE in cluster ..."

0 commit comments

Comments
 (0)