Browse code

Introduces auto-generation of CLI documents

fabianofranz authored on 2015/06/19 07:06:29
Showing 14 changed files
... ...
@@ -63,6 +63,7 @@ check-test:
63 63
 	hack/verify-generated-deep-copies.sh
64 64
 	hack/verify-generated-conversions.sh
65 65
 	hack/verify-generated-completions.sh
66
+	hack/verify-generated-docs.sh
66 67
 	hack/test-cmd.sh
67 68
 	KUBE_RACE=" " hack/test-integration.sh
68 69
 .PHONY: check-test
... ...
@@ -89,6 +90,7 @@ test:
89 89
 	hack/verify-generated-deep-copies.sh
90 90
 	hack/verify-generated-conversions.sh
91 91
 	hack/verify-generated-completions.sh
92
+	hack/verify-generated-docs.sh
92 93
 	hack/test-cmd.sh
93 94
 	KUBE_RACE=" " hack/test-integration-docker.sh
94 95
 	hack/test-end-to-end-docker.sh
95 96
new file mode 100644
... ...
@@ -0,0 +1,54 @@
0
+package main
1
+
2
+import (
3
+	"fmt"
4
+	"io/ioutil"
5
+	"os"
6
+	"path/filepath"
7
+
8
+	"github.com/openshift/origin/pkg/cmd/admin"
9
+	"github.com/openshift/origin/pkg/cmd/cli"
10
+	"github.com/openshift/origin/pkg/cmd/util/gendocs"
11
+)
12
+
13
+func OutDir(path string) (string, error) {
14
+	outDir, err := filepath.Abs(path)
15
+	if err != nil {
16
+		return "", err
17
+	}
18
+
19
+	stat, err := os.Stat(outDir)
20
+	if err != nil {
21
+		return "", err
22
+	}
23
+
24
+	if !stat.IsDir() {
25
+		return "", fmt.Errorf("output directory %s is not a directory\n", outDir)
26
+	}
27
+	outDir = outDir + "/"
28
+	return outDir, nil
29
+}
30
+
31
+func main() {
32
+	path := "docs/generated/"
33
+	if len(os.Args) == 2 {
34
+		path = os.Args[1]
35
+	} else if len(os.Args) > 2 {
36
+		fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
37
+		os.Exit(1)
38
+	}
39
+
40
+	outDir, err := OutDir(path)
41
+	if err != nil {
42
+		fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
43
+		os.Exit(1)
44
+	}
45
+
46
+	outFile := outDir + "oc_by_example_content.adoc"
47
+	cmd := cli.NewCommandCLI("oc", "openshift cli")
48
+	gendocs.GenDocs(cmd, outFile)
49
+
50
+	outFile = outDir + "oadm_by_example_content.adoc"
51
+	cmd = admin.NewCommandAdmin("oadm", "openshift admin", ioutil.Discard)
52
+	gendocs.GenDocs(cmd, outFile)
53
+}
0 54
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+oadm_by_example_content.adoc
1
+oc_by_example_content.adoc
0 2
new file mode 100644
... ...
@@ -0,0 +1,217 @@
0
+:toc: macro
1
+:toc-title:
2
+
3
+toc::[]
4
+
5
+
6
+== oadm build-chain
7
+Output build dependencies of a specific image stream
8
+
9
+====
10
+
11
+[options="nowrap"]
12
+----
13
+  // Build dependency tree for the specified image stream and tag
14
+  $ openshift ex build-chain [image-stream]:[tag]
15
+
16
+  // Build dependency trees for all tags in the specified image stream
17
+  $ openshift ex build-chain [image-stream] --all-tags
18
+
19
+  // Build the dependency tree using tag 'latest' in 'testing' namespace
20
+  $ openshift ex build-chain [image-stream] -n testing
21
+
22
+  // Build the dependency tree and output it in DOT syntax
23
+  $ openshift ex build-chain [image-stream] -o dot
24
+
25
+  // Build dependency trees for all image streams in the current namespace
26
+  $ openshift ex build-chain
27
+
28
+  // Build dependency trees for all image streams across all namespaces
29
+  $ openshift ex build-chain --all
30
+----
31
+====
32
+
33
+
34
+== oadm config
35
+Change configuration files for the client
36
+
37
+====
38
+
39
+[options="nowrap"]
40
+----
41
+  // Change the config context to use
42
+  openshift admin config use-context my-context
43
+  
44
+  // Set the value of a config preference
45
+  openshift admin config set preferences.some true
46
+----
47
+====
48
+
49
+
50
+== oadm config set-cluster
51
+Sets a cluster entry in kubeconfig
52
+
53
+====
54
+
55
+[options="nowrap"]
56
+----
57
+  // Set only the server field on the e2e cluster entry without touching other values.
58
+  $ openshift admin config set-cluster e2e --server=https://1.2.3.4
59
+  
60
+  // Embed certificate authority data for the e2e cluster entry
61
+  $ openshift admin config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
62
+  
63
+  // Disable cert checking for the dev cluster entry
64
+  $ openshift admin config set-cluster e2e --insecure-skip-tls-verify=true
65
+----
66
+====
67
+
68
+
69
+== oadm config set-context
70
+Sets a context entry in kubeconfig
71
+
72
+====
73
+
74
+[options="nowrap"]
75
+----
76
+  // Set the user field on the gce context entry without touching other values
77
+  $ openshift admin config set-context gce --user=cluster-admin
78
+----
79
+====
80
+
81
+
82
+== oadm config set-credentials
83
+Sets a user entry in kubeconfig
84
+
85
+====
86
+
87
+[options="nowrap"]
88
+----
89
+  // Set only the "client-key" field on the "cluster-admin"
90
+  // entry, without touching other values:
91
+  $ openshift admin config set-credentials cluster-admin --client-key=~/.kube/admin.key
92
+  
93
+  // Set basic auth for the "cluster-admin" entry
94
+  $ openshift admin config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
95
+  
96
+  // Embed client certificate data in the "cluster-admin" entry
97
+  $ openshift admin config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
98
+----
99
+====
100
+
101
+
102
+== oadm config view
103
+displays Merged kubeconfig settings or a specified kubeconfig file.
104
+
105
+====
106
+
107
+[options="nowrap"]
108
+----
109
+  // Show Merged kubeconfig settings.
110
+  $ openshift admin config view
111
+  
112
+  // Show only local kubeconfig settings
113
+  $ openshift admin config view --local
114
+  
115
+  // Get the password for the e2e user
116
+  $ openshift admin config view -o template --template='{{range .users}}{{ if eq .name "e2e" }}{{ index .user.password }}{{end}}{{end}}'
117
+----
118
+====
119
+
120
+
121
+== oadm ipfailover
122
+Install an IP failover group to a set of nodes
123
+
124
+====
125
+
126
+[options="nowrap"]
127
+----
128
+  // Check the default IP failover configuration ("ipfailover"):
129
+  $ openshift admin ipfailover
130
+
131
+  // See what the IP failover configuration would look like if it is created:
132
+  $ openshift admin ipfailover -o json
133
+
134
+  // Create an IP failover configuration if it does not already exist:
135
+  $ openshift admin ipfailover ipf --virtual-ips="10.1.1.1-4" --create
136
+
137
+  // Create an IP failover configuration on a selection of nodes labeled
138
+  // "router=us-west-ha" (on 4 nodes with 7 virtual IPs monitoring a service
139
+  // listening on port 80 (aka the OpenShift router process).
140
+  $ openshift admin ipfailover 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
141
+
142
+  // Use a different IP failover config image and see the configuration:
143
+  $ openshift admin ipfailover ipf-alt --selector="hagroup=us-west-ha" --virtual-ips="1.2.3.4" -o yaml --images=myrepo/myipfailover:mytag
144
+----
145
+====
146
+
147
+
148
+== oadm manage-node
149
+Manage nodes - list pods, evacuate, or mark ready
150
+
151
+====
152
+
153
+[options="nowrap"]
154
+----
155
+	// Block accepting any pods on given nodes
156
+	$ openshift admin manage-node <mynode> --schedulable=false
157
+
158
+	// Mark selected nodes as schedulable
159
+	$ openshift admin manage-node --selector="<env=dev>" --schedulable=true
160
+
161
+	// Migrate selected pods
162
+	$ openshift admin manage-node <mynode> --evacuate --pod-selector="<service=myapp>"
163
+
164
+	// Show pods that will be migrated
165
+	$ openshift admin manage-node <mynode> --evacuate --dry-run --pod-selector="<service=myapp>"
166
+
167
+	// List all pods on given nodes
168
+	$ openshift admin manage-node <mynode1> <mynode2> --list-pods
169
+----
170
+====
171
+
172
+
173
+== oadm registry
174
+Install the OpenShift Docker registry
175
+
176
+====
177
+
178
+[options="nowrap"]
179
+----
180
+  // Check if default Docker registry ("docker-registry") has been created
181
+  $ openshift admin registry --dry-run
182
+
183
+  // See what the registry would look like if created
184
+  $ openshift admin registry -o json
185
+
186
+  // Create a registry if it does not exist with two replicas
187
+  $ openshift admin registry --replicas=2 --credentials=registry-user.kubeconfig
188
+
189
+  // Use a different registry image and see the registry configuration
190
+  $ openshift admin registry -o yaml --images=myrepo/docker-registry:mytag
191
+----
192
+====
193
+
194
+
195
+== oadm router
196
+Install an OpenShift router
197
+
198
+====
199
+
200
+[options="nowrap"]
201
+----
202
+  // Check the default router ("router")
203
+  $ openshift admin router --dry-run
204
+
205
+  // See what the router would look like if created
206
+  $ openshift admin router -o json
207
+
208
+  // Create a router if it does not exist
209
+  $ openshift admin router router-west --create --replicas=2
210
+
211
+  // Use a different router image and see the router configuration
212
+  $ openshift admin router region-west -o yaml --images=myrepo/somerouter:mytag
213
+----
214
+====
215
+
216
+
0 217
new file mode 100644
... ...
@@ -0,0 +1,795 @@
0
+:toc: macro
1
+:toc-title:
2
+
3
+toc::[]
4
+
5
+
6
+== oc build-logs
7
+Show container logs from the build container
8
+
9
+====
10
+
11
+[options="nowrap"]
12
+----
13
+  // Stream logs from container to stdout
14
+  $ openshift cli build-logs 566bed879d2d
15
+----
16
+====
17
+
18
+
19
+== oc cancel-build
20
+Cancel a pending or running build
21
+
22
+====
23
+
24
+[options="nowrap"]
25
+----
26
+  // Cancel the build with the given name
27
+  $ openshift cli cancel-build 1da32cvq
28
+
29
+  // Cancel the named build and print the build logs
30
+  $ openshift cli cancel-build 1da32cvq --dump-logs
31
+
32
+  // Cancel the named build and create a new one with the same parameters
33
+  $ openshift cli cancel-build 1da32cvq --restart
34
+----
35
+====
36
+
37
+
38
+== oc config
39
+Change configuration files for the client
40
+
41
+====
42
+
43
+[options="nowrap"]
44
+----
45
+  // Change the config context to use
46
+  openshift cli config use-context my-context
47
+  
48
+  // Set the value of a config preference
49
+  openshift cli config set preferences.some true
50
+----
51
+====
52
+
53
+
54
+== oc config set-cluster
55
+Sets a cluster entry in kubeconfig
56
+
57
+====
58
+
59
+[options="nowrap"]
60
+----
61
+  // Set only the server field on the e2e cluster entry without touching other values.
62
+  $ openshift cli config set-cluster e2e --server=https://1.2.3.4
63
+  
64
+  // Embed certificate authority data for the e2e cluster entry
65
+  $ openshift cli config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
66
+  
67
+  // Disable cert checking for the dev cluster entry
68
+  $ openshift cli config set-cluster e2e --insecure-skip-tls-verify=true
69
+----
70
+====
71
+
72
+
73
+== oc config set-context
74
+Sets a context entry in kubeconfig
75
+
76
+====
77
+
78
+[options="nowrap"]
79
+----
80
+  // Set the user field on the gce context entry without touching other values
81
+  $ openshift cli config set-context gce --user=cluster-admin
82
+----
83
+====
84
+
85
+
86
+== oc config set-credentials
87
+Sets a user entry in kubeconfig
88
+
89
+====
90
+
91
+[options="nowrap"]
92
+----
93
+  // Set only the "client-key" field on the "cluster-admin"
94
+  // entry, without touching other values:
95
+  $ openshift cli config set-credentials cluster-admin --client-key=~/.kube/admin.key
96
+  
97
+  // Set basic auth for the "cluster-admin" entry
98
+  $ openshift cli config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
99
+  
100
+  // Embed client certificate data in the "cluster-admin" entry
101
+  $ openshift cli config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
102
+----
103
+====
104
+
105
+
106
+== oc config view
107
+displays Merged kubeconfig settings or a specified kubeconfig file.
108
+
109
+====
110
+
111
+[options="nowrap"]
112
+----
113
+  // Show Merged kubeconfig settings.
114
+  $ openshift cli config view
115
+  
116
+  // Show only local kubeconfig settings
117
+  $ openshift cli config view --local
118
+  
119
+  // Get the password for the e2e user
120
+  $ openshift cli config view -o template --template='{{range .users}}{{ if eq .name "e2e" }}{{ index .user.password }}{{end}}{{end}}'
121
+----
122
+====
123
+
124
+
125
+== oc create
126
+Create a resource by filename or stdin
127
+
128
+====
129
+
130
+[options="nowrap"]
131
+----
132
+  // Create a pod using the data in pod.json.
133
+  $ openshift cli create -f pod.json
134
+
135
+  // Create a pod based on the JSON passed into stdin.
136
+  $ cat pod.json | openshift cli create -f -
137
+----
138
+====
139
+
140
+
141
+== oc delete
142
+Delete a resource by filename, stdin, resource and ID, or by resources and label selector.
143
+
144
+====
145
+
146
+[options="nowrap"]
147
+----
148
+  // Delete a pod using the type and ID specified in pod.json.
149
+  $ openshift cli delete -f pod.json
150
+
151
+  // Delete a pod based on the type and ID in the JSON passed into stdin.
152
+  $ cat pod.json | openshift cli delete -f -
153
+
154
+  // Delete pods and services with label name=myLabel.
155
+  $ openshift cli delete pods,services -l name=myLabel
156
+
157
+  // Delete a pod with ID 1234-56-7890-234234-456456.
158
+  $ openshift cli delete pod 1234-56-7890-234234-456456
159
+
160
+  // Delete all pods
161
+  $ openshift cli delete pods --all
162
+----
163
+====
164
+
165
+
166
+== oc deploy
167
+View, start, cancel, or retry deployments
168
+
169
+====
170
+
171
+[options="nowrap"]
172
+----
173
+  // Display the latest deployment for the 'database' DeploymentConfig
174
+  $ openshift cli deploy database
175
+
176
+  // Start a new deployment based on the 'database' DeploymentConfig
177
+  $ openshift cli deploy database --latest
178
+
179
+  // Retry the latest failed deployment based on the 'frontend' DeploymentConfig
180
+  // The deployer pod and any hook pods are deleted for the latest failed deployment
181
+  $ openshift cli deploy frontend --retry
182
+
183
+  // Cancel the in-progress deployment based on the 'frontend' DeploymentConfig
184
+  $ openshift cli deploy frontend --cancel
185
+----
186
+====
187
+
188
+
189
+== oc describe
190
+Show details of a specific resource
191
+
192
+====
193
+
194
+[options="nowrap"]
195
+----
196
+  // Provide details about the ruby-20-centos7 image repository
197
+  $ openshift cli describe imageRepository ruby-20-centos7
198
+
199
+  // Provide details about the ruby-sample-build build configuration
200
+  $ openshift cli describe bc ruby-sample-build
201
+----
202
+====
203
+
204
+
205
+== oc edit
206
+Edit a resource on the server
207
+
208
+====
209
+
210
+[options="nowrap"]
211
+----
212
+  // Edit the service named 'docker-registry':
213
+  $ openshift cli edit svc/docker-registry
214
+
215
+  // Edit the DeploymentConfig named 'my-deployment':
216
+  $ openshift cli edit dc/my-deployment
217
+
218
+  // Use an alternative editor
219
+  $ OSC_EDITOR="nano" openshift cli edit dc/my-deployment
220
+
221
+  // Edit the service 'docker-registry' in JSON using the v1beta3 API format:
222
+  $ openshift cli edit svc/docker-registry --output-version=v1beta3 -o json
223
+----
224
+====
225
+
226
+
227
+== oc env
228
+Update the environment on a resource with a pod template
229
+
230
+====
231
+
232
+[options="nowrap"]
233
+----
234
+  // Update deployment 'registry' with a new environment variable
235
+  $ openshift cli env dc/registry STORAGE_DIR=/local
236
+
237
+  // List the environment variables defined on a deployment config 'registry'
238
+  $ openshift cli env dc/registry --list
239
+
240
+  // List the environment variables defined on all pods
241
+  $ openshift cli env pods --all --list
242
+
243
+  // Output modified deployment config in YAML, and does not alter the object on the server
244
+  $ openshift cli env dc/registry STORAGE_DIR=/data -o yaml
245
+
246
+  // Update all containers in all replication controllers in the project to have ENV=prod
247
+  $ openshift cli env rc --all ENV=prod
248
+
249
+  // Remove the environment variable ENV from container 'c1' in all deployment configs
250
+  $ openshift cli env dc --all --containers="c1" ENV-
251
+
252
+  // Remove the environment variable ENV from a deployment config definition on disk and
253
+  // update the deployment config on the server
254
+  $ openshift cli env -f dc.json ENV-
255
+
256
+  // Set some of the local shell environment into a deployment config on the server
257
+  $ env | grep RAILS_ | openshift cli env -e - dc/registry
258
+----
259
+====
260
+
261
+
262
+== oc exec
263
+Execute a command in a container.
264
+
265
+====
266
+
267
+[options="nowrap"]
268
+----
269
+  // Get output from running 'date' in ruby-container from pod 123456-7890
270
+  $ openshift cli exec -p 123456-7890 -c ruby-container date
271
+
272
+  // Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-780 and sends stdout/stderr from 'bash' back to the client
273
+  $ openshift cli exec -p 123456-7890 -c ruby-container -i -t -- bash -il
274
+----
275
+====
276
+
277
+
278
+== oc export
279
+Export resources so they can be used elsewhere
280
+
281
+====
282
+
283
+[options="nowrap"]
284
+----
285
+  // export the services and deployment configurations labeled name=test
286
+  openshift cli export svc,dc -l name=test
287
+
288
+  // export all services to a template
289
+  openshift cli export service --all --as-template=test
290
+
291
+  // export to JSON
292
+  openshift cli export service --all -o json
293
+
294
+  // convert a file on disk to the latest API version (in YAML, the default)
295
+  openshift cli export -f a_v1beta3_service.json --output-version=v1 --exact
296
+----
297
+====
298
+
299
+
300
+== oc expose
301
+Expose a replicated application as a service or route
302
+
303
+====
304
+
305
+[options="nowrap"]
306
+----
307
+  // Create a route based on service nginx. The new route will re-use nginx's labels
308
+  $ openshift cli expose service nginx
309
+
310
+  // Create a route and specify your own label and route name
311
+  $ openshift cli expose service nginx -l name=myroute --name=fromdowntown
312
+
313
+  // Create a route and specify a hostname
314
+  $ openshift cli expose service nginx --hostname=www.example.com
315
+
316
+  // Expose a deployment configuration as a service and use the specified port
317
+  $ openshift cli expose dc ruby-hello-world --port=8080 --generator=service/v1
318
+----
319
+====
320
+
321
+
322
+== oc get
323
+Display one or many resources
324
+
325
+====
326
+
327
+[options="nowrap"]
328
+----
329
+  // List all pods in ps output format.
330
+  $ openshift cli get pods
331
+
332
+  // List a single replication controller with specified ID in ps output format.
333
+  $ openshift cli get replicationController 1234-56-7890-234234-456456
334
+
335
+  // List a single pod in JSON output format.
336
+  $ openshift cli get -o json pod 1234-56-7890-234234-456456
337
+
338
+  // Return only the status value of the specified pod.
339
+  $ openshift cli get -o template pod 1234-56-7890-234234-456456 --template={{.currentState.status}}
340
+----
341
+====
342
+
343
+
344
+== oc import-image
345
+Imports images from a Docker registry
346
+
347
+====
348
+
349
+[options="nowrap"]
350
+----
351
+  $ openshift cli import-image mystream
352
+----
353
+====
354
+
355
+
356
+== oc label
357
+Update the labels on a resource
358
+
359
+====
360
+
361
+[options="nowrap"]
362
+----
363
+  // Update pod 'foo' with the label 'unhealthy' and the value 'true'.
364
+  $ openshift cli label pods foo unhealthy=true
365
+
366
+  // Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.
367
+  $ openshift cli label --overwrite pods foo status=unhealthy
368
+
369
+  // Update all pods in the namespace
370
+  $ openshift cli label pods --all status=unhealthy
371
+
372
+  // Update pod 'foo' only if the resource is unchanged from version 1.
373
+  $ openshift cli label pods foo status=unhealthy --resource-version=1
374
+
375
+  // Update pod 'foo' by removing a label named 'bar' if it exists.
376
+  // Does not require the --overwrite flag.
377
+  $ openshift cli label pods foo bar-
378
+----
379
+====
380
+
381
+
382
+== oc login
383
+Log in to an OpenShift server
384
+
385
+====
386
+
387
+[options="nowrap"]
388
+----
389
+  // Log in interactively
390
+  $ openshift cli login
391
+
392
+  // Log in to the given server with the given certificate authority file
393
+  $ openshift cli login localhost:8443 --certificate-authority=/path/to/cert.crt
394
+
395
+  // Log in to the given server with the given credentials (will not prompt interactively)
396
+  $ openshift cli login localhost:8443 --username=myuser --password=mypass
397
+----
398
+====
399
+
400
+
401
+== oc logout
402
+End the current server session
403
+
404
+====
405
+
406
+[options="nowrap"]
407
+----
408
+  // Logout
409
+  $ openshift cli logout
410
+----
411
+====
412
+
413
+
414
+== oc logs
415
+Print the logs for a container in a pod.
416
+
417
+====
418
+
419
+[options="nowrap"]
420
+----
421
+  // Returns snapshot of ruby-container logs from pod 123456-7890.
422
+  $ openshift cli logs 123456-7890 ruby-container
423
+
424
+  // Starts streaming of ruby-container logs from pod 123456-7890.
425
+  $ openshift cli logs -f 123456-7890 ruby-container
426
+----
427
+====
428
+
429
+
430
+== oc new-app
431
+Create a new application
432
+
433
+====
434
+
435
+[options="nowrap"]
436
+----
437
+  // Create an application based on the source code in the current git repository (with a public remote) and a Docker image
438
+  $ openshift cli new-app . --docker-image=repo/langimage
439
+
440
+  // Create a Ruby application based on the provided [image]~[source code] combination
441
+  $ openshift cli new-app openshift/ruby-20-centos7~https://github.com/openshift/ruby-hello-world.git
442
+
443
+  // Use the public Docker Hub MySQL image to create an app. Generated artifacts will be labeled with db=mysql
444
+  $ openshift cli new-app mysql -l db=mysql
445
+
446
+  // Use a MySQL image in a private registry to create an app and override application artifacts' names
447
+  $ openshift cli new-app --docker-image=myregistry.com/mycompany/mysql --name=private
448
+
449
+  // Create an application from a remote repository using its beta4 branch
450
+  $ openshift cli new-app https://github.com/openshift/ruby-hello-world#beta4
451
+
452
+  // Create an application based on a stored template, explicitly setting a parameter value
453
+  $ openshift cli new-app --template=ruby-helloworld-sample --param=MYSQL_USER=admin
454
+
455
+  // Create an application from a remote repository and specify a context directory
456
+  $ openshift cli new-app https://github.com/youruser/yourgitrepo --context-dir=src/build
457
+ 
458
+  // Create an application based on a template file, explicitly setting a parameter value
459
+  $ openshift cli new-app --file=./example/myapp/template.json --param=MYSQL_USER=admin
460
+----
461
+====
462
+
463
+
464
+== oc new-build
465
+Create a new build configuration
466
+
467
+====
468
+
469
+[options="nowrap"]
470
+----
471
+  // Create a build config based on the source code in the current git repository (with a public remote) and a Docker image
472
+  $ openshift cli new-build . --docker-image=repo/langimage
473
+
474
+  // Create a NodeJS build config based on the provided [image]~[source code] combination
475
+  $ openshift cli new-build openshift/nodejs-010-centos7~https://bitbucket.com/user/nodejs-app
476
+
477
+  // Create a build config from a remote repository using its beta2 branch
478
+  $ openshift cli new-build https://github.com/openshift/ruby-hello-world#beta2
479
+----
480
+====
481
+
482
+
483
+== oc new-project
484
+Request a new project
485
+
486
+====
487
+
488
+[options="nowrap"]
489
+----
490
+  // Create a new project with minimal information
491
+  $ openshift cli new-project web-team-dev
492
+
493
+  // Create a new project with a display name and description
494
+  $ openshift cli new-project web-team-dev --display-name="Web Team Development" --description="Development project for the web team."
495
+----
496
+====
497
+
498
+
499
+== oc port-forward
500
+Forward one or more local ports to a pod.
501
+
502
+====
503
+
504
+[options="nowrap"]
505
+----
506
+  // Listens on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
507
+  $ openshift cli port-forward -p mypod 5000 6000
508
+
509
+  // Listens on port 8888 locally, forwarding to 5000 in the pod
510
+  $ openshift cli port-forward -p mypod 8888:5000
511
+
512
+  // Listens on a random port locally, forwarding to 5000 in the pod
513
+  $ openshift cli port-forward -p mypod :5000
514
+
515
+  // Listens on a random port locally, forwarding to 5000 in the pod
516
+  $ openshift cli port-forward -p mypod 0:5000
517
+----
518
+====
519
+
520
+
521
+== oc process
522
+Process a template into list of resources
523
+
524
+====
525
+
526
+[options="nowrap"]
527
+----
528
+  // Convert template.json file into resource list
529
+  $ openshift cli process -f template.json
530
+
531
+  // Process template while passing a user-defined label
532
+  $ openshift cli process -f template.json -l name=mytemplate
533
+
534
+  // Convert stored template into resource list
535
+  $ openshift cli process foo
536
+
537
+  // Convert template.json into resource list
538
+  $ cat template.json | openshift cli process -f -
539
+
540
+  // Combine multiple templates into single resource list
541
+  $ cat template.json second_template.json | openshift cli process -f -
542
+----
543
+====
544
+
545
+
546
+== oc project
547
+Switch to another project
548
+
549
+====
550
+
551
+[options="nowrap"]
552
+----
553
+  // Switch to 'myapp' project
554
+  $ openshift cli project myapp
555
+
556
+  // Display the project currently in use
557
+  $ openshift cli project
558
+----
559
+====
560
+
561
+
562
+== oc proxy
563
+Run a proxy to the Kubernetes API server
564
+
565
+====
566
+
567
+[options="nowrap"]
568
+----
569
+  // Run a proxy to kubernetes apiserver on port 8011, serving static content from ./local/www/
570
+  $ openshift cli proxy --port=8011 --www=./local/www/
571
+
572
+  // Run a proxy to kubernetes apiserver, changing the api prefix to k8s-api
573
+  // This makes e.g. the pods api available at localhost:8011/k8s-api/v1beta3/pods/
574
+  $ openshift cli proxy --api-prefix=k8s-api
575
+----
576
+====
577
+
578
+
579
+== oc rollback
580
+Revert part of an application back to a previous deployment
581
+
582
+====
583
+
584
+[options="nowrap"]
585
+----
586
+  // Perform a rollback
587
+  $ openshift cli rollback deployment-1
588
+
589
+  // See what the rollback will look like, but don't perform the rollback
590
+  $ openshift cli rollback deployment-1 --dry-run
591
+
592
+  // Perform the rollback manually by piping the JSON of the new config back to openshift cli
593
+  $ openshift cli rollback deployment-1 --output=json | openshift cli update deploymentConfigs deployment -f -
594
+----
595
+====
596
+
597
+
598
+== oc scale
599
+Change the number of pods in a deployment
600
+
601
+====
602
+
603
+[options="nowrap"]
604
+----
605
+  // Scale replication controller named 'foo' to 3.
606
+  $ openshift cli scale --replicas=3 replicationcontrollers foo
607
+
608
+  // If the replication controller named foo's current size is 2, scale foo to 3.
609
+  $ openshift cli scale --current-replicas=2 --replicas=3 replicationcontrollers foo
610
+----
611
+====
612
+
613
+
614
+== oc secrets new
615
+Create a new secret based on a key file or on files within a directory
616
+
617
+====
618
+
619
+[options="nowrap"]
620
+----
621
+  // Create a new secret named my-secret with a key named ssh-privatekey
622
+  $ openshift cli secrets new my-secret ~/.ssh/ssh-privatekey
623
+
624
+  // Create a new secret named my-secret with keys named ssh-privatekey and ssh-publickey instead of the names of the keys on disk
625
+  $ openshift cli secrets new my-secret ssh-privatekey=~/.ssh/id_rsa ssh-publickey=~/.ssh/id_rsa.pub
626
+
627
+  // Create a new secret named my-secret with keys for each file in the folder "bar"
628
+  $ openshift cli secrets new my-secret path/to/bar
629
+----
630
+====
631
+
632
+
633
+== oc start-build
634
+Starts a new build
635
+
636
+====
637
+
638
+[options="nowrap"]
639
+----
640
+  // Starts build from BuildConfig matching the name "3bd2ug53b"
641
+  $ openshift cli start-build 3bd2ug53b
642
+
643
+  // Starts build from build matching the name "3bd2ug53b"
644
+  $ openshift cli start-build --from-build=3bd2ug53b
645
+
646
+  // Starts build from BuildConfig matching the name "3bd2ug53b" and watches the logs until the build
647
+  // completes or fails
648
+  $ openshift cli start-build 3bd2ug53b --follow
649
+----
650
+====
651
+
652
+
653
+== oc status
654
+Show an overview of the current project
655
+
656
+====
657
+
658
+[options="nowrap"]
659
+----
660
+  // Show an overview of the current project
661
+  $ openshift cli status
662
+----
663
+====
664
+
665
+
666
+== oc stop
667
+Gracefully shut down a resource by id or filename.
668
+
669
+====
670
+
671
+[options="nowrap"]
672
+----
673
+  // Shut down foo.
674
+  $ openshift cli stop replicationcontroller foo
675
+
676
+  // Stop pods and services with label name=myLabel.
677
+  $ openshift cli stop pods,services -l name=myLabel
678
+
679
+  // Shut down the service defined in service.json
680
+  $ openshift cli stop -f service.json
681
+
682
+  // Shut down all resources in the path/to/resources directory
683
+  $ openshift cli stop -f path/to/resources
684
+----
685
+====
686
+
687
+
688
+== oc tag
689
+Tag existing images into image streams
690
+
691
+====
692
+
693
+[options="nowrap"]
694
+----
695
+  // Tag the current image for the image stream 'openshift/ruby' and tag '2.0' into the image stream 'yourproject/ruby with tag 'tip':
696
+  $ openshift cli tag openshift/ruby:2.0 yourproject/ruby:tip
697
+
698
+  // Tag a specific image:
699
+  $ openshift cli tag openshift/ruby@sha256:6b646fa6bf5e5e4c7fa41056c27910e679c03ebe7f93e361e6515a9da7e258cc yourproject/ruby:tip
700
+
701
+  // Tag an external Docker image:
702
+  $ openshift cli tag --source=docker openshift/origin:latest yourproject/ruby:tip
703
+----
704
+====
705
+
706
+
707
+== oc types
708
+An introduction to the concepts and types in OpenShift
709
+
710
+====
711
+
712
+[options="nowrap"]
713
+----
714
+  // View all projects you have access to
715
+  $ openshift cli projects
716
+
717
+  // See a list of all services in the current project
718
+  $ openshift cli get svc
719
+
720
+  // Describe a deployment configuration in detail
721
+  $ openshift cli describe dc mydeploymentconfig
722
+
723
+  // Show the images tagged into an image stream
724
+  $ openshift cli describe is ruby-centos7
725
+----
726
+====
727
+
728
+
729
+== oc update
730
+Update a resource by filename or stdin.
731
+
732
+====
733
+
734
+[options="nowrap"]
735
+----
736
+  // Update a pod using the data in pod.json.
737
+  $ openshift cli update -f pod.json
738
+
739
+  // Update a pod based on the JSON passed into stdin.
740
+  $ cat pod.json | openshift cli update -f -
741
+----
742
+====
743
+
744
+
745
+== oc volume
746
+Update volume on a resource with a pod template
747
+
748
+====
749
+
750
+[options="nowrap"]
751
+----
752
+  // Add new volume of type 'emptyDir' for deployment config 'registry' and mount under /opt inside the containers
753
+  // The volume name is auto generated
754
+  $ openshift cli volume dc/registry --add --mount-path=/opt
755
+
756
+  // Add new volume 'v1' with secret 'magic' for replication controller 'r1'
757
+  $ openshift cli volume rc/r1 --add --name=v1 -m /etc --type=secret --secret-name=magic
758
+
759
+  // Add new volume to replication controller 'r1' based on git repository
760
+  // or other volume sources not supported by --type
761
+  $ openshift cli volume rc/r1 --add -m /repo --source=<json-string>
762
+
763
+  // Add emptyDir volume 'v1' to a deployment config definition on disk and 
764
+  // update the deployment config on the server
765
+  $ openshift cli volume -f dc.json --add --name=v1
766
+
767
+  // Create a new persistent volume and overwrite existing volume 'v1' for replication controller 'r1'
768
+  $ openshift cli volume rc/r1 --add --name=v1 -t persistentVolumeClaim --claim-name=pvc1 --overwrite
769
+
770
+  // Overwrite the replication controller 'r1' mount point to /data for volume v1
771
+  $ openshift cli volume rc r1 --add --name=v1 -m /data --overwrite
772
+
773
+  // Remove all volumes for deployment config 'd1'
774
+  $ openshift cli volume dc/d1 --remove --confirm
775
+
776
+  // Remove volume 'v1' from deployment config 'registry'  
777
+  $ openshift cli volume dc/registry --remove --name=v1
778
+
779
+  // Modify the deployment config "d1" by removing volume mount "v1" from container "c1"
780
+  // (and by removing the volume "v1" if no other containers have volume mounts that reference it)
781
+  $ openshift cli volume dc/d1 --remove --name=v1 --containers=c1
782
+
783
+  // List volumes defined on replication controller 'r1'
784
+  $ openshift cli volume rc r1 --list
785
+
786
+  // List volumes defined on all pods
787
+  $ openshift cli volume pods --all --list
788
+
789
+  // Output json object with volume info for deployment config 'd1' but don't alter the object on server
790
+  $ openshift cli volume dc/d1 --add --name=v1 --mount=/opt -o json
791
+----
792
+====
793
+
794
+
0 795
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+:toc: macro
1
+:toc-title:
2
+
3
+toc::[]
4
+
5
+{{range .items}}
6
+== {{.Object.fullName}}
7
+{{.Object.description}}
8
+
9
+====
10
+
11
+[options="nowrap"]
12
+----
13
+{{.Object.examples}}
14
+----
15
+====
16
+
17
+{{end}}
... ...
@@ -467,7 +467,7 @@ os::build::ldflags() {
467 467
   )
