@@ -16,18 +16,27 @@ import sys
1616from mas .devops .slack import SlackUtil
1717
1818
19- def notifyProvisionFyre ( channel : str , rc : int ) -> bool :
20- name = os .getenv ("CLUSTER_NAME" , None )
21- if name is None :
19+ def _getClusterName ( ) -> str :
20+ name = os .getenv ("CLUSTER_NAME" , "" )
21+ if name == "" :
2222 print ("CLUSTER_NAME env var must be set" )
2323 sys .exit (1 )
24+ return name
2425
25- # Support optional metadata from standard IBM CD Toolchains environment variables
26- toolchainLink = ""
26+
27+ def _getToolchainLink () -> str :
2728 toolchainUrl = os .getenv ("TOOLCHAIN_PIPELINERUN_URL" , None )
2829 toolchainTriggerName = os .getenv ("TOOLCHAIN_TRIGGER_NAME" , None )
2930 if toolchainUrl is not None and toolchainTriggerName is not None :
30- toolchainLink = f" | <{ toolchainUrl } |Pipeline Run>"
31+ toolchainLink = f"<{ toolchainUrl } |{ toolchainTriggerName } >"
32+ return toolchainLink
33+ return ""
34+
35+
36+ def notifyProvisionFyre (channels : list [str ], rc : int , additionalMsg : str = None ) -> bool :
37+ """Send Slack notification about Fyre OCP cluster provisioning status."""
38+ name = _getClusterName ()
39+ toolchainLink = _getToolchainLink ()
3140
3241 if rc == 0 :
3342 url = os .getenv ("OCP_CONSOLE_URL" , None )
@@ -44,13 +53,47 @@ def notifyProvisionFyre(channel: str, rc: int) -> bool:
4453 SlackUtil .buildSection (f"- Username: `{ username } `\n - Password: `{ password } `" ),
4554 SlackUtil .buildSection (f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{ toolchainLink } " )
4655 ]
56+ if additionalMsg is not None :
57+ message .append (SlackUtil .buildSection (additionalMsg ))
4758 else :
4859 message = [
4960 SlackUtil .buildHeader (f":glyph-fail: Your IBM DevIT Fyre OCP cluster ({ name } ) failed to deploy" ),
5061 SlackUtil .buildSection (f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{ toolchainLink } " )
5162 ]
5263
53- response = SlackUtil .postMessageBlocks (channel , message )
64+ response = SlackUtil .postMessageBlocks (channels , message )
65+ if isinstance (response , list ):
66+ return all ([res .data .get ("ok" , False ) for res in response ])
67+ return response .data .get ("ok" , False )
68+
69+
70+ def notifyProvisionRoks (channels : list [str ], rc : int , additionalMsg : str = None ) -> bool :
71+ """Send Slack notification about ROKS cluster provisioning status."""
72+ name = _getClusterName ()
73+ toolchainLink = _getToolchainLink ()
74+
75+ if rc == 0 :
76+ url = os .getenv ("OCP_CONSOLE_URL" , None )
77+ if url is None :
78+ print ("OCP_CONSOLE_URL env var must be set" )
79+ sys .exit (1 )
80+
81+ message = [
82+ SlackUtil .buildHeader (f":glyph-ok: Your IBM Cloud ROKS cluster ({ name } ) is ready" ),
83+ SlackUtil .buildSection (f"{ url } " ),
84+ SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
85+ ]
86+ if additionalMsg is not None :
87+ message .append (SlackUtil .buildSection (additionalMsg ))
88+ else :
89+ message = [
90+ SlackUtil .buildHeader (f":glyph-fail: Your IBM Cloud ROKS cluster ({ name } ) failed to deploy" ),
91+ SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
92+ ]
93+
94+ response = SlackUtil .postMessageBlocks (channels , message )
95+ if isinstance (response , list ):
96+ return all ([res .data .get ("ok" , False ) for res in response ])
5497 return response .data .get ("ok" , False )
5598
5699
@@ -61,13 +104,20 @@ if __name__ == "__main__":
61104 if SLACK_TOKEN == "" or SLACK_CHANNEL == "" :
62105 sys .exit (0 )
63106
107+ # Parse comma-separated channel list
108+ channelList = [ch .strip () for ch in SLACK_CHANNEL .split ("," )]
109+
64110 # Initialize the properties we need
65111 parser = argparse .ArgumentParser ()
66112
67113 # Primary Options
68114 parser .add_argument ("--action" , required = True )
69115 parser .add_argument ("--rc" , required = True , type = int )
116+ parser .add_argument ("--msg" , required = False , default = None )
117+
70118 args , unknown = parser .parse_known_args ()
71119
72120 if args .action == "ocp-provision-fyre" :
73- notifyProvisionFyre (SLACK_CHANNEL , args .rc )
121+ notifyProvisionFyre (channelList , args .rc , args .msg )
122+ elif args .action == "ocp-provision-roks" :
123+ notifyProvisionRoks (channelList , args .rc , args .msg )
0 commit comments