@@ -3,7 +3,7 @@ package pod
33import (
44 "fmt"
55 "strings"
6-
6+
77 "github.com/arttor/helmify/pkg/cluster"
88 "github.com/arttor/helmify/pkg/helmify"
99 securityContext "github.com/arttor/helmify/pkg/processor/security-context"
@@ -21,46 +21,46 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe
2121 if err != nil {
2222 return nil , nil , err
2323 }
24-
24+
2525 // replace PVC to templated name
2626 for i := 0 ; i < len (spec .Volumes ); i ++ {
2727 vol := spec .Volumes [i ]
2828 if vol .PersistentVolumeClaim == nil {
2929 continue
3030 }
3131 tempPVCName := appMeta .TemplatedName (vol .PersistentVolumeClaim .ClaimName )
32-
32+
3333 spec .Volumes [i ].PersistentVolumeClaim .ClaimName = tempPVCName
3434 }
35-
35+
3636 // replace container resources with template to values.
3737 specMap , err := runtime .DefaultUnstructuredConverter .ToUnstructured (& spec )
3838 if err != nil {
3939 return nil , nil , fmt .Errorf ("%w: unable to convert podSpec to map" , err )
4040 }
41-
41+
4242 specMap , values , err = processNestedContainers (specMap , objName , values , "containers" )
4343 if err != nil {
4444 return nil , nil , err
4545 }
46-
46+
4747 specMap , values , err = processNestedContainers (specMap , objName , values , "initContainers" )
4848 if err != nil {
4949 return nil , nil , err
5050 }
51-
51+
5252 if appMeta .Config ().ImagePullSecrets {
5353 if _ , defined := specMap ["imagePullSecrets" ]; ! defined {
5454 specMap ["imagePullSecrets" ] = "{{ .Values.imagePullSecrets | default list | toJson }}"
5555 values ["imagePullSecrets" ] = []string {}
5656 }
5757 }
58-
58+
5959 err = securityContext .ProcessContainerSecurityContext (objName , specMap , & values )
6060 if err != nil {
6161 return nil , nil , err
6262 }
63-
63+
6464 // process nodeSelector if presented:
6565 if spec .NodeSelector != nil {
6666 err = unstructured .SetNestedField (specMap , fmt .Sprintf (`{{- toYaml .Values.%s.nodeSelector | nindent 8 }}` , objName ), "nodeSelector" )
@@ -72,7 +72,7 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe
7272 return nil , nil , err
7373 }
7474 }
75-
75+
7676 return specMap , values , nil
7777}
7878
@@ -81,19 +81,19 @@ func processNestedContainers(specMap map[string]interface{}, objName string, val
8181 if err != nil {
8282 return nil , nil , err
8383 }
84-
84+
8585 if len (containers ) > 0 {
8686 containers , values , err = processContainers (objName , values , containerKey , containers )
8787 if err != nil {
8888 return nil , nil , err
8989 }
90-
90+
9191 err = unstructured .SetNestedSlice (specMap , containers , containerKey )
9292 if err != nil {
9393 return nil , nil , err
9494 }
9595 }
96-
96+
9797 return specMap , values , nil
9898}
9999
@@ -110,7 +110,7 @@ func processContainers(objName string, values helmify.Values, containerType stri
110110 return nil , nil , err
111111 }
112112 }
113-
113+
114114 args , exists , err := unstructured .NestedStringSlice (containers [i ].(map [string ]interface {}), "args" )
115115 if err != nil {
116116 return nil , nil , err
@@ -120,7 +120,7 @@ func processContainers(objName string, values helmify.Values, containerType stri
120120 if err != nil {
121121 return nil , nil , err
122122 }
123-
123+
124124 err = unstructured .SetNestedStringSlice (values , args , objName , containerName , "args" )
125125 if err != nil {
126126 return nil , nil , fmt .Errorf ("%w: unable to set deployment value field" , err )
@@ -139,15 +139,15 @@ func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpe
139139 }
140140 pod .Containers [i ] = processed
141141 }
142-
142+
143143 for i , c := range pod .InitContainers {
144144 processed , err := processPodContainer (name , appMeta , c , & values )
145145 if err != nil {
146146 return nil , err
147147 }
148148 pod .InitContainers [i ] = processed
149149 }
150-
150+
151151 for _ , v := range pod .Volumes {
152152 if v .ConfigMap != nil {
153153 v .ConfigMap .Name = appMeta .TemplatedName (v .ConfigMap .Name )
@@ -157,11 +157,11 @@ func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpe
157157 }
158158 }
159159 pod .ServiceAccountName = appMeta .TemplatedName (pod .ServiceAccountName )
160-
160+
161161 for i , s := range pod .ImagePullSecrets {
162162 pod .ImagePullSecrets [i ].Name = appMeta .TemplatedName (s .Name )
163163 }
164-
164+
165165 return values , nil
166166}
167167
@@ -173,7 +173,7 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
173173 repo , tag := c .Image [:index ], c .Image [index + 1 :]
174174 containerName := strcase .ToLowerCamel (c .Name )
175175 c .Image = fmt .Sprintf ("{{ .Values.%[1]s.%[2]s.image.repository }}:{{ .Values.%[1]s.%[2]s.image.tag | default .Chart.AppVersion }}" , name , containerName )
176-
176+
177177 err := unstructured .SetNestedField (* values , repo , name , containerName , "image" , "repository" )
178178 if err != nil {
179179 return c , fmt .Errorf ("%w: unable to set deployment value field" , err )
@@ -182,12 +182,12 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
182182 if err != nil {
183183 return c , fmt .Errorf ("%w: unable to set deployment value field" , err )
184184 }
185-
185+
186186 c , err = processEnv (name , appMeta , c , values )
187187 if err != nil {
188188 return c , err
189189 }
190-
190+
191191 for _ , e := range c .EnvFrom {
192192 if e .SecretRef != nil {
193193 e .SecretRef .Name = appMeta .TemplatedName (e .SecretRef .Name )
@@ -212,7 +212,7 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
212212 return c , fmt .Errorf ("%w: unable to set container resources value" , err )
213213 }
214214 }
215-
215+
216216 if c .ImagePullPolicy != "" {
217217 err = unstructured .SetNestedField (* values , string (c .ImagePullPolicy ), name , containerName , "imagePullPolicy" )
218218 if err != nil {
@@ -237,7 +237,7 @@ func processEnv(name string, appMeta helmify.AppMetadata, c corev1.Container, va
237237 }
238238 continue
239239 }
240-
240+
241241 err := unstructured .SetNestedField (* values , c .Env [i ].Value , name , containerName , "env" , strcase .ToLowerCamel (strings .ToLower (c .Env [i ].Name )))
242242 if err != nil {
243243 return c , fmt .Errorf ("%w: unable to set deployment value field" , err )
0 commit comments