@@ -210,15 +210,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
210210 buf .WriteString (" # Environment variables\n " )
211211 buf .WriteString (" env:\n " )
212212 if envYaml , err := yaml .Marshal (env ); err == nil {
213- // Indent the YAML properly
214- lines := bytes .Split (envYaml , []byte ("\n " ))
215- for _ , line := range lines {
216- if len (line ) > 0 {
217- buf .WriteString (" " )
218- buf .Write (line )
219- buf .WriteString ("\n " )
220- }
221- }
213+ f .IndentYamlProperly (buf , envYaml )
222214 } else {
223215 buf .WriteString (" []\n " )
224216 }
@@ -233,14 +225,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
233225 buf .WriteString (" # Pod-level security settings\n " )
234226 buf .WriteString (" podSecurityContext:\n " )
235227 if secYaml , err := yaml .Marshal (podSecCtx ); err == nil {
236- lines := bytes .Split (secYaml , []byte ("\n " ))
237- for _ , line := range lines {
238- if len (line ) > 0 {
239- buf .WriteString (" " )
240- buf .Write (line )
241- buf .WriteString ("\n " )
242- }
243- }
228+ f .IndentYamlProperly (buf , secYaml )
244229 }
245230 buf .WriteString ("\n " )
246231 } else {
@@ -252,14 +237,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
252237 buf .WriteString (" # Container-level security settings\n " )
253238 buf .WriteString (" securityContext:\n " )
254239 if secYaml , err := yaml .Marshal (secCtx ); err == nil {
255- lines := bytes .Split (secYaml , []byte ("\n " ))
256- for _ , line := range lines {
257- if len (line ) > 0 {
258- buf .WriteString (" " )
259- buf .Write (line )
260- buf .WriteString ("\n " )
261- }
262- }
240+ f .IndentYamlProperly (buf , secYaml )
263241 }
264242 buf .WriteString ("\n " )
265243 } else {
@@ -271,14 +249,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
271249 buf .WriteString (" # Resource limits and requests\n " )
272250 buf .WriteString (" resources:\n " )
273251 if resYaml , err := yaml .Marshal (resources ); err == nil {
274- lines := bytes .Split (resYaml , []byte ("\n " ))
275- for _ , line := range lines {
276- if len (line ) > 0 {
277- buf .WriteString (" " )
278- buf .Write (line )
279- buf .WriteString ("\n " )
280- }
281- }
252+ f .IndentYamlProperly (buf , resYaml )
282253 }
283254 buf .WriteString ("\n " )
284255 } else {
@@ -289,14 +260,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
289260 if affinity , exists := f .DeploymentConfig ["podAffinity" ]; exists && affinity != nil {
290261 buf .WriteString (" affinity:\n " )
291262 if affYaml , err := yaml .Marshal (affinity ); err == nil {
292- lines := bytes .Split (affYaml , []byte ("\n " ))
293- for _ , line := range lines {
294- if len (line ) > 0 {
295- buf .WriteString (" " )
296- buf .Write (line )
297- buf .WriteString ("\n " )
298- }
299- }
263+ f .IndentYamlProperly (buf , affYaml )
300264 }
301265 buf .WriteString ("\n " )
302266 } else {
@@ -308,14 +272,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
308272 if nodeSelector , exists := f .DeploymentConfig ["podNodeSelector" ]; exists && nodeSelector != nil {
309273 buf .WriteString (" nodeSelector:\n " )
310274 if nodYaml , err := yaml .Marshal (nodeSelector ); err == nil {
311- lines := bytes .Split (nodYaml , []byte ("\n " ))
312- for _ , line := range lines {
313- if len (line ) > 0 {
314- buf .WriteString (" " )
315- buf .Write (line )
316- buf .WriteString ("\n " )
317- }
318- }
275+ f .IndentYamlProperly (buf , nodYaml )
319276 }
320277 buf .WriteString ("\n " )
321278 } else {
@@ -327,14 +284,7 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
327284 if tolerations , exists := f .DeploymentConfig ["podTolerations" ]; exists && tolerations != nil {
328285 buf .WriteString (" tolerations:\n " )
329286 if tolYaml , err := yaml .Marshal (tolerations ); err == nil {
330- lines := bytes .Split (tolYaml , []byte ("\n " ))
331- for _ , line := range lines {
332- if len (line ) > 0 {
333- buf .WriteString (" " )
334- buf .Write (line )
335- buf .WriteString ("\n " )
336- }
337- }
287+ f .IndentYamlProperly (buf , tolYaml )
338288 }
339289 buf .WriteString ("\n " )
340290 } else {
@@ -343,6 +293,17 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
343293 }
344294}
345295
296+ func (f * HelmValuesBasic ) IndentYamlProperly (buf * bytes.Buffer , envYaml []byte ) {
297+ lines := bytes .Split (envYaml , []byte ("\n " ))
298+ for _ , line := range lines {
299+ if len (line ) > 0 {
300+ buf .WriteString (" " )
301+ buf .Write (line )
302+ buf .WriteString ("\n " )
303+ }
304+ }
305+ }
306+
346307// addDefaultDeploymentSections adds default sections when no deployment config is available
347308func (f * HelmValuesBasic ) addDefaultDeploymentSections (buf * bytes.Buffer ) {
348309 buf .WriteString (" # Environment variables\n " )
0 commit comments