Skip to content

Commit 9d47eaf

Browse files
committed
UPSTREAM: <carry>: Update catalogs for 4.23/5.0
Set catalog image tags to v5.0 for the 4.23/5.0 release. Dynamically discover an installable package from the serving catalogs instead of hardcoding quay-operator v3.13.10, preferring quay-operator, cluster-logging, serverless-operator, cli-manager, logic-operator in that order then falling back to the first available package. Signed-off-by: Todd Short <tshort@redhat.com>
1 parent 02c626b commit 9d47eaf

5 files changed

Lines changed: 139 additions & 12 deletions

File tree

openshift/catalogd/manifests-experimental.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ spec:
10051005
type: Image
10061006
image:
10071007
pollIntervalMinutes: 10
1008-
ref: registry.redhat.io/redhat/certified-operator-index:v5.0
1008+
ref: registry.redhat.io/redhat/certified-operator-index:v4.23
10091009
---
10101010
# Source: olmv1/templates/openshift-catalogs/clustercatalog-openshift-community-operators.yml
10111011
apiVersion: olm.operatorframework.io/v1
@@ -1018,7 +1018,7 @@ spec:
10181018
type: Image
10191019
image:
10201020
pollIntervalMinutes: 10
1021-
ref: registry.redhat.io/redhat/community-operator-index:v5.0
1021+
ref: registry.redhat.io/redhat/community-operator-index:v4.23
10221022
---
10231023
# Source: olmv1/templates/openshift-catalogs/clustercatalog-openshift-redhat-operators.yml
10241024
apiVersion: olm.operatorframework.io/v1
@@ -1031,7 +1031,7 @@ spec:
10311031
type: Image
10321032
image:
10331033
pollIntervalMinutes: 10
1034-
ref: registry.redhat.io/redhat/redhat-operator-index:v5.0
1034+
ref: registry.redhat.io/redhat/redhat-operator-index:v4.23
10351035
---
10361036
# Source: olmv1/templates/mutatingwebhookconfiguration-catalogd-mutating-webhook-configuration.yml
10371037
apiVersion: admissionregistration.k8s.io/v1

openshift/catalogd/manifests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ spec:
10041004
type: Image
10051005
image:
10061006
pollIntervalMinutes: 10
1007-
ref: registry.redhat.io/redhat/certified-operator-index:v5.0
1007+
ref: registry.redhat.io/redhat/certified-operator-index:v4.23
10081008
---
10091009
# Source: olmv1/templates/openshift-catalogs/clustercatalog-openshift-community-operators.yml
10101010
apiVersion: olm.operatorframework.io/v1
@@ -1017,7 +1017,7 @@ spec:
10171017
type: Image
10181018
image:
10191019
pollIntervalMinutes: 10
1020-
ref: registry.redhat.io/redhat/community-operator-index:v5.0
1020+
ref: registry.redhat.io/redhat/community-operator-index:v4.23
10211021
---
10221022
# Source: olmv1/templates/openshift-catalogs/clustercatalog-openshift-redhat-operators.yml
10231023
apiVersion: olm.operatorframework.io/v1
@@ -1030,7 +1030,7 @@ spec:
10301030
type: Image
10311031
image:
10321032
pollIntervalMinutes: 10
1033-
ref: registry.redhat.io/redhat/redhat-operator-index:v5.0
1033+
ref: registry.redhat.io/redhat/redhat-operator-index:v4.23
10341034
---
10351035
# Source: olmv1/templates/mutatingwebhookconfiguration-catalogd-mutating-webhook-configuration.yml
10361036
apiVersion: admissionregistration.k8s.io/v1

openshift/helm/catalogd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ options:
1616
openshift:
1717
enabled: true
1818
catalogs:
19-
version: v5.0
19+
version: v4.23
2020

