Skip to content

Commit 6dbc1d4

Browse files
committed
OPRUN-3692: OLMv1-catalogd tests for API endpoints
Introduces tests for the new `api/v1/metas` endpoint when NewOLMCatalogdAPIV1Metas feature gate in enabled. Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent 585968f commit 6dbc1d4

File tree

3 files changed

+125
-3
lines changed

3 files changed

+125
-3
lines changed

test/extended/olm/olmv1.go

+112-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
g "github.com/onsi/ginkgo/v2"
1313
o "github.com/onsi/gomega"
14+
batchv1 "k8s.io/api/batch/v1"
15+
corev1 "k8s.io/api/core/v1"
1416
"k8s.io/apimachinery/pkg/api/meta"
1517
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1618
"k8s.io/apimachinery/pkg/util/wait"
@@ -71,7 +73,7 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs", func() {
7173
})
7274
})
7375

74-
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 Catalogs", func() {
76+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 default Catalogs", func() {
7577
defer g.GinkgoRecover()
7678
oc := exutil.NewCLIWithoutNamespace("default")
7779

@@ -99,6 +101,29 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLM
99101
})
100102
})
101103

104+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 Catalogs /v1/api/all endpoint", func() {
105+
defer g.GinkgoRecover()
106+
oc := exutil.NewCLIWithoutNamespace("default")
107+
108+
g.It("should serve FBC", func(ctx g.SpecContext) {
109+
checkFeatureCapability(ctx, oc)
110+
111+
g.By("Testing /api/v1/all endpoint for catalog openshift-community-operators")
112+
verifyAPIEndpoint(ctx, oc, oc.Namespace(), "openshift-community-operators", "all")
113+
})
114+
})
115+
116+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected] OLMv1 Catalogs /v1/api/metas endpoint", func() {
117+
defer g.GinkgoRecover()
118+
oc := exutil.NewCLIWithoutNamespace("default")
119+
g.It(" should serve the /v1/api/metas API endpoint", func(ctx g.SpecContext) {
120+
checkFeatureCapability(ctx, oc)
121+
122+
g.By("Testing api/v1/metas endpoint for catalog openshift-community-operators")
123+
verifyAPIEndpoint(ctx, oc, oc.Namespace(), "openshift-community-operators", "metas?schema=olm.package")
124+
})
125+
})
126+
102127
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 New Catalog Install", func() {
103128
defer g.GinkgoRecover()
104129

@@ -419,3 +444,89 @@ func checkFeatureCapability(ctx context.Context, oc *exutil.CLI) {
419444
g.Skip("Test only runs with OperatorLifecycleManagerV1 capability")
420445
}
421446
}
447+
448+
// verifyAPIEndpoint runs a job to validate the given service endpoint of a ClusterCatalog
449+
func verifyAPIEndpoint(ctx g.SpecContext, oc *exutil.CLI, namespace, catalogName, endpoint string) {
450+
jobName := fmt.Sprintf("test-catalog-%s-%s", catalogName, endpoint)
451+
452+
baseURL, err := oc.AsAdmin().Run("get").Args(
453+
"clustercatalogs.olm.operatorframework.io",
454+
catalogName,
455+
"-o=jsonpath={.status.urls.base}").Output()
456+
o.Expect(err).NotTo(o.HaveOccurred())
457+
o.Expect(baseURL).NotTo(o.BeEmpty(), fmt.Sprintf("Base URL not found for catalog %s", catalogName))
458+
459+
serviceURL := fmt.Sprintf("%s/api/v1/%s", baseURL, endpoint)
460+
g.GinkgoLogr.Info(fmt.Sprintf("Using service URL: %s", serviceURL))
461+
462+
job := &batchv1.Job{
463+
ObjectMeta: metav1.ObjectMeta{
464+
Name: jobName,
465+
Namespace: namespace,
466+
},
467+
Spec: batchv1.JobSpec{
468+
Template: corev1.PodTemplateSpec{
469+
Spec: corev1.PodSpec{
470+
Containers: []corev1.Container{
471+
{
472+
Name: "api-tester",
473+
Image: "registry.redhat.io/rhel8/httpd-24:latest",
474+
Command: []string{
475+
"/bin/bash",
476+
"-c",
477+
fmt.Sprintf(`
478+
set -ex
479+
response=$(curl -s -k "%s" || echo "ERROR: Failed to access endpoint")
480+
if [[ "$response" == ERROR* ]]; then
481+
echo "$response"
482+
exit 1
483+
fi
484+
echo "$response" > /tmp/api-response
485+
486+
# check if response can be parsed as new line delimited JSON
487+
if cat /tmp/api-response | jq -s . > /dev/null 2>&1; then
488+
echo "Valid JSON response detected"
489+
exit 0
490+
fi
491+
echo "ERROR: Invalid JSON response"
492+
exit 1
493+
`, serviceURL),
494+
},
495+
},
496+
},
497+
RestartPolicy: corev1.RestartPolicyNever,
498+
},
499+
},
500+
},
501+
}
502+
503+
_, err = oc.AdminKubeClient().BatchV1().Jobs(namespace).Create(context.TODO(), job, metav1.CreateOptions{})
504+
o.Expect(err).NotTo(o.HaveOccurred())
505+
506+
err = wait.PollUntilContextTimeout(ctx, 5*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) {
507+
job, err := oc.AdminKubeClient().BatchV1().Jobs(namespace).Get(context.TODO(), jobName, metav1.GetOptions{})
508+
if err != nil {
509+
return false, err
510+
}
511+
512+
if job.Status.Succeeded > 0 {
513+
return true, nil
514+
}
515+
if job.Status.Failed > 0 {
516+
return false, fmt.Errorf("job failed")
517+
}
518+
519+
return false, nil
520+
})
521+
o.Expect(err).NotTo(o.HaveOccurred())
522+
523+
pods, err := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
524+
LabelSelector: fmt.Sprintf("job-name=%s", jobName),
525+
})
526+
o.Expect(err).NotTo(o.HaveOccurred())
527+
o.Expect(pods.Items).NotTo(o.BeEmpty())
528+
529+
logs, err := oc.AdminKubeClient().CoreV1().Pods(namespace).GetLogs(pods.Items[0].Name, &corev1.PodLogOptions{}).DoRaw(context.TODO())
530+
o.Expect(err).NotTo(o.HaveOccurred())
531+
g.GinkgoLogr.Info(fmt.Sprintf("Job logs for %s endpoint: %s", endpoint, string(logs)))
532+
}

test/extended/util/annotate/generated/zz_generated.annotations.go

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zz_generated.manifests/test-reporting.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,23 @@ spec:
381381
tests:
382382
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should be installed'
383383
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 Catalogs
384-
should be installed'
384+
/v1/api/all endpoint should serve FBC'
385385
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 New
386386
Catalog Install should fail to install if it has an invalid reference'
387+
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 default
388+
Catalogs should be installed'
387389
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator
388390
installation should block cluster upgrades if an incompatible operator is
389391
installed'
390392
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator
391393
installation should fail to install a non-existing cluster extension'
392394
- testName: '[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator
393395
installation should install a cluster extension'
396+
- featureGate: NewOLMCatalogdAPIV1Metas
397+
tests:
398+
- testName: '[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected]
399+
OLMv1 Catalogs /v1/api/metas endpoint should serve the /v1/api/metas API
400+
endpoint'
394401
- featureGate: PersistentIPsForVirtualization
395402
tests:
396403
- testName: '[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][Feature:Layer2LiveMigration]

0 commit comments

Comments
 (0)