@@ -97,19 +97,21 @@ def notifyProvisionRoks(channels: list[str], rc: int, additionalMsg: str | None
9797 return response .data .get ("ok" , False )
9898
9999
100- def notifyPipelineStart (channels : list [str ], instanceId : str | None = None , pipelineName : str | None = None ) -> dict | None :
100+ def notifyPipelineStart (channels : list [str ], instanceId : str | None = None , pipelineName : str | None = None , namespace : str | None = None ) -> dict | None :
101101 """Send Slack notification about pipeline start and create thread for all channels."""
102102 # Exit early if no channels provided
103103 if not channels or len (channels ) == 0 :
104104 print ("No Slack channels provided - skipping pipeline start notification" )
105105 return None
106106
107- # For update pipeline, use mas-pipelines namespace (no instance ID)
108- # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
109- if instanceId is None or instanceId == "" :
110- namespace = "mas-pipelines"
111- else :
112- namespace = f"mas-{ instanceId } -pipelines"
107+ # Use provided namespace, or fall back to legacy logic for backward compatibility
108+ if namespace is None or namespace == "" :
109+ # For update pipeline, use mas-pipelines namespace (no instance ID)
110+ # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
111+ if instanceId is None or instanceId == "" :
112+ namespace = "mas-pipelines"
113+ else :
114+ namespace = f"mas-{ instanceId } -pipelines"
113115
114116 # Check if thread already exists
115117 threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId , pipelineName )
@@ -157,25 +159,27 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipe
157159 return SlackUtil .getThreadConfigMap (namespace , instanceId , pipelineName )
158160
159161
160- def notifyAnsibleStart (channels : list [str ], taskName : str , instanceId : str | None = None , pipelineName : str | None = None ) -> bool :
162+ def notifyAnsibleStart (channels : list [str ], taskName : str , instanceId : str | None = None , pipelineName : str | None = None , namespace : str | None = None ) -> bool :
161163 """Send Slack notification about Ansible task start to all channels."""
162164 # Exit early if no channels provided
163165 if not channels or len (channels ) == 0 :
164166 print ("No Slack channels provided - skipping Ansible task start notification" )
165167 return False
166168
167- # For update pipeline, use mas-pipelines namespace (no instance ID)
168- # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
169- if instanceId is None or instanceId == "" :
170- namespace = "mas-pipelines"
171- else :
172- namespace = f"mas-{ instanceId } -pipelines"
169+ # Use provided namespace, or fall back to legacy logic for backward compatibility
170+ if namespace is None or namespace == "" :
171+ # For update pipeline, use mas-pipelines namespace (no instance ID)
172+ # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
173+ if instanceId is None or instanceId == "" :
174+ namespace = "mas-pipelines"
175+ else :
176+ namespace = f"mas-{ instanceId } -pipelines"
173177
174178 # Get thread information, create if doesn't exist
175179 threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId , pipelineName )
176180 if threadInfo is None :
177181 print ("No thread found - creating pipeline start notification" )
178- threadInfo = notifyPipelineStart (channels , instanceId , pipelineName )
182+ threadInfo = notifyPipelineStart (channels , instanceId , pipelineName , namespace )
179183
180184 # Get channel count
181185 channelCount = int (threadInfo .get ("channel_count" , "0" ))
@@ -216,25 +220,27 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
216220 return allSuccess
217221
218222
219- def notifyAnsibleComplete (channels : list [str ], rc : int , taskName : str , instanceId : str | None = None , pipelineName : str | None = None ) -> bool :
223+ def notifyAnsibleComplete (channels : list [str ], rc : int , taskName : str , instanceId : str | None = None , pipelineName : str | None = None , namespace : str | None = None ) -> bool :
220224 """Send Slack notification about Ansible task completion status to all channels."""
221225 # Exit early if no channels provided
222226 if not channels or len (channels ) == 0 :
223227 print ("No Slack channels provided - skipping Ansible task completion notification" )
224228 return False
225229
226- # For update pipeline, use mas-pipelines namespace (no instance ID)
227- # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
228- if instanceId is None or instanceId == "" :
229- namespace = "mas-pipelines"
230- else :
231- namespace = f"mas-{ instanceId } -pipelines"
230+ # Use provided namespace, or fall back to legacy logic for backward compatibility
231+ if namespace is None or namespace == "" :
232+ # For update pipeline, use mas-pipelines namespace (no instance ID)
233+ # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
234+ if instanceId is None or instanceId == "" :
235+ namespace = "mas-pipelines"
236+ else :
237+ namespace = f"mas-{ instanceId } -pipelines"
232238
233239 # Get thread information, create if doesn't exist
234240 threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId , pipelineName )
235241 if threadInfo is None :
236242 print ("No thread found - creating pipeline start notification" )
237- threadInfo = notifyPipelineStart (channels , instanceId , pipelineName )
243+ threadInfo = notifyPipelineStart (channels , instanceId , pipelineName , namespace )
238244
239245 # Get channel count
240246 channelCount = int (threadInfo .get ("channel_count" , "0" ))
@@ -306,24 +312,26 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceI
306312 # Special case, mas-update pipeline
307313 if namespace == "mas-pipelines" and taskName == "post-deps-update-verify-ingress" :
308314 print (f"mas-update pipeline completed with status: { rc } , sending pipeline complete message" )
309- allSuccess : bool = notifyPipelineComplete (channels , rc , instanceId , pipelineName )
315+ allSuccess : bool = notifyPipelineComplete (channels , rc , instanceId , pipelineName , namespace )
310316
311317 return allSuccess
312318
313319
314- def notifyPipelineComplete (channels : list [str ], rc : int , instanceId : str | None = None , pipelineName : str | None = None ) -> bool :
320+ def notifyPipelineComplete (channels : list [str ], rc : int , instanceId : str | None = None , pipelineName : str | None = None , namespace : str | None = None ) -> bool :
315321 """Send Slack notification about pipeline completion to all channels and cleanup ConfigMap."""
316322 # Exit early if no channels provided
317323 if not channels or len (channels ) == 0 :
318324 print ("No Slack channels provided - skipping pipeline completion notification" )
319325 return False
320326
321- # For update pipeline, use mas-pipelines namespace (no instance ID)
322- # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
323- if instanceId is None or instanceId == "" :
324- namespace = "mas-pipelines"
325- else :
326- namespace = f"mas-{ instanceId } -pipelines"
327+ # Use provided namespace, or fall back to legacy logic for backward compatibility
328+ if namespace is None or namespace == "" :
329+ # For update pipeline, use mas-pipelines namespace (no instance ID)
330+ # For install/upgrade pipelines, use mas-{instanceId}-pipelines namespace
331+ if instanceId is None or instanceId == "" :
332+ namespace = "mas-pipelines"
333+ else :
334+ namespace = f"mas-{ instanceId } -pipelines"
327335
328336 # Get thread information
329337 threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId , pipelineName )
@@ -411,18 +419,22 @@ if __name__ == "__main__":
411419 parser .add_argument ("--task-name" , required = False , default = "" )
412420 parser .add_argument ("--instance-id" , required = False , default = None )
413421 parser .add_argument ("--pipeline-name" , required = False , default = None )
422+ parser .add_argument ("--namespace" , required = False , default = None , help = "Pipeline namespace (e.g., mas-{instanceId}-pipelines or aiservice-{instanceId}-pipelines)" )
414423
415424 args , unknown = parser .parse_known_args ()
416425
426+ # Use namespace from command line arg, or fall back to PIPELINE_NAMESPACE env var
427+ namespace = args .namespace if args .namespace else os .getenv ("PIPELINE_NAMESPACE" , None )
428+
417429 if args .action == "ocp-provision-fyre" :
418430 notifyProvisionFyre (channelList , args .rc , args .msg )
419431 elif args .action == "ocp-provision-roks" :
420432 notifyProvisionRoks (channelList , args .rc , args .msg )
421433 elif args .action == "pipeline-start" :
422- notifyPipelineStart (channelList , args .instance_id , args .pipeline_name )
434+ notifyPipelineStart (channelList , args .instance_id , args .pipeline_name , namespace )
423435 elif args .action == "ansible-start" :
424- notifyAnsibleStart (channelList , args .task_name , args .instance_id , args .pipeline_name )
436+ notifyAnsibleStart (channelList , args .task_name , args .instance_id , args .pipeline_name , namespace )
425437 elif args .action == "ansible-complete" :
426- notifyAnsibleComplete (channelList , args .rc , args .task_name , args .instance_id , args .pipeline_name )
438+ notifyAnsibleComplete (channelList , args .rc , args .task_name , args .instance_id , args .pipeline_name , namespace )
427439 elif args .action == "pipeline-complete" :
428- notifyPipelineComplete (channelList , args .rc , args .instance_id , args .pipeline_name )
440+ notifyPipelineComplete (channelList , args .rc , args .instance_id , args .pipeline_name , namespace )
0 commit comments