Skip to content

Commit 6e5ccfd

Browse files
committed
Restrict major version annotation to FeatureGate and CustomResourceDefinition
1 parent c5ea32a commit 6e5ccfd

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pkg/manifest/manifest.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func checkFeatureGates(enabledGates sets.Set[string], annotations map[string]str
235235
}
236236

237237
// checkMajorVersion validates if manifest should be included based on major version requirements
238-
func checkMajorVersion(clusterMajorVersion uint64, annotations map[string]string) error {
238+
func checkMajorVersion(gvk schema.GroupVersionKind, clusterMajorVersion uint64, annotations map[string]string) error {
239239
if annotations == nil {
240240
return nil // No annotations, include by default
241241
}
@@ -244,6 +244,11 @@ func checkMajorVersion(clusterMajorVersion uint64, annotations map[string]string
244244
return nil // No requirements, include by default
245245
}
246246

247+
if !isFeatureGate(gvk) && !isCustomResource(gvk) {
248+
// Has a requirement, but is not of the expected kind
249+
return fmt.Errorf("major version filtering is only supported for feature gates and custom resources")
250+
}
251+
247252
requirements := strings.Split(majorVersionRequirements, ",")
248253
includedVersions := sets.New[uint64]()
249254
excludedVersions := sets.New[uint64]()
@@ -338,7 +343,7 @@ func (m *Manifest) IncludeAllowUnknownCapabilities(excludeIdentifier *string, re
338343

339344
// Major version filtering
340345
if majorVersion != nil {
341-
err := checkMajorVersion(*majorVersion, annotations)
346+
err := checkMajorVersion(m.GVK, *majorVersion, annotations)
342347
if err != nil {
343348
return err
344349
}
@@ -543,3 +548,11 @@ func addIfNotDuplicateResource(manifest Manifest, resourceIds map[resourceId]boo
543548
}
544549
return fmt.Errorf("duplicate resource: (%s)", manifest.id)
545550
}
551+
552+
func isFeatureGate(gvk schema.GroupVersionKind) bool {
553+
return gvk.Group == "config.openshift.io" && gvk.Kind == "FeatureGate"
554+
}
555+
556+
func isCustomResource(gvk schema.GroupVersionKind) bool {
557+
return gvk.Group == "apiextensions.k8s.io" && gvk.Kind == "CustomResourceDefinition"
558+
}

pkg/manifest/manifest_test.go

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

13841385
// Test through the Include method which calls checkMajorVersion
13851386
err := manifest.Include(nil, nil, nil, nil, nil, nil, tt.clusterMajorVersion)
@@ -1449,6 +1450,7 @@ func TestMajorVersionFilteringInteractionWithOtherFilters(t *testing.T) {
14491450
for _, tt := range tests {
14501451
t.Run(tt.name, func(t *testing.T) {
14511452
manifest := createTestManifest(tt.annotations)
1453+
manifest.GVK = schema.GroupVersionKind{Group: "config.openshift.io", Kind: "FeatureGate"}
14521454

14531455
err := manifest.Include(nil, tt.requiredFeatureSet, nil, nil, nil, tt.enabledFeatureGates, tt.clusterMajorVersion)
14541456

0 commit comments

Comments
 (0)