2121
# The set of namespaces
2222
namespaces:
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package helpers
2+
3+
import (
4+
"bufio"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
"net/http"
9+
"strings"
10+
11+
//nolint:staticcheck // ST1001: dot-imports for readability
12+
. "github.com/onsi/ginkgo/v2"
13+
//nolint:staticcheck // ST1001: dot-imports for readability
14+
. "github.com/onsi/gomega"
15+
16+
"k8s.io/apimachinery/pkg/api/meta"
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/client-go/rest"
19+
20+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
21+
22+
"github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/env"
23+
)
24+
25+
// preferredPackages is tried in order; the first one present in any serving catalog wins.
26+
// Falls back to the first available package if none of these are found.
27+
var preferredPackages = []string{
28+
"quay-operator",
29+
"cluster-logging",
30+
"serverless-operator",
31+
"cli-manager",
32+
"logic-operator",
33+
}
34+
35+
// FindInstallablePackage searches all serving ClusterCatalogs for an installable package,
36+
// favouring preferredPackages in order. Returns the catalog name and package name,
37+
// or fails the test if no packages are found in any serving catalog.
38+
func FindInstallablePackage(ctx context.Context) (string, string) {
39+
cfg := env.Get().RestCfg
40+
httpClient, err := rest.HTTPClientFor(cfg)
41+
Expect(err).ToNot(HaveOccurred(), "failed to build HTTP client from REST config")
42+
43+
k8sClient := env.Get().K8sClient
44+
catalogList := &olmv1.ClusterCatalogList{}
45+
Expect(k8sClient.List(ctx, catalogList)).To(Succeed(), "failed to list ClusterCatalogs")
46+
47+
// Collect packages from every serving catalog: map[catalogName][]packageName
48+
available := map[string][]string{}
49+
for i := range catalogList.Items {
50+
cc := &catalogList.Items[i]
51+
if !meta.IsStatusConditionPresentAndEqual(cc.Status.Conditions, olmv1.TypeServing, metav1.ConditionTrue) {
52+
fmt.Fprintf(GinkgoWriter, "Catalog %q is not serving, skipping\n", cc.Name)
53+
continue
54+
}
55+
pkgs, err := listPackagesInCatalog(ctx, httpClient, cfg.Host, cc.Name)
56+
if err != nil {
57+
fmt.Fprintf(GinkgoWriter, "Warning: could not list packages in catalog %q: %v\n", cc.Name, err)
58+
continue
59+
}
60+
available[cc.Name] = pkgs
61+
fmt.Fprintf(GinkgoWriter, "Catalog %q: %d packages available\n", cc.Name, len(pkgs))
62+
}
63+
64+
// Try preferred packages in order across all serving catalogs.
65+
for _, preferred := range preferredPackages {
66+
for cat, pkgs := range available {
67+
for _, pkg := range pkgs {
68+
if pkg == preferred {
69+
fmt.Fprintf(GinkgoWriter, "Selected package %q from catalog %q (preferred)\n", pkg, cat)
70+
return cat, pkg
71+
}
72+
}
73+
}
74+
}
75+
76+
// Fall back to the first package found in any catalog.
77+
for cat, pkgs := range available {
78+
if len(pkgs) > 0 {
79+
fmt.Fprintf(GinkgoWriter, "Selected package %q from catalog %q (fallback)\n", pkgs[0], cat)
80+
return cat, pkgs[0]
81+
}
82+
}
83+
84+
Fail("no installable packages found in any serving catalog")
85+
return "", "" // unreachable
86+
}
87+
88+
// listPackagesInCatalog queries the catalogd /api/v1/metas?schema=olm.package endpoint
89+
// via the Kubernetes API-server proxy and returns all package names.
90+
func listPackagesInCatalog(ctx context.Context, httpClient *http.Client, apiServerHost, catalogName string) ([]string, error) {
91+
url := strings.TrimRight(apiServerHost, "/") +
92+
fmt.Sprintf("/api/v1/namespaces/openshift-catalogd/services/https:catalogd-service:443/proxy/catalogs/%s/api/v1/metas?schema=olm.package",
93+
catalogName)
94+
95+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
96+
if err != nil {
97+
return nil, fmt.Errorf("build request: %w", err)
98+
}
99+
resp, err := httpClient.Do(req)
100+
if err != nil {
101+
return nil, fmt.Errorf("GET %s: %w", url, err)
102+
}
103+
defer resp.Body.Close()
104+
105+
if resp.StatusCode != http.StatusOK {
106+
return nil, fmt.Errorf("unexpected status %d from %s", resp.StatusCode, url)
107+
}
108+
109+
// Response is JSONL: one JSON object per line.
110+
// Each olm.package line has at minimum a "name" field.
111+
var packages []string
112+
scanner := bufio.NewScanner(resp.Body)
113+
scanner.Buffer(make([]byte, 1024*1024), 1024*1024)
114+
for scanner.Scan() {
115+
var obj struct {
116+
Name string `json:"name"`
117+
}
118+
if err := json.Unmarshal(scanner.Bytes(), &obj); err != nil || obj.Name == "" {
119+
continue
120+
}
121+
packages = append(packages, obj.Name)
122+
}
123+
return packages, scanner.Err()
124+
}

openshift/tests-extension/test/olmv1.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,17 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1
107107
})
108108

109109
It("should install an openshift catalog cluster extension", Label("original-name:[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator installation should install an openshift catalog cluster extension"), func(ctx SpecContext) {
110-
By("ensuring no ClusterExtension and CRD for quay-operator")
111-
helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com")
110+
catalog, pkg := helpers.FindInstallablePackage(ctx)
112111

113-
By("applying the ClusterExtension resource")
114-
name, cleanup := helpers.CreateClusterExtension("quay-operator", "3.13.10", namespace, "")
112+
By(fmt.Sprintf("ensuring no existing ClusterExtension for %q", pkg))
113+
helpers.EnsureCleanupClusterExtension(context.Background(), pkg, "")
114+
115+
By(fmt.Sprintf("applying ClusterExtension for %q from catalog %q", pkg, catalog))
116+
name, cleanup := helpers.CreateClusterExtension(pkg, "", namespace, "",
117+
helpers.WithCatalogNameSelector(catalog))
115118
DeferCleanup(cleanup)
116119

117-
By("waiting for the quay-operator ClusterExtension to be installed")
120+
By(fmt.Sprintf("waiting for %q to be installed", pkg))
118121
helpers.ExpectClusterExtensionToBeInstalled(ctx, name)
119122
})
120123
})

0 commit comments

Comments
 (0)