Skip to content

Commit bee9eda

Browse files
author
Ravi Sankar Penta
committed
Group commands in oadm for ease of use
Group oadm certificate related cmds under 'oadm ca' To maintain backward compatibility, old commands still work with deprecated message but are not surfaced in the help message.
1 parent a6e1afb commit bee9eda

File tree

11 files changed

+444
-331
lines changed

11 files changed

+444
-331
lines changed

hack/test-cmd.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ do
112112
SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}"
113113
done <<< "${ALL_IP_ADDRESSES}"
114114

115-
openshift admin create-master-certs \
115+
openshift admin ca create-master-certs \
116116
--overwrite=false \
117117
--cert-dir="${MASTER_CONFIG_DIR}" \
118118
--hostnames="${SERVER_HOSTNAME_LIST}" \
@@ -283,7 +283,15 @@ echo "templates: ok"
283283
[ "$(openshift kubectl 2>&1 | grep 'Kubernetes cluster')" ]
284284
[ "$(oadm 2>&1 | grep 'OpenShift Administrative Commands')" ]
285285
[ "$(openshift admin 2>&1 | grep 'OpenShift Administrative Commands')" ]
286+
[ "$(oadm | grep 'Basic Commands:')" ]
287+
[ "$(oadm | grep 'Install Commands:')" ]
288+
[ "$(oadm ca | grep 'Manage certificates')" ]
286289
[ "$(openshift start kubernetes 2>&1 | grep 'Kubernetes server components')" ]
290+
# check deprecated admin cmds for backward compatibility
291+
[ "$(oadm create-master-certs -h 2>&1 | grep 'Create keys and certificates')" ]
292+
[ "$(oadm create-key-pair -h 2>&1 | grep 'Create a 2048-bit RSA key pair')" ]
293+
[ "$(oadm create-server-cert -h 2>&1 | grep 'Create a key and server certificate')" ]
294+
[ "$(oadm create-signer-cert -h 2>&1 | grep 'Create a self-signed CA')" ]
287295

288296
# help for root commands with --help flag must be consistent
289297
[ "$(openshift --help 2>&1 | grep 'OpenShift Application Platform')" ]

hack/test-end-to-end.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ do
197197
SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}"
198198
done <<< "${ALL_IP_ADDRESSES}"
199199

200-
openshift admin create-master-certs \
200+
openshift admin ca create-master-certs \
201201
--overwrite=false \
202202
--cert-dir="${MASTER_CONFIG_DIR}" \
203203
--hostnames="${SERVER_HOSTNAME_LIST}" \

