Skip to content

Commit c2618cf

Browse files
author
Robin LIORET
committed
feat: helm v2-alpha: add nodeSelector, tolerations and affinity to the values generator
1 parent 2942a7d commit c2618cf

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

pkg/plugins/optional/helm/v2alpha/scaffolds/internal/templates/values_basic.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,63 @@ func (f *HelmValuesBasic) addDeploymentConfig(buf *bytes.Buffer) {
284284
} else {
285285
f.addDefaultResources(buf)
286286
}
287+
288+
buf.WriteString(" # Pod's affinity\n")
289+
if affinity, exists := f.DeploymentConfig["podAffinity"]; exists && affinity != nil {
290+
buf.WriteString(" affinity:\n")
291+
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+
}
300+
}
301+
buf.WriteString("\n")
302+
} else {
303+
buf.WriteString(" affinity: {}\n")
304+
buf.WriteString("\n")
305+
}
306+
307+
buf.WriteString(" # Pod's node selector\n")
308+
if nodeSelector, exists := f.DeploymentConfig["podNodeSelector"]; exists && nodeSelector != nil {
309+
buf.WriteString(" nodeSelector:\n")
310+
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+
}
319+
}
320+
buf.WriteString("\n")
321+
} else {
322+
buf.WriteString(" nodeSelector: {}\n")
323+
buf.WriteString("\n")
324+
}
325+
326+
buf.WriteString(" # Pod's tolerations\n")
327+
if tolerations, exists := f.DeploymentConfig["podTolerations"]; exists && tolerations != nil {
328+
buf.WriteString(" tolerations:\n")
329+
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+
}
338+
}
339+
buf.WriteString("\n")
340+
} else {
341+
buf.WriteString(" tolerations: []\n")
342+
buf.WriteString("\n")
343+
}
287344
}
288345

289346
// addDefaultDeploymentSections adds default sections when no deployment config is available

pkg/plugins/optional/helm/v2alpha/scaffolds/internal/templates/values_basic_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ var _ = Describe("HelmValuesBasic", func() {
159159
Expect(content).To(ContainSubstring("resources:"))
160160
Expect(content).To(ContainSubstring("cpu: 100m"))
161161
Expect(content).To(ContainSubstring("memory: 128Mi"))
162+
Expect(content).To(ContainSubstring("affinity: {}"))
163+
Expect(content).To(ContainSubstring("nodeSelector: {}"))
164+
Expect(content).To(ContainSubstring("tolerations: []"))
162165
})
163166
})
164167

0 commit comments

Comments
 (0)