Skip to content

Commit 059f3f0

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 835b4b7 commit 059f3f0

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"
@@ -308,47 +309,77 @@ data:
308309
return yaml
309310
}
310311
func Test_cvoManifests(t *testing.T) {
311-
installDir := filepath.Join("../../install")
312-
files, err := os.ReadDir(installDir)
313-
if err != nil {
314-
t.Fatalf("failed to read directory: %v", err)
312+
config := manifestRenderConfig{
313+
ReleaseImage: "quay.io/cvo/release:latest",
314+
ClusterProfile: "some-profile",
315315
}
316316

317-
if len(files) == 0 {
318-
t.Fatalf("no files found in %s", installDir)
317+
tests := []struct {
318+
name string
319+
dir string
320+
}{
321+
{
322+
name: "install dir",
323+
dir: filepath.Join("../../install"),
324+
},
325+
{
326+
name: "bootstrap dir",
327+
dir: filepath.Join("../../bootstrap"),
328+
},
319329
}
330+
for _, tt := range tests {
331+
t.Run(tt.name, func(t *testing.T) {
332+
files, err := os.ReadDir(tt.dir)
333+
if err != nil {
334+
t.Fatalf("failed to read directory: %v", err)
335+
}
320336

321-
var manifestsWithoutIncludeAnnotation []manifest.Manifest
322-
const prefix = "include.release.openshift.io/"
323-
for _, manifestFile := range files {
324-
if manifestFile.IsDir() {
325-
continue
326-
}
327-
filePath := filepath.Join(installDir, manifestFile.Name())
328-
manifests, err := manifest.ManifestsFromFiles([]string{filePath})
329-
if err != nil {
330-
t.Fatalf("failed to load manifests: %v", err)
331-
}
337+
if len(files) == 0 {
338+
t.Fatalf("no files found in %s", tt.dir)
339+
}
332340

333-
for _, m := range manifests {
334-
var found bool
335-
for k := range m.Obj.GetAnnotations() {
336-
if strings.HasPrefix(k, prefix) {
337-
found = true
338-
break
341+
var manifestsWithoutIncludeAnnotation []manifest.Manifest
342+
const prefix = "include.release.openshift.io/"
343+
for _, manifestFile := range files {
344+
if manifestFile.IsDir() {
345+
continue
346+
}
347+
filePath := filepath.Join(tt.dir, manifestFile.Name())
348+
data, err := os.ReadFile(filePath)
349+
if err != nil {
350+
t.Fatalf("failed to read manifest file: %v", err)
351+
}
352+
data, err = renderManifest(config, data)
353+
if err != nil {
354+
t.Fatalf("failed to render manifest: %v", err)
355+
}
356+
manifests, err := manifest.ParseManifests(bytes.NewReader(data))
357+
if err != nil {
358+
t.Fatalf("failed to load manifests: %v", err)
359+
}
360+
361+
for _, m := range manifests {
362+
m.OriginalFilename = filePath
363+
var found bool
364+
for k := range m.Obj.GetAnnotations() {
365+
if strings.HasPrefix(k, prefix) {
366+
found = true
367+
break
368+
}
369+
}
370+
if !found {
371+
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
372+
}
339373
}
340374
}
341-
if !found {
342-
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
343-
}
344-
}
345-
}
346375

347-
if len(manifestsWithoutIncludeAnnotation) > 0 {
348-
var messages []string
349-
for _, m := range manifestsWithoutIncludeAnnotation {
350-
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
351-
}
352-
t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '"))
376+
if len(manifestsWithoutIncludeAnnotation) > 0 {
377+
var messages []string
378+
for _, m := range manifestsWithoutIncludeAnnotation {
379+
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
380+
}
381+
t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '"))
382+
}
383+
})
353384
}
354385
}

0 commit comments

Comments
 (0)