hack/test-extended.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ start_server() {
6060
done <<< "${ALL_IP_ADDRESSES}"
6161

6262
echo "[INFO] Create certificates for the OpenShift master"
63-
env "PATH=${PATH}" openshift admin create-master-certs \
63+
env "PATH=${PATH}" openshift admin ca create-master-certs \
6464
--overwrite=false \
6565
--cert-dir="${MASTER_CONFIG_DIR}" \
6666
--hostnames="${SERVER_HOSTNAME_LIST}" \

pkg/cmd/admin/admin.go

+61-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
"github.com/openshift/origin/pkg/cmd/admin/cert"
910
"github.com/openshift/origin/pkg/cmd/admin/node"
1011
"github.com/openshift/origin/pkg/cmd/admin/policy"
1112
"github.com/openshift/origin/pkg/cmd/admin/project"
@@ -38,31 +39,68 @@ func NewCommandAdmin(name, fullName string, out io.Writer) *cobra.Command {
3839

3940
f := clientcmd.New(cmds.PersistentFlags())
4041

41-
cmds.AddCommand(project.NewCmdNewProject(project.NewProjectRecommendedName, fullName+" "+project.NewProjectRecommendedName, f, out))
42-
cmds.AddCommand(policy.NewCmdPolicy(policy.PolicyRecommendedName, fullName+" "+policy.PolicyRecommendedName, f, out))
43-
cmds.AddCommand(exipfailover.NewCmdIPFailoverConfig(f, fullName, "ipfailover", out))
44-
cmds.AddCommand(router.NewCmdRouter(f, fullName, "router", out))
45-
cmds.AddCommand(registry.NewCmdRegistry(f, fullName, "registry", out))
46-
cmds.AddCommand(buildchain.NewCmdBuildChain(f, fullName, "build-chain"))
47-
cmds.AddCommand(node.NewCommandManageNode(f, node.ManageNodeCommandName, fullName+" "+node.ManageNodeCommandName, out))
48-
cmds.AddCommand(cmd.NewCmdConfig(fullName, "config"))
49-
cmds.AddCommand(prune.NewCommandPrune(prune.PruneRecommendedName, fullName+" "+prune.PruneRecommendedName, f, out))
42+
groups := templates.CommandGroups{
43+
{
44+
Message: "Basic Commands:",
45+
Commands: []*cobra.Command{
46+
project.NewCmdNewProject(project.NewProjectRecommendedName, fullName+" "+project.NewProjectRecommendedName, f, out),
47+
policy.NewCmdPolicy(policy.PolicyRecommendedName, fullName+" "+policy.PolicyRecommendedName, f, out),
48+
},
49+
},
50+
{
51+
Message: "Install Commands:",
52+
Commands: []*cobra.Command{
53+
router.NewCmdRouter(f, fullName, "router", out),
54+
exipfailover.NewCmdIPFailoverConfig(f, fullName, "ipfailover", out),
55+
registry.NewCmdRegistry(f, fullName, "registry", out),
56+
},
57+
},
58+
{
59+
Message: "Maintenance Commands:",
60+
Commands: []*cobra.Command{
61+
buildchain.NewCmdBuildChain(f, fullName, "build-chain"),
62+
node.NewCommandManageNode(f, node.ManageNodeCommandName, fullName+" "+node.ManageNodeCommandName, out),
63+
prune.NewCommandPrune(prune.PruneRecommendedName, fullName+" "+prune.PruneRecommendedName, f, out),
64+
},
65+
},
66+
{
67+
Message: "Settings Commands:",
68+
Commands: []*cobra.Command{
69+
cmd.NewCmdConfig(fullName, "config"),
5070

51-
// TODO: these probably belong in a sub command
52-
cmds.AddCommand(admin.NewCommandCreateKubeConfig(admin.CreateKubeConfigCommandName, fullName+" "+admin.CreateKubeConfigCommandName, out))
53-
cmds.AddCommand(admin.NewCommandCreateBootstrapPolicyFile(admin.CreateBootstrapPolicyFileCommand, fullName+" "+admin.CreateBootstrapPolicyFileCommand, out))
54-
cmds.AddCommand(admin.NewCommandCreateBootstrapProjectTemplate(f, admin.CreateBootstrapProjectTemplateCommand, fullName+" "+admin.CreateBootstrapProjectTemplateCommand, out))
55-
cmds.AddCommand(admin.NewCommandOverwriteBootstrapPolicy(admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.CreateBootstrapPolicyFileCommand, out))
56-
cmds.AddCommand(admin.NewCommandNodeConfig(admin.NodeConfigCommandName, fullName+" "+admin.NodeConfigCommandName, out))
57-
// TODO: these should be rolled up together
58-
cmds.AddCommand(admin.NewCommandCreateMasterCerts(admin.CreateMasterCertsCommandName, fullName+" "+admin.CreateMasterCertsCommandName, out))
59-
cmds.AddCommand(admin.NewCommandCreateClient(admin.CreateClientCommandName, fullName+" "+admin.CreateClientCommandName, out))
60-
cmds.AddCommand(admin.NewCommandCreateKeyPair(admin.CreateKeyPairCommandName, fullName+" "+admin.CreateKeyPairCommandName, out))
61-
cmds.AddCommand(admin.NewCommandCreateServerCert(admin.CreateServerCertCommandName, fullName+" "+admin.CreateServerCertCommandName, out))
62-
cmds.AddCommand(admin.NewCommandCreateSignerCert(admin.CreateSignerCertCommandName, fullName+" "+admin.CreateSignerCertCommandName, out))
71+
// TODO: these probably belong in a sub command
72+
admin.NewCommandCreateKubeConfig(admin.CreateKubeConfigCommandName, fullName+" "+admin.CreateKubeConfigCommandName, out),
73+
admin.NewCommandCreateClient(admin.CreateClientCommandName, fullName+" "+admin.CreateClientCommandName, out),
74+
},
75+
},
76+
{
77+
Message: "Advanced Commands:",
78+
Commands: []*cobra.Command{
79+
admin.NewCommandCreateBootstrapProjectTemplate(f, admin.CreateBootstrapProjectTemplateCommand, fullName+" "+admin.CreateBootstrapProjectTemplateCommand, out),
80+
admin.NewCommandCreateBootstrapPolicyFile(admin.CreateBootstrapPolicyFileCommand, fullName+" "+admin.CreateBootstrapPolicyFileCommand, out),
81+
admin.NewCommandOverwriteBootstrapPolicy(admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.OverwriteBootstrapPolicyCommandName, fullName+" "+admin.CreateBootstrapPolicyFileCommand, out),
82+
admin.NewCommandNodeConfig(admin.NodeConfigCommandName, fullName+" "+admin.NodeConfigCommandName, out),
83+
cert.NewCmdCert(cert.CertRecommendedName, fullName+" "+cert.CertRecommendedName, out),
84+
},
85+
},
86+
}
87+
88+
groups.Add(cmds)
89+
templates.ActsAsRootCommand(cmds, groups...)
6390

64-
// TODO: use groups
65-
templates.ActsAsRootCommand(cmds)
91+
// Deprecated commands that are bundled with the binary but not displayed to end users directly
92+
deprecatedCommands := []*cobra.Command{
93+
admin.NewCommandCreateMasterCerts(admin.CreateMasterCertsCommandName, fullName+" "+admin.CreateMasterCertsCommandName, out),
94+
admin.NewCommandCreateKeyPair(admin.CreateKeyPairCommandName, fullName+" "+admin.CreateKeyPairCommandName, out),
95+
admin.NewCommandCreateServerCert(admin.CreateServerCertCommandName, fullName+" "+admin.CreateServerCertCommandName, out),
96+
admin.NewCommandCreateSignerCert(admin.CreateSignerCertCommandName, fullName+" "+admin.CreateSignerCertCommandName, out),
97+
}
98+
for _, cmd := range deprecatedCommands {
99+
// Unsetting Short description will not show this command in help
100+
cmd.Short = ""
101+
cmd.Deprecated = fmt.Sprintf("Use '%s ca' instead.", fullName)
102+
cmds.AddCommand(cmd)
103+
}
66104

67105
if name == fullName {
68106
cmds.AddCommand(version.NewVersionCommand(fullName))

pkg/cmd/admin/cert/cert.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cert
2+
3+
import (
4+
"io"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/openshift/origin/pkg/cmd/server/admin"
9+
"github.com/openshift/origin/pkg/cmd/util"
10+
)
11+
12+
const CertRecommendedName = "ca"
13+
14+
// NewCmdCert implements the OpenShift cli ca command
15+
func NewCmdCert(name, fullName string, out io.Writer) *cobra.Command {
16+
// Parent command to which all subcommands are added.
17+
cmds := &cobra.Command{
18+
Use: name,
19+
Short: "Manage certificates and keys",
20+
Long: `Manage certificates and keys`,
21+
Run: util.DefaultSubCommandRun(out),
22+
}
23+
24+
cmds.AddCommand(admin.NewCommandCreateMasterCerts(admin.CreateMasterCertsCommandName, fullName+" "+admin.CreateMasterCertsCommandName, out))
25+
cmds.AddCommand(admin.NewCommandCreateKeyPair(admin.CreateKeyPairCommandName, fullName+" "+admin.CreateKeyPairCommandName, out))
26+
cmds.AddCommand(admin.NewCommandCreateServerCert(admin.CreateServerCertCommandName, fullName+" "+admin.CreateServerCertCommandName, out))
27+
cmds.AddCommand(admin.NewCommandCreateSignerCert(admin.CreateSignerCertCommandName, fullName+" "+admin.CreateSignerCertCommandName, out))
28+
29+
return cmds
30+
}

pkg/cmd/server/admin/create_mastercerts.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ server cert and run the command to fill it in:
5252
--public-master=https://external.master.fqdn:8443 \
5353
--hostnames=external.master.fqdn,internal.master.fqdn,localhost,127.0.0.1,172.17.42.1,kubernetes.default.local
5454
55-
Alternatively, use the related "create-server-cert" command to explicitly
55+
Alternatively, use the related "ca create-server-cert" command to explicitly
5656
create a certificate.
5757
5858
Regardless of --overwrite, the master server key/cert will be updated
@@ -81,7 +81,7 @@ func NewCommandCreateMasterCerts(commandName string, fullName string, out io.Wri
8181

8282
cmd := &cobra.Command{
8383
Use: commandName,
84-
Short: "Create certificates for an OpenShift master",
84+
Short: "Create certificates and keys for an OpenShift master",
8585
Long: fmt.Sprintf(masterCertLong, fullName),
8686
Run: func(cmd *cobra.Command, args []string) {
8787
if err := options.Validate(args); err != nil {

pkg/cmd/server/admin/create_signercert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewCommandCreateSignerCert(commandName string, fullName string, out io.Writ
5252

5353
cmd := &cobra.Command{
5454
Use: commandName,
55-
Short: "Create a signer (certificate authority/CA) certificate",
55+
Short: "Create a signer (certificate authority/CA) certificate and key",
5656
Long: createSignerLong,
5757
Run: func(cmd *cobra.Command, args []string) {
5858
if err := options.Validate(args); err != nil {

pkg/cmd/templates/templater.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func (g CommandGroups) Has(c *cobra.Command) bool {
4040
func AddAdditionalCommands(g CommandGroups, message string, cmds []*cobra.Command) CommandGroups {
4141
group := CommandGroup{Message: message}
4242
for _, c := range cmds {
43-
if !g.Has(c) {
43+
// Don't show commands that has no short description
44+
if !g.Has(c) && len(c.Short) != 0 {
4445
group.Commands = append(group.Commands, c)
4546
}
4647
}

0 commit comments

Comments
 (0)