Skip to content

Commit 3e3cbf8

Browse files
committed
Remove must-gather pod after it completes when explicit namespace is used
Currently, when user passes `--run-namespace` flag, must-gather pod becomes stale and is not removed. The reason is that `copy` container in the pod is set sleeping infinite, thus pod never falls into `completed` status to be collected by garbage collector. One option is setting to a precise duration for sleeping. But that also means that we will delay pod removal to a certain time which is presumably long(2 hours maybe?). Other option is removing the must-gather pod manually. This PR applies second option because we know when task is completed and there might be no need to delay this removal.
1 parent 619c8d7 commit 3e3cbf8

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)