Skip to content

Commit 8b0bde2

Browse files
authored
Merge branch 'openshift:main' into master
2 parents e9f3105 + ec3434b commit 8b0bde2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/cli/admin/mustgather/mustgather.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff 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{

0 commit comments

Comments
 (0)