forked from goharbor/harbor-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
31 lines (25 loc) · 922 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package test
import (
"context"
"fmt"
"github.com/plotly/harbor-operator/pkg/factories/application"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func NewRestConfig(ctx context.Context) *rest.Config {
config := rest.CopyConfig(GetRestConfig(ctx))
config = rest.AddUserAgent(config, fmt.Sprintf("%s(%s)", application.GetName(ctx), application.GetVersion(ctx)))
config.APIPath = "api"
config.NegotiatedSerializer = serializer.NewCodecFactory(GetScheme(ctx))
config.GroupVersion = &corev1.SchemeGroupVersion
return config
}
func NewClient(ctx context.Context) client.Client {
k8sClient, err := client.New(GetRestConfig(ctx), client.Options{Scheme: GetScheme(ctx)})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(k8sClient).ToNot(gomega.BeNil())
return k8sClient
}