Skip to content

Commit 594b873

Browse files
DavidHurtaclaude
authored andcommitted
pkg/cvo: Add scenario test for major version filtering
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent fb54461 commit 594b873

9 files changed

Lines changed: 196 additions & 0 deletions

File tree

pkg/cvo/cvo_scenarios_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,90 @@ func TestCVO_FeatureGateManifestInclusion(t *testing.T) {
43894389
}
43904390
}
43914391

4392+
// TestCVO_MajorVersionManifestFiltering tests that manifest inclusion is filtered
4393+
// based on the major version of the release payload.
4394+
func TestCVO_MajorVersionManifestFiltering(t *testing.T) {
4395+
o, cvs, _, client, shutdownFn := setupCVOTest("testdata/majorversiontest-v5")
4396+
4397+
ctx, cancel := context.WithCancel(context.Background())
4398+
defer cancel()
4399+
4400+
defer shutdownFn()
4401+
worker := o.configSync.(*SyncWorker)
4402+
go worker.Start(ctx, 1)
4403+
4404+
o.release.Image = "image/image:v5"
4405+
o.release.Version = "5.0.0-xyz"
4406+
uid, _ := uuid.NewRandom()
4407+
clusterUID := configv1.ClusterID(uid.String())
4408+
cvs["version"] = &configv1.ClusterVersion{
4409+
ObjectMeta: metav1.ObjectMeta{
4410+
Name: "version",
4411+
},
4412+
Spec: configv1.ClusterVersionSpec{
4413+
ClusterID: clusterUID,
4414+
Channel: "fast",
4415+
},
4416+
}
4417+
4418+
// Execute: Sync the payload
4419+
err := o.sync(ctx, o.queueKey())
4420+
if err != nil {
4421+
t.Fatal(err)
4422+
}
4423+
waitForStatusCompleted(t, worker)
4424+
4425+
// Step 1: Payload contains expected number of filtered manifests
4426+
if worker.payload == nil {
4427+
t.Fatal("Expected payload to be loaded")
4428+
}
4429+
if len(worker.payload.Manifests) != 4 {
4430+
t.Fatalf("Expected 4 manifests in payload, got %d", len(worker.payload.Manifests))
4431+
}
4432+
4433+
manifestNames := make(map[string]bool)
4434+
for _, m := range worker.payload.Manifests {
4435+
manifestNames[m.Obj.GetName()] = true
4436+
}
4437+
4438+
// Step 2: Expected manifests are included
4439+
expectedManifests := []string{"noversion", "version5only", "version4or5", "excludeversion3"}
4440+
for _, expected := range expectedManifests {
4441+
if !manifestNames[expected] {
4442+
t.Errorf("Expected manifest %s to be included in version 5 payload, but it was not", expected)
4443+
}
4444+
}
4445+
4446+
// Step 3: Expected manifests are not included
4447+
if manifestNames["version4only"] {
4448+
t.Error("Expected manifest version4only to be excluded from version 5 payload, but it was included")
4449+
}
4450+
4451+
// Step 4: Major version is parsed from release metadata
4452+
if worker.payload.ParsedVersion.Major != 5 {
4453+
t.Errorf("Expected MajorVersion to be 5, got %d", worker.payload.ParsedVersion.Major)
4454+
}
4455+
4456+
// Step 5: Filtered manifests were applied to cluster
4457+
appliedCRDs := make(map[string]bool)
4458+
for _, action := range client.Actions() {
4459+
if createAction, ok := action.(clientgotesting.CreateAction); ok {
4460+
obj := createAction.GetObject().(*unstructured.Unstructured)
4461+
appliedCRDs[obj.GetName()] = true
4462+
}
4463+
}
4464+
4465+
for _, expected := range expectedManifests {
4466+
if !appliedCRDs[expected] {
4467+
t.Errorf("Expected CRD %s to be applied, but it was not", expected)
4468+
}
4469+
}
4470+
4471+
if appliedCRDs["version4only"] {
4472+
t.Error("Expected CRD version4only NOT to be applied, but it was")
4473+
}
4474+
}
4475+
43924476
// verifyCVSingleUpdate ensures that the only object to be updated is a ClusterVersion type and it is updated only once
43934477
func verifyCVSingleUpdate(t *testing.T, actions []clientgotesting.Action) {
43944478
var count int

pkg/cvo/testdata/majorversiontest-v5/manifests/.gitkeep

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: noversion
5+
annotations:
6+
include.release.openshift.io/self-managed-high-availability: "true"
7+
spec:
8+
group: test.io
9+
names:
10+
kind: NoVersion
11+
plural: noversions
12+
scope: Cluster
13+
versions:
14+
- name: v1
15+
served: true
16+
storage: true
17+
schema:
18+
openAPIV3Schema:
19+
type: object
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: version4only
5+
annotations:
6+
include.release.openshift.io/self-managed-high-availability: "true"
7+
release.openshift.io/major-version: "4"
8+
spec:
9+
group: test.io
10+
names:
11+
kind: Version4Only
12+
plural: version4onlies
13+
scope: Cluster
14+
versions:
15+
- name: v1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: version5only
5+
annotations:
6+
include.release.openshift.io/self-managed-high-availability: "true"
7+
release.openshift.io/major-version: "5"
8+
spec:
9+
group: test.io
10+
names:
11+
kind: Version5Only
12+
plural: version5onlies
13+
scope: Cluster
14+
versions:
15+
- name: v1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: version4or5
5+
annotations:
6+
include.release.openshift.io/self-managed-high-availability: "true"
7+
release.openshift.io/major-version: "4,5"
8+
spec:
9+
group: test.io
10+
names:
11+
kind: Version4Or5
12+
plural: version4or5s
13+
scope: Cluster
14+
versions:
15+
- name: v1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: excludeversion3
5+
annotations:
6+
include.release.openshift.io/self-managed-high-availability: "true"
7+
release.openshift.io/major-version: "-3"
8+
spec:
9+
group: test.io
10+
names:
11+
kind: ExcludeVersion3
12+
plural: excludeversion3s
13+
scope: Cluster
14+
versions:
15+
- name: v1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kind: ImageStream
2+
apiVersion: image.openshift.io/v1
3+
metadata:
4+
name: 5.0.0-xyz
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"kind": "cincinnati-metadata-v0",
3+
"version": "5.0.0-xyz",
4+
"previous": [],
5+
"metadata": {
6+
"description": "",
7+
"url": "https://example.com/v5.0.0-xyz"
8+
}
9+
}

0 commit comments

Comments
 (0)