forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
openshift.go
232 lines (192 loc) · 8.42 KB
/
openshift.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package openshift
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
proxyapp "k8s.io/kubernetes/cmd/kube-proxy/app"
ktemplates "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/cmd/flagtypes"
"github.com/openshift/origin/pkg/cmd/infra/builder"
"github.com/openshift/origin/pkg/cmd/infra/deployer"
irouter "github.com/openshift/origin/pkg/cmd/infra/router"
"github.com/openshift/origin/pkg/cmd/recycle"
"github.com/openshift/origin/pkg/cmd/server/start"
"github.com/openshift/origin/pkg/cmd/server/start/kubernetes"
"github.com/openshift/origin/pkg/cmd/templates"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/oc/admin"
diagnostics "github.com/openshift/origin/pkg/oc/admin/diagnostics"
sync "github.com/openshift/origin/pkg/oc/admin/groups/sync/cli"
"github.com/openshift/origin/pkg/oc/admin/validate"
"github.com/openshift/origin/pkg/oc/cli"
"github.com/openshift/origin/pkg/oc/cli/cmd"
"github.com/openshift/origin/pkg/oc/experimental/buildchain"
configcmd "github.com/openshift/origin/pkg/oc/experimental/config"
"github.com/openshift/origin/pkg/oc/experimental/dockergc"
exipfailover "github.com/openshift/origin/pkg/oc/experimental/ipfailover"
)
var (
openshiftLong = ktemplates.LongDesc(`
%[2]s
The %[3]s helps you build, deploy, and manage your applications on top of
Docker containers. To start an all-in-one server with the default configuration, run:
$ %[1]s start &`)
)
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
var cmd *cobra.Command
in, out, errout := os.Stdin, os.Stdout, os.Stderr
// Make case-insensitive and strip executable suffix if present
if runtime.GOOS == "windows" {
basename = strings.ToLower(basename)
basename = strings.TrimSuffix(basename, ".exe")
}
switch basename {
case "openshift-router":
cmd = irouter.NewCommandTemplateRouter(basename)
case "openshift-f5-router":
cmd = irouter.NewCommandF5Router(basename)
case "openshift-deploy":
cmd = deployer.NewCommandDeployer(basename)
case "openshift-recycle":
cmd = recycle.NewCommandRecycle(basename, out)
case "openshift-sti-build":
cmd = builder.NewCommandS2IBuilder(basename)
case "openshift-docker-build":
cmd = builder.NewCommandDockerBuilder(basename)
case "openshift-git-clone":
cmd = builder.NewCommandGitClone(basename)
case "openshift-manage-dockerfile":
cmd = builder.NewCommandManageDockerfile(basename)
case "openshift-extract-image-content":
cmd = builder.NewCommandExtractImageContent(basename)
case "oc", "osc":
cmd = cli.NewCommandCLI(basename, basename, in, out, errout)
case "oadm", "osadm":
cmd = admin.NewCommandAdmin(basename, basename, in, out, errout)
case "kubectl":
cmd = cli.NewCmdKubectl(basename, out)
case "kube-apiserver":
cmd = kubernetes.NewAPIServerCommand(basename, basename, out)
case "kube-controller-manager":
cmd = kubernetes.NewControllersCommand(basename, basename, out)
case "kubelet":
cmd = kubernetes.NewKubeletCommand(basename, basename, out)
case "kube-proxy":
cmd = proxyapp.NewProxyCommand()
case "kube-scheduler":
cmd = kubernetes.NewSchedulerCommand(basename, basename, out)
case "kubernetes":
cmd = kubernetes.NewCommand(basename, basename, out, errout)
case "origin":
cmd = NewCommandOpenShift(basename)
default:
cmd = NewCommandOpenShift("openshift")
}
if cmd.UsageFunc() == nil {
templates.ActsAsRootCommand(cmd, []string{"options"})
}
flagtypes.GLog(cmd.PersistentFlags())
return cmd
}
// NewCommandOpenShift creates the standard OpenShift command
func NewCommandOpenShift(name string) *cobra.Command {
in, out, errout := os.Stdin, os.Stdout, os.Stderr
root := &cobra.Command{
Use: name,
Short: "Build, deploy, and manage your cloud applications",
Long: fmt.Sprintf(openshiftLong, name, cmdutil.GetPlatformName(name), cmdutil.GetDistributionName(name)),
Run: kcmdutil.DefaultSubCommandRun(out),
}
f := clientcmd.New(pflag.NewFlagSet("", pflag.ContinueOnError))
startAllInOne, _ := start.NewCommandStartAllInOne(name, out, errout)
root.AddCommand(startAllInOne)
root.AddCommand(admin.NewCommandAdmin("admin", name+" admin", in, out, errout))
root.AddCommand(cli.NewCommandCLI("cli", name+" cli", in, out, errout))
root.AddCommand(cli.NewCmdKubectl("kube", out))
root.AddCommand(newExperimentalCommand("ex", name+" ex"))
root.AddCommand(newCompletionCommand("completion", name+" completion"))
root.AddCommand(cmd.NewCmdVersion(name, f, out, cmd.VersionOptions{PrintEtcdVersion: true, IsServer: true}))
// infra commands are those that are bundled with the binary but not displayed to end users
// directly
infra := &cobra.Command{
Use: "infra", // Because this command exposes no description, it will not be shown in help
}
infra.AddCommand(
irouter.NewCommandTemplateRouter("router"),
irouter.NewCommandF5Router("f5-router"),
deployer.NewCommandDeployer("deploy"),
recycle.NewCommandRecycle("recycle", out),
builder.NewCommandS2IBuilder("sti-build"),
builder.NewCommandDockerBuilder("docker-build"),
diagnostics.NewCommandPodDiagnostics("diagnostic-pod", out),
diagnostics.NewCommandNetworkPodDiagnostics("network-diagnostic-pod", out),
)
root.AddCommand(infra)
root.AddCommand(cmd.NewCmdOptions(out))
// TODO: add groups
templates.ActsAsRootCommand(root, []string{"options"})
return root
}
func newExperimentalCommand(name, fullName string) *cobra.Command {
out := os.Stdout
errout := os.Stderr
experimental := &cobra.Command{
Use: name,
Short: "Experimental commands under active development",
Long: "The commands grouped here are under development and may change without notice.",
Run: func(c *cobra.Command, args []string) {
c.SetOutput(out)
c.Help()
},
BashCompletionFunction: admin.BashCompletionFunc,
}
f := clientcmd.New(experimental.PersistentFlags())
experimental.AddCommand(validate.NewCommandValidate(validate.ValidateRecommendedName, fullName+" "+validate.ValidateRecommendedName, out, errout))
experimental.AddCommand(exipfailover.NewCmdIPFailoverConfig(f, fullName, "ipfailover", out, errout))
experimental.AddCommand(dockergc.NewCmdDockerGCConfig(f, fullName, "dockergc", out, errout))
experimental.AddCommand(buildchain.NewCmdBuildChain(name, fullName+" "+buildchain.BuildChainRecommendedCommandName, f, out))
experimental.AddCommand(configcmd.NewCmdConfig(configcmd.ConfigRecommendedName, fullName+" "+configcmd.ConfigRecommendedName, f, out, errout))
deprecatedDiag := diagnostics.NewCmdDiagnostics(diagnostics.DiagnosticsRecommendedName, fullName+" "+diagnostics.DiagnosticsRecommendedName, out)
deprecatedDiag.Deprecated = fmt.Sprintf(`use "oc adm %[1]s" to run diagnostics instead.`, diagnostics.DiagnosticsRecommendedName)
experimental.AddCommand(deprecatedDiag)
experimental.AddCommand(cmd.NewCmdOptions(out))
// these groups also live under `oc adm groups {sync,prune}` and are here only for backwards compatibility
experimental.AddCommand(sync.NewCmdSync("sync-groups", fullName+" "+"sync-groups", f, out))
experimental.AddCommand(sync.NewCmdPrune("prune-groups", fullName+" "+"prune-groups", f, out))
return experimental
}
var (
completion_long = ktemplates.LongDesc(`
Output shell completion code for the given shell (bash or zsh).
This command prints shell code which must be evaluation to provide interactive
completion of kubectl commands.`)
completion_example = ktemplates.Examples(`
$ source <(kubectl completion bash)
will load the kubectl completion code for bash. Note that this depends on the bash-completion
framework. It must be sourced before sourcing the kubectl completion, i.e. on the Mac:
$ brew install bash-completion
$ source $(brew --prefix)/etc/bash_completion
$ source <(kubectl completion bash)
If you use zsh, the following will load kubectl zsh completion:
$ source <(kubectl completion zsh)`)
)
func newCompletionCommand(name, fullName string) *cobra.Command {
out := os.Stdout
completion := &cobra.Command{
Use: fmt.Sprintf("%s SHELL", name),
Short: "Output shell completion code for the given shell (bash or zsh)",
Long: completion_long,
Example: completion_example,
Run: func(cmd *cobra.Command, args []string) {
},
}
f := clientcmd.New(completion.PersistentFlags())
return cmd.NewCmdCompletion(fullName, f, out)
}