Merge pull request #97645 from pandaamanda/kubectl_auth_reconcile_fatal

cleanup: change klog.Fatalf to fmt.Errorf for `kubectl auth reconcile`
This commit is contained in:
Kubernetes Prow Robot 2021-01-06 13:53:45 -08:00 committed by GitHub
commit 3552bb5d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}