Skip to content

Commit 4f5d0e3

Browse files
committed
Check bootstrap CVO too
Because `bootstrap-pod.yaml` is not a valid yaml [1], we have to render it and then parse out manifests from it. We could make it valid as we did for the others, but it might be dangerous to do so. We have only one manifest for bootstrap. I am fine with a rendering step. #1171 (comment)
1 parent f6ab856 commit 4f5d0e3

1 file changed

Lines changed: 65 additions & 34 deletions

File tree

pkg/payload/render_test.go

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package payload
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -64,47 +65,77 @@ func TestRenderManifest(t *testing.T) {
6465
}
6566

6667
func Test_cvoManifests(t *testing.T) {
67-
installDir := filepath.Join("../../install")
68-
files, err := os.ReadDir(installDir)
69-
if err != nil {
70-
t.Fatalf("failed to read directory: %v", err)
68+
config := manifestRenderConfig{
69+
ReleaseImage: "quay.io/cvo/release:latest",
70+
ClusterProfile: "some-profile",
7171
}
7272

73-
if len(files) == 0 {
74-
t.Fatalf("no files found in %s", installDir)
73+
tests := []struct {
74+
name string
75+
dir string
76+
}{
77+
{
78+
name: "install dir",
79+
dir: filepath.Join("../../install"),
80+
},
81+
{
82+
name: "bootstrap dir",
83+
dir: filepath.Join("../../bootstrap"),
84+
},
7585
}
86+
for _, tt := range tests {
87+
t.Run(tt.name, func(t *testing.T) {
88+
files, err := os.ReadDir(tt.dir)
89+
if err != nil {
90+
t.Fatalf("failed to read directory: %v", err)
91+
}
7692

77-
var manifestsWithoutIncludeAnnotation []manifest.Manifest
78-
const prefix = "include.release.openshift.io/"
79-
for _, manifestFile := range files {
80-
if manifestFile.IsDir() {
81-
continue
82-
}
83-
filePath := filepath.Join(installDir, manifestFile.Name())
84-
manifests, err := manifest.ManifestsFromFiles([]string{filePath})
85-
if err != nil {
86-
t.Fatalf("failed to load manifests: %v", err)
87-
}
93+
if len(files) == 0 {
94+
t.Fatalf("no files found in %s", tt.dir)
95+
}
8896

89-
for _, m := range manifests {
90-
var found bool
91-
for k := range m.Obj.GetAnnotations() {
92-
if strings.HasPrefix(k, prefix) {
93-
found = true
94-
break
97+
var manifestsWithoutIncludeAnnotation []manifest.Manifest
98+
const prefix = "include.release.openshift.io/"
99+
for _, manifestFile := range files {
100+
if manifestFile.IsDir() {
101+
continue
102+
}
103+
filePath := filepath.Join(tt.dir, manifestFile.Name())
104+
data, err := os.ReadFile(filePath)
105+
if err != nil {
106+
t.Fatalf("failed to read manifest file: %v", err)
107+
}
108+
data, err = renderManifest(config, data)
109+
if err != nil {
110+
t.Fatalf("failed to render manifest: %v", err)
111+
}
112+
manifests, err := manifest.ParseManifests(bytes.NewReader(data))
113+
if err != nil {
114+
t.Fatalf("failed to load manifests: %v", err)
115+
}
116+
117+
for _, m := range manifests {
118+
m.OriginalFilename = filePath
119+
var found bool
120+
for k := range m.Obj.GetAnnotations() {
121+
if strings.HasPrefix(k, prefix) {
122+
found = true
123+
break
124+
}
125+
}
126+
if !found {
127+
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
128+
}
95129
}
96130
}
97-
if !found {
98-
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
99-
}
100-
}
101-
}
102131

103-
if len(manifestsWithoutIncludeAnnotation) > 0 {
104-
var messages []string
105-
for _, m := range manifestsWithoutIncludeAnnotation {
106-
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
107-
}
108-
t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '"))
132+
if len(manifestsWithoutIncludeAnnotation) > 0 {
133+
var messages []string
134+
for _, m := range manifestsWithoutIncludeAnnotation {
135+
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
136+
}
137+
t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '"))
138+
}
139+
})
109140
}
110141
}

0 commit comments

Comments
 (0)