468 468
 }
469 469
 
470
-os::build::gen-doc() {
470
+os::build::gen-docs() {
471 471
   local cmd="$1"
472 472
   local dest="$2"
473 473
   local skipprefix="${3:-}"
... ...
@@ -500,4 +500,6 @@ os::build::gen-doc() {
500 500
   find "${tmpdir}" -exec rsync -pt {} "${dest}" \; >/dev/null
501 501
   #cleanup
502 502
   rm -rf "${tmpdir}"
503
-}
503
+
504
+  echo "Assets generated in ${dest}"
505
+}
504 506
\ No newline at end of file
... ...
@@ -24,4 +24,4 @@ if [[ ! "$genbashcomp" ]]; then
24 24
   exit 1
25 25
 fi
26 26
 
27
-os::build::gen-doc "${genbashcomp}" "${OS_ROOT}/rel-eng/completions/bash/"
27
+os::build::gen-docs "${genbashcomp}" "${OS_ROOT}/rel-eng/completions/bash/"
28 28
new file mode 100755
... ...
@@ -0,0 +1,27 @@
0
+#!/bin/bash
1
+
2
+# This script sets up a go workspace locally and builds all go components.
3
+
4
+set -o errexit
5
+set -o nounset
6
+set -o pipefail
7
+
8
+OS_ROOT=$(dirname "${BASH_SOURCE}")/..
9
+source "${OS_ROOT}/hack/common.sh"
10
+
11
+"${OS_ROOT}/hack/build-go.sh" cmd/gendocs
12
+
13
+# Find binary
14
+gendocs=$( (ls -t _output/local/go/bin/gendocs) 2>/dev/null || true | head -1 )
15
+
16
+if [[ ! "$gendocs" ]]; then
17
+  {
18
+    echo "It looks as if you don't have a compiled gendocs binary"
19
+    echo
20
+    echo "If you are running from a clone of the git repo, please run"
21
+    echo "'./hack/build-go.sh cmd/gendocs'."
22
+  } >&2
23
+  exit 1
24
+fi
25
+
26
+os::build::gen-docs "${gendocs}" "${OS_ROOT}/docs/generated"
0 27
new file mode 100755
... ...
@@ -0,0 +1,31 @@
0
+#!/bin/bash
1
+
2
+set -o errexit
3
+set -o nounset
4
+set -o pipefail
5
+
6
+OS_ROOT=$(dirname "${BASH_SOURCE}")/..
7
+source "${OS_ROOT}/hack/common.sh"
8
+
9
+cd "${OS_ROOT}"
10
+
11
+GENERATED_DOCS_ROOT="${OS_ROOT}/docs/generated"
12
+_tmp="${OS_ROOT}/_tmp"
13
+TMP_GENERATED_DOCS_ROOT="${_tmp}/generated"
14
+
15
+mkdir -p "${_tmp}"
16
+cp -a "${GENERATED_DOCS_ROOT}/" "${_tmp}"
17
+
18
+"${OS_ROOT}/hack/update-generated-docs.sh"
19
+echo "diffing ${GENERATED_DOCS_ROOT} against freshly generated docs"
20
+ret=0
21
+diff -Naupr "${GENERATED_DOCS_ROOT}" "${TMP_GENERATED_DOCS_ROOT}" || ret=$?
22
+cp -a "${TMP_GENERATED_DOCS_ROOT}" "${GENERATED_DOCS_ROOT}/.."
23
+rm -rf "${_tmp}"
24
+if [[ $ret -eq 0 ]]
25
+then
26
+  echo "${GENERATED_DOCS_ROOT} up to date."
27
+else
28
+  echo "${GENERATED_DOCS_ROOT} is out of date. Please run hack/update-generated-docs.sh"
29
+  exit 1
30
+fi
0 31
new file mode 100644
... ...
@@ -0,0 +1,89 @@
0
+package gendocs
1
+
2
+import (
3
+	"bytes"
4
+	"io/ioutil"
5
+	"os"
6
+	"path/filepath"
7
+	"sort"
8
+
9
+	kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
10
+	"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
11
+	"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
12
+	"github.com/spf13/cobra"
13
+)
14
+
15
+type Examples []*runtime.Unstructured
16
+
17
+func (x Examples) Len() int      { return len(x) }
18
+func (x Examples) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
19
+func (x Examples) Less(i, j int) bool {
20
+	xi, _ := x[i].Object["fullName"].(string)
21
+	xj, _ := x[j].Object["fullName"].(string)
22
+	return xi < xj
23
+}
24
+
25
+func GenDocs(cmd *cobra.Command, filename string) error {
26
+	out := new(bytes.Buffer)
27
+	templateFile, err := filepath.Abs("hack/clibyexample/template")
28
+	if err != nil {
29
+		return err
30
+	}
31
+	template, err := ioutil.ReadFile(templateFile)
32
+	if err != nil {
33
+		return err
34
+	}
35
+
36
+	examples := extractExamples(cmd)
37
+	items := []runtime.Object{}
38
+	for _, example := range examples {
39
+		items = append(items, example)
40
+	}
41
+
42
+	printer, _, err := kubectl.GetPrinter("template", string(template))
43
+	if err != nil {
44
+		return err
45
+	}
46
+
47
+	err = printer.PrintObj(&kapi.List{
48
+		ListMeta: kapi.ListMeta{},
49
+		Items:    items,
50
+	}, out)
51
+	if err != nil {
52
+		return err
53
+	}
54
+
55
+	outFile, err := os.Create(filename)
56
+	if err != nil {
57
+		return err
58
+	}
59
+	defer outFile.Close()
60
+
61
+	_, err = outFile.Write(out.Bytes())
62
+	if err != nil {
63
+		return err
64
+	}
65
+	return nil
66
+}
67
+
68
+func extractExamples(cmd *cobra.Command) Examples {
69
+	objs := Examples{}
70
+	for _, c := range cmd.Commands() {
71
+		if len(c.Deprecated) > 0 {
72
+			continue
73
+		}
74
+		objs = append(objs, extractExamples(c)...)
75
+	}
76
+	if cmd.HasExample() {
77
+		o := &runtime.Unstructured{
78
+			Object: make(map[string]interface{}),
79
+		}
80
+		o.Object["name"] = cmd.Name()
81
+		o.Object["fullName"] = cmd.CommandPath()
82
+		o.Object["description"] = cmd.Short
83
+		o.Object["examples"] = cmd.Example
84
+		objs = append(objs, o)
85
+	}
86
+	sort.Sort(objs)
87
+	return objs
88
+}
... ...
@@ -96,3 +96,9 @@ func IsTerminal(r io.Reader) bool {
96 96
 	file, ok := r.(*os.File)
97 97
 	return ok && term.IsTerminal(file.Fd())
98 98
 }
99
+
100
+// IsTerminalWriter returns whether the passed io.Writer is a terminal or not
101
+func IsTerminalWriter(w io.Writer) bool {
102
+	file, ok := w.(*os.File)
103
+	return ok && term.IsTerminal(file.Fd())
104
+}
... ...
@@ -1570,27 +1570,6 @@ _oc_options()
1570 1570
     must_have_one_noun=()
1571 1571
 }
