Skip to content

Commit 5046e19

Browse files
committed
Deprecate oc secrets subcomands
1 parent 00c6589 commit 5046e19

File tree

7 files changed

+40
-23
lines changed

7 files changed

+40
-23
lines changed

pkg/oc/cli/cli.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
9292
f := clientcmd.New(cmds.PersistentFlags())
9393

9494
loginCmd := login.NewCmdLogin(fullName, f, in, out, errout)
95-
secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, in, out, errout, fullName+" edit")
95+
secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, out, errout)
9696

9797
groups := ktemplates.CommandGroups{
9898
{
@@ -185,6 +185,10 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
185185
}
186186
groups.Add(cmds)
187187

188+
ocEditFullName := fullName + " edit"
189+
ocSecretsFullName := fullName + " " + secrets.SecretsRecommendedName
190+
ocSecretsNewFullName := ocSecretsFullName + " " + secrets.NewSecretRecommendedCommandName
191+
188192
filters := []string{
189193
"options",
190194
"deploy",
@@ -193,6 +197,10 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
193197
moved(fullName, "set volume", cmds, set.NewCmdVolume(fullName, f, out, errout)),
194198
moved(fullName, "logs", cmds, cmd.NewCmdBuildLogs(fullName, f, out)),
195199
moved(fullName, "secrets link", secretcmds, secrets.NewCmdLinkSecret("add", fullName, f, out)),
200+
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSecret(secrets.NewSecretRecommendedCommandName, fullName, f, out)),
201+
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateDockerConfigSecret(secrets.CreateDockerConfigSecretRecommendedName, fullName, f, out, ocSecretsNewFullName, ocEditFullName)),
202+
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateBasicAuthSecret(secrets.CreateBasicAuthSecretRecommendedCommandName, fullName, f, in, out, ocSecretsNewFullName, ocEditFullName)),
203+
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSSHAuthSecret(secrets.CreateSSHAuthSecretRecommendedCommandName, fullName, f, out, ocSecretsNewFullName, ocEditFullName)),
196204
}
197205

198206
changeSharedFlagDefaults(cmds)

pkg/oc/cli/secrets/basicauth.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ func NewCmdCreateBasicAuthSecret(name, fullName string, f kcmdutil.Factory, read
6565
}
6666

