Skip to content

Commit

Permalink
revert f.NewBuilder changes from overwrite_bootstrappolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Jul 20, 2017
1 parent d9229c5 commit 8f29bb3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewCommandAdmin(name, fullName string, in io.Reader, out io.Writer, errout
policy.NewCmdPolicy(policy.PolicyRecommendedName, fullName+" "+policy.PolicyRecommendedName, f, out, errout),
groups.NewCmdGroups(groups.GroupsRecommendedName, fullName+" "+groups.GroupsRecommendedName, f, out, errout),
cert.NewCmdCert(cert.CertRecommendedName, fullName+" "+cert.CertRecommendedName, out, errout),
admin.NewCommandOverwriteBootstrapPolicy(admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.CreateBootstrapPolicyFileCommand, f.NewBuilder(true), out),
admin.NewCommandOverwriteBootstrapPolicy(admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.CreateBootstrapPolicyFileCommand, out),
kubecmd.NewCmdCertificate(f, out),
},
},
Expand Down
21 changes: 11 additions & 10 deletions pkg/cmd/server/admin/overwrite_bootstrappolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
kerrors "k8s.io/apimachinery/pkg/util/errors"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
Expand All @@ -32,17 +33,14 @@ type OverwriteBootstrapPolicyOptions struct {
File string
MasterConfigFile string

Builder *resource.Builder

Force bool
Out io.Writer
CreateBootstrapPolicyCommand string
}

func NewCommandOverwriteBootstrapPolicy(commandName string, fullName string, createBootstrapPolicyCommand string, builder *resource.Builder, out io.Writer) *cobra.Command {
func NewCommandOverwriteBootstrapPolicy(commandName string, fullName string, createBootstrapPolicyCommand string, out io.Writer) *cobra.Command {
options := &OverwriteBootstrapPolicyOptions{Out: out}
options.CreateBootstrapPolicyCommand = createBootstrapPolicyCommand
options.Builder = builder

cmd := &cobra.Command{
Use: commandName,
Expand Down Expand Up @@ -81,9 +79,6 @@ func (o OverwriteBootstrapPolicyOptions) Validate(args []string) error {
if len(o.MasterConfigFile) == 0 {
return errors.New("master-config must be provided")
}
if o.Builder == nil {
return errors.New("resource builder must be provided")
}

return nil
}
Expand All @@ -100,15 +95,21 @@ func (o OverwriteBootstrapPolicyOptions) OverwriteBootstrapPolicy() error {
return err
}

return OverwriteBootstrapPolicy(optsGetter, o.Builder, o.File, o.CreateBootstrapPolicyCommand, o.Force, o.Out)
return OverwriteBootstrapPolicy(optsGetter, o.File, o.CreateBootstrapPolicyCommand, o.Force, o.Out)
}

func OverwriteBootstrapPolicy(optsGetter restoptions.Getter, builder *resource.Builder, policyFile, createBootstrapPolicyCommand string, change bool, out io.Writer) error {
func OverwriteBootstrapPolicy(optsGetter restoptions.Getter, policyFile, createBootstrapPolicyCommand string, change bool, out io.Writer) error {
if !change {
fmt.Fprintf(out, "Performing a dry run of policy overwrite:\n\n")
}

r := builder.
mapper := kapi.Registry.RESTMapper()
typer := kapi.Scheme
clientMapper := resource.ClientMapperFunc(func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return nil, nil
})

r := resource.NewBuilder(mapper, resource.SimpleCategoryExpander{}, typer, clientMapper, kapi.Codecs.UniversalDecoder()).
FilenameParam(false, &resource.FilenameOptions{Recursive: false, Filenames: []string{policyFile}}).
Flatten().
Do()
Expand Down
10 changes: 1 addition & 9 deletions pkg/cmd/server/origin/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"github.com/golang/glog"

kapierror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/retry"
"k8s.io/kubernetes/pkg/kubectl/resource"

"github.com/openshift/origin/pkg/cmd/admin/policy"

Expand Down Expand Up @@ -177,13 +175,7 @@ func (c *MasterConfig) ensureComponentAuthorizationRules() {
if _, err := clusterPolicyRegistry.GetClusterPolicy(ctx, authorizationapi.PolicyName, &metav1.GetOptions{}); kapierror.IsNotFound(err) {
glog.Infof("No cluster policy found. Creating bootstrap policy based on: %v", c.Options.PolicyConfig.BootstrapPolicyFile)

mapper := kapi.Registry.RESTMapper()
typer := kapi.Scheme
clientMapper := resource.ClientMapperFunc(func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return nil, nil
})
builder := resource.NewBuilder(mapper, resource.SimpleCategoryExpander{}, typer, clientMapper, kapi.Codecs.UniversalDecoder())
if err := admin.OverwriteBootstrapPolicy(c.RESTOptionsGetter, builder, c.Options.PolicyConfig.BootstrapPolicyFile, admin.CreateBootstrapPolicyFileFullCommand, true, ioutil.Discard); err != nil {
if err := admin.OverwriteBootstrapPolicy(c.RESTOptionsGetter, c.Options.PolicyConfig.BootstrapPolicyFile, admin.CreateBootstrapPolicyFileFullCommand, true, ioutil.Discard); err != nil {
glog.Errorf("Error creating bootstrap policy: %v", err)
}

Expand Down
12 changes: 1 addition & 11 deletions test/integration/bootstrap_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import (
"time"

kapierror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubectl/resource"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
"github.com/openshift/origin/pkg/client"
Expand Down Expand Up @@ -118,14 +115,7 @@ func TestBootstrapPolicyOverwritePolicyCommand(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}

mapper := kapi.Registry.RESTMapper()
typer := kapi.Scheme
clientMapper := resource.ClientMapperFunc(func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return nil, nil
})

builder := resource.NewBuilder(mapper, resource.SimpleCategoryExpander{}, typer, clientMapper, kapi.Codecs.UniversalDecoder())
if err := admin.OverwriteBootstrapPolicy(optsGetter, builder, masterConfig.PolicyConfig.BootstrapPolicyFile, admin.CreateBootstrapPolicyFileFullCommand, true, ioutil.Discard); err != nil {
if err := admin.OverwriteBootstrapPolicy(optsGetter, masterConfig.PolicyConfig.BootstrapPolicyFile, admin.CreateBootstrapPolicyFileFullCommand, true, ioutil.Discard); err != nil {
t.Errorf("unexpected error: %v", err)
}

Expand Down

0 comments on commit 8f29bb3

Please sign in to comment.