@@ -11,6 +11,8 @@ import (
11
11
12
12
g "github.com/onsi/ginkgo/v2"
13
13
o "github.com/onsi/gomega"
14
+ batchv1 "k8s.io/api/batch/v1"
15
+ corev1 "k8s.io/api/core/v1"
14
16
"k8s.io/apimachinery/pkg/api/meta"
15
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
18
"k8s.io/apimachinery/pkg/util/wait"
@@ -71,7 +73,7 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs", func() {
71
73
})
72
74
})
73
75
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 () {
75
77
defer g .GinkgoRecover ()
76
78
oc := exutil .NewCLIWithoutNamespace ("default" )
77
79
@@ -99,6 +101,29 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLM
99
101
})
100
102
})
101
103
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
+
102
127
var _ = g .Describe ("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 New Catalog Install" , func () {
103
128
defer g .GinkgoRecover ()
104
129
@@ -419,3 +444,89 @@ func checkFeatureCapability(ctx context.Context, oc *exutil.CLI) {
419
444
g .Skip ("Test only runs with OperatorLifecycleManagerV1 capability" )
420
445
}
421
446
}
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
+ }
0 commit comments