@@ -71,7 +71,12 @@ func (g CodeGenerator) Execute() error {
71
71
getClusterRoleBinding (p ),
72
72
)
73
73
result = append (result , getCrds (p )... )
74
- result = append (result , getDeployment (p ))
74
+ if controllerType == "deployment" {
75
+ result = append (result , getDeployment (p ))
76
+ } else {
77
+ result = append (result , getStatefuleSetService (p ))
78
+ result = append (result , getStatefuleSet (p ))
79
+ }
75
80
76
81
util .WriteString (output , strings .Join (result , "---\n " ))
77
82
return nil
@@ -141,7 +146,10 @@ func getClusterRoleBinding(p *parse.APIs) string {
141
146
}
142
147
143
148
func getDeployment (p * parse.APIs ) string {
144
- labels := addLabels (map [string ]string {})
149
+ var replicas int32 = 1
150
+ labels := addLabels (map [string ]string {
151
+ "control-plane" : "controller-manager" ,
152
+ })
145
153
dep := appsv1.Deployment {
146
154
TypeMeta : metav1.TypeMeta {
147
155
APIVersion : "apps/v1" ,
@@ -153,34 +161,11 @@ func getDeployment(p *parse.APIs) string {
153
161
Labels : labels ,
154
162
},
155
163
Spec : appsv1.DeploymentSpec {
164
+ Replicas : & replicas ,
156
165
Selector : & metav1.LabelSelector {
157
166
MatchLabels : labels ,
158
167
},
159
- Template : corev1.PodTemplateSpec {
160
- ObjectMeta : metav1.ObjectMeta {
161
- Labels : labels ,
162
- },
163
- Spec : corev1.PodSpec {
164
- Containers : []corev1.Container {
165
- {
166
- Name : "controller-manager" ,
167
- Image : controllerImage ,
168
- Command : []string {"/root/controller-manager" },
169
- Args : []string {"--install-crds=false" },
170
- Resources : corev1.ResourceRequirements {
171
- Requests : map [corev1.ResourceName ]resource.Quantity {
172
- "cpu" : resource .MustParse ("100m" ),
173
- "memory" : resource .MustParse ("20Mi" ),
174
- },
175
- Limits : map [corev1.ResourceName ]resource.Quantity {
176
- "cpu" : resource .MustParse ("100m" ),
177
- "memory" : resource .MustParse ("30Mi" ),
178
- },
179
- },
180
- },
181
- },
182
- },
183
- },
168
+ Template : getPodTemplate (labels ),
184
169
},
185
170
}
186
171
@@ -191,6 +176,97 @@ func getDeployment(p *parse.APIs) string {
191
176
return string (s )
192
177
}
193
178
179
+ func getStatefuleSet (p * parse.APIs ) string {
180
+ var replicas int32 = 1
181
+ labels := addLabels (map [string ]string {
182
+ "control-plane" : "controller-manager" ,
183
+ })
184
+ statefulset := appsv1.StatefulSet {
185
+ TypeMeta : metav1.TypeMeta {
186
+ APIVersion : "apps/v1" ,
187
+ Kind : "StatefulSet" ,
188
+ },
189
+ ObjectMeta : metav1.ObjectMeta {
190
+ Name : fmt .Sprintf ("%v-controller-manager" , name ),
191
+ Namespace : fmt .Sprintf ("%v-system" , name ),
192
+ Labels : labels ,
193
+ },
194
+ Spec : appsv1.StatefulSetSpec {
195
+ ServiceName : fmt .Sprintf ("%v-controller-manager-service" , name ),
196
+ Replicas : & replicas ,
197
+ Selector : & metav1.LabelSelector {
198
+ MatchLabels : labels ,
199
+ },
200
+ Template : getPodTemplate (labels ),
201
+ },
202
+ }
203
+
204
+ s , err := yaml .Marshal (statefulset )
205
+ if err != nil {
206
+ glog .Fatalf ("Error: %v" , err )
207
+ }
208
+ return string (s )
209
+
210
+ }
211
+
212
+ func getStatefuleSetService (p * parse.APIs ) string {
213
+ labels := addLabels (map [string ]string {
214
+ "control-plane" : "controller-manager" ,
215
+ })
216
+ statefulsetservice := corev1.Service {
217
+ TypeMeta : metav1.TypeMeta {
218
+ APIVersion : "v1" ,
219
+ Kind : "Service" ,
220
+ },
221
+ ObjectMeta : metav1.ObjectMeta {
222
+ Name : fmt .Sprintf ("%v-controller-manager-service" , name ),
223
+ Namespace : fmt .Sprintf ("%v-system" , name ),
224
+ Labels : labels ,
225
+ },
226
+ Spec : corev1.ServiceSpec {
227
+ Selector : labels ,
228
+ ClusterIP : "None" ,
229
+ },
230
+ }
231
+
232
+ s , err := yaml .Marshal (statefulsetservice )
233
+ if err != nil {
234
+ glog .Fatalf ("Error: %v" , err )
235
+ }
236
+ return string (s )
237
+
238
+ }
239
+
240
+ func getPodTemplate (labels map [string ]string ) corev1.PodTemplateSpec {
241
+ var terminationPeriod int64 = 10
242
+ return corev1.PodTemplateSpec {
243
+ ObjectMeta : metav1.ObjectMeta {
244
+ Labels : labels ,
245
+ },
246
+ Spec : corev1.PodSpec {
247
+ TerminationGracePeriodSeconds : & terminationPeriod ,
248
+ Containers : []corev1.Container {
249
+ {
250
+ Name : "controller-manager" ,
251
+ Image : controllerImage ,
252
+ Command : []string {"/root/controller-manager" },
253
+ Args : []string {"--install-crds=false" },
254
+ Resources : corev1.ResourceRequirements {
255
+ Requests : map [corev1.ResourceName ]resource.Quantity {
256
+ "cpu" : resource .MustParse ("100m" ),
257
+ "memory" : resource .MustParse ("20Mi" ),
258
+ },
259
+ Limits : map [corev1.ResourceName ]resource.Quantity {
260
+ "cpu" : resource .MustParse ("100m" ),
261
+ "memory" : resource .MustParse ("30Mi" ),
262
+ },
263
+ },
264
+ },
265
+ },
266
+ },
267
+ }
268
+ }
269
+
194
270
func getCrds (p * parse.APIs ) []string {
195
271
result := []string {}
196
272
for _ , g := range p .APIs .Groups {
0 commit comments