Skip to content

Commit ea989e2

Browse files
Merge pull request #304 from nutanix-cloud-native/nutanix-failuredomains
SPLAT-1272: create fixtures for Nutanix failure domains support
2 parents b6681f5 + 3991b9c commit ea989e2

File tree

42 files changed

+3274
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3274
-100
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/uuid v1.3.0
88
github.com/onsi/ginkgo/v2 v2.12.1
99
github.com/onsi/gomega v1.28.0
10-
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d
10+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
1111
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20230830212214-7c11ddb9aedf
1212
github.com/openshift/cluster-autoscaler-operator v0.0.1-0.20230424082009-f7f168cc5145
1313
github.com/openshift/library-go v0.0.0-20231002085549-82582312568f

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA
468468
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
469469
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
470470
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
471-
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d h1:076BQ9iaz/giM0wRT9grdbkYsdy6WHQ2vg/asQ3lv6c=
472-
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
471+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3 h1:nLhV2lbWrJ3E3hx0/97G3ZZvppC67cNwo+CLp7/PAbA=
472+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
473473
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1 h1:W1N/3nVciqmjPjn2xldHjb0AwwCQzlGxLvX5BCgE8H4=
474474
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1/go.mod h1:ihUJrhBcYAGYQrJu/gP2OMgfVds5f5z5kbeLNBqjHLo=
475475
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20230830212214-7c11ddb9aedf h1:hU/hAAs8Cp4Xy4sjmyt1UTDQtGBUdBFu3Qnj5g3Np28=

testutils/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/golangci/golangci-lint v1.54.2
88
github.com/onsi/ginkgo/v2 v2.12.1
99
github.com/onsi/gomega v1.28.0
10-
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc
10+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
1111
k8s.io/api v0.28.2
1212
k8s.io/apimachinery v0.28.2
1313
k8s.io/client-go v0.28.2

testutils/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA
436436
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
437437
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
438438
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
439-
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc h1:oSF6SWbkbm2l2ecKSDm2yjZiX4TklpHDkV5utV2J61U=
440-
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
439+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3 h1:nLhV2lbWrJ3E3hx0/97G3ZZvppC67cNwo+CLp7/PAbA=
440+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
441441
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
442442
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
443443
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

testutils/resourcebuilder/config/v1/infrastructure.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1
1919
import (
2020
configv1 "github.com/openshift/api/config/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/utils/ptr"
2223
)
2324

2425
// Infrastructure creates a new infrastructure builder.
@@ -161,6 +162,100 @@ func (i InfrastructureBuilder) AsOpenStack(name string) InfrastructureBuilder {
161162
return i
162163
}
163164

