Skip to content

Commit c25968f

Browse files
committed
[patch] create notification for roks
1 parent fd67c58 commit c25968f

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

bin/mas-devops-notify-slack

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _getToolchainLink() -> str:
2929
toolchainLink = f"<{toolchainUrl}|{toolchainTriggerName}>"
3030
return toolchainLink
3131
return ""
32-
32+
3333

3434
def notifyProvisionFyre(channel: str, rc: int) -> bool:
3535
"""Send Slack notification about Fyre OCP cluster provisioning status."""
@@ -61,7 +61,7 @@ def notifyProvisionFyre(channel: str, rc: int) -> bool:
6161
return response.data.get("ok", False)
6262

6363

64-
def notifyProvisionRoks(channel: str, rc: int) -> bool:
64+
def notifyProvisionRoks(channel: str, rc: int, additionalDetails: str = "") -> bool:
6565
"""Send Slack notification about ROKS cluster provisioning status."""
6666
name = _getClusterName()
6767
toolchainLink = _getToolchainLink()
@@ -77,6 +77,8 @@ def notifyProvisionRoks(channel: str, rc: int) -> bool:
7777
SlackUtil.buildSection(f"{url}"),
7878
SlackUtil.buildSection(f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{toolchainLink}")
7979
]
80+
if additionalDetails != "":
81+
message.append(SlackUtil.buildSection(additionalDetails))
8082
else:
8183
message = [
8284
SlackUtil.buildHeader(f":glyph-fail: Your IBM Cloud ROKS cluster ({name}) failed to deploy"),
@@ -100,9 +102,14 @@ if __name__ == "__main__":
100102
# Primary Options
101103
parser.add_argument("--action", required=True)
102104
parser.add_argument("--rc", required=True, type=int)
105+
parser.add_argument("--add-details")
106+
103107
args, unknown = parser.parse_known_args()
104108

105109
if args.action == "ocp-provision-fyre":
106110
notifyProvisionFyre(SLACK_CHANNEL, args.rc)
107111
elif args.action == "ocp-provision-roks":
108-
notifyProvisionRoks(SLACK_CHANNEL, args.rc)
112+
if args.add_details:
113+
notifyProvisionRoks(SLACK_CHANNEL, args.rc, args.add_details)
114+
else:
115+
notifyProvisionRoks(SLACK_CHANNEL, args.rc)

src/mas/devops/slack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def client(cls) -> WebClient:
3939

4040
# Post message to Slack
4141
# -----------------------------------------------------------------------------
42-
def postMessageBlocks(cls, channelName: str, messageBlocks: list, threadId: str = None) -> SlackResponse:
43-
if threadId is None:
42+
def postMessageBlocks(cls, channelName: str, messageBlocks: list, threadId: str = "") -> SlackResponse:
43+
if threadId == "":
4444
logger.debug(f"Posting {len(messageBlocks)} block message to {channelName} in Slack")
4545
response = cls.client.chat_postMessage(
4646
channel=channelName,
@@ -108,12 +108,12 @@ def postMessageText(cls, channelName, message, attachments=None, threadId=None):
108108
return response
109109

110110
def createMessagePermalink(
111-
cls, slackResponse: SlackResponse = None, channelId: str = None, messageTimestamp: str = None, domain: str = "ibm-mas"
111+
cls, slackResponse: SlackResponse = None, channelId: str = "", messageTimestamp: str = "", domain: str = "ibm-mas"
112112
) -> str:
113113
if slackResponse is not None:
114114
channelId = slackResponse["channel"]
115115
messageTimestamp = slackResponse["ts"]
116-
elif channelId is None or messageTimestamp is None:
116+
elif channelId == "" or messageTimestamp == "":
117117
raise Exception("Either channelId and messageTimestamp, or slackReponse params must be provided")
118118

119119
return f"https://{domain}.slack.com/archives/{channelId}/p{messageTimestamp.replace('.', '')}"

0 commit comments

Comments
 (0)