diff --git a/pkg/kubectl/cmd/auth/reconcile.go b/pkg/kubectl/cmd/auth/reconcile.go index 948d8f3fac5..da2b57ebbce 100644 --- a/pkg/kubectl/cmd/auth/reconcile.go +++ b/pkg/kubectl/cmd/auth/reconcile.go @@ -35,9 +35,9 @@ import ( // ReconcileOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of // referencing the cmd.Flags() type ReconcileOptions struct { - ResourceBuilder *resource.Builder + Visitor resource.Visitor RBACClient internalrbacclient.RbacInterface - CoreClient internalcoreclient.CoreInterface + NamespaceClient internalcoreclient.NamespaceInterface Print func(*resource.Info) error @@ -92,18 +92,24 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args if err != nil { return err } - o.ResourceBuilder = f.NewBuilder(). + + r := f.NewBuilder(). ContinueOnError(). NamespaceParam(namespace).DefaultNamespace(). FilenameParam(enforceNamespace, options). - Flatten() + Flatten(). + Do() + if err := r.Err(); err != nil { + return err + } + o.Visitor = r client, err := f.ClientSet() if err != nil { return err } o.RBACClient = client.Rbac() - o.CoreClient = client.Core() + o.NamespaceClient = client.Core().Namespaces() mapper, _ := f.Object() dryRun := false @@ -121,17 +127,29 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args } func (o *ReconcileOptions) Validate() error { + if o.Visitor == nil { + return errors.New("ReconcileOptions.Visitor must be set") + } + if o.RBACClient == nil { + return errors.New("ReconcileOptions.RBACClient must be set") + } + if o.NamespaceClient == nil { + return errors.New("ReconcileOptions.NamespaceClient must be set") + } + if o.Print == nil { + return errors.New("ReconcileOptions.Print must be set") + } + if o.Out == nil { + return errors.New("ReconcileOptions.Out must be set") + } + if o.Err == nil { + return errors.New("ReconcileOptions.Err must be set") + } return nil } func (o *ReconcileOptions) RunReconcile() error { - r := o.ResourceBuilder.Do() - err := r.Err() - if err != nil { - return err - } - - err = r.Visit(func(info *resource.Info, err error) error { + return o.Visitor.Visit(func(info *resource.Info, err error) error { if err != nil { return err } @@ -147,7 +165,7 @@ func (o *ReconcileOptions) RunReconcile() error { RemoveExtraPermissions: false, Role: reconciliation.RoleRuleOwner{Role: t}, Client: reconciliation.RoleModifier{ - NamespaceClient: o.CoreClient.Namespaces(), + NamespaceClient: o.NamespaceClient, Client: o.RBACClient, }, } @@ -181,7 +199,7 @@ func (o *ReconcileOptions) RunReconcile() error { RoleBinding: reconciliation.RoleBindingAdapter{RoleBinding: t}, Client: reconciliation.RoleBindingClientAdapter{ Client: o.RBACClient, - NamespaceClient: o.CoreClient.Namespaces(), + NamespaceClient: o.NamespaceClient, }, } result, err := reconcileOptions.Run() @@ -214,6 +232,4 @@ func (o *ReconcileOptions) RunReconcile() error { return nil }) - - return err }