@@ -17,6 +17,7 @@ import (
17
17
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
18
18
"k8s.io/apimachinery/pkg/runtime"
19
19
"k8s.io/apimachinery/pkg/runtime/schema"
20
+ "k8s.io/apimachinery/pkg/util/intstr"
20
21
)
21
22
22
23
var deploymentGVC = schema.GroupVersionKind {
33
34
{{- end }}
34
35
{{- if .RevisionHistoryLimit }}
35
36
{{ .RevisionHistoryLimit }}
37
+ {{- end }}
38
+ {{- if .Strategy }}
39
+ {{ .Strategy }}
36
40
{{- end }}
37
41
selector:
38
42
{{ .Selector }}
@@ -84,6 +88,11 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
84
88
return true , nil , err
85
89
}
86
90
91
+ strategy , err := processStrategy (name , & depl , & values )
92
+ if err != nil {
93
+ return true , nil , err
94
+ }
95
+
87
96
matchLabels , err := yamlformat .Marshal (map [string ]interface {}{"matchLabels" : depl .Spec .Selector .MatchLabels }, 0 )
88
97
if err != nil {
89
98
return true , nil , err
@@ -141,6 +150,7 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
141
150
Meta string
142
151
Replicas string
143
152
RevisionHistoryLimit string
153
+ Strategy string
144
154
Selector string
145
155
PodLabels string
146
156
PodAnnotations string
@@ -149,6 +159,7 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
149
159
Meta : meta ,
150
160
Replicas : replicas ,
151
161
RevisionHistoryLimit : revisionHistoryLimit ,
162
+ Strategy : strategy ,
152
163
Selector : selector ,
153
164
PodLabels : podLabels ,
154
165
PodAnnotations : podAnnotations ,
@@ -218,11 +229,68 @@ func processRevisionHistoryLimit(name string, deployment *appsv1.Deployment, val
218
229
return revisionHistoryLimit , nil
219
230
}
220
231
232
+ func processStrategy (name string , deployment * appsv1.Deployment , values * helmify.Values ) (string , error ) {
233
+ if deployment .Spec .Strategy .Type == "" {
234
+ return "" , nil
235
+ }
236
+ allowedStrategyTypes := map [appsv1.DeploymentStrategyType ]bool {
237
+ appsv1 .RecreateDeploymentStrategyType : true ,
238
+ appsv1 .RollingUpdateDeploymentStrategyType : true ,
239
+ }
240
+ if ! allowedStrategyTypes [deployment .Spec .Strategy .Type ] {
241
+ return "" , fmt .Errorf ("invalid deployment strategy type: %s" , deployment .Spec .Strategy .Type )
242
+ }
243
+ strategyTypeTpl , err := values .Add (string (deployment .Spec .Strategy .Type ), name , "strategy" , "type" )
244
+ if err != nil {
245
+ return "" , err
246
+ }
247
+ strategyMap := map [string ]interface {}{
248
+ "type" : strategyTypeTpl ,
249
+ }
250
+ if deployment .Spec .Strategy .Type == appsv1 .RollingUpdateDeploymentStrategyType {
251
+ if rollingUpdate := deployment .Spec .Strategy .RollingUpdate ; rollingUpdate != nil {
252
+ rollingUpdateMap := map [string ]interface {}{}
253
+ setRollingUpdateField := func (value * intstr.IntOrString , fieldName string ) error {
254
+ var tpl string
255
+ var err error
256
+ if value .Type == intstr .Int {
257
+ tpl , err = values .Add (value .IntValue (), name , "strategy" , "rollingUpdate" , fieldName )
258
+ } else {
259
+ tpl , err = values .Add (value .String (), name , "strategy" , "rollingUpdate" , fieldName )
260
+ }
261
+ if err != nil {
262
+ return err
263
+ }
264
+ rollingUpdateMap [fieldName ] = tpl
265
+ return nil
266
+ }
267
+ if rollingUpdate .MaxSurge != nil {
268
+ if err := setRollingUpdateField (rollingUpdate .MaxSurge , "maxSurge" ); err != nil {
269
+ return "" , err
270
+ }
271
+ }
272
+ if rollingUpdate .MaxUnavailable != nil {
273
+ if err := setRollingUpdateField (rollingUpdate .MaxUnavailable , "maxUnavailable" ); err != nil {
274
+ return "" , err
275
+ }
276
+ }
277
+ strategyMap ["rollingUpdate" ] = rollingUpdateMap
278
+ }
279
+ }
280
+ strategy , err := yamlformat .Marshal (map [string ]interface {}{"strategy" : strategyMap }, 2 )
281
+ if err != nil {
282
+ return "" , err
283
+ }
284
+ strategy = strings .ReplaceAll (strategy , "'" , "" )
285
+ return strategy , nil
286
+ }
287
+
221
288
type result struct {
222
289
data struct {
223
290
Meta string
224
291
Replicas string
225
292
RevisionHistoryLimit string
293
+ Strategy string
226
294
Selector string
227
295
PodLabels string
228
296
PodAnnotations string
0 commit comments