Skip to content

Commit 03c183e

Browse files
committed
override catalog tag to 4.x when RELEASE_VERSION is 4.x and catalogd.yaml pins v5.0
Partially reverts commit 7a85fa8: removes the ocp-release sentinel mechanism (GetCatalogImageTag, ClusterCatalogImageTag, applyCatalogImageTagOverride, and the associated Builder field and main.go changes). Replaces it with a targeted check in renderHelmTemplate: when openshift/helm/catalogd.yaml (operator-framework-operator-controller) pins options.openshift.catalogs.version to "v5.0" and RELEASE_VERSION is a 4.x stream (the 4.23/5.0 co-release), substitute the 4.x catalog tag so images match the release stream. For 5.x releases, including 5.1 running against a "v5.0" or "v5.1" catalog, the value in catalogd.yaml is left untouched.
1 parent f563a1d commit 03c183e

6 files changed

Lines changed: 70 additions & 101 deletions

File tree

cmd/cluster-olm-operator/main.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ func runOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
230230

231231
log := klog.FromContext(ctx)
232232

233-
operatorImageVersion := status.VersionForOperatorFromEnv()
234-
currentOCPMinorVersion, err := versionutils.GetCurrentOCPMinorVersion(operatorImageVersion)
235-
if err != nil {
236-
return err
237-
}
238-
catalogImageTag := versionutils.GetCatalogImageTag(currentOCPMinorVersion)
239-
240233
fg, err := cl.ConfigClient.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
241234
if err != nil {
242235
return fmt.Errorf("unable to retrieve featureSet: %w", err)
@@ -259,9 +252,8 @@ func runOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
259252
Scope: meta.RESTScopeRoot,
260253
},
261254
},
262-
FeatureGate: *fg,
263-
Infrastructure: infra,
264-
ClusterCatalogImageTag: catalogImageTag,
255+
FeatureGate: *fg,
256+
Infrastructure: infra,
265257
}
266258

267259
staticResourceControllers, deploymentControllers, clusterCatalogControllers, relatedObjects, err := cb.BuildControllers("catalogd", "operator-controller")
@@ -296,6 +288,12 @@ func runOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
296288
clusterCatalogControllerList = append(clusterCatalogControllerList, controller)
297289
}
298290

291+
operatorImageVersion := status.VersionForOperatorFromEnv()
292+
currentOCPMinorVersion, err := versionutils.GetCurrentOCPMinorVersion(operatorImageVersion)
293+
if err != nil {
294+
return err
295+
}
296+
299297
upgradeableConditionController := controller.NewStaticUpgradeableConditionController(
300298
"OLMStaticUpgradeableConditionController",
301299
cl.OperatorClient,
@@ -340,7 +338,7 @@ func runOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
340338
)
341339

342340
versionGetter := status.NewVersionGetter()
343-
versionGetter.SetVersion("operator", operatorImageVersion)
341+
versionGetter.SetVersion("operator", status.VersionForOperatorFromEnv())
344342

345343
// Add all resources to relatedObjects to ensure that must-gather picks them up.
346344
// Note: These resources are also hard-coded in the ClusterOperator manifest. This way,

internal/versionutils/version_utils.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ func ToAllowedSemver(data []byte) (*semver.Version, error) {
6161
return &version, nil
6262
}
6363

64-
// GetCatalogImageTag converts an OCP version to the catalog image tag format used by default catalogs.
65-
// For example, version 4.22.0 returns "v4.22", and version 5.0.0 returns "v5.0".
66-
func GetCatalogImageTag(version *semver.Version) string {
67-
return fmt.Sprintf("v%d.%d", version.Major, version.Minor)
68-
}
69-
7064
// ocpVersion500 is the semver representation of OCP 5.0, which is co-released with 4.23 as an
7165
// equivalent release. Neither upgrades to the other; both upgrade exclusively to 5.1.
7266
var ocpVersion500 = semver.Version{Major: 5, Minor: 0, Patch: 0}

internal/versionutils/version_utils_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,6 @@ func TestToAllowedSemver(t *testing.T) {
9595
}
9696
}
9797

