1
1
package utils
2
2
3
3
import (
4
- "context"
5
- "fmt"
6
- "io"
7
- "net/url"
8
4
"os/exec"
9
- "strings"
10
5
"testing"
11
-
12
- "k8s.io/client-go/kubernetes"
13
-
14
- ocv1 "github.com/operator-framework/operator-controller/api/v1"
15
6
)
16
7
17
8
// FindK8sClient returns the first available Kubernetes CLI client from the system,
@@ -30,40 +21,3 @@ func FindK8sClient(t *testing.T) string {
30
21
t .Fatal ("k8s client not found" )
31
22
return ""
32
23
}
33
-
34
- func ReadTestCatalogServerContents (ctx context.Context , catalog * ocv1.ClusterCatalog , kubeClient kubernetes.Interface ) ([]byte , error ) {
35
- if catalog == nil {
36
- return nil , fmt .Errorf ("cannot read nil catalog" )
37
- }
38
- if catalog .Status .URLs == nil {
39
- return nil , fmt .Errorf ("catalog %q has no catalog urls" , catalog .Name )
40
- }
41
- url , err := url .Parse (catalog .Status .URLs .Base )
42
- if err != nil {
43
- return nil , fmt .Errorf ("error parsing clustercatalog url %q: %v" , catalog .Status .URLs .Base , err )
44
- }
45
- // url is expected to be in the format of
46
- // http://{service_name}.{namespace}.svc/catalogs/{catalog_name}/
47
- // so to get the namespace and name of the service we grab only
48
- // the hostname and split it on the '.' character
49
- ns := strings .Split (url .Hostname (), "." )[1 ]
50
- name := strings .Split (url .Hostname (), "." )[0 ]
51
- port := url .Port ()
52
- // the ProxyGet() call below needs an explicit port value, so if
53
- // value from url.Port() is empty, we assume port 443.
54
- if port == "" {
55
- if url .Scheme == "https" {
56
- port = "443"
57
- } else {
58
- port = "80"
59
- }
60
- }
61
- resp := kubeClient .CoreV1 ().Services (ns ).ProxyGet (url .Scheme , name , port , url .JoinPath ("api" , "v1" , "all" ).Path , map [string ]string {})
62
- rc , err := resp .Stream (ctx )
63
- if err != nil {
64
- return nil , err
65
- }
66
- defer rc .Close ()
67
-
68
- return io .ReadAll (rc )
69
- }
0 commit comments