@@ -15,19 +15,26 @@ import os
1515import sys
1616from mas .devops .slack import SlackUtil
1717
18-
19- def notifyProvisionFyre (channel : str , rc : int ) -> bool :
20- name = os .getenv ("CLUSTER_NAME" , None )
21- if name is None :
18+ def _getClusterName () -> str :
19+ name = os .getenv ("CLUSTER_NAME" , "" )
20+ if name == "" :
2221 print ("CLUSTER_NAME env var must be set" )
2322 sys .exit (1 )
23+ return name
2424
25- # Support optional metadata from standard IBM CD Toolchains environment variables
26- toolchainLink = ""
25+ def _getToolchainLink () -> str :
2726 toolchainUrl = os .getenv ("TOOLCHAIN_PIPELINERUN_URL" , None )
2827 toolchainTriggerName = os .getenv ("TOOLCHAIN_TRIGGER_NAME" , None )
2928 if toolchainUrl is not None and toolchainTriggerName is not None :
30- toolchainLink = f" | <{ toolchainUrl } |Pipeline Run>"
29+ toolchainLink = f"<{ toolchainUrl } |{ toolchainTriggerName } >"
30+ return toolchainLink
31+ return ""
32+
33+
34+ def notifyProvisionFyre (channel : str , rc : int ) -> bool :
35+ """Send Slack notification about Fyre OCP cluster provisioning status."""
36+ name = _getClusterName ()
37+ toolchainLink = _getToolchainLink ()
3138
3239 if rc == 0 :
3340 url = os .getenv ("OCP_CONSOLE_URL" , None )
@@ -54,6 +61,32 @@ def notifyProvisionFyre(channel: str, rc: int) -> bool:
5461 return response .data .get ("ok" , False )
5562
5663
64+ def notifyProvisionRoks (channel : str , rc : int ) -> bool :
65+ """Send Slack notification about ROKS cluster provisioning status."""
66+ name = _getClusterName ()
67+ toolchainLink = _getToolchainLink ()
68+
69+ if rc == 0 :
70+ url = os .getenv ("OCP_CONSOLE_URL" , None )
71+ if url is None :
72+ print ("OCP_CONSOLE_URL env var must be set" )
73+ sys .exit (1 )
74+
75+ message = [
76+ SlackUtil .buildHeader (f":glyph-ok: Your IBM Cloud ROKS cluster ({ name } ) is ready" ),
77+ SlackUtil .buildSection (f"{ url } " ),
78+ SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
79+ ]
80+ else :
81+ message = [
82+ SlackUtil .buildHeader (f":glyph-fail: Your IBM Cloud ROKS cluster ({ name } ) failed to deploy" ),
83+ SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
84+ ]
85+
86+ response = SlackUtil .postMessageBlocks (channel , message )
87+ return response .data .get ("ok" , False )
88+
89+
5790if __name__ == "__main__" :
5891 # If SLACK_TOKEN or SLACK_CHANNEL env vars are not set then silently exit taking no action
5992 SLACK_TOKEN = os .getenv ("SLACK_TOKEN" , "" )
@@ -71,3 +104,5 @@ if __name__ == "__main__":
71104
72105 if args .action == "ocp-provision-fyre" :
73106 notifyProvisionFyre (SLACK_CHANNEL , args .rc )
107+ elif args .action == "ocp-provision-roks" :
108+ notifyProvisionRoks (SLACK_CHANNEL , args .rc )
0 commit comments