-
Notifications
You must be signed in to change notification settings - Fork 8
/
provider.go
144 lines (124 loc) · 4.08 KB
/
provider.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
e2e "k8s.io/kubernetes/test/e2e/framework"
exutil "github.com/openshift/origin/test/extended/util"
exutilcluster "github.com/openshift/origin/test/extended/util/cluster"
// Initialize baremetal as a provider
_ "github.com/openshift/origin/test/extended/util/baremetal"
// Initialize ovirt as a provider
_ "github.com/openshift/origin/test/extended/util/ovirt"
// Initialize kubevirt as a provider
_ "github.com/openshift/origin/test/extended/util/kubevirt"
// Initialize alibabacloud as a provider
_ "github.com/openshift/origin/test/extended/util/alibabacloud"
// Initialize nutanix as a provider
_ "github.com/openshift/origin/test/extended/util/nutanix"
// these are loading important global flags that we need to get and set
_ "k8s.io/kubernetes/test/e2e"
_ "k8s.io/kubernetes/test/e2e/lifecycle"
)
func initializeTestFramework(context *e2e.TestContextType, config *exutilcluster.ClusterConfiguration, dryRun bool) error {
// update context with loaded config
context.Provider = config.ProviderName
context.CloudConfig = e2e.CloudConfig{
ProjectID: config.ProjectID,
Region: config.Region,
Zone: config.Zone,
Zones: config.Zones,
NumNodes: config.NumNodes,
MultiMaster: config.MultiMaster,
MultiZone: config.MultiZone,
ConfigFile: config.ConfigFile,
}
context.AllowedNotReadyNodes = -1
context.MinStartupPods = -1
context.MaxNodesToGather = 0
context.KubeConfig = os.Getenv("KUBECONFIG")
// allow the CSI tests to access test data, but only briefly
// TODO: ideally CSI would not use any of these test methods
var err error
exutil.WithCleanup(func() { err = initCSITests(dryRun) })
if err != nil {
return err
}
if err := exutil.InitTest(dryRun); err != nil {
return err
}
gomega.RegisterFailHandler(ginkgo.Fail)
e2e.AfterReadingAllFlags(context)
context.DumpLogsOnFailure = true
// these constants are taken from kube e2e and used by tests
context.IPFamily = "ipv4"
if config.HasIPv6 && !config.HasIPv4 {
context.IPFamily = "ipv6"
}
return nil
}
func decodeProvider(provider string, dryRun, discover bool, clusterState *exutilcluster.ClusterState) (*exutilcluster.ClusterConfiguration, error) {
switch provider {
case "none":
return &exutilcluster.ClusterConfiguration{ProviderName: "skeleton"}, nil
case "":
if _, ok := os.LookupEnv("KUBE_SSH_USER"); ok {
if _, ok := os.LookupEnv("LOCAL_SSH_KEY"); ok {
return &exutilcluster.ClusterConfiguration{ProviderName: "local"}, nil
}
}
if dryRun {
return &exutilcluster.ClusterConfiguration{ProviderName: "skeleton"}, nil
}
fallthrough
case "azure", "aws", "baremetal", "gce", "vsphere", "alibabacloud":
if clusterState == nil {
clientConfig, err := e2e.LoadConfig(true)
if err != nil {
return nil, err
}
clusterState, err = exutilcluster.DiscoverClusterState(clientConfig)
if err != nil {
return nil, err
}
}
config, err := exutilcluster.LoadConfig(clusterState)
if err != nil {
return nil, err
}
if len(config.ProviderName) == 0 {
config.ProviderName = "skeleton"
}
return config, nil
default:
var providerInfo struct {
Type string
}
if err := json.Unmarshal([]byte(provider), &providerInfo); err != nil {
return nil, fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum: %v", err)
}
if len(providerInfo.Type) == 0 {
return nil, fmt.Errorf("provider must be a JSON object with the 'type' key")
}
var config *exutilcluster.ClusterConfiguration
if discover {
if clusterState == nil {
if clientConfig, err := e2e.LoadConfig(true); err == nil {
clusterState, _ = exutilcluster.DiscoverClusterState(clientConfig)
}
}
if clusterState != nil {
config, _ = exutilcluster.LoadConfig(clusterState)
}
}
if config == nil {
config = &exutilcluster.ClusterConfiguration{}
}
if err := json.Unmarshal([]byte(provider), config); err != nil {
return nil, fmt.Errorf("provider must decode into the ClusterConfig object: %v", err)
}
return config, nil
}
}