@@ -7,10 +7,10 @@ import (
77 "text/template"
88
99 "github.com/arttor/helmify/pkg/cluster"
10+ "github.com/arttor/helmify/pkg/helmify"
1011 "github.com/arttor/helmify/pkg/processor"
1112 "github.com/arttor/helmify/pkg/processor/imagePullSecrets"
12-
13- "github.com/arttor/helmify/pkg/helmify"
13+ "github.com/arttor/helmify/pkg/processor/probes"
1414 yamlformat "github.com/arttor/helmify/pkg/yaml"
1515 "github.com/iancoleman/strcase"
1616 "github.com/pkg/errors"
@@ -47,7 +47,7 @@ const selectorTempl = `%[1]s
4747{{- include "%[2]s.selectorLabels" . | nindent 6 }}
4848%[3]s`
4949
50- const envValue = "{{ .Values.%[1]s.%[2]s.%[3]s }}"
50+ const envValue = "{{ .Values.%[1]s.%[2]s.%[3]s.%[4]s }}"
5151
5252// New creates processor for k8s Deployment resource.
5353func New () helmify.Processor {
@@ -139,19 +139,20 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
139139 if err != nil {
140140 return true , nil , err
141141 }
142+
142143 for i := range containers {
143144 containerName := strcase .ToLowerCamel ((containers [i ].(map [string ]interface {})["name" ]).(string ))
144145 res , exists , err := unstructured .NestedMap (values , nameCamel , containerName , "resources" )
145146 if err != nil {
146147 return true , nil , err
147148 }
148- if ! exists || len (res ) == 0 {
149- continue
150- }
151- err = unstructured .SetNestedField (containers [i ].(map [string ]interface {}), fmt .Sprintf (`{{- toYaml .Values.%s.%s.resources | nindent 10 }}` , nameCamel , containerName ), "resources" )
152- if err != nil {
153- return true , nil , err
149+ if exists && len (res ) > 0 {
150+ err = unstructured .SetNestedField (containers [i ].(map [string ]interface {}), fmt .Sprintf (`{{- toYaml .Values.%s.%s.resources | nindent 10 }}` , nameCamel , containerName ), "resources" )
151+ if err != nil {
152+ return true , nil , err
153+ }
154154 }
155+
155156 }
156157 err = unstructured .SetNestedSlice (specMap , containers , "containers" )
157158 if err != nil {
@@ -162,12 +163,21 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
162163 imagePullSecrets .ProcessSpecMap (specMap , & values )
163164 }
164165
166+ if appMeta .Config ().Probes {
167+ err = probes .ProcessSpecMap (nameCamel , specMap , & values )
168+ if err != nil {
169+ return true , nil , err
170+ }
171+ }
172+
165173 spec , err := yamlformat .Marshal (specMap , 6 )
166174 if err != nil {
167175 return true , nil , err
168176 }
169- spec = strings .ReplaceAll (spec , "'" , "" )
170177
178+ spec = strings .ReplaceAll (spec , "'" , "" )
179+ spec = strings .ReplaceAll (spec , "|\n " , "" )
180+ spec = strings .ReplaceAll (spec , "|-\n " , "" )
171181 return true , & result {
172182 values : values ,
173183 data : struct {
@@ -208,6 +218,7 @@ func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpe
208218 values := helmify.Values {}
209219 for i , c := range pod .Containers {
210220 processed , err := processPodContainer (name , appMeta , c , & values )
221+
211222 if err != nil {
212223 return nil , err
213224 }
@@ -260,13 +271,16 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
260271 if e .ConfigMapRef != nil {
261272 e .ConfigMapRef .Name = appMeta .TemplatedName (e .ConfigMapRef .Name )
262273 }
274+
263275 }
276+
264277 c .Env = append (c .Env , corev1.EnvVar {
265278 Name : cluster .DomainEnv ,
266279 Value : fmt .Sprintf ("{{ .Values.%s }}" , cluster .DomainKey ),
267280 })
268281 for k , v := range c .Resources .Requests {
269282 err = unstructured .SetNestedField (* values , v .ToUnstructured (), name , containerName , "resources" , "requests" , k .String ())
283+
270284 if err != nil {
271285 return c , errors .Wrap (err , "unable to set container resources value" )
272286 }
@@ -277,7 +291,8 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
277291 return c , errors .Wrap (err , "unable to set container resources value" )
278292 }
279293 }
280- return c , nil
294+
295+ return c , err
281296}
282297
283298func processEnv (name string , appMeta helmify.AppMetadata , c corev1.Container , values * helmify.Values ) (corev1.Container , error ) {
@@ -293,7 +308,7 @@ func processEnv(name string, appMeta helmify.AppMetadata, c corev1.Container, va
293308 if err != nil {
294309 return c , errors .Wrap (err , "unable to set deployment value field" )
295310 }
296- c .Env [i ].Value = fmt .Sprintf (envValue , name , containerName , strcase .ToLowerCamel (strings .ToLower (c .Env [i ].Name )))
311+ c .Env [i ].Value = fmt .Sprintf (envValue , name , containerName , "env" , strcase .ToLowerCamel (strings .ToLower (c .Env [i ].Name )))
297312 }
298313 }
299314 return c , nil
0 commit comments