Skip to content

Commit 2e784ee

Browse files
author
OpenShift Bot
committed
Merge pull request #1446 from smarterclayton/create_official_admin_command
Merged by openshift-bot
2 parents a65d56d + ac38ade commit 2e784ee

File tree

20 files changed

+234
-99
lines changed

20 files changed

+234
-99
lines changed

hack/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ readonly OPENSHIFT_BINARY_SYMLINKS=(
5454
openshift-sti-build
5555
openshift-docker-build
5656
osc
57+
osadm
5758
)
5859
readonly OPENSHIFT_BINARY_COPY=(
5960
osc

hack/test-cmd.sh

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,34 @@ echo "templates: ok"
170170
# verify some default commands
171171
[ "$(openshift cli)" ]
172172
[ "$(openshift ex)" ]
173-
[ "$(openshift ex config 2>&1)" ]
173+
[ "$(openshift admin config 2>&1)" ]
174+
[ "$(openshift cli config 2>&1)" ]
174175
[ "$(openshift ex tokens)" ]
175-
[ "$(openshift ex policy 2>&1)" ]
176+
[ "$(openshift admin policy 2>&1)" ]
176177
[ "$(openshift kubectl 2>&1)" ]
177178
[ "$(openshift kube 2>&1)" ]
179+
[ "$(openshift admin 2>&1)" ]
178180

179181
# help for root commands must be consistent
180-
[ "$(openshift | grep 'OpenShift for Admins')" ]
182+
[ "$(openshift | grep 'OpenShift Application Platform')" ]
181183
[ "$(osc | grep 'OpenShift Client')" ]
182184
[ "$(openshift cli | grep 'OpenShift Client')" ]
183185
[ "$(openshift kubectl 2>&1 | grep 'Kubernetes cluster')" ]
186+
[ "$(osadm 2>&1 | grep 'OpenShift Administrative Commands')" ]
187+
[ "$(openshift admin 2>&1 | grep 'OpenShift Administrative Commands')" ]
184188

185189
# help for root commands with --help flag must be consistent
186-
[ "$(openshift --help 2>&1 | grep 'OpenShift for Admins')" ]
190+
[ "$(openshift --help 2>&1 | grep 'OpenShift Application Platform')" ]
187191
[ "$(osc --help 2>&1 | grep 'OpenShift Client')" ]
188192
[ "$(openshift cli --help 2>&1 | grep 'OpenShift Client')" ]
189193
[ "$(openshift kubectl --help 2>&1 | grep 'Kubernetes cluster')" ]
194+
[ "$(osadm --help 2>&1 | grep 'OpenShift Administrative Commands')" ]
195+
[ "$(openshift admin --help 2>&1 | grep 'OpenShift Administrative Commands')" ]
190196

191197
# help for root commands through help command must be consistent
192198
[ "$(openshift help cli 2>&1 | grep 'OpenShift Client')" ]
193199
[ "$(openshift help kubectl 2>&1 | grep 'Kubernetes cluster')" ]
200+
[ "$(openshift help admin 2>&1 | grep 'OpenShift Administrative Commands')" ]
194201

195202
# help for given command with --help flag must be consistent
196203
[ "$(osc get --help 2>&1 | grep 'Display one or many resources')" ]
@@ -308,44 +315,44 @@ osc describe build ${started} | grep openshift/ruby-20-centos7:success$
308315
osc cancel-build "${started}" --dump-logs --restart
309316
echo "cancel-build: ok"
310317

311-
openshift ex policy add-group cluster-admin system:unauthenticated
312-
openshift ex policy remove-group cluster-admin system:unauthenticated
313-
openshift ex policy remove-group-from-project system:unauthenticated
314-
openshift ex policy add-user cluster-admin system:no-user
315-
openshift ex policy remove-user cluster-admin system:no-user
316-
openshift ex policy remove-user-from-project system:no-user
318+
openshift admin policy add-role-to-group cluster-admin system:unauthenticated
319+
openshift admin policy remove-role-from-group cluster-admin system:unauthenticated
320+
openshift admin policy remove-role-from-group-from-project system:unauthenticated
321+
openshift admin policy add-role-to-user cluster-admin system:no-user
322+
openshift admin policy remove-user cluster-admin system:no-user
323+
openshift admin policy remove-user-from-project system:no-user
317324
echo "ex policy: ok"
318325

319326
# Test the commands the UI projects page tells users to run
320327
# These should match what is described in projects.html
321-
openshift ex new-project ui-test-project --admin="anypassword:createuser"
322-
openshift ex policy add-user admin anypassword:adduser -n ui-test-project
328+
osadm new-project ui-test-project --admin="anypassword:createuser"
329+
osadm policy add-role-to-user admin anypassword:adduser -n ui-test-project
323330
# Make sure project can be listed by osc (after auth cache syncs)
324-
sleep 2 && osc get projects | grep 'ui-test-project'
331+
sleep 2 && [ "$(osc get projects | grep 'ui-test-project')" ]
325332
# Make sure users got added
326-
osc describe policybinding master -n ui-test-project | grep createuser
327-
osc describe policybinding master -n ui-test-project | grep adduser
333+
[ "$(osc describe policybinding master -n ui-test-project | grep createuser)" ]
334+
[ "$(osc describe policybinding master -n ui-test-project | grep adduser)" ]
328335
echo "ui-project-commands: ok"
329336

330337
# Test deleting and recreating a project
331-
openshift ex new-project recreated-project --admin="anypassword:createuser1"
338+
osadm new-project recreated-project --admin="anypassword:createuser1"
332339
osc delete project recreated-project
333-
openshift ex new-project recreated-project --admin="anypassword:createuser2"
340+
osadm new-project recreated-project --admin="anypassword:createuser2"
334341
osc describe policybinding master -n recreated-project | grep anypassword:createuser2
335342
echo "ex new-project: ok"
336343

337344
# Test running a router
338-
[ ! "$(openshift ex router | grep 'does not exist')"]
339-
[ "$(openshift ex router -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-haproxy-')" ]
340-
openshift ex router --create --credentials="${OPENSHIFTCONFIG}"
341-
[ "$(openshift ex router | grep 'service exists')" ]
345+
[ ! "$(osadm router | grep 'does not exist')" ]
346+
[ "$(osadm router -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-haproxy-')" ]
347+
osadm router --create --credentials="${OPENSHIFTCONFIG}"
348+
[ "$(osadm router | grep 'service exists')" ]
342349
echo "ex router: ok"
343350

344351
# Test running a registry
345-
[ ! "$(openshift ex registry | grep 'does not exist')"]
346-
[ "$(openshift ex registry -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-docker-registry')" ]
347-
openshift ex registry --create --credentials="${OPENSHIFTCONFIG}"
348-
[ "$(openshift ex registry | grep 'service exists')" ]
352+
[ ! "$(osadm registry | grep 'does not exist')"]
353+
[ "$(osadm registry -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-docker-registry')" ]
354+
osadm registry --create --credentials="${OPENSHIFTCONFIG}"
355+
[ "$(osadm registry | grep 'service exists')" ]
349356
echo "ex registry: ok"
350357

351358
# verify the image repository had its tags populated

pkg/cmd/admin/admin.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package admin
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/openshift/origin/pkg/cmd/experimental/buildchain"
10+
"github.com/openshift/origin/pkg/cmd/experimental/config"
11+
"github.com/openshift/origin/pkg/cmd/experimental/policy"
12+
"github.com/openshift/origin/pkg/cmd/experimental/project"
13+
exregistry "github.com/openshift/origin/pkg/cmd/experimental/registry"
14+
exrouter "github.com/openshift/origin/pkg/cmd/experimental/router"
15+
"github.com/openshift/origin/pkg/cmd/server/admin"
16+
"github.com/openshift/origin/pkg/cmd/templates"
17+
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
18+
"github.com/openshift/origin/pkg/version"
19+
)
20+
21+
const longDesc = `
22+
OpenShift Administrative Commands
23+
24+
Commands for managing an OpenShift cluster are exposed here. Many administrative
25+
actions involve interaction with the OpenShift client as well.
26+
27+
Note: This is a beta release of OpenShift and may change significantly. See
28+
https://github.com/openshift/origin for the latest information on OpenShift.
29+
`
30+
31+
func NewCommandAdmin(name, fullName string) *cobra.Command {
32+
// Main command
33+
cmd := &cobra.Command{
34+
Use: name,
35+
Short: "tools for managing an OpenShift cluster",
36+
Long: fmt.Sprintf(longDesc),
37+
Run: func(c *cobra.Command, args []string) {
38+
c.SetOutput(os.Stdout)
39+
c.Help()
40+
},
41+
}
42+
43+
f := clientcmd.New(cmd.PersistentFlags())
44+
//in := os.Stdin
45+
out := os.Stdout
46+
47+
templates.UseAdminTemplates(cmd)
48+
49+
cmd.AddCommand(project.NewCmdNewProject(f, fullName, "new-project"))
50+
cmd.AddCommand(policy.NewCommandPolicy(f, fullName, "policy"))
51+
cmd.AddCommand(exrouter.NewCmdRouter(f, fullName, "router", out))
52+
cmd.AddCommand(exregistry.NewCmdRegistry(f, fullName, "registry", out))
53+
cmd.AddCommand(buildchain.NewCmdBuildChain(f, fullName, "build-chain"))
54+
cmd.AddCommand(config.NewCmdConfig(fullName, "config"))
55+
56+
// TODO: these probably belong in a sub command
57+
cmd.AddCommand(admin.NewCommandCreateKubeConfig())
58+
cmd.AddCommand(admin.NewCommandCreateBootstrapPolicyFile())
59+
cmd.AddCommand(admin.NewCommandOverwriteBootstrapPolicy(out))
60+
cmd.AddCommand(admin.NewCommandNodeConfig())
61+
// TODO: these should be rolled up together
62+
cmd.AddCommand(admin.NewCommandCreateAllCerts())
63+
cmd.AddCommand(admin.NewCommandCreateClientCert())
64+
cmd.AddCommand(admin.NewCommandCreateNodeClientCert())
65+
cmd.AddCommand(admin.NewCommandCreateServerCert())
66+
cmd.AddCommand(admin.NewCommandCreateSignerCert())
67+
cmd.AddCommand(admin.NewCommandCreateClient())
68+
69+
if name == fullName {
70+
cmd.AddCommand(version.NewVersionCommand(fullName))
71+
}
72+
73+
return cmd
74+
}

