Browse code

Add types command showing OpenShift concepts

Acts as a simple help reference for new users

Clayton Coleman authored on 2015/06/08 12:26:39
Showing 3 changed files
... ...
@@ -267,6 +267,7 @@ echo "templates: ok"
267 267
 [ ! "$(oc 2>&1 | grep 'Options')" ]
268 268
 [ ! "$(oc 2>&1 | grep 'Global Options')" ]
269 269
 [ "$(openshift cli 2>&1 | grep 'OpenShift Client')" ]
270
+[ "$(oc types | grep 'Deployment Config')" ]
270 271
 [ "$(openshift kubectl 2>&1 | grep 'Kubernetes cluster')" ]
271 272
 [ "$(oadm 2>&1 | grep 'OpenShift Administrative Commands')" ]
272 273
 [ "$(openshift admin 2>&1 | grep 'OpenShift Administrative Commands')" ]
... ...
@@ -72,6 +72,7 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
72 72
 				cmd.NewCmdNewApplication(fullName, f, out),
73 73
 				cmd.NewCmdStatus(fullName, f, out),
74 74
 				cmd.NewCmdProject(fullName+" project", f, out),
75
+				cmd.NewCmdTypes(fullName, f, out),
75 76
 			},
76 77
 		},
77 78
 		{
78 79
new file mode 100644
... ...
@@ -0,0 +1,212 @@
0
+package cmd
1
+
2
+import (
3
+	"bytes"
4
+	"fmt"
5
+	"io"
6
+	"strings"
7
+
8
+	. "github.com/MakeNowJust/heredoc/dot"
9
+	"github.com/spf13/cobra"
10
+
11
+	ocutil "github.com/openshift/origin/pkg/cmd/util"
12
+	"github.com/openshift/origin/pkg/cmd/util/clientcmd"
13
+)
14
+
15
+type term struct {
16
+	Name         string
17
+	Abbreviation string
18
+	Description  string
19
+}
20
+
21
+var concepts = []term{
22
+	{
23
+		"Containers",
24
+		"",
25
+		D(`
26
+      A definition of how to run one or more processes inside of a portable Linux
27
+      environment. Containers are started from an Image and are usually isolated
28
+      from other containers on the same machine.
29
+    `),
30
+	},
31
+	{
32
+		"Image",
33
+		"",
34
+		D(`
35
+      A layered Linux filesystem that contains application code, dependencies,
36
+      and any supporting operating system libraries. An image is identified by
37
+      a name that can be local to the current cluster or point to a remote Docker
38
+      registry (a storage server for images).
39
+    `),
40
+	}, {
41
+		"Pods",
42
+		"pod",
43
+		D(`
44
+      A set of one or more containers that are deployed onto a Node together and
45
+      share a unique IP and Volumes (persistent storage). Pods also define the
46
+      security and runtime policy for each container.
47
+    `),
48
+	}, {
49
+		"Labels",
50
+		"",
51
+		D(`
52
+      Labels are key value pairs that can be assigned to any resource in the
53
+      system for grouping and selection. Many resources use labels to identify
54
+      sets of other resources.
55
+    `),
56
+	}, {
57
+		"Volumes",
58
+		"",
59
+		D(`
60
+      Containers are not persistent by default - on restart their contents are
61
+      cleared. Volumes are mounted filesystems available to Pods and their
62
+      containers which may be backed by a number of host-local or network
63
+      attached storage endpoints. The simplest volume type is EmptyDir, which
64
+      is a temporary directory on a single machine. Administrators may also
65
+      allow you to request a Persistent Volume that is automatically attached
66
+      to your pods.
67
+    `),
68
+	}, {
69
+		"Nodes",
70
+		"node",
71
+		D(`
72
+      Machines set up in the cluster to run containers. Usually managed
73
+      by administrators and not by end users.
74
+    `),
75
+	}, {
76
+		"Services",
77
+		"svc",
78
+		D(`
79
+      A name representing a set of pods (or external servers) that are
80
+      accessed by other pods. The service gets an IP and a DNS name, and can be
81
+      exposed externally to the cluster via a port or a Route. It's also easy
82
+      to consume services from pods because an environment variable with the
83
+      name <SERVICE>_HOST is automatically injected into other pods.
84
+    `),
85
+	}, {
86
+		"Routes",
87
+		"route",
88
+		D(`
89
+      A route is an external DNS entry (either a top level domain or a
90
+      dynamically allocated name) that is created to point to a service so that
91
+      it can be accessed outside the cluster. The administrator may configure
92
+      one or more Routers to handle those routes, typically through an Apache
93
+      or HAProxy load balancer / proxy.
94
+    `),
95
+	},
96
+	{
97
+		"Replication Controllers",
98
+		"rc",
99
+		D(`
100
+      A replication controller maintains a specific number of pods based on a
101
+      template that match a set of labels. If pods are deleted (because the
102
+      node they run on is taken out of service) the controller creates a new
103
+      copy of that pod. A replication controller is most commonly used to
104
+      represent a single deployment of part of an application based on a
105
+      built image.
106
+    `),
107
+	},
108
+	{
109
+		"Deployment Configuration",
110
+		"dc",
111
+		D(`
112
+      Defines the template for a pod and manages deploying new images or 
113
+      configuration changes whenever those change. A single deployment 
114
+      configuration is usually analogous to a single micro-service. Can support 
115
+      many different deployment pattrens, including full restart, customizable 
116
+      rolling updates, and fully custom behaviors, as well as pre- and post- 
117
+      hooks. Each deployment is represented as a replication controller.
118
+    `),
119
+	},
120
+	{
121
+		"Build Configuration",
122
+		"bc",
123
+		D(`
124
+      Contains a description of how to build source code and a base image into a
125
+      new image - the primary method for delivering changes to your application.
126
+      Builds can be source based and use builder images for common languages like
127
+      Java, PHP, Ruby, or Python, or be Docker based and create builds from a
128
+      Dockerfile. Each build configuration has web-hooks and can be triggered
129
+      automatically by changes to their base images.
130
+    `),
131
+	},
132
+	{
133
+		"Image Streams and Image Stream Tags",
134
+		"is,istag",
135
+		D(`
136
+      An image stream groups sets of related images under tags - analogous to a
137
+      branch in a source code repository. Each image stream may have one or
138
+      more tags (the default tag is called "latest") and those tags may point
139
+      at external Docker registries, at other tags in the same stream, or be
140
+      controlled to directly point at known images. In addition, images can be
141
+      pushed to an image stream tag directly via the integrated Docker 
142
+      registry.
143
+    `),
144
+	},
145
+	{
146
+		"Projects",
147
+		"project",
148
+		D(`
149
+      All of the above resources (except Nodes) exist inside of a project.
150
+      Projects have a list of members and their roles, like viewer, editor,
151
+      or admin, as well as a set of security controls on the running pods, and
152
+      limits on how many resources the project can use. The names of each
153
+      resource are unique within a project. Developers may request projects
154
+      be created, but administrators control the resources allocated to
155
+      projects.
156
+    `),
157
+	},
158
+}
159
+
160
+func writeTerm(w io.Writer, t term) {
161
+	fmt.Fprintf(w, "* %s", t.Name)
162
+	if len(t.Abbreviation) > 0 {
163
+		fmt.Fprintf(w, " [%s]", t.Abbreviation)
164
+	}
165
+	fmt.Fprintln(w, ":")
166
+	for _, s := range strings.Split(t.Description, "\n") {
167
+		fmt.Fprintf(w, "    %s\n", s)
168
+	}
169
+}
170
+
171
+var (
172
+	typesLong = D(`
173
+    OpenShift Concepts and Types
174
+
175
+    OpenShift helps developers and operators build, test, and deploy applications in
176
+    a containerized cloud environment. Applications may be composed of all of the
177
+    components below, although most developers will be concerned with Services,
178
+    Deployments, and Builds for delivering changes.
179
+
180
+    Concepts:
181
+
182
+    %[1]sFor more, see https://docs.openshift.com
183
+  `)
184
+
185
+	typesExample = `  // View all projects you have access to
186
+  $ %[1]s projects
187
+
188
+  // See a list of all services in the current project
189
+  $ %[1]s get svc
190
+
191
+  // Describe a deployment configuration in detail
192
+  $ %[1]s describe dc mydeploymentconfig
193
+
194
+  // Show the images tagged into an image stream
195
+  $ %[1]s describe is ruby-centos7`
196
+)
197
+
198
+func NewCmdTypes(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
199
+	buf := &bytes.Buffer{}
200
+	for _, c := range concepts {
201
+		writeTerm(buf, c)
202
+	}
203
+	cmd := &cobra.Command{
204
+		Use:     "types",
205
+		Short:   "An introduction to the concepts and types in OpenShift",
206
+		Long:    fmt.Sprintf(typesLong, buf.String()),
207
+		Example: fmt.Sprintf(typesExample, fullName),
208
+		Run:     ocutil.DefaultSubCommandRun(out),
209
+	}
210
+	return cmd
211
+}