/
test_utils.go
128 lines (116 loc) · 4.01 KB
/
test_utils.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
package machine
import (
"github.com/nutanix-cloud-native/prism-go-client/pkg/utils"
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// defaultCredentialsSecretName is the default name of the secret holding the credentials for PC client
defaultCredentialsSecretName = "nutanix-credentials"
userDataSecretName = "nutanix-userdata"
credentialsData = `[{"type":"basic_auth","data":{"prismCentral":{"username":"pc_user","password":"pc_password"},"prismElements":[{"name":"pe_name","username":"pe_user","password":"pe_password"}]}}]`
)
var (
infrastructure = configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{},
PlatformSpec: configv1.PlatformSpec{
Type: configv1.NutanixPlatformType,
Nutanix: &configv1.NutanixPlatformSpec{
PrismCentral: configv1.NutanixPrismEndpoint{Address: "10.40.42.15", Port: 9440},
PrismElements: []configv1.NutanixPrismElementEndpoint{
{Name: "test-pe", Endpoint: configv1.NutanixPrismEndpoint{Address: "10.40.131.30", Port: 9440}},
},
},
},
},
}
infrastructureStatus = configv1.InfrastructureStatus{
InfrastructureName: "test-cluster-1",
ControlPlaneTopology: configv1.HighlyAvailableTopologyMode,
InfrastructureTopology: configv1.SingleReplicaTopologyMode,
PlatformStatus: &configv1.PlatformStatus{
Type: configv1.NutanixPlatformType,
Nutanix: &configv1.NutanixPlatformStatus{
APIServerInternalIPs: []string{"10.40.42.5"},
IngressIPs: []string{"10.40.42.6"},
},
},
}
failureDomains = []configv1.NutanixFailureDomain{
{
Name: "fd.pe0",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierName,
Name: Ptr[string]("pe0"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierName,
Name: Ptr[string]("pe0-net"),
}},
},
{
Name: "fd.pe1",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierUUID,
UUID: Ptr[string]("0005a0f3-8f43-a0f5-02b7-3cecef194315"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierName,
Name: Ptr[string]("pe1-net"),
}},
},
{
Name: "fd.pe2",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierName,
Name: Ptr[string]("pe2"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierUUID,
UUID: Ptr[string]("a8938dc6-7659-6801-a688-e26020c68241"),
}},
},
}
)
// getInfrastructureObject returns the Infrastructure object for test
func getInfrastructureObject(withFailureDomains bool) *configv1.Infrastructure {
infra := infrastructure.DeepCopy()
if withFailureDomains {
fds := []configv1.NutanixFailureDomain{}
for _, fd := range failureDomains {
fds = append(fds, fd)
}
infra.Spec.PlatformSpec.Nutanix.FailureDomains = fds
}
return infra
}
// getValidProviderSpec returns the valid NutanixMachineProviderConfig object for test
func getValidProviderSpec(fdName string) *machinev1.NutanixMachineProviderConfig {
return &machinev1.NutanixMachineProviderConfig{
Cluster: machinev1.NutanixResourceIdentifier{Type: "name", Name: utils.StringPtr("test-pe")},
Image: machinev1.NutanixResourceIdentifier{Type: "name", Name: utils.StringPtr("rhcos-4.10-nutanix")},
Subnets: []machinev1.NutanixResourceIdentifier{
{Type: "name", Name: Ptr[string]("test_net")},
},
VCPUsPerSocket: 2,
VCPUSockets: 1,
MemorySize: resource.MustParse("4096Mi"),
SystemDiskSize: resource.MustParse("120Gi"),
CredentialsSecret: &corev1.LocalObjectReference{
Name: defaultCredentialsSecretName,
},
UserDataSecret: &corev1.LocalObjectReference{
Name: userDataSecretName,
},
FailureDomain: &machinev1.NutanixFailureDomainReference{
Name: fdName,
},
}
}