Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions pkg/payload/render_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package payload
Copy link
Copy Markdown
Contributor

@DavidHurta DavidHurta Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting the 059f3f0 commit message:

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.

The message sounds like we render the bootstrap-pod.yaml file, because it is not a valid YAML file. Technically, we render all CVO manifests, which are later applied. Be it CVO install manifests and CVO bootstrap manifests. Specific manifests are rendered during various specific stages:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, wrong function, checking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed my original comment.


import (
"bytes"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -12,6 +16,7 @@ import (
"k8s.io/utils/ptr"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/library-go/pkg/manifest"
)

func TestRenderManifest(t *testing.T) {
Expand Down Expand Up @@ -304,3 +309,86 @@ data:

return yaml
}
func Test_cvoManifests(t *testing.T) {
config := manifestRenderConfig{
ReleaseImage: "quay.io/cvo/release:latest",
ClusterProfile: "some-profile",
}

tests := []struct {
name string
dir string
}{
{
name: "install dir",
dir: filepath.Join("../../install"),
},
{
name: "bootstrap dir",
dir: filepath.Join("../../bootstrap"),
},
}
const prefix = "include.release.openshift.io/"
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var count int
err := filepath.WalkDir(tt.dir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
return nil
}

var manifestsWithoutIncludeAnnotation []manifest.Manifest
filePath := filepath.Join(tt.dir, d.Name())
Copy link
Copy Markdown
Contributor

@DavidHurta DavidHurta Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are joining the tt.dir and d.Name, which is described as:

// Name returns the name of the file (or subdirectory) described by the entry.
// This name is only the final element of the path (the base name), not the entire path.
// For example, Name would return "hello.go" not "home/gopher/hello.go".

Thus, this would not work for files in sub-directories if such files were present in a recursive search, which is something that the f0e561d commit aims to implement. Please correct me if I am mistaken. I don't mind implementing or not implementing the recursive search; however, I am noting the correctness in this case.

data, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("failed to read manifest file: %v", err)
}
data, err = renderManifest(config, data)
if err != nil {
t.Fatalf("failed to render manifest: %v", err)
}
manifests, err := manifest.ParseManifests(bytes.NewReader(data))
if err != nil {
t.Fatalf("failed to load manifests: %v", err)
}

for _, m := range manifests {
m.OriginalFilename = filePath
var found bool
for k := range m.Obj.GetAnnotations() {
if strings.HasPrefix(k, prefix) {
found = true
break
}
}
if !found {
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
}
}

if len(manifestsWithoutIncludeAnnotation) > 0 {
var messages []string
for _, m := range manifestsWithoutIncludeAnnotation {
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
}
t.Errorf("Those manifests have no annotation with prefix %q and will not be installed by CVO: %s", prefix, strings.Join(messages, ", "))
}
count++
return nil
})

if err != nil {
t.Fatalf("failed to walk directory: %v", err)
}

if count == 0 {
t.Errorf("no files found in %s", tt.dir)
}

})
}
}