165+
// AsNutanix sets the Status for the infrastructure builder.
166+
func (i InfrastructureBuilder) AsNutanix(name string) InfrastructureBuilder {
167+
i.spec = &configv1.InfrastructureSpec{
168+
PlatformSpec: configv1.PlatformSpec{
169+
Type: configv1.NutanixPlatformType,
170+
Nutanix: &configv1.NutanixPlatformSpec{
171+
PrismCentral: configv1.NutanixPrismEndpoint{
172+
Address: "https://pc0_address",
173+
Port: 9440,
174+
},
175+
PrismElements: []configv1.NutanixPrismElementEndpoint{
176+
{
177+
Name: "pe0",
178+
Endpoint: configv1.NutanixPrismEndpoint{
179+
Address: "pe0-address",
180+
Port: 9440,
181+
},
182+
},
183+
},
184+
},
185+
},
186+
}
187+
188+
i.status = &configv1.InfrastructureStatus{
189+
InfrastructureName: name,
190+
APIServerURL: "https://api.test-cluster.test-domain:6443",
191+
APIServerInternalURL: "https://api-int.test-cluster.test-domain:6443",
192+
EtcdDiscoveryDomain: "",
193+
ControlPlaneTopology: configv1.HighlyAvailableTopologyMode,
194+
InfrastructureTopology: configv1.HighlyAvailableTopologyMode,
195+
PlatformStatus: &configv1.PlatformStatus{
196+
Type: configv1.NutanixPlatformType,
197+
Nutanix: &configv1.NutanixPlatformStatus{
198+
APIServerInternalIPs: []string{"10.0.0.5"},
199+
IngressIPs: []string{"10.0.0.7"},
200+
},
201+
},
202+
}
203+
204+
return i
205+
}
206+
207+
// AsNutanixWithFailureDomains returns a Nutanix infrastructure resource with failure domains.
208+
// if failureDomains is nil, default failure domains will be applied to the resource which are
209+
// compatible with machinev1beta1resourcebuilder default failure domain names.
210+
func (i InfrastructureBuilder) AsNutanixWithFailureDomains(name string, failureDomains *[]configv1.NutanixFailureDomain) InfrastructureBuilder {
211+
infraBuilder := i.AsNutanix(name)
212+
213+
if failureDomains != nil {
214+
infraBuilder.spec.PlatformSpec.Nutanix.FailureDomains = *failureDomains
215+
} else {
216+
infraBuilder.spec.PlatformSpec.Nutanix.FailureDomains = []configv1.NutanixFailureDomain{
217+
{
218+
Name: "fd-pe0",
219+
Cluster: configv1.NutanixResourceIdentifier{
220+
Type: configv1.NutanixIdentifierName,
221+
Name: ptr.To[string]("pe0"),
222+
},
223+
Subnets: []configv1.NutanixResourceIdentifier{{
224+
Type: configv1.NutanixIdentifierName,
225+
Name: ptr.To[string]("pe0-subnet"),
226+
}},
227+
},
228+
{
229+
Name: "fd-pe1",
230+
Cluster: configv1.NutanixResourceIdentifier{
231+
Type: configv1.NutanixIdentifierUUID,
232+
UUID: ptr.To[string]("0005a0f3-8f43-a0f5-02b7-3cecef194315"),
233+
},
234+
Subnets: []configv1.NutanixResourceIdentifier{{
235+
Type: configv1.NutanixIdentifierName,
236+
Name: ptr.To[string]("pe1-subnet"),
237+
}},
238+
},
239+
{
240+
Name: "fd-pe2",
241+
Cluster: configv1.NutanixResourceIdentifier{
242+
Type: configv1.NutanixIdentifierName,
243+
Name: ptr.To[string]("pe2"),
244+
},
245+
Subnets: []configv1.NutanixResourceIdentifier{{
246+
Type: configv1.NutanixIdentifierUUID,
247+
UUID: ptr.To[string]("a8938dc6-7659-6801-a688-e26020c68241"),
248+
}},
249+
},
250+
}
251+
}
252+
253+
i.spec = infraBuilder.spec
254+
i.status = infraBuilder.status
255+
256+
return i
257+
}
258+
164259
// AsVSphere sets the Status for the infrastructure builder.
165260
func (i InfrastructureBuilder) AsVSphere(name string) InfrastructureBuilder {
166261
i.spec = &configv1.InfrastructureSpec{
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2022 Red Hat, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package v1
15+
16+
import (
17+
configv1 "github.com/openshift/api/config/v1"
18+
machinev1 "github.com/openshift/api/machine/v1"
19+
)
20+
21+
// NutanixFailureDomains creates a new failure domains builder for Nutanix.
22+
func NutanixFailureDomains() NutanixFailureDomainsBuilder {
23+
fdsBuilder := NutanixFailureDomainsBuilder{
24+
failureDomainsBuilders: []NutanixFailureDomainBuilder{
25+
{Name: "fd-pe0"},
26+
{Name: "fd-pe1"},
27+
{Name: "fd-pe2"},
28+
},
29+
}
30+
31+
return fdsBuilder
32+
}
33+
34+
// NutanixFailureDomainsBuilder is used to build a failuredomains for Nutanix.
35+
type NutanixFailureDomainsBuilder struct {
36+
failureDomainsBuilders []NutanixFailureDomainBuilder
37+
}
38+
39+
// BuildFailureDomains builds a failuredomains from the configuration.
40+
func (b NutanixFailureDomainsBuilder) BuildFailureDomains() machinev1.FailureDomains {
41+
fds := machinev1.FailureDomains{
42+
Platform: configv1.NutanixPlatformType,
43+
Nutanix: []machinev1.NutanixFailureDomainReference{},
44+
}
45+
46+
for _, builder := range b.failureDomainsBuilders {
47+
fds.Nutanix = append(fds.Nutanix, builder.Build())
48+
}
49+
50+
return fds
51+
}
52+
53+
// WithFailureDomainBuilder adds a failure domain builder to the failure domains builder's builders.
54+
func (b NutanixFailureDomainsBuilder) WithFailureDomainBuilder(fdbuilder NutanixFailureDomainBuilder) NutanixFailureDomainsBuilder {
55+
b.failureDomainsBuilders = append(b.failureDomainsBuilders, fdbuilder)
56+
return b
57+
}
58+
59+
// WithFailureDomainBuilders replaces the failure domains builder's builders with the given builders.
60+
func (b NutanixFailureDomainsBuilder) WithFailureDomainBuilders(fdbuilders ...NutanixFailureDomainBuilder) NutanixFailureDomainsBuilder {
61+
b.failureDomainsBuilders = fdbuilders
62+
return b
63+
}
64+
65+
// NewNutanixFailureDomainBuilder creates a new failure domain builder for Nutanix.
66+
func NewNutanixFailureDomainBuilder() NutanixFailureDomainBuilder {
67+
return NutanixFailureDomainBuilder{}
68+
}
69+
70+
// NutanixFailureDomainBuilder is used to build a Nutanix failuredomain.
71+
type NutanixFailureDomainBuilder struct {
72+
Name string
73+
}
74+
75+
// Build builds a Nutanix failuredomain from the configuration.
76+
func (g NutanixFailureDomainBuilder) Build() machinev1.NutanixFailureDomainReference {
77+
return machinev1.NutanixFailureDomainReference{
78+
Name: g.Name,
79+
}
80+
}
81+
82+
// WithName sets the zone for the Nutanix failuredomain builder.
83+
func (g NutanixFailureDomainBuilder) WithName(name string) NutanixFailureDomainBuilder {
84+
g.Name = name
85+
return g
86+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Copyright 2022 Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"encoding/json"
21+
"fmt"
22+
23+
configv1 "github.com/openshift/api/config/v1"
24+
machinev1 "github.com/openshift/api/machine/v1"
25+
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/api/resource"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/runtime"
29+
"k8s.io/utils/ptr"
30+
)
31+
32+
// NewNutanixMachineProviderConfigBuilder returns a NutanixMachineProviderConfigBuilder.
33+
func NewNutanixMachineProviderConfigBuilder() *NutanixMachineProviderConfigBuilder {
34+
return &NutanixMachineProviderConfigBuilder{}
35+
}
36+
37+
// NutanixMachineProviderConfigBuilder is used to build a NutanixMachineProviderConfig.
38+
type NutanixMachineProviderConfigBuilder struct {
39+
// failureDomains holds the Nutanix failure domains data for the builder to use
40+
failureDomains []configv1.NutanixFailureDomain
41+
// failureDomainName configures the failure domain name the build will use
42+
failureDomainName string
43+
}
44+
45+
// Build returns the generated NutanixMachineProviderConfig.
46+
func (n *NutanixMachineProviderConfigBuilder) Build() *machinev1.NutanixMachineProviderConfig {
47+
providerConfig := &machinev1.NutanixMachineProviderConfig{
48+
TypeMeta: metav1.TypeMeta{
49+
APIVersion: machinev1.GroupVersion.String(),
50+
Kind: "NutanixMachineProviderConfig",
51+
},
52+
UserDataSecret: &corev1.LocalObjectReference{Name: "nutanix-user-data"},
53+
CredentialsSecret: &corev1.LocalObjectReference{Name: "nutanix-credentials"},
54+
Image: machinev1.NutanixResourceIdentifier{
55+
Type: machinev1.NutanixIdentifierName,
56+
Name: ptr.To[string]("rhcos"),
57+
},
58+
Subnets: []machinev1.NutanixResourceIdentifier{{Type: machinev1.NutanixIdentifierName, Name: ptr.To[string]("default-net")}},
59+
VCPUsPerSocket: int32(1),
60+
VCPUSockets: int32(4),
61+
MemorySize: resource.MustParse(fmt.Sprintf("%dMi", 8096)),
62+
Cluster: machinev1.NutanixResourceIdentifier{
63+
Type: machinev1.NutanixIdentifierUUID,
64+
UUID: ptr.To[string]("pe-uuid"),
65+
},
66+
SystemDiskSize: resource.MustParse(fmt.Sprintf("%dGi", 120)),
67+
}
68+
69+
if len(n.failureDomainName) > 0 {
70+
var failureDomain *configv1.NutanixFailureDomain
71+
72+
for _, fd := range n.failureDomains {
73+
if fd.Name == n.failureDomainName {
74+
failureDomain = ptr.To[configv1.NutanixFailureDomain](fd)
75+
break
76+
}
77+
}
78+
79+
if failureDomain == nil {
80+
// The failureDomainName is not found in the Infrastructure resource
81+
panic(fmt.Sprintf("The failure domain with name %q is not configured.", n.failureDomainName))
82+
}
83+
84+
providerConfig.FailureDomain = &machinev1.NutanixFailureDomainReference{
85+
Name: failureDomain.Name,
86+
}
87+
88+
// update Cluster
89+
providerConfig.Cluster = machinev1.NutanixResourceIdentifier{
90+
Name: failureDomain.Cluster.Name,
91+
UUID: failureDomain.Cluster.UUID,
92+
}
93+
94+
switch failureDomain.Cluster.Type {
95+
case configv1.NutanixIdentifierName:
96+
providerConfig.Cluster.Type = machinev1.NutanixIdentifierName
97+
case configv1.NutanixIdentifierUUID:
98+
providerConfig.Cluster.Type = machinev1.NutanixIdentifierUUID
99+
default:
100+
}
101+
102+
// update Subnets
103+
providerConfig.Subnets = []machinev1.NutanixResourceIdentifier{}
104+
105+
for _, fdSubnet := range failureDomain.Subnets {
106+
pcSubnet := machinev1.NutanixResourceIdentifier{
107+
Name: fdSubnet.Name,
108+
UUID: fdSubnet.UUID,
109+
}
110+
111+
switch fdSubnet.Type {
112+
case configv1.NutanixIdentifierName:
113+
pcSubnet.Type = machinev1.NutanixIdentifierName
114+
case configv1.NutanixIdentifierUUID:
115+
pcSubnet.Type = machinev1.NutanixIdentifierUUID
116+
default:
117+
}
118+
119+
providerConfig.Subnets = append(providerConfig.Subnets, pcSubnet)
120+
}
121+
}
122+
123+
return providerConfig
124+
}
125+
126+
// BuildRawExtension builds a new Nutanix machine config based on the configuration provided.
127+
func (n *NutanixMachineProviderConfigBuilder) BuildRawExtension() *runtime.RawExtension {
128+
providerConfig := n.Build()
129+
130+
raw, err := json.Marshal(providerConfig)
131+
if err != nil {
132+
// As we are building the input to json.Marshal, this should never happen.
133+
panic(err)
134+
}
135+
136+
return &runtime.RawExtension{
137+
Raw: raw,
138+
}
139+
}
140+
141+
// WithFailureDomains sets the failureDomains field with the input value.
142+
func (n *NutanixMachineProviderConfigBuilder) WithFailureDomains(failureDomains []configv1.NutanixFailureDomain) *NutanixMachineProviderConfigBuilder {
143+
n.failureDomains = failureDomains
144+
return n
145+
}
146+
147+
// WithFailureDomainName sets the failureDomainName field with the input value.
148+
func (n *NutanixMachineProviderConfigBuilder) WithFailureDomainName(failureDomainName string) *NutanixMachineProviderConfigBuilder {
149+
n.failureDomainName = failureDomainName
150+
return n
151+
}

0 commit comments

Comments
 (0)