Skip to content

Commit

Permalink
Change scheme to kubectl and fix test-cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed Aug 2, 2018
1 parent 6b08d2c commit ffe036a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 40 deletions.
1 change: 0 additions & 1 deletion pkg/oc/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*cor

// identify the command to be run
originalCommand, _ := o.getContainerImageCommand(pod, container)
//originalCommand := []string{"<image entrypoint>"}
if len(container.Command) > 0 {
originalCommand = container.Command
originalCommand = append(originalCommand, container.Args...)
Expand Down
21 changes: 8 additions & 13 deletions pkg/oc/cli/secrets/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
"k8s.io/kubernetes/pkg/kubectl/scheme"
kterm "k8s.io/kubernetes/pkg/kubectl/util/term"

"github.com/openshift/origin/pkg/cmd/util/term"
"github.com/openshift/origin/pkg/oc/util/ocscheme"
)

// CreateBasicAuthSecretRecommendedCommandName represents name of subcommand for `oc secrets` command
Expand Down Expand Up @@ -64,7 +64,7 @@ type CreateBasicAuthSecretOptions struct {

func NewCreateBasicAuthSecretOptions(streams genericclioptions.IOStreams) *CreateBasicAuthSecretOptions {
return &CreateBasicAuthSecretOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(ocscheme.PrintingInternalScheme),
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: streams,
}
}
Expand Down Expand Up @@ -105,7 +105,6 @@ func (o *CreateBasicAuthSecretOptions) Run() error {
if err != nil {
return err
}

if _, err := o.SecretsInterface.Create(secret); err != nil {
return err
}
Expand Down Expand Up @@ -154,10 +153,12 @@ func (o *CreateBasicAuthSecretOptions) Complete(f kcmdutil.Factory, args []strin
if len(args) != 1 {
return errors.New("must have exactly one argument: secret name")
}

o.SecretName = args[0]

if o.PromptForPassword {
if len(o.Password) > 0 {
return errors.New("must provide either --prompt or --password flag")
}
if !kterm.IsTerminal(o.In) {
return errors.New("provided reader is not a terminal")
}
Expand All @@ -168,16 +169,15 @@ func (o *CreateBasicAuthSecretOptions) Complete(f kcmdutil.Factory, args []strin
}
}

config, err := f.ToRESTConfig()
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}

clientset, err := corev1client.NewForConfig(config)
config, err := f.ToRESTConfig()
if err != nil {
return err
}
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
clientset, err := corev1client.NewForConfig(config)
if err != nil {
return err
}
Expand All @@ -196,14 +196,9 @@ func (o CreateBasicAuthSecretOptions) Validate() error {
if len(o.SecretName) == 0 {
return errors.New("basic authentication secret name must be present")
}

if len(o.Username) == 0 && len(o.Password) == 0 {
return errors.New("must provide basic authentication credentials")
}

if o.PromptForPassword && len(o.Password) > 0 {
return errors.New("must provide either --prompt or --password flag")
}

return nil
}
12 changes: 0 additions & 12 deletions pkg/oc/cli/secrets/basicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ func TestValidateBasicAuth(t *testing.T) {
},
expErr: true, //"Must provide basic authentication credentials"
},
{
testName: "passwordAndPrompt",
options: func(streams genericclioptions.IOStreams) *CreateBasicAuthSecretOptions {
o := NewCreateBasicAuthSecretOptions(streams)
o.Username = "testUser"
o.Password = "testPassword"
o.SecretName = "testSecret"
o.PromptForPassword = true
return o
},
expErr: true, //"Must provide either --prompt or --password flag"
},
}

for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/secrets/dockercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (

"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
corev1 "k8s.io/api/core/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/kubernetes/pkg/credentialprovider"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)

const CreateDockerConfigSecretRecommendedName = "new-dockercfg"
Expand Down Expand Up @@ -67,7 +67,7 @@ type CreateDockerConfigOptions struct {

func NewCreateDockerConfigOptions(streams genericclioptions.IOStreams) *CreateDockerConfigOptions {
return &CreateDockerConfigOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(ocscheme.PrintingInternalScheme),
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: streams,
}
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/oc/cli/secrets/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)

const NewSecretRecommendedCommandName = "new"
Expand Down Expand Up @@ -76,7 +75,7 @@ type CreateSecretOptions struct {

func NewCreateSecretOptions(streams genericclioptions.IOStreams) *CreateSecretOptions {
return &CreateSecretOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(ocscheme.PrintingInternalScheme),
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: streams,
}
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/oc/cli/secrets/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
)

// SecretOptions Structure holding state for processing secret linking and
Expand Down Expand Up @@ -155,7 +153,7 @@ func (o SecretOptions) GetSecrets(allowNonExisting bool) ([]*corev1.Secret, bool

for _, secretName := range o.SecretNames {
r := o.BuilderFunc().
WithScheme(ocscheme.ReadingInternalScheme, ocscheme.ReadingInternalScheme.PrioritizedVersionsAllGroups()...).
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
NamespaceParam(o.Namespace).
ResourceNames("secrets", secretName).
SingleResourceType().
Expand Down
5 changes: 2 additions & 3 deletions pkg/oc/cli/secrets/sshauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)

// CreateSSHAuthSecretRecommendedCommandName represents name of subcommand for `oc secrets` command
Expand Down Expand Up @@ -61,7 +60,7 @@ type CreateSSHAuthSecretOptions struct {

func NewCreateSSHAuthSecretOptions(streams genericclioptions.IOStreams) *CreateSSHAuthSecretOptions {
return &CreateSSHAuthSecretOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(ocscheme.PrintingInternalScheme),
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: streams,
}
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/oc/cli/secrets/unlink_secret_from_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)

const UnlinkSecretRecommendedName = "unlink"
Expand All @@ -39,7 +38,7 @@ type UnlinkSecretOptions struct {

func NewUnlinkSecretOptions(streams genericclioptions.IOStreams) *UnlinkSecretOptions {
return &UnlinkSecretOptions{
PrintFlags: genericclioptions.NewPrintFlags("updated").WithTypeSetter(ocscheme.PrintingInternalScheme),
PrintFlags: genericclioptions.NewPrintFlags("updated").WithTypeSetter(scheme.Scheme),
SecretOptions: SecretOptions{},
IOStreams: streams,
}
Expand Down

0 comments on commit ffe036a

Please sign in to comment.