@@ -2,6 +2,7 @@ package config_test
22
33import (
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