1572 1572
 
1573
-_oc_examples()
1574
-{
1575
-    last_command="oc_examples"
1576
-    commands=()
1577
-
1578
-    flags=()
1579
-    two_word_flags=()
1580
-    flags_with_completion=()
1581
-    flags_completion=()
1582
-
1583
-    flags+=("--help")
1584
-    flags+=("-h")
1585
-    flags+=("--output=")
1586
-    two_word_flags+=("-o")
1587
-    flags+=("--template=")
1588
-    two_word_flags+=("-t")
1589
-
1590
-    must_have_one_flag=()
1591
-    must_have_one_noun=()
1592
-}
1593
-
1594 1573
 _oc()
1595 1574
 {
1596 1575
     last_command="oc"
... ...
@@ -1633,7 +1612,6 @@ _oc()
1633 1633
     commands+=("config")
1634 1634
     commands+=("whoami")
1635 1635
     commands+=("options")
1636
-    commands+=("examples")
1637 1636
 
1638 1637
     flags=()
1639 1638
     two_word_flags=()
... ...
@@ -2959,27 +2959,6 @@ _openshift_cli_options()
2959 2959
     must_have_one_noun=()
2960 2960
 }
2961 2961
 
2962
-_openshift_cli_examples()
2963
-{
2964
-    last_command="openshift_cli_examples"
2965
-    commands=()
2966
-
2967
-    flags=()
2968
-    two_word_flags=()
2969
-    flags_with_completion=()
2970
-    flags_completion=()
2971
-
2972
-    flags+=("--help")
2973
-    flags+=("-h")
2974
-    flags+=("--output=")
2975
-    two_word_flags+=("-o")
2976
-    flags+=("--template=")
2977
-    two_word_flags+=("-t")
2978
-
2979
-    must_have_one_flag=()
2980
-    must_have_one_noun=()
2981
-}
2982
-
2983 2962
 _openshift_cli()
2984 2963
 {
2985 2964
     last_command="openshift_cli"
... ...
@@ -3022,7 +3001,6 @@ _openshift_cli()
3022 3022
     commands+=("config")
3023 3023
     commands+=("whoami")
3024 3024
     commands+=("options")
3025
-    commands+=("examples")
3026 3025
 
3027 3026
     flags=()
3028 3027
     two_word_flags=()