Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.24.0
toolchain go1.24.5

require (
github.com/blang/semver/v4 v4.0.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
Expand All @@ -30,7 +31,6 @@ require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
Expand Down
65 changes: 65 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/blang/semver/v4"
"github.com/openshift/api/features"

"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -255,6 +257,11 @@ func (o *OperatorOptions) getFeatureGateMappingFromDisk(ctx context.Context, con
clusterProfileAnnotation = "include.release.openshift.io/self-managed-high-availability"
}

operatorVersion, err := semver.ParseTolerant(o.OperatorVersion)
if err != nil {
return nil, fmt.Errorf("unable to parse operator version: %w", err)
}

ret := map[configv1.FeatureSet]*features.FeatureGateEnabledDisabled{}

err = filepath.Walk(o.AuthoritativeFeatureGateDir,
Expand Down Expand Up @@ -285,6 +292,11 @@ func (o *OperatorOptions) getFeatureGateMappingFromDisk(ctx context.Context, con
}
}

if excludesOperatorVersion(featureGate.Annotations, operatorVersion.Major) {
// This manifest includes a range of versions it applies to, but it does not apply to our current version.
return nil
}

featureGateValues := &features.FeatureGateEnabledDisabled{}
for _, possibleGates := range featureGate.Status.FeatureGates {
if possibleGates.Version != o.OperatorVersion {
Expand Down Expand Up @@ -363,3 +375,56 @@ func extractOperatorStatus(obj *unstructured.Unstructured, fieldManager string)
}
return &ret.Status.OperatorStatusApplyConfiguration, nil
}

func excludesOperatorVersion(annotations map[string]string, operatorMajorVersion uint64) bool {
var versionsRaw string

for k, v := range annotations {
if k == "release.openshift.io/major-version" {
versionsRaw = v
break
}
}

if versionsRaw == "" {
return false
}

versions := strings.Split(versionsRaw, ",")

hasOperatorVersion, err := includesDesiredVersion(versions, operatorMajorVersion)
if err != nil {
// Malformed annotation so should be excluded.
return true
}

return !hasOperatorVersion
}

func includesDesiredVersion(versions []string, desiredVersion uint64) (bool, error) {
for _, versionStr := range versions {
versionStr = strings.TrimSpace(versionStr)
if len(versionStr) == 0 {
continue
}

// Skip excluded versions.
if strings.HasPrefix(versionStr, "-") {
// If the version starts with a '-', it means that the version is excluded.
// Since we are only looking for positive matches we can skip processing
// this version any further.
continue
}

version, err := strconv.ParseUint(versionStr, 10, 64)
if err != nil {
// Malformed annotation so should be excluded
return false, fmt.Errorf("malformed annotation: %s", versionStr)
}
if version == desiredVersion {
return true, nil
}
}

return false, nil
}