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 @@ -586,6 +586,16 @@ func (o *MustGatherOptions) Run() error {
586586 o .PrintBasicClusterState (context .TODO ())
587587 }()
588588
589+ // Ensure resource cleanup unless instructed otherwise ...
590+ var cleanupNamespace func ()
591+ if ! o .Keep {
592+ defer func () {
593+ if cleanupNamespace != nil {
594+ cleanupNamespace ()
595+ }
596+ }()
597+ }
598+
589599 // Due to 'stack unwiding', this should happen after 'clusterState' printing, to ensure that we always
590600 // print our ClusterState information.
591601 runBackCollection := true
@@ -597,18 +607,14 @@ func (o *MustGatherOptions) Run() error {
597607 }()
598608
599609 // Get or create "working" namespace ...
600- ns , cleanupNamespace , err := o .getNamespace ()
610+ var ns * corev1.Namespace
611+ ns , cleanupNamespace , err = o .getNamespace ()
601612 if err != nil {
602613 // ensure the errors bubble up to BackupGathering method for display
603614 errs = []error {err }
604615 return err
605616 }
606617
607- // ... ensure resource cleanup unless instructed otherwise ...
608- if ! o .Keep {
609- defer cleanupNamespace ()
610- }
611-
612618 // Prefer to run in master if there's any but don't be explicit otherwise.
613619 // This enables the command to run by default in hypershift where there's no masters.
614620 nodes , err := o .Client .CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {
You can’t perform that action at this time.
0 commit comments