Skip to content

Commit 0cba804

Browse files
committed
Restrict major version annotation to FeatureGate and CustomResourceDefinition
1 parent 4a5bec0 commit 0cba804

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/manifest/manifest.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ func (m *Manifest) IncludeAllowUnknownCapabilities(excludeIdentifier *string, re
451451

452452
// Major version filtering
453453
if majorVersion != nil {
454+
if !isFeatureGate(m.GVK) && !isCustomResource(m.GVK) {
455+
return fmt.Errorf("major version filtering is only supported for feature gates and custom resources")
456+
}
457+
454458
err := checkMajorVersion(*majorVersion, annotations)
455459
if err != nil {
456460
return err
@@ -656,3 +660,11 @@ func addIfNotDuplicateResource(manifest Manifest, resourceIds map[resourceId]boo
656660
}
657661
return fmt.Errorf("duplicate resource: (%s)", manifest.id)
658662
}
663+
664+
func isFeatureGate(gvk schema.GroupVersionKind) bool {
665+
return gvk.Group == "config.openshift.io" && gvk.Kind == "FeatureGate"
666+
}
667+
668+
func isCustomResource(gvk schema.GroupVersionKind) bool {
669+
return gvk.Group == "apiextensions.k8s.io/" && gvk.Kind == "CustomResourceDefinition"
670+
}

pkg/manifest/manifest_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ func TestMajorVersionFiltering(t *testing.T) {
15621562
for _, tt := range tests {
15631563
t.Run(tt.name, func(t *testing.T) {
15641564
manifest := createTestManifest(tt.annotations)
1565+
manifest.GVK = schema.GroupVersionKind{Group: "config.openshift.io", Kind: "FeatureGate"}
15651566

15661567
// Test through the Include method which calls checkMajorVersion
15671568
err := manifest.Include(nil, nil, nil, nil, nil, nil, tt.clusterMajorVersion)
@@ -1631,6 +1632,7 @@ func TestMajorVersionFilteringInteractionWithOtherFilters(t *testing.T) {
16311632
for _, tt := range tests {
16321633
t.Run(tt.name, func(t *testing.T) {
16331634
manifest := createTestManifest(tt.annotations)
1635+
manifest.GVK = schema.GroupVersionKind{Group: "config.openshift.io", Kind: "FeatureGate"}
16341636

16351637
err := manifest.Include(nil, tt.requiredFeatureSet, nil, nil, nil, tt.enabledFeatureGates, tt.clusterMajorVersion)
16361638

0 commit comments

Comments
 (0)