cleanup: change klog.Fatalf to fmt.Errorf for kubectl auth reconcile

cleanup: change klog.Fatalf to fmt.Errorf for kubectl auth reconcile

cleanup: change klog.Fatalf to fmt.Errorf for

Kubernetes-commit: 3b3a6d27cd1a55fff173427ac9d74d35de7f5acf
This commit is contained in:
xiongzhongliang 2021-01-01 22:43:51 +08:00 committed by Kubernetes Publisher
parent afa9f60606
commit 862982a5ec
1 changed files with 11 additions and 7 deletions

View File

@ -58,7 +58,7 @@ type ReconcileOptions struct {
var (
reconcileLong = templates.LongDesc(`
Reconciles rules for RBAC Role, RoleBinding, ClusterRole, and ClusterRole binding objects.
Reconciles rules for RBAC Role, RoleBinding, ClusterRole, and ClusterRoleBinding objects.
Missing objects are created, and the containing namespace is created for namespaced objects, if required.
@ -91,7 +91,7 @@ func NewCmdReconcile(f cmdutil.Factory, streams genericclioptions.IOStreams) *co
cmd := &cobra.Command{
Use: "reconcile -f FILENAME",
DisableFlagsInUseLine: true,
Short: "Reconciles rules for RBAC Role, RoleBinding, ClusterRole, and ClusterRole binding objects",
Short: "Reconciles rules for RBAC Role, RoleBinding, ClusterRole, and ClusterRoleBinding objects",
Long: reconcileLong,
Example: reconcileExample,
Run: func(cmd *cobra.Command, args []string) {
@ -121,7 +121,11 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
return errors.New("no arguments are allowed")
}
o.DryRun = getClientSideDryRun(cmd)
dryRun, err := getClientSideDryRun(cmd)
if err != nil {
return err
}
o.DryRun = dryRun
namespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
@ -331,13 +335,13 @@ func (o *ReconcileOptions) printResults(object runtime.Object,
}
}
func getClientSideDryRun(cmd *cobra.Command) bool {
func getClientSideDryRun(cmd *cobra.Command) (bool, error) {
dryRunStrategy, err := cmdutil.GetDryRunStrategy(cmd)
if err != nil {
klog.Fatalf("error accessing --dry-run flag for command %s: %v", cmd.Name(), err)
return false, fmt.Errorf("error accessing --dry-run flag for command %s: %v", cmd.Name(), err)
}
if dryRunStrategy == cmdutil.DryRunServer {
klog.Fatalf("--dry-run=server for command %s is not supported yet", cmd.Name())
return false, fmt.Errorf("--dry-run=server for command %s is not supported yet", cmd.Name())
}
return dryRunStrategy == cmdutil.DryRunClient
return dryRunStrategy == cmdutil.DryRunClient, nil
}