Skip to content

Commit 7a94ed9

Browse files
committed
must-gather: Do cleanup on role binding error
When the temporary must-gather role binding fails to be created, no namespace cleanup function is returned and the namespace is left behind. This is now fixed by returning the namespace cleanup function on error.
1 parent c1fa788 commit 7a94ed9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/cli/admin/mustgather/mustgather.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,12 +1012,6 @@ func (o *MustGatherOptions) createTempNamespace() (*corev1.Namespace, func(), er
10121012
}
10131013
o.PrinterCreated.PrintObj(ns, o.LogOut)
10141014

1015-
crb, err := o.Client.RbacV1().ClusterRoleBindings().Create(context.TODO(), newClusterRoleBinding(ns), metav1.CreateOptions{})
1016-
if err != nil {
1017-
return nil, nil, fmt.Errorf("creating temp clusterRoleBinding: %w", err)
1018-
}
1019-
o.PrinterCreated.PrintObj(crb, o.LogOut)
1020-
10211015
cleanup := func() {
10221016
if err := o.Client.CoreV1().Namespaces().Delete(context.TODO(), ns.Name, metav1.DeleteOptions{}); err != nil {
10231017
fmt.Printf("%v\n", err)
@@ -1026,6 +1020,12 @@ func (o *MustGatherOptions) createTempNamespace() (*corev1.Namespace, func(), er
10261020
}
10271021
}
10281022

1023+
crb, err := o.Client.RbacV1().ClusterRoleBindings().Create(ctx, newClusterRoleBinding(ns), metav1.CreateOptions{})
1024+
if err != nil {
1025+
return nil, cleanup, fmt.Errorf("creating temp clusterRoleBinding: %w", err)
1026+
}
1027+
o.PrinterCreated.PrintObj(crb, o.LogOut)
1028+
10291029
return ns, cleanup, nil
10301030
}
10311031

0 commit comments

Comments
 (0)