Skip to content

Commit 1cfad5d

Browse files
committed
include workload allowed_annotations in crio config output
Signed-off-by: prasad89 <[email protected]>
1 parent 81e69a5 commit 1cfad5d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

pkg/config/template.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,9 @@ const templateStringCrioRuntimeWorkloads = `# The workloads table defines ways t
14081408
{{ $.Comment }}[crio.runtime.workloads.{{ $workload_type }}]
14091409
{{ $.Comment }}activation_annotation = "{{ $workload_config.ActivationAnnotation }}"
14101410
{{ $.Comment }}annotation_prefix = "{{ $workload_config.AnnotationPrefix }}"
1411+
{{ if gt (len $workload_config.AllowedAnnotations) 0 }}{{ $.Comment }}allowed_annotations = [
1412+
{{ range $opt := $workload_config.AllowedAnnotations }}{{ $.Comment }}{{ printf "\t%q," $opt }}
1413+
{{ end }}{{ $.Comment }}]{{ end }}
14111414
{{ if $workload_config.Resources }}{{ $.Comment }}[crio.runtime.workloads.{{ $workload_type }}.resources]
14121415
{{ $.Comment }}cpuset = "{{ $workload_config.Resources.CPUSet }}"
14131416
{{ $.Comment }}cpuquota = {{ $workload_config.Resources.CPUQuota }}

pkg/config/template_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config_test
22

33
import (
44
"bytes"
5+
"strings"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
@@ -23,6 +24,68 @@ var _ = t.Describe("Config", func() {
2324
// Then
2425
Expect(err).ToNot(HaveOccurred())
2526
})
27+
28+
It("should include workload allowed_annotations in template output", func() {
29+
// Given
30+
sut.Workloads = config.Workloads{
31+
"test-workload": &config.WorkloadConfig{
32+
ActivationAnnotation: "io.test.workload",
33+
AnnotationPrefix: "io.test.prefix",
34+
AllowedAnnotations: []string{
35+
"io.kubernetes.cri-o.userns-mode",
36+
"io.kubernetes.cri-o.umask",
37+
"io.kubernetes.cri-o.Devices",
38+
},
39+
},
40+
}
41+
var wr bytes.Buffer
42+
43+
// When
44+
err := sut.WriteTemplate(true, &wr)
45+
46+
// Then
47+
Expect(err).ToNot(HaveOccurred())
48+
output := wr.String()
49+
Expect(output).To(ContainSubstring("allowed_annotations = ["))
50+
Expect(output).To(ContainSubstring(`"io.kubernetes.cri-o.userns-mode",`))
51+
Expect(output).To(ContainSubstring(`"io.kubernetes.cri-o.umask",`))
52+
Expect(output).To(ContainSubstring(`"io.kubernetes.cri-o.Devices",`))
53+
})
54+
55+
It("should not include workload allowed_annotations when empty", func() {
56+
// Given
57+
sut.Workloads = config.Workloads{
58+
"test-workload": &config.WorkloadConfig{
59+
ActivationAnnotation: "io.test.workload",
60+
AnnotationPrefix: "io.test.prefix",
61+
AllowedAnnotations: []string{},
62+
},
63+
}
64+
var wr bytes.Buffer
65+
66+
// When
67+
err := sut.WriteTemplate(true, &wr)
68+
69+
// Then
70+
Expect(err).ToNot(HaveOccurred())
71+
output := wr.String()
72+
73+
// Extract just the workload section to verify allowed_annotations is not present
74+
lines := strings.Split(output, "\n")
75+
workloadSection := ""
76+
inWorkloadSection := false
77+
for _, line := range lines {
78+
if strings.Contains(line, "[crio.runtime.workloads.test-workload]") {
79+
inWorkloadSection = true
80+
} else if strings.HasPrefix(line, "[") && inWorkloadSection {
81+
break // End of workload section
82+
}
83+
if inWorkloadSection {
84+
workloadSection += line + "\n"
85+
}
86+
}
87+
Expect(workloadSection).ToNot(ContainSubstring("allowed_annotations = ["))
88+
})
2689
})
2790
t.Describe("RuntimesEqual", func() {
2891
It("not equal if different length", func() {

0 commit comments

Comments
 (0)