Skip to content

Commit 983567b

Browse files
Merge pull request #1320 from ardaguclu/ocpbugs-5010
OCPBUGS-5010: Remove must-gather pod after it completes when explicit namespace is used
2 parents a0c13fc + 3e3cbf8 commit 983567b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/cli/admin/mustgather/mustgather.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,19 @@ func (o *MustGatherOptions) Run() error {
379379
go func(pod *corev1.Pod) {
380380
defer wg.Done()
381381

382+
if len(o.RunNamespace) > 0 && !o.Keep {
383+
defer func() {
384+
// must-gather runs in its own separate namespace as default , so after it is completed
385+
// it deletes this namespace and all the pods are removed by garbage collector.
386+
// However, if user specifies namespace via `run-namespace`, these pods need to
387+
// be deleted manually.
388+
err = o.Client.CoreV1().Pods(o.RunNamespace).Delete(context.TODO(), pod.Name, metav1.DeleteOptions{})
389+
if err != nil {
390+
klog.V(4).Infof("pod deletion error %v", err)
391+
}
392+
}()
393+
}
394+
382395
log := newPodOutLogger(o.Out, pod.Name)
383396

384397
// wait for gather container to be running (gather is running)

0 commit comments

Comments
 (0)