98-
func TestGetCatalogImageTag(t *testing.T) {
99-
tests := []struct {
100-
name string
101-
version semver.Version
102-
want string
103-
}{
104-
{
105-
name: "4.22",
106-
version: semver.Version{Major: 4, Minor: 22, Patch: 0},
107-
want: "v4.22",
108-
},
109-
{
110-
name: "5.0",
111-
version: semver.Version{Major: 5, Minor: 0, Patch: 0},
112-
want: "v5.0",
113-
},
114-
{
115-
name: "patch ignored",
116-
version: semver.Version{Major: 4, Minor: 22, Patch: 5},
117-
want: "v4.22",
118-
},
119-
}
120-
121-
for _, tt := range tests {
122-
t.Run(tt.name, func(t *testing.T) {
123-
got := GetCatalogImageTag(&tt.version)
124-
assert.Equal(t, tt.want, got, "unexpected catalog image tag")
125-
})
126-
}
127-
}
128-
12998
func TestIsOperatorMaxOCPVersionCompatibleWithCluster(t *testing.T) {
13099
tests := []struct {
131100
name string

pkg/controller/builder.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ import (
4040
)
4141

4242
type Builder struct {
43-
Assets string
44-
Clients *clients.Clients
45-
ControllerContext *controllercmd.ControllerContext
46-
KnownRESTMappings map[schema.GroupVersionKind]*meta.RESTMapping
47-
FeatureGate configv1.FeatureGate
48-
Infrastructure *configv1.Infrastructure
49-
ClusterCatalogImageTag string
43+
Assets string
44+
Clients *clients.Clients
45+
ControllerContext *controllercmd.ControllerContext
46+
KnownRESTMappings map[schema.GroupVersionKind]*meta.RESTMapping
47+
FeatureGate configv1.FeatureGate
48+
Infrastructure *configv1.Infrastructure
5049
}
5150

5251
func (b *Builder) BuildControllers(subDirectories ...string) (map[string]factory.Controller, map[string]factory.Controller, map[string]factory.Controller, []configv1.ObjectReference, error) {

pkg/controller/helm.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
configv1 "github.com/openshift/api/config/v1"
13+
"github.com/openshift/cluster-olm-operator/internal/versionutils"
1314
"github.com/openshift/cluster-olm-operator/pkg/helmvalues"
1415

1516
yaml3 "gopkg.in/yaml.v3"
@@ -20,11 +21,6 @@ import (
2021
"k8s.io/klog/v2"
2122
)
2223

23-
// catalogVersionSentinel is a placeholder value that openshift.yaml sets for
24-
// options.openshift.catalogs.version to indicate the catalog tag should be
25-
// resolved dynamically from the running cluster's OCP major.minor version.
26-
const catalogVersionSentinel = "ocp-release"
27-
2824
// Expected path structure:
2925
// ${assets}/helm/${subDir}/olmv1/ = chart
3026
// ${assets}/helm/${subDir}/openshift.yaml = primary values file
@@ -85,10 +81,21 @@ func (b *Builder) renderHelmTemplate(helmPath, manifestDir string) error {
8581
if err := values.SetStringValue("options.operatorController.deployment.image", os.Getenv("OPERATOR_CONTROLLER_IMAGE")); err != nil {
8682
return fmt.Errorf("error setting OPERATOR_CONTROLLER_IMAGE: %w", err)
8783
}
88-
// When openshift.yaml sets options.openshift.catalogs.version to catalogVersionSentinel,
89-
// replace it with the tag derived from the running cluster's OCP major.minor version.
90-
if err := applyCatalogImageTagOverride(values, b.ClusterCatalogImageTag); err != nil {
91-
return fmt.Errorf("error setting catalog image tag: %w", err)
84+
// OCP 4.23 and 5.0 are co-released. If catalogd.yaml pins "v5.0" but RELEASE_VERSION is
85+
// a 4.x stream, substitute the 4.x catalog tag so images match the release stream.
86+
// For 5.x releases (including 5.1) the value in catalogd.yaml is left untouched.
87+
releaseVersion := os.Getenv("RELEASE_VERSION")
88+
if strings.HasPrefix(releaseVersion, "4.") {
89+
currentCatalogVersion, found := values.GetStringValue("options.openshift.catalogs.version")
90+
if found && currentCatalogVersion == "v5.0" {
91+
v, err := versionutils.GetCurrentOCPMinorVersion(releaseVersion)
92+
if err != nil {
93+
return fmt.Errorf("error parsing release version for catalog tag: %w", err)
94+
}
95+
if err := values.SetStringValue("options.openshift.catalogs.version", fmt.Sprintf("v%d.%d", v.Major, v.Minor)); err != nil {
96+
return fmt.Errorf("error setting catalog image tag: %w", err)
97+
}
98+
}
9299
}
93100

94101
// On HighlyAvailable topologies scale to 2 replicas and enable the PDB so that rolling
@@ -232,21 +239,6 @@ type DocumentInfo struct {
232239
Order int
233240
}
234241

235-
// applyCatalogImageTagOverride replaces options.openshift.catalogs.version in the
236-
// Helm values when it equals catalogVersionSentinel, substituting the tag derived
237-
// from the running cluster's OCP major.minor version. It is a no-op when clusterTag
238-
// is empty or when the current value is not catalogVersionSentinel.
239-
func applyCatalogImageTagOverride(values *helmvalues.HelmValues, clusterTag string) error {
240-
if clusterTag == "" {
241-
return nil
242-
}
243-
currentTag, found := values.GetStringValue("options.openshift.catalogs.version")
244-
if !found || currentTag != catalogVersionSentinel {
245-
return nil
246-
}
247-
return values.SetStringValue("options.openshift.catalogs.version", clusterTag)
248-
}
249-
250242
func splitYAMLDocuments(content string) []string {
251243
// Split by document separators but preserve the original text
252244
lines := strings.Split(content, "\n")

pkg/controller/helm_test.go

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controller
22

33
import (
4+
"fmt"
45
"io/fs"
56
"os"
67
"path/filepath"
@@ -13,6 +14,7 @@ import (
1314
yaml3 "gopkg.in/yaml.v3"
1415

1516
internalfeatures "github.com/openshift/cluster-olm-operator/internal/featuregates"
17+
"github.com/openshift/cluster-olm-operator/internal/versionutils"
1618
"github.com/openshift/cluster-olm-operator/pkg/clients"
1719
"github.com/openshift/cluster-olm-operator/pkg/helmvalues"
1820
)
@@ -76,49 +78,64 @@ func TestRenderHelmTemplate(t *testing.T) {
7678
require.Equal(t, compareData, testData)
7779
}
7880

79-
func TestApplyCatalogImageTagOverride(t *testing.T) {
81+
func TestCatalogImageTagOverride(t *testing.T) {
8082
const versionKey = "options.openshift.catalogs.version"
8183

8284
tests := []struct {
83-
name string
84-
initialTag string // set at versionKey before the call; empty means key is absent
85-
clusterTag string
86-
expectedTag string // expected value at versionKey after the call; empty means key absent
85+
name string
86+
initialTag string // catalog version in Helm values; empty means key absent
87+
releaseVersion string // RELEASE_VERSION env var value
88+
expectedTag string // expected catalog version after renderHelmTemplate logic
8789
}{
8890
{
89-
name: "clusterTag empty - no override regardless of Helm value",
90-
initialTag: catalogVersionSentinel,
91-
clusterTag: "",
92-
expectedTag: catalogVersionSentinel,
91+
name: "4.23 release with v5.0 catalog - override to v4.23",
92+
initialTag: "v5.0",
93+
releaseVersion: "4.23.0",
94+
expectedTag: "v4.23",
95+
},
96+
{
97+
name: "5.0 release with v5.0 catalog - no override",
98+
initialTag: "v5.0",
99+
releaseVersion: "5.0.0",
100+
expectedTag: "v5.0",
93101
},
94102
{
95-
name: "sentinel present, cluster is 4.23 - override to v4.23",
96-
initialTag: catalogVersionSentinel,
97-
clusterTag: "v4.23",
98-
expectedTag: "v4.23",
103+
name: "5.1 release with v5.0 catalog - no override",
104+
initialTag: "v5.0",
105+
releaseVersion: "5.1.0",
106+
expectedTag: "v5.0",
99107
},
100108
{
101-
name: "Helm pins v4.23 - not the sentinel, no override",
102-
initialTag: "v4.23",
103-
clusterTag: "v4.23",
104-
expectedTag: "v4.23",
109+
name: "5.1 release with v5.1 catalog - no override",
110+
initialTag: "v5.1",
111+
releaseVersion: "5.1.0",
112+
expectedTag: "v5.1",
105113
},
106114
{
107-
name: "version key absent in Helm values - no override",
108-
initialTag: "",
109-
clusterTag: "v4.23",
110-
expectedTag: "",
115+
name: "4.22 release with v4.22 catalog - no override (not v5.0)",
116+
initialTag: "v4.22",
117+
releaseVersion: "4.22.0",
118+
expectedTag: "v4.22",
111119
},
112120
}
113121

114122
for _, tt := range tests {
115123
t.Run(tt.name, func(t *testing.T) {
124+
t.Setenv("RELEASE_VERSION", tt.releaseVersion)
116125
hv := helmvalues.NewHelmValues()
117126
if tt.initialTag != "" {
118127
require.NoError(t, hv.SetStringValue(versionKey, tt.initialTag))
119128
}
120129

121-
require.NoError(t, applyCatalogImageTagOverride(hv, tt.clusterTag))
130+
releaseVersion := os.Getenv("RELEASE_VERSION")
131+
if strings.HasPrefix(releaseVersion, "4.") {
132+
currentCatalogVersion, found := hv.GetStringValue(versionKey)
133+
if found && currentCatalogVersion == "v5.0" {
134+
v, err := versionutils.GetCurrentOCPMinorVersion(releaseVersion)
135+
require.NoError(t, err)
136+
require.NoError(t, hv.SetStringValue(versionKey, fmt.Sprintf("v%d.%d", v.Major, v.Minor)))
137+
}
138+
}
122139

123140
got, _ := hv.GetStringValue(versionKey)
124141
require.Equal(t, tt.expectedTag, got)

0 commit comments

Comments
 (0)