This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
environment.go
95 lines (81 loc) · 2.41 KB
/
environment.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package environment
import (
"context"
"sync/atomic"
"time"
gomegaConfig "github.com/onsi/ginkgo/config"
"github.com/onsi/gomega"
"github.com/spf13/afero"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc" //from https://github.com/kubernetes/client-go/issues/345
"k8s.io/client-go/rest"
"code.cloudfoundry.org/quarks-statefulset/pkg/kube/client/clientset/versioned"
"code.cloudfoundry.org/quarks-statefulset/pkg/kube/operator"
"code.cloudfoundry.org/quarks-statefulset/testing"
"code.cloudfoundry.org/quarks-utils/pkg/config"
utils "code.cloudfoundry.org/quarks-utils/testing/integration"
"code.cloudfoundry.org/quarks-utils/testing/machine"
)
// Environment starts our operator and handles interaction with the k8s
// cluster used in the tests
type Environment struct {
*utils.Environment
Machine
testing.Catalog
}
var (
namespaceCounter int32
)
const (
defaultTestMeltdownDuration = 10
defaultTestMeltdownRequeueAfter = 1
)
// NewEnvironment returns a new struct
func NewEnvironment(kubeConfig *rest.Config) *Environment {
atomic.AddInt32(&namespaceCounter, 1)
namespaceID := gomegaConfig.GinkgoConfig.ParallelNode*200 + int(namespaceCounter)
// the single namespace used by this test
ns := utils.GetNamespaceName(namespaceID)
env := &Environment{
Environment: &utils.Environment{
ID: namespaceID,
Namespace: ns,
KubeConfig: kubeConfig,
Config: &config.Config{
CtxTimeOut: 10 * time.Second,
MeltdownDuration: defaultTestMeltdownDuration * time.Second,
MeltdownRequeueAfter: defaultTestMeltdownRequeueAfter * time.Second,
MonitoredID: ns,
OperatorNamespace: ns,
Fs: afero.NewOsFs(),
},
},
Machine: Machine{
Machine: machine.NewMachine(),
},
}
gomega.SetDefaultEventuallyTimeout(env.PollTimeout)
gomega.SetDefaultEventuallyPollingInterval(env.PollInterval)
return env
}
// SetupClientsets initializes kube clientsets
func (e *Environment) SetupClientsets() error {
var err error
e.Clientset, err = kubernetes.NewForConfig(e.KubeConfig)
if err != nil {
return err
}
e.VersionedClientset, err = versioned.NewForConfig(e.KubeConfig)
if err != nil {
return err
}
return nil
}
// ApplyCRDs applies the CRDs to the cluster
func ApplyCRDs(kubeConfig *rest.Config) error {
err := operator.ApplyCRDs(context.Background(), kubeConfig)
if err != nil {
return err
}
return nil
}