Skip to content

Commit f16e1de

Browse files
[patch] work with mas update pipeline
1 parent a0724aa commit f16e1de

2 files changed

Lines changed: 36 additions & 19 deletions

File tree

bin/mas-devops-notify-slack

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ def notifyProvisionRoks(channels: list[str], rc: int, additionalMsg: str | None
9999

100100
def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipelineName: str | None = None) -> dict | None:
101101
"""Send Slack notification about pipeline start and create thread for all channels."""
102-
namespace = f"mas-{instanceId}-pipelines"
102+
# For update pipeline, use mas-pipelines namespace (no instance ID)
103+
# For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
103104
if instanceId is None or instanceId == "":
104-
print("instanceId must be set")
105-
sys.exit(1)
105+
namespace = "mas-pipelines"
106+
else:
107+
namespace = f"mas-{instanceId}-pipelines"
106108

107109
# Check if thread already exists
108110
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
@@ -152,10 +154,12 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipe
152154

153155
def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
154156
"""Send Slack notification about Ansible task start to all channels."""
155-
namespace = f"mas-{instanceId}-pipelines"
157+
# For update pipeline, use mas-pipelines namespace (no instance ID)
158+
# For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
156159
if instanceId is None or instanceId == "":
157-
print("instanceId must be set")
158-
sys.exit(1)
160+
namespace = "mas-pipelines"
161+
else:
162+
namespace = f"mas-{instanceId}-pipelines"
159163

160164
# Get thread information, create if doesn't exist
161165
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
@@ -204,10 +208,12 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
204208

205209
def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
206210
"""Send Slack notification about Ansible task completion status to all channels."""
207-
namespace = f"mas-{instanceId}-pipelines"
211+
# For update pipeline, use mas-pipelines namespace (no instance ID)
212+
# For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
208213
if instanceId is None or instanceId == "":
209-
print("instanceId must be set")
210-
sys.exit(1)
214+
namespace = "mas-pipelines"
215+
else:
216+
namespace = f"mas-{instanceId}-pipelines"
211217

212218
# Get thread information, create if doesn't exist
213219
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)
@@ -287,10 +293,12 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceI
287293

288294
def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
289295
"""Send Slack notification about pipeline completion to all channels and cleanup ConfigMap."""
290-
namespace = f"mas-{instanceId}-pipelines"
296+
# For update pipeline, use mas-pipelines namespace (no instance ID)
297+
# For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
291298
if instanceId is None or instanceId == "":
292-
print("instanceId must be set")
293-
sys.exit(1)
299+
namespace = "mas-pipelines"
300+
else:
301+
namespace = f"mas-{instanceId}-pipelines"
294302

295303
# Get thread information
296304
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId, pipelineName)

src/mas/devops/slack.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def createThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName:
279279
namespace (str): Kubernetes namespace for the ConfigMap
280280
channelId (str): Slack channel ID where the thread was created
281281
threadId (str): Slack thread timestamp
282-
instanceId (str): Name of the Mas Instance ID
282+
instanceId (str): Name of the Mas Instance ID (can be None or empty for update pipeline)
283283
284284
Returns:
285285
bool: True if ConfigMap was created successfully, False otherwise
@@ -291,7 +291,9 @@ def createThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName:
291291
except Exception:
292292
config.load_kube_config()
293293
v1 = client.CoreV1Api()
294-
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
294+
# For update pipeline (no instance ID), use "update" as identifier
295+
instance_identifier = instanceId if instanceId else "update"
296+
configmap_name = f"slack-thread-{instance_identifier}-{pipelineRunName}"
295297
configmap = client.V1ConfigMap(
296298
metadata=client.V1ObjectMeta(
297299
name=configmap_name,
@@ -316,7 +318,7 @@ def getThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName: st
316318
317319
Parameters:
318320
namespace (str): Kubernetes namespace containing the ConfigMap
319-
instanceId (str): Unique identifier for the pipeline run
321+
instanceId (str): Unique identifier for the pipeline run (can be None or empty for update pipeline)
320322
321323
Returns:
322324
dict | None: Dictionary containing threadId, channelId, pipelineName, and startTime, or None if not found
@@ -328,7 +330,9 @@ def getThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName: st
328330
except Exception:
329331
config.load_kube_config()
330332
v1 = client.CoreV1Api()
331-
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
333+
# For update pipeline (no instance ID), use "update" as identifier
334+
instance_identifier = instanceId if instanceId else "update"
335+
configmap_name = f"slack-thread-{instance_identifier}-{pipelineRunName}"
332336
configmap = v1.read_namespaced_config_map(name=configmap_name, namespace=namespace)
333337
logger.debug(f"Retrieved ConfigMap {configmap_name} from namespace {namespace}")
334338
return configmap.data
@@ -348,7 +352,7 @@ def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict, p
348352
349353
Parameters:
350354
namespace (str): Kubernetes namespace containing the ConfigMap
351-
instanceId (str): Unique identifier for the pipeline run
355+
instanceId (str): Unique identifier for the pipeline run (can be None or empty for update pipeline)
352356
updates (dict): Dictionary of key-value pairs to add/update in the ConfigMap
353357
354358
Returns:
@@ -361,7 +365,9 @@ def updateThreadConfigMap(cls, namespace: str, instanceId: str, updates: dict, p
361365
except Exception:
362366
config.load_kube_config()
363367
v1 = client.CoreV1Api()
364-
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
368+
# For update pipeline (no instance ID), use "update" as identifier
369+
instance_identifier = instanceId if instanceId else "update"
370+
configmap_name = f"slack-thread-{instance_identifier}-{pipelineRunName}"
365371

366372
# Get existing ConfigMap
367373
configmap = v1.read_namespaced_config_map(name=configmap_name, namespace=namespace)
@@ -385,6 +391,7 @@ def deleteThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName:
385391
386392
Parameters:
387393
namespace (str): Kubernetes namespace containing the ConfigMap
394+
instanceId (str): Unique identifier for the pipeline run (can be None or empty for update pipeline)
388395
pipelineRunName (str): Unique identifier for the pipeline run
389396
390397
Returns:
@@ -398,7 +405,9 @@ def deleteThreadConfigMap(cls, namespace: str, instanceId: str, pipelineRunName:
398405
config.load_kube_config()
399406

400407
v1 = client.CoreV1Api()
401-
configmap_name = f"slack-thread-{instanceId}-{pipelineRunName}"
408+
# For update pipeline (no instance ID), use "update" as identifier
409+
instance_identifier = instanceId if instanceId else "update"
410+
configmap_name = f"slack-thread-{instance_identifier}-{pipelineRunName}"
402411
v1.delete_namespaced_config_map(name=configmap_name, namespace=namespace)
403412
logger.info(f"Deleted ConfigMap {configmap_name} from namespace {namespace}")
404413
return True

0 commit comments

Comments
 (0)