-
Notifications
You must be signed in to change notification settings - Fork 21
/
framework.go
76 lines (62 loc) · 1.59 KB
/
framework.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package framework
import (
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// unique identifier of the e2e run
var RunID = rand.String(6)
type Framework interface {
HubRESTConfig() *rest.Config
TestClusterName() string
HubNativeClient() kubernetes.Interface
HubRuntimeClient() client.Client
}
var _ Framework = &framework{}
type framework struct {
basename string
ctx *E2EContext
}
func NewE2EFramework(basename string) Framework {
f := &framework{
basename: basename,
ctx: e2eContext,
}
BeforeEach(f.BeforeEach)
AfterEach(f.AfterEach)
return f
}
func (f *framework) HubRESTConfig() *rest.Config {
restConfig, err := clientcmd.BuildConfigFromFlags("", f.ctx.HubKubeConfig)
Expect(err).NotTo(HaveOccurred())
return restConfig
}
func (f *framework) HubNativeClient() kubernetes.Interface {
cfg := f.HubRESTConfig()
nativeClient, err := kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
return nativeClient
}
func (f *framework) HubRuntimeClient() client.Client {
cfg := f.HubRESTConfig()
runtimeClient, err := client.New(cfg, client.Options{
Scheme: scheme,
})
Expect(err).NotTo(HaveOccurred())
return runtimeClient
}
func (f *framework) TestClusterName() string {
return f.ctx.TestCluster
}
func (f *framework) BeforeEach() {
logger := klogr.New()
ctrl.SetLogger(logger)
}
func (f *framework) AfterEach() {
}