6767
cmd := &cobra.Command{
68-
Use: fmt.Sprintf("%s SECRET --username=USERNAME --password=PASSWORD [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
69-
Short: "Create a new secret for basic authentication",
70-
Long: createBasicAuthSecretLong,
71-
Example: fmt.Sprintf(createBasicAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
68+
Use: fmt.Sprintf("%s SECRET --username=USERNAME --password=PASSWORD [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
69+
Short: "Create a new secret for basic authentication",
70+
Long: createBasicAuthSecretLong,
71+
Example: fmt.Sprintf(createBasicAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
72+
Deprecated: "use oc create secret",
7273
Run: func(c *cobra.Command, args []string) {
7374
if err := o.Complete(f, args); err != nil {
7475
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))

pkg/oc/cli/secrets/dockercfg.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ func NewCmdCreateDockerConfigSecret(name, fullName string, f kcmdutil.Factory, o
6565
o := &CreateDockerConfigOptions{Out: out}
6666

6767
cmd := &cobra.Command{
68-
Use: fmt.Sprintf("%s SECRET --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL", name),
69-
Short: "Create a new dockercfg secret",
70-
Long: createDockercfgLong,
71-
Example: fmt.Sprintf(createDockercfgExample, fullName, newSecretFullName, ocEditFullName),
68+
Use: fmt.Sprintf("%s SECRET --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL", name),
69+
Short: "Create a new dockercfg secret",
70+
Long: createDockercfgLong,
71+
Example: fmt.Sprintf(createDockercfgExample, fullName, newSecretFullName, ocEditFullName),
72+
Deprecated: "use oc create secret",
7273
Run: func(c *cobra.Command, args []string) {
7374
if err := o.Complete(f, args); err != nil {
7475
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))

pkg/oc/cli/secrets/link_secret_to_obj.go

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"os"
78
"strings"
89

910
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -51,6 +52,11 @@ func NewCmdLinkSecret(name, fullName string, f kcmdutil.Factory, out io.Writer)
5152
Short: "Link secrets to a ServiceAccount",
5253
Long: linkSecretLong,
5354
Example: fmt.Sprintf(linkSecretExample, fullName),
55+
PreRun: func(cmd *cobra.Command, args []string) {
56+
if len(os.Args) > 1 && os.Args[1] == "add" {
57+
printDeprecationWarning("secrets add", "secrets link")
58+
}
59+
},
5460
Run: func(c *cobra.Command, args []string) {
5561
if err := o.Complete(f, args); err != nil {
5662
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
@@ -160,3 +166,7 @@ func (o LinkSecretOptions) linkSecretsToServiceAccount(serviceaccount *kapi.Serv
160166

161167
return nil
162168
}
169+
170+
func printDeprecationWarning(command, alias string) {
171+
fmt.Fprintf(os.Stderr, "%s is DEPRECATED and will be removed in a future version. Use %s instead.\n", alias, command)
172+
}

pkg/oc/cli/secrets/new.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ func NewCmdCreateSecret(name, fullName string, f *clientcmd.Factory, out io.Writ
7676
options.Out = out
7777

7878
cmd := &cobra.Command{
79-
Use: fmt.Sprintf("%s NAME [KEY=]SOURCE ...", name),
80-
Short: "Create a new secret based on a key file or on files within a directory",
81-
Long: newLong,
82-
Example: fmt.Sprintf(newExample, fullName),
79+
Use: fmt.Sprintf("%s NAME [KEY=]SOURCE ...", name),
80+
Short: "Create a new secret based on a key file or on files within a directory",
81+
Long: newLong,
82+
Example: fmt.Sprintf(newExample, fullName),
83+
Deprecated: "use oc create secret",
8384
Run: func(c *cobra.Command, args []string) {
8485
if err := options.Complete(args, f); err != nil {
8586
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))

pkg/oc/cli/secrets/sshauth.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ func NewCmdCreateSSHAuthSecret(name, fullName string, f kcmdutil.Factory, out io
5959
}
6060

6161
cmd := &cobra.Command{
62-
Use: fmt.Sprintf("%s SECRET --ssh-privatekey=FILENAME [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
63-
Short: "Create a new secret for SSH authentication",
64-
Long: createSSHAuthSecretLong,
65-
Example: fmt.Sprintf(createSSHAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
62+
Use: fmt.Sprintf("%s SECRET --ssh-privatekey=FILENAME [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
63+
Short: "Create a new secret for SSH authentication",
64+
Long: createSSHAuthSecretLong,
65+
Example: fmt.Sprintf(createSSHAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
66+
Deprecated: "use oc create secret",
6667
Run: func(c *cobra.Command, args []string) {
6768
if err := o.Complete(f, args); err != nil {
6869
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))

pkg/oc/cli/secrets/subcommand.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
Docker registries.`)
3535
)
3636

37-
func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, reader io.Reader, out, errOut io.Writer, ocEditFullName string) *cobra.Command {
37+
func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
3838
// Parent command to which all subcommands are added.
3939
cmds := &cobra.Command{
4040
Use: name,
@@ -44,11 +44,6 @@ func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, reader io.Reader
4444
Run: cmdutil.DefaultSubCommandRun(errOut),
4545
}
4646

47-
newSecretFullName := fullName + " " + NewSecretRecommendedCommandName
48-
cmds.AddCommand(NewCmdCreateSecret(NewSecretRecommendedCommandName, newSecretFullName, f, out))
49-
cmds.AddCommand(NewCmdCreateDockerConfigSecret(CreateDockerConfigSecretRecommendedName, fullName+" "+CreateDockerConfigSecretRecommendedName, f, out, newSecretFullName, ocEditFullName))
50-
cmds.AddCommand(NewCmdCreateBasicAuthSecret(CreateBasicAuthSecretRecommendedCommandName, fullName+" "+CreateBasicAuthSecretRecommendedCommandName, f, reader, out, newSecretFullName, ocEditFullName))
51-
cmds.AddCommand(NewCmdCreateSSHAuthSecret(CreateSSHAuthSecretRecommendedCommandName, fullName+" "+CreateSSHAuthSecretRecommendedCommandName, f, out, newSecretFullName, ocEditFullName))
5247
cmds.AddCommand(NewCmdLinkSecret(LinkSecretRecommendedName, fullName+" "+LinkSecretRecommendedName, f, out))
5348
cmds.AddCommand(NewCmdUnlinkSecret(UnlinkSecretRecommendedName, fullName+" "+UnlinkSecretRecommendedName, f, out))
5449

0 commit comments

Comments
 (0)