From 65f15bfc6de5683f108ba0521a675d8e63f36028 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Tue, 5 Nov 2024 18:09:12 +1300 Subject: [PATCH] fix potential panic --- pkg/supportbundle/collect.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index 35e946b8a..0d25a046a 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -439,7 +439,16 @@ func runRemoteHostCollectors(ctx context.Context, hostCollectors []*troubleshoot // TODO: // delete the config map // delete the remote pods - clientset.AppsV1().DaemonSets(ds.Namespace).Delete(ctx, ds.Name, metav1.DeleteOptions{}) + // check if the daemonset still exists + _, err := clientset.AppsV1().DaemonSets(ds.Namespace).Get(ctx, ds.Name, metav1.GetOptions{}) + if err != nil { + klog.Errorf("Failed to verify remote host collector daemonset %s still exists: %v", ds.Name, err) + return + } + + if err := clientset.AppsV1().DaemonSets(ds.Namespace).Delete(ctx, ds.Name, metav1.DeleteOptions{}); err != nil { + klog.Errorf("Failed to delete remote host collector daemonset %s: %v", ds.Name, err) + } }() for node, logs := range nodeLogs {