File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -598,6 +598,16 @@ func (o *MustGatherOptions) Run() error {
598598 o .PrintBasicClusterState (context .TODO ())
599599 }()
600600
601+ // Ensure resource cleanup unless instructed otherwise ...
602+ var cleanupNamespace func ()
603+ if ! o .Keep {
604+ defer func () {
605+ if cleanupNamespace != nil {
606+ cleanupNamespace ()
607+ }
608+ }()
609+ }
610+
601611 // Due to 'stack unwiding', this should happen after 'clusterState' printing, to ensure that we always
602612 // print our ClusterState information.
603613 runBackCollection := true
@@ -609,18 +619,14 @@ func (o *MustGatherOptions) Run() error {
609619 }()
610620
611621 // Get or create "working" namespace ...
612- ns , cleanupNamespace , err := o .getNamespace ()
622+ var ns * corev1.Namespace
623+ ns , cleanupNamespace , err = o .getNamespace ()
613624 if err != nil {
614625 // ensure the errors bubble up to BackupGathering method for display
615626 errs = []error {err }
616627 return err
617628 }
618629
619- // ... ensure resource cleanup unless instructed otherwise ...
620- if ! o .Keep {
621- defer cleanupNamespace ()
622- }
623-
624630 // Prefer to run in master if there's any but don't be explicit otherwise.
625631 // This enables the command to run by default in hypershift where there's no masters.
626632 nodes , err := o .Client .CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {
You can’t perform that action at this time.
0 commit comments