pkg/cmd/cli/cli.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/spf13/pflag"
1010

1111
"github.com/openshift/origin/pkg/cmd/cli/cmd"
12+
"github.com/openshift/origin/pkg/cmd/experimental/config"
1213
"github.com/openshift/origin/pkg/cmd/templates"
1314
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
1415
"github.com/openshift/origin/pkg/version"
@@ -64,6 +65,7 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
6465
templates.UseCliTemplates(cmds)
6566

6667
cmds.AddCommand(cmd.NewCmdLogin(f, in, out))
68+
cmds.AddCommand(cmd.NewCmdProject(f, out))
6769
cmds.AddCommand(cmd.NewCmdNewApplication(fullName, f, out))
6870
cmds.AddCommand(cmd.NewCmdStartBuild(fullName, f, out))
6971
cmds.AddCommand(cmd.NewCmdCancelBuild(fullName, f, out))
@@ -80,9 +82,11 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
8082
cmds.AddCommand(cmd.NewCmdExec(fullName, f, os.Stdin, out, os.Stderr))
8183
cmds.AddCommand(cmd.NewCmdPortForward(fullName, f))
8284
cmds.AddCommand(f.NewCmdProxy(out))
83-
cmds.AddCommand(cmd.NewCmdProject(f, out))
8485
cmds.AddCommand(cmd.NewCmdOptions(f, out))
85-
cmds.AddCommand(version.NewVersionCommand(fullName))
86+
if name == fullName {
87+
cmds.AddCommand(version.NewVersionCommand(fullName))
88+
}
89+
cmds.AddCommand(config.NewCmdConfig(fullName, "config"))
8690

