Skip to content

Commit d94bc03

Browse files
[patch] add pipeline name in config name
1 parent b2d7e9e commit d94bc03

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

bin/mas-devops-notify-slack

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipe
105105
sys.exit(1)
106106

107107
# Check if thread already exists
108-
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
108+
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
109109
if threadInfo is not None:
110110
print("Pipeline start notification already sent")
111111
return threadInfo
@@ -145,9 +145,9 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipe
145145
return False
146146

147147
# Create ConfigMap with all channel/thread info
148-
SlackUtil.createThreadConfigMap(namespace, "", "", instanceId)
149-
SlackUtil.updateThreadConfigMap(namespace, instanceId, configMapData)
150-
return SlackUtil.getThreadConfigMap(namespace, instanceId)
148+
SlackUtil.createThreadConfigMap(namespace, instanceId, pipelineName)
149+
SlackUtil.updateThreadConfigMap(namespace, instanceId, configMapData, pipelineName)
150+
return SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
151151

152152

153153
def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
@@ -158,7 +158,7 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
158158
sys.exit(1)
159159

160160
# Get thread information, create if doesn't exist
161-
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
161+
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
162162
if threadInfo is None:
163163
print("No thread found - creating pipeline start notification")
164164
threadInfo = notifyPipelineStart(channels, instanceId, pipelineName)
@@ -197,7 +197,7 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
197197

198198
# Update ConfigMap with all task message timestamps
199199
if taskMessageData:
200-
SlackUtil.updateThreadConfigMap(namespace, instanceId, taskMessageData)
200+
SlackUtil.updateThreadConfigMap(namespace, instanceId, taskMessageData, pipelineName)
201201

202202
return allSuccess
203203

@@ -210,7 +210,7 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceI
210210
sys.exit(1)
211211

212212
# Get thread information, create if doesn't exist
213-
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
213+
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
214214
if threadInfo is None:
215215
print("No thread found - creating pipeline start notification")
216216
threadInfo = notifyPipelineStart(channels, instanceId, pipelineName)
@@ -293,7 +293,7 @@ def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None
293293
sys.exit(1)
294294

295295
# Get thread information
296-
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
296+
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
297297
if threadInfo is None:
298298
print("No thread information found - pipeline may not have started properly")
299299
return False
@@ -353,7 +353,7 @@ def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None
353353
allSuccess = False
354354

355355
# Clean up ConfigMap
356-
SlackUtil.deleteThreadConfigMap(namespace, instanceId)
356+
SlackUtil.deleteThreadConfigMap(namespace, instanceId, pipelineName)
357357

358358
return allSuccess
359359

src/mas/devops/slack.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def buildDivider(cls) -> dict:
271271
Returns:
272272
dict: Slack block kit divider element
273273
"""
274-
def createThreadConfigMap(cls, namespace: str, channelId: str, threadId: str, instanceId: str) -> bool:
274+
def createThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName: str) -> bool:
275275
"""
276276
Create a ConfigMap to store Slack thread information for a pipeline run.
277277
@@ -291,15 +291,14 @@ def createThreadConfigMap(cls, namespace: str, channelId: str, threadId: str, in
291291
except Exception:
292292
config.load_kube_config()
293293
v1 = client.CoreV1Api()
294-
configmap_name = f"slack-thread-{instanceId}"
294+
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
295295
configmap = client.V1ConfigMap(
296296
metadata=client.V1ObjectMeta(
297297
name=configmap_name,
298298
namespace=namespace
299299
),
300300
data={
301-
"threadId": threadId,
302-
"channelId": channelId,
301+
"pipelineName": pipelineRunName,
303302
"instanceId": instanceId,
304303
"startTime": datetime.now(timezone.utc)
305304
}
@@ -311,7 +310,7 @@ def createThreadConfigMap(cls, namespace: str, channelId: str, threadId: str, in
311310
logger.error(f"Failed to create ConfigMap: {e}")
312311
return False
313312

314-
def getThreadConfigMap(cls, namespace: str, instanceId: str) -> dict | None:
313+
def getThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName: str) -> dict | None:
315314
"""
316315
Retrieve Slack thread information from a ConfigMap.
317316
@@ -329,7 +328,7 @@ def getThreadConfigMap(cls, namespace: str, instanceId: str) -> dict | None:
329328
except Exception:
330329
config.load_kube_config()
331330
v1 = client.CoreV1Api()
332-
configmap_name = f"slack-thread-{instanceId}"
331+
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
333332
configmap = v1.read_namespaced_config_map(name=configmap_name, namespace=namespace)
334333
logger.debug(f"Retrieved ConfigMap {configmap_name} from namespace {namespace}")
335334
return configmap.data
@@ -343,7 +342,7 @@ def getThreadConfigMap(cls, namespace: str, instanceId: str) -> dict | None:
343342
logger.error(f"Failed to retrieve ConfigMap: {e}")
344343
return None
345344

346-
def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict) -> bool:
345+
def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict, pipelineRunName: str) -> bool:
347346
"""
348347
Update the ConfigMap with additional data (e.g., task message timestamps).
349348
@@ -362,7 +361,7 @@ def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict) -
362361
except Exception:
363362
config.load_kube_config()
364363
v1 = client.CoreV1Api()
365-
configmap_name = f"slack-thread-{instanceId}"
364+
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
366365

367366
# Get existing ConfigMap
368367
configmap = v1.read_namespaced_config_map(name=configmap_name, namespace=namespace)
@@ -380,7 +379,7 @@ def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict) -
380379
logger.error(f"Failed to update ConfigMap: {e}")
381380
return False
382381

383-
def deleteThreadConfigMap(cls, namespace: str, instanceId: str) -> bool:
382+
def deleteThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName: str) -> bool:
384383
"""
385384
Delete the ConfigMap containing Slack thread information.
386385
@@ -399,7 +398,7 @@ def deleteThreadConfigMap(cls, namespace: str, instanceId: str) -> bool:
399398
config.load_kube_config()
400399

401400
v1 = client.CoreV1Api()
402-
configmap_name = f"slack-thread-{instanceId}"
401+
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
403402
v1.delete_namespaced_config_map(name=configmap_name, namespace=namespace)
404403
logger.info(f"Deleted ConfigMap {configmap_name} from namespace {namespace}")
405404
return True

0 commit comments

Comments
 (0)