Skip to content

Commit

Permalink
Expose kubernetes components as symlink binaries
Browse files Browse the repository at this point in the history
Also cleanup help description on admin commands
  • Loading branch information
smarterclayton committed May 16, 2015
1 parent ee47aef commit fc6cb9f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 23 deletions.
10 changes: 10 additions & 0 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ readonly OPENSHIFT_BINARY_SYMLINKS=(
openshift-sti-build
openshift-docker-build
openshift-gitserver
origin
osc
os
osadm
oadm
kubectl
kubernetes
kubelet
kube-proxy
kube-apiserver
kube-controller-manager
kube-scheduler
)
readonly OPENSHIFT_BINARY_COPY=(
osc
Expand Down
11 changes: 11 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ osc get templates
echo "templates: ok"

# verify some default commands
[ "$(openshift 2>&1)" ]
[ "$(openshift cli)" ]
[ "$(openshift ex)" ]
[ "$(openshift admin config 2>&1)" ]
Expand All @@ -216,6 +217,14 @@ echo "templates: ok"
[ "$(openshift kubectl 2>&1)" ]
[ "$(openshift kube 2>&1)" ]
[ "$(openshift admin 2>&1)" ]
[ "$(openshift start kubernetes 2>&1)" ]
[ "$(kubernetes 2>&1)" ]
[ "$(kubectl 2>&1)" ]
[ "$(osc 2>&1)" ]
[ "$(os 2>&1)" ]
[ "$(osadm 2>&1)" ]
[ "$(oadm 2>&1)" ]
[ "$(origin 2>&1)" ]

# help for root commands must be consistent
[ "$(openshift | grep 'OpenShift Application Platform')" ]
Expand All @@ -226,6 +235,7 @@ echo "templates: ok"
[ "$(openshift kubectl 2>&1 | grep 'Kubernetes cluster')" ]
[ "$(osadm 2>&1 | grep 'OpenShift Administrative Commands')" ]
[ "$(openshift admin 2>&1 | grep 'OpenShift Administrative Commands')" ]
[ "$(openshift start kubernetes 2>&1 | grep 'Kubernetes server components')" ]

# help for root commands with --help flag must be consistent
[ "$(openshift --help 2>&1 | grep 'OpenShift Application Platform')" ]
Expand Down Expand Up @@ -390,6 +400,7 @@ echo "edit: ok"

osc delete all --all
osc new-app https://github.com/openshift/ruby-hello-world -l app=ruby
wait_for_command 'osc get rc/ruby-hello-world-1' "${TIME_MIN}"
# resize rc via deployment configuration
osc resize dc ruby-hello-world --replicas=1
# resize directly
Expand Down
11 changes: 9 additions & 2 deletions pkg/cmd/admin/project/new_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ type NewProjectOptions struct {
AdminUser string
}

const newProjectLong = `Create a new project
Use this command to create a project. You may optionally specify metadata about the project,
an admin user (and role, if you want to use a non-default admin role), and a node selector
to restrict which nodes pods in this project can be scheduled to.
`

func NewCmdNewProject(name, fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
options := &NewProjectOptions{}

cmd := &cobra.Command{
Use: name + " NAME [--display-name=DISPLAYNAME] [--description=DESCRIPTION]",
Short: "create a new project",
Long: `create a new project`,
Short: "Create a new project",
Long: newProjectLong,
Run: func(cmd *cobra.Command, args []string) {
if err := options.complete(args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error()))
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"io"
"os"

"github.com/golang/glog"
Expand Down Expand Up @@ -97,11 +98,10 @@ func NewCommandCLI(name, fullName string) *cobra.Command {

// NewCmdKubectl provides exactly the functionality from Kubernetes,
// but with support for OpenShift resources
func NewCmdKubectl(name string) *cobra.Command {
func NewCmdKubectl(name string, out io.Writer) *cobra.Command {
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
f := clientcmd.New(flags)
out := os.Stdout
cmds := kubecmd.NewKubectlCommand(f.Factory, os.Stdin, os.Stdout, os.Stderr)
cmds := kubecmd.NewKubectlCommand(f.Factory, os.Stdin, out, os.Stderr)
cmds.Aliases = []string{"kubectl"}
cmds.Use = name
cmds.Short = "Kubernetes cluster management via kubectl"
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/experimental/ipfailover/ipfailover.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ALPHA: This command is currently being actively developed. It is intended
$ %[1]s %[2]s ipfailover --selector="router=us-west-ha" --virtual-ips="1.2.3.4,10.1.1.100-104,5.6.7.8" --watch-port=80 --replicas=4 --create
// Use a different IP failover config image and see the configuration:
$ %[1]s %[2]s ipf-alt --selector="jack=the-vipper" --virtual-ips="1.2.3.4" -o yaml --images=myrepo/myipfailover:mytag`
$ %[1]s %[2]s ipf-alt --selector="hagroup=us-west-ha" --virtual-ips="1.2.3.4" -o yaml --images=myrepo/myipfailover:mytag`
)

func NewCmdIPFailoverConfig(f *clientcmd.Factory, parentName, name string, out io.Writer) *cobra.Command {
Expand All @@ -62,7 +62,7 @@ func NewCmdIPFailoverConfig(f *clientcmd.Factory, parentName, name string, out i

cmd := &cobra.Command{
Use: fmt.Sprintf("%s [NAME]", name),
Short: "Configure or view IP Failover configuration",
Short: "Install an IP failover group to a set of nodes",
Long: ipFailover_long,
Example: fmt.Sprintf(ipFailover_example, parentName, name),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/experimental/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewCmdRegistry(f *clientcmd.Factory, parentName, name string, out io.Writer

cmd := &cobra.Command{
Use: name,
Short: "Install and check OpenShift Docker registry",
Short: "Install the OpenShift Docker registry",
Long: registry_long,
Example: fmt.Sprintf(registry_example, parentName, name),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/experimental/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewCmdRouter(f *clientcmd.Factory, parentName, name string, out io.Writer)

cmd := &cobra.Command{
Use: fmt.Sprintf("%s [NAME]", name),
Short: "Install and check OpenShift routers",
Short: "Install an OpenShift router",
Long: router_long,
Example: fmt.Sprintf(router_example, parentName, name),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
39 changes: 28 additions & 11 deletions pkg/cmd/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/openshift/origin/pkg/cmd/infra/gitserver"
"github.com/openshift/origin/pkg/cmd/infra/router"
"github.com/openshift/origin/pkg/cmd/server/start"
"github.com/openshift/origin/pkg/cmd/server/start/kubernetes"
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/version"
Expand Down Expand Up @@ -61,12 +62,28 @@ func CommandFor(basename string) *cobra.Command {
cmd = builder.NewCommandDockerBuilder(basename)
case "openshift-gitserver":
cmd = gitserver.NewCommandGitServer(basename)
case "osc":
case "osc", "os":
cmd = cli.NewCommandCLI(basename, basename)
case "osadm":
case "osadm", "oadm":
cmd = admin.NewCommandAdmin(basename, basename, os.Stdout)
case "kubectl":
cmd = cli.NewCmdKubectl(basename, os.Stdout)
case "kube-apiserver":
cmd = kubernetes.NewAPIServerCommand(basename, basename, os.Stdout)
case "kube-controller-manager":
cmd = kubernetes.NewControllersCommand(basename, basename, os.Stdout)
case "kubelet":
cmd = kubernetes.NewKubeletCommand(basename, basename, os.Stdout)
case "kube-proxy":
cmd = kubernetes.NewProxyCommand(basename, basename, os.Stdout)
case "kube-scheduler":
cmd = kubernetes.NewSchedulerCommand(basename, basename, os.Stdout)
case "kubernetes":
cmd = kubernetes.NewCommand(basename, basename, os.Stdout)
case "origin":
cmd = NewCommandOpenShift("origin")
default:
cmd = NewCommandOpenShift()
cmd = NewCommandOpenShift("openshift")
}

templates.UseMainTemplates(cmd)
Expand All @@ -76,9 +93,9 @@ func CommandFor(basename string) *cobra.Command {
}

// NewCommandOpenShift creates the standard OpenShift command
func NewCommandOpenShift() *cobra.Command {
func NewCommandOpenShift(name string) *cobra.Command {
root := &cobra.Command{
Use: "openshift",
Use: name,
Short: "OpenShift helps you build, deploy, and manage your cloud applications",
Long: openshift_long,
Run: func(c *cobra.Command, args []string) {
Expand All @@ -87,13 +104,13 @@ func NewCommandOpenShift() *cobra.Command {
},
}

startAllInOne, _ := start.NewCommandStartAllInOne(os.Stdout)
startAllInOne, _ := start.NewCommandStartAllInOne(name, os.Stdout)
root.AddCommand(startAllInOne)
root.AddCommand(admin.NewCommandAdmin("admin", "openshift admin", os.Stdout))
root.AddCommand(cli.NewCommandCLI("cli", "openshift cli"))
root.AddCommand(cli.NewCmdKubectl("kube"))
root.AddCommand(newExperimentalCommand("ex", "openshift ex"))
root.AddCommand(version.NewVersionCommand("openshift"))
root.AddCommand(admin.NewCommandAdmin("admin", name+" admin", os.Stdout))
root.AddCommand(cli.NewCommandCLI("cli", name+" cli"))
root.AddCommand(cli.NewCmdKubectl("kube", os.Stdout))
root.AddCommand(newExperimentalCommand("ex", name+" ex"))
root.AddCommand(version.NewVersionCommand(name))

// infra commands are those that are bundled with the binary but not displayed to end users
// directly
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/admin/create_nodeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewCommandNodeConfig(commandName string, fullName string, out io.Writer) *c

cmd := &cobra.Command{
Use: commandName,
Short: "Create a portable client folder containing a client certificate, a client key, a server certificate authority, and a .kubeconfig file.",
Short: "Create a configuration bundle for a node",
Run: func(cmd *cobra.Command, args []string) {
if err := options.Validate(args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You may also pass --etcd=<address> to connect to an external etcd server.
You may also pass --kubeconfig=<path> to connect to an external Kubernetes cluster.`

// NewCommandStartMaster provides a CLI handler for 'start' command
func NewCommandStartAllInOne(out io.Writer) (*cobra.Command, *AllInOneOptions) {
func NewCommandStartAllInOne(fullName string, out io.Writer) (*cobra.Command, *AllInOneOptions) {
options := &AllInOneOptions{Output: cmdutil.Output{out}}

cmd := &cobra.Command{
Expand Down Expand Up @@ -114,7 +114,7 @@ func NewCommandStartAllInOne(out io.Writer) (*cobra.Command, *AllInOneOptions) {
cmd.AddCommand(startMaster)
cmd.AddCommand(startNode)

startKube := kubernetes.NewCommand("kubernetes", "openshift", out)
startKube := kubernetes.NewCommand("kubernetes", fullName, out)
cmd.AddCommand(startKube)

return cmd, options
Expand Down

0 comments on commit fc6cb9f

Please sign in to comment.