8791
return cmds
8892
}

pkg/cmd/cli/describe/describer.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,23 +480,45 @@ func (d *RoleBindingDescriber) Describe(namespace, name string) (string, error)
480480
return "", err
481481
}
482482

483-
role, roleErr := d.Roles(roleBinding.RoleRef.Namespace).Get(roleBinding.RoleRef.Name)
483+
role, err := d.Roles(roleBinding.RoleRef.Namespace).Get(roleBinding.RoleRef.Name)
484+
return DescribeRoleBinding(roleBinding, role, err)
485+
}
484486

487+
// DescribeRoleBinding prints out information about a role binding and its associated role
488+
func DescribeRoleBinding(roleBinding *authorizationapi.RoleBinding, role *authorizationapi.Role, err error) (string, error) {
485489
return tabbedString(func(out *tabwriter.Writer) error {
486490
formatMeta(out, roleBinding.ObjectMeta)
487491

488492
formatString(out, "Role", roleBinding.RoleRef.Namespace+"/"+roleBinding.RoleRef.Name)
489493
formatString(out, "Users", roleBinding.Users.List())
490494
formatString(out, "Groups", roleBinding.Groups.List())
491495

492-
if roleErr != nil {
493-
formatString(out, "ROLE RESOLUTION ERROR", roleErr)
496+
switch {
497+
case err != nil:
498+
formatString(out, "Policy Rules", fmt.Sprintf("error: %v", err))
494499

495-
} else {
500+
case role != nil:
496501
fmt.Fprint(out, policyRuleHeadings+"\n")
497502
for _, rule := range role.Rules {
498503
describePolicyRule(out, rule, "")
499504
}
505+
506+
default:
507+
formatString(out, "Policy Rules", "<none>")
508+
}
509+
510+
return nil
511+
})
512+
}
513+
514+
// DescribeRole prints out information about a role
515+
func DescribeRole(role *authorizationapi.Role) (string, error) {
516+
return tabbedString(func(out *tabwriter.Writer) error {
517+
formatMeta(out, role.ObjectMeta)
518+
519+
fmt.Fprint(out, policyRuleHeadings+"\n")
520+
for _, rule := range role.Rules {
521+
describePolicyRule(out, rule, "")
500522
}
501523

502524
return nil

pkg/cmd/experimental/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
func NewCmdConfig(parentName, name string) *cobra.Command {
1212
cmd := config.NewCmdConfig(os.Stdout)
13-
cmd.Long = fmt.Sprintf(`Manages .kubeconfig files using subcommands like:
13+
cmd.Short = "Change configuration files for the client"
14+
cmd.Long = fmt.Sprintf(`Manages the OpenShift config files using subcommands like:
1415
1516
%[1]s %[2]s use-context my-context
1617
%[1]s %[2]s set preferences.some true

pkg/cmd/experimental/policy/add_group.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func NewCmdAddGroup(f *clientcmd.Factory) *cobra.Command {
2525
options := &addGroupOptions{}
2626

2727
cmd := &cobra.Command{
28-
Use: "add-group <role> <group> [group]...",
29-
Short: "add group to role",
30-
Long: `add group to role`,
28+
Use: "add-role-to-group",
29+
Short: "add groups to a role",
30+
Long: `add groups to a role`,
3131
Run: func(cmd *cobra.Command, args []string) {
3232
if !options.complete(cmd) {
3333
return

pkg/cmd/experimental/policy/add_user.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ func NewCmdAddUser(f *clientcmd.Factory) *cobra.Command {
2525
options := &AddUserOptions{}
2626

2727
cmd := &cobra.Command{
28-
Use: "add-user <role> <user> [user]...",
29-
Short: "add user to role",
30-
Long: `add user to role`,
28+
Use: "add-role-to-user",
29+
Short: "add users to a role",
30+
Long: `add users to a role`,
3131
Run: func(cmd *cobra.Command, args []string) {
32-
if !options.complete(cmd) {
33-
return
32+
if !options.complete(cmd, args) {
33+
glog.Fatalf("You must specify two arguments")
3434
}
3535

3636
var err error
@@ -51,10 +51,8 @@ func NewCmdAddUser(f *clientcmd.Factory) *cobra.Command {
5151
return cmd
5252
}
5353

54-
func (o *AddUserOptions) complete(cmd *cobra.Command) bool {
55-
args := cmd.Flags().Args()
54+
func (o *AddUserOptions) complete(cmd *cobra.Command, args []string) bool {
5655
if len(args) < 2 {
57-
cmd.Help()
5856
return false
5957
}
6058

pkg/cmd/experimental/policy/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func NewCommandPolicy(f *clientcmd.Factory, parentName, name string) *cobra.Comm
2020
// Parent command to which all subcommands are added.
2121
cmds := &cobra.Command{
2222
Use: name,
23-
Short: "manage authorization policy",
24-
Long: `manage authorization policy`,
23+
Short: "Manage authorization policy",
24+
Long: `Manage authorization policy`,
2525
Run: runHelp,
2626
}
2727

pkg/cmd/experimental/policy/remove_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewCmdRemoveGroup(f *clientcmd.Factory) *cobra.Command {
2424
options := &RemoveGroupOptions{}
2525

2626
cmd := &cobra.Command{
27-
Use: "remove-group <role> <group> [group]...",
27+
Use: "remove-role-from-group <role> <group> [group]...",
2828
Short: "remove group from role",
2929
Long: `remove group from role`,
3030
Run: func(cmd *cobra.Command, args []string) {

pkg/cmd/experimental/policy/remove_group_from_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewCmdRemoveGroupFromProject(f *clientcmd.Factory) *cobra.Command {
2222
options := &removeGroupFromProjectOptions{}
2323

2424
cmd := &cobra.Command{
25-
Use: "remove-group-from-project <group> [group]...",
25+
Use: "remove-group <group> [group]...",
2626
Short: "remove group from project",
2727
Long: `remove group from project`,
2828
Run: func(cmd *cobra.Command, args []string) {

pkg/cmd/experimental/policy/remove_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewCmdRemoveUser(f *clientcmd.Factory) *cobra.Command {
2424
options := &removeUserOptions{}
2525

2626
cmd := &cobra.Command{
27-
Use: "remove-user <role> <user> [user]...",
27+
Use: "remove-role-from-user <role> <user> [user]...",
2828
Short: "remove user from role",
2929
Long: `remove user from role`,
3030
Run: func(cmd *cobra.Command, args []string) {

pkg/cmd/experimental/policy/remove_user_from_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewCmdRemoveUserFromProject(f *clientcmd.Factory) *cobra.Command {
2222
options := &removeUserFromProjectOptions{}
2323

2424
cmd := &cobra.Command{
25-
Use: "remove-user-from-project <user> [user]...",
25+
Use: "remove-user <user> [user]...",
2626
Short: "remove user from project",
2727
Long: `remove user from project`,
2828
Run: func(cmd *cobra.Command, args []string) {

0 commit comments

Comments
 (0)