Skip to content

Commit 1dddcea

Browse files
committed
Merge pull request kubernetes#1980 from bgrant0607/config
Config generator suite
2 parents c1ce1fc + b8959bf commit 1dddcea

File tree

8 files changed

+1312
-0
lines changed

8 files changed

+1312
-0
lines changed

contrib/enscope/README.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# enscope
2+
3+
Typically a configuration is comprised of a set of objects (e.g., a simple service, replication controller, and template). Within that configuration, objects may refer to each other by object reference (as with replication controller to template, as of v1beta3) and/or by label selector (as with service and replication controller to pods generated from the pod template).
4+
5+
If one wants to create multiple instances of that configuration, such as for dev and prod deployments (aka horizontal composition) or to embed in composite macro-services (aka hierarchical composition), the names must be uniquified and the label selectors must be scoped to just one instance of the configuration, by adding deployment-specific labels and label selector requirements (e.g., env=prod, app==coolapp).
6+
7+
Enscope is a standalone minimally schema-aware transformation pass for this purpose. It identifies all names, references, label sets, and label selectors that must be uniquified/scoped. An alternative would be to use a generic templating mechanism, such as [Mustache](http://mustache.github.io), but the scoping mechanism would need to be reimplemented in every templating language, and it would also make configurations more complex.
8+
9+
Currently targets only v1beta3, which isn't yet fully implemented.
10+
11+
## Usage
12+
```
13+
$ enscope specFilename configFilename
14+
```
15+
16+
## Scope schema
17+
```
18+
type EnscopeSpec struct {
19+
NameSuffix string `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
20+
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
21+
}
22+
```
23+
24+
## Example
25+
The following name suffix and labels applied to the output from the [contrib/srvexpand example](../srvexpand/README.md):
26+
```
27+
nameSuffix: -coolapp-prod
28+
labels:
29+
app: coolapp
30+
env: prod
31+
```
32+
Output:
33+
```
34+
- apiVersion: v1beta3
35+
kind: Service
36+
metadata:
37+
creationTimestamp: "null"
38+
labels:
39+
app: coolapp
40+
env: prod
41+
service: foo
42+
name: foo-coolapp-prod
43+
spec:
44+
containerPort: 8080
45+
port: 80
46+
selector:
47+
app: coolapp
48+
env: prod
49+
service: foo
50+
status: {}
51+
- apiVersion: v1beta3
52+
kind: PodTemplate
53+
metadata:
54+
creationTimestamp: "null"
55+
labels:
56+
app: coolapp
57+
env: prod
58+
service: foo
59+
track: canary
60+
name: foo-canary-coolapp-prod
61+
spec:
62+
metadata:
63+
creationTimestamp: "null"
64+
labels:
65+
app: coolapp
66+
env: prod
67+
service: foo
68+
track: canary
69+
spec:
70+
containers:
71+
- image: me/coolappserver:canary
72+
imagePullPolicy: ""
73+
name: web
74+
restartPolicy: {}
75+
volumes: []
76+
- apiVersion: v1beta3
77+
kind: ReplicationController
78+
metadata:
79+
creationTimestamp: "null"
80+
labels:
81+
app: coolapp
82+
env: prod
83+
service: foo
84+
track: canary
85+
name: foo-canary-coolapp-prod
86+
spec:
87+
replicas: 2
88+
selector:
89+
app: coolapp
90+
env: prod
91+
service: foo
92+
track: canary
93+
template:
94+
apiVersion: v1beta3
95+
kind: PodTemplate
96+
name: foo-canary-coolapp-prod
97+
status:
98+
replicas: 0
99+
- apiVersion: v1beta3
100+
kind: PodTemplate
101+
metadata:
102+
creationTimestamp: "null"
103+
labels:
104+
app: coolapp
105+
env: prod
106+
service: foo
107+
track: stable
108+
name: foo-stable-coolapp-prod
109+
spec:
110+
metadata:
111+
creationTimestamp: "null"
112+
labels:
113+
app: coolapp
114+
env: prod
115+
service: foo
116+
track: stable
117+
spec:
118+
containers:
119+
- image: me/coolappserver:stable
120+
imagePullPolicy: ""
121+
name: web
122+
restartPolicy: {}
123+
volumes: []
124+
- apiVersion: v1beta3
125+
kind: ReplicationController
126+
metadata:
127+
creationTimestamp: "null"
128+
labels:
129+
app: coolapp
130+
env: prod
131+
service: foo
132+
track: stable
133+
name: foo-stable-coolapp-prod
134+
spec:
135+
replicas: 10
136+
selector:
137+
app: coolapp
138+
env: prod
139+
service: foo
140+
track: stable
141+
template:
142+
apiVersion: v1beta3
143+
kind: PodTemplate
144+
name: foo-stable-coolapp-prod
145+
status:
146+
replicas: 0
147+
- apiVersion: v1beta3
148+
kind: Service
149+
metadata:
150+
creationTimestamp: "null"
151+
labels:
152+
app: coolapp
153+
env: prod
154+
service: bar
155+
name: bar-coolapp-prod
156+
spec:
157+
containerPort: 3306
158+
port: 3306
159+
selector:
160+
app: coolapp
161+
env: prod
162+
service: bar
163+
status: {}
164+
- apiVersion: v1beta3
165+
kind: PodTemplate
166+
metadata:
167+
creationTimestamp: "null"
168+
labels:
169+
app: coolapp
170+
env: prod
171+
service: bar
172+
track: solo
173+
name: bar-solo-coolapp-prod
174+
spec:
175+
metadata:
176+
creationTimestamp: "null"
177+
labels:
178+
app: coolapp
179+
env: prod
180+
service: bar
181+
track: solo
182+
spec:
183+
containers:
184+
- image: mysql
185+
imagePullPolicy: ""
186+
name: db
187+
restartPolicy: {}
188+
volumes:
189+
- name: dbdir
190+
source: null
191+
- apiVersion: v1beta3
192+
kind: ReplicationController
193+
metadata:
194+
creationTimestamp: "null"
195+
labels:
196+
app: coolapp
197+
env: prod
198+
service: bar
199+
track: solo
200+
name: bar-solo-coolapp-prod
201+
spec:
202+
replicas: 1
203+
selector:
204+
app: coolapp
205+
env: prod
206+
service: bar
207+
track: solo
208+
template:
209+
apiVersion: v1beta3
210+
kind: PodTemplate
211+
name: bar-solo-coolapp-prod
212+
status:
213+
replicas: 0
214+
```

0 commit comments

Comments
 (0)