@@ -2,7 +2,12 @@ package catalogde2e
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "io"
7
+ "k8s.io/client-go/kubernetes"
8
+ "net/url"
5
9
"os"
10
+ "strings"
6
11
7
12
. "github.com/onsi/ginkgo/v2"
8
13
. "github.com/onsi/gomega"
@@ -76,7 +81,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
76
81
Expect (catalog .ObjectMeta .Labels ).To (HaveKeyWithValue ("olm.operatorframework.io/metadata.name" , catalogName ))
77
82
78
83
By ("Making sure the catalog content is available via the http server" )
79
- actualFBC , err := ReadTestCatalogServerContents (ctx , catalog , c , kubeClient )
84
+ actualFBC , err := readTestCatalogServerContents (ctx , catalog , kubeClient )
80
85
Expect (err ).To (Not (HaveOccurred ()))
81
86
82
87
expectedFBC , err := os .ReadFile ("../../catalogd/testdata/catalogs/test-catalog/expected_all.json" )
@@ -102,3 +107,40 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
102
107
})
103
108
})
104
109
})
110
+
111
+ func readTestCatalogServerContents (ctx context.Context , catalog * catalogdv1.ClusterCatalog , kubeClient kubernetes.Interface ) ([]byte , error ) {
112
+ if catalog == nil {
113
+ return nil , fmt .Errorf ("cannot read nil catalog" )
114
+ }
115
+ if catalog .Status .URLs == nil {
116
+ return nil , fmt .Errorf ("catalog %q has no catalog urls" , catalog .Name )
117
+ }
118
+ url , err := url .Parse (catalog .Status .URLs .Base )
119
+ if err != nil {
120
+ return nil , fmt .Errorf ("error parsing clustercatalog url %q: %v" , catalog .Status .URLs .Base , err )
121
+ }
122
+ // url is expected to be in the format of
123
+ // http://{service_name}.{namespace}.svc/catalogs/{catalog_name}/
124
+ // so to get the namespace and name of the service we grab only
125
+ // the hostname and split it on the '.' character
126
+ ns := strings .Split (url .Hostname (), "." )[1 ]
127
+ name := strings .Split (url .Hostname (), "." )[0 ]
128
+ port := url .Port ()
129
+ // the ProxyGet() call below needs an explicit port value, so if
130
+ // value from url.Port() is empty, we assume port 443.
131
+ if port == "" {
132
+ if url .Scheme == "https" {
133
+ port = "443"
134
+ } else {
135
+ port = "80"
136
+ }
137
+ }
138
+ resp := kubeClient .CoreV1 ().Services (ns ).ProxyGet (url .Scheme , name , port , url .JoinPath ("api" , "v1" , "all" ).Path , map [string ]string {})
139
+ rc , err := resp .Stream (ctx )
140
+ if err != nil {
141
+ return nil , err
142
+ }
143
+ defer rc .Close ()
144
+
145
+ return io .ReadAll (rc )
146
+ }
0 commit comments