Skip to content

Commit 08ec719

Browse files
committed
must-gather: Align cleanup order
Delete the temporary namespace after the backup gathering.
1 parent fa1bc38 commit 08ec719

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
@@ -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{

0 commit comments

Comments
 (0)