Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.3.0
github.com/onsi/ginkgo/v2 v2.12.1
github.com/onsi/gomega v1.28.0
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20230830212214-7c11ddb9aedf
github.com/openshift/cluster-autoscaler-operator v0.0.1-0.20230424082009-f7f168cc5145
github.com/openshift/library-go v0.0.0-20231002085549-82582312568f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d h1:076BQ9iaz/giM0wRT9grdbkYsdy6WHQ2vg/asQ3lv6c=
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3 h1:nLhV2lbWrJ3E3hx0/97G3ZZvppC67cNwo+CLp7/PAbA=
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1 h1:W1N/3nVciqmjPjn2xldHjb0AwwCQzlGxLvX5BCgE8H4=
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1/go.mod h1:ihUJrhBcYAGYQrJu/gP2OMgfVds5f5z5kbeLNBqjHLo=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20230830212214-7c11ddb9aedf h1:hU/hAAs8Cp4Xy4sjmyt1UTDQtGBUdBFu3Qnj5g3Np28=
Expand Down
2 changes: 1 addition & 1 deletion testutils/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/golangci/golangci-lint v1.54.2
github.com/onsi/ginkgo/v2 v2.12.1
github.com/onsi/gomega v1.28.0
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
Expand Down
4 changes: 2 additions & 2 deletions testutils/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc h1:oSF6SWbkbm2l2ecKSDm2yjZiX4TklpHDkV5utV2J61U=
github.com/openshift/api v0.0.0-20231111020126-d7cd9fe8a9bc/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3 h1:nLhV2lbWrJ3E3hx0/97G3ZZvppC67cNwo+CLp7/PAbA=
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down
95 changes: 95 additions & 0 deletions testutils/resourcebuilder/config/v1/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1
import (
configv1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

// Infrastructure creates a new infrastructure builder.
Expand Down Expand Up @@ -161,6 +162,100 @@ func (i InfrastructureBuilder) AsOpenStack(name string) InfrastructureBuilder {
return i
}

// AsNutanix sets the Status for the infrastructure builder.
func (i InfrastructureBuilder) AsNutanix(name string) InfrastructureBuilder {
i.spec = &configv1.InfrastructureSpec{
PlatformSpec: configv1.PlatformSpec{
Type: configv1.NutanixPlatformType,
Nutanix: &configv1.NutanixPlatformSpec{
PrismCentral: configv1.NutanixPrismEndpoint{
Address: "https://pc0_address",
Port: 9440,
},
PrismElements: []configv1.NutanixPrismElementEndpoint{
{
Name: "pe0",
Endpoint: configv1.NutanixPrismEndpoint{
Address: "pe0-address",
Port: 9440,
},
},
},
},
},
}

i.status = &configv1.InfrastructureStatus{
InfrastructureName: name,
APIServerURL: "https://api.test-cluster.test-domain:6443",
APIServerInternalURL: "https://api-int.test-cluster.test-domain:6443",
EtcdDiscoveryDomain: "",
ControlPlaneTopology: configv1.HighlyAvailableTopologyMode,
InfrastructureTopology: configv1.HighlyAvailableTopologyMode,
PlatformStatus: &configv1.PlatformStatus{
Type: configv1.NutanixPlatformType,
Nutanix: &configv1.NutanixPlatformStatus{
APIServerInternalIPs: []string{"10.0.0.5"},
IngressIPs: []string{"10.0.0.7"},
},
},
}

return i
}

// AsNutanixWithFailureDomains returns a Nutanix infrastructure resource with failure domains.
// if failureDomains is nil, default failure domains will be applied to the resource which are
// compatible with machinev1beta1resourcebuilder default failure domain names.
func (i InfrastructureBuilder) AsNutanixWithFailureDomains(name string, failureDomains *[]configv1.NutanixFailureDomain) InfrastructureBuilder {
infraBuilder := i.AsNutanix(name)

if failureDomains != nil {
infraBuilder.spec.PlatformSpec.Nutanix.FailureDomains = *failureDomains
} else {
infraBuilder.spec.PlatformSpec.Nutanix.FailureDomains = []configv1.NutanixFailureDomain{
{
Name: "fd-pe0",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierName,
Name: ptr.To[string]("pe0"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierName,
Name: ptr.To[string]("pe0-subnet"),
}},
},
{
Name: "fd-pe1",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierUUID,
UUID: ptr.To[string]("0005a0f3-8f43-a0f5-02b7-3cecef194315"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierName,
Name: ptr.To[string]("pe1-subnet"),
}},
},
{
Name: "fd-pe2",
Cluster: configv1.NutanixResourceIdentifier{
Type: configv1.NutanixIdentifierName,
Name: ptr.To[string]("pe2"),
},
Subnets: []configv1.NutanixResourceIdentifier{{
Type: configv1.NutanixIdentifierUUID,
UUID: ptr.To[string]("a8938dc6-7659-6801-a688-e26020c68241"),
}},
},
}
}

i.spec = infraBuilder.spec
i.status = infraBuilder.status

return i
}

// AsVSphere sets the Status for the infrastructure builder.
func (i InfrastructureBuilder) AsVSphere(name string) InfrastructureBuilder {
i.spec = &configv1.InfrastructureSpec{
Expand Down
86 changes: 86 additions & 0 deletions testutils/resourcebuilder/machine/v1/nutanix_failure_domains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2022 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
)

// NutanixFailureDomains creates a new failure domains builder for Nutanix.
func NutanixFailureDomains() NutanixFailureDomainsBuilder {
fdsBuilder := NutanixFailureDomainsBuilder{
failureDomainsBuilders: []NutanixFailureDomainBuilder{
{Name: "fd-pe0"},
{Name: "fd-pe1"},
{Name: "fd-pe2"},
},
}

return fdsBuilder
}

// NutanixFailureDomainsBuilder is used to build a failuredomains for Nutanix.
type NutanixFailureDomainsBuilder struct {
failureDomainsBuilders []NutanixFailureDomainBuilder
}

// BuildFailureDomains builds a failuredomains from the configuration.
func (b NutanixFailureDomainsBuilder) BuildFailureDomains() machinev1.FailureDomains {
fds := machinev1.FailureDomains{
Platform: configv1.NutanixPlatformType,
Nutanix: []machinev1.NutanixFailureDomainReference{},
}

for _, builder := range b.failureDomainsBuilders {
fds.Nutanix = append(fds.Nutanix, builder.Build())
}

return fds
}

// WithFailureDomainBuilder adds a failure domain builder to the failure domains builder's builders.
func (b NutanixFailureDomainsBuilder) WithFailureDomainBuilder(fdbuilder NutanixFailureDomainBuilder) NutanixFailureDomainsBuilder {
b.failureDomainsBuilders = append(b.failureDomainsBuilders, fdbuilder)
return b
}

// WithFailureDomainBuilders replaces the failure domains builder's builders with the given builders.
func (b NutanixFailureDomainsBuilder) WithFailureDomainBuilders(fdbuilders ...NutanixFailureDomainBuilder) NutanixFailureDomainsBuilder {
b.failureDomainsBuilders = fdbuilders
return b
}

// NewNutanixFailureDomainBuilder creates a new failure domain builder for Nutanix.
func NewNutanixFailureDomainBuilder() NutanixFailureDomainBuilder {
return NutanixFailureDomainBuilder{}
}

// NutanixFailureDomainBuilder is used to build a Nutanix failuredomain.
type NutanixFailureDomainBuilder struct {
Name string
}

// Build builds a Nutanix failuredomain from the configuration.
func (g NutanixFailureDomainBuilder) Build() machinev1.NutanixFailureDomainReference {
return machinev1.NutanixFailureDomainReference{
Name: g.Name,
}
}

// WithName sets the zone for the Nutanix failuredomain builder.
func (g NutanixFailureDomainBuilder) WithName(name string) NutanixFailureDomainBuilder {
g.Name = name
return g
}
151 changes: 151 additions & 0 deletions testutils/resourcebuilder/machine/v1/nutanix_provider_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
Copyright 2022 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"encoding/json"
"fmt"

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"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
)

// NewNutanixMachineProviderConfigBuilder returns a NutanixMachineProviderConfigBuilder.
func NewNutanixMachineProviderConfigBuilder() *NutanixMachineProviderConfigBuilder {
return &NutanixMachineProviderConfigBuilder{}
}

// NutanixMachineProviderConfigBuilder is used to build a NutanixMachineProviderConfig.
type NutanixMachineProviderConfigBuilder struct {
// failureDomains holds the Nutanix failure domains data for the builder to use
failureDomains []configv1.NutanixFailureDomain
// failureDomainName configures the failure domain name the build will use
failureDomainName string
}

// Build returns the generated NutanixMachineProviderConfig.
func (n *NutanixMachineProviderConfigBuilder) Build() *machinev1.NutanixMachineProviderConfig {
providerConfig := &machinev1.NutanixMachineProviderConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: machinev1.GroupVersion.String(),
Kind: "NutanixMachineProviderConfig",
},
UserDataSecret: &corev1.LocalObjectReference{Name: "nutanix-user-data"},
CredentialsSecret: &corev1.LocalObjectReference{Name: "nutanix-credentials"},
Image: machinev1.NutanixResourceIdentifier{
Type: machinev1.NutanixIdentifierName,
Name: ptr.To[string]("rhcos"),
},
Subnets: []machinev1.NutanixResourceIdentifier{{Type: machinev1.NutanixIdentifierName, Name: ptr.To[string]("default-net")}},
VCPUsPerSocket: int32(1),
VCPUSockets: int32(4),
MemorySize: resource.MustParse(fmt.Sprintf("%dMi", 8096)),
Cluster: machinev1.NutanixResourceIdentifier{
Type: machinev1.NutanixIdentifierUUID,
UUID: ptr.To[string]("pe-uuid"),
},
SystemDiskSize: resource.MustParse(fmt.Sprintf("%dGi", 120)),
}

if len(n.failureDomainName) > 0 {
var failureDomain *configv1.NutanixFailureDomain

for _, fd := range n.failureDomains {
if fd.Name == n.failureDomainName {
failureDomain = ptr.To[configv1.NutanixFailureDomain](fd)
break
}
}

if failureDomain == nil {
// The failureDomainName is not found in the Infrastructure resource
panic(fmt.Sprintf("The failure domain with name %q is not configured.", n.failureDomainName))
}

providerConfig.FailureDomain = &machinev1.NutanixFailureDomainReference{
Name: failureDomain.Name,
}

// update Cluster
providerConfig.Cluster = machinev1.NutanixResourceIdentifier{
Name: failureDomain.Cluster.Name,
UUID: failureDomain.Cluster.UUID,
}

switch failureDomain.Cluster.Type {
case configv1.NutanixIdentifierName:
providerConfig.Cluster.Type = machinev1.NutanixIdentifierName
case configv1.NutanixIdentifierUUID:
providerConfig.Cluster.Type = machinev1.NutanixIdentifierUUID
default:
}

// update Subnets
providerConfig.Subnets = []machinev1.NutanixResourceIdentifier{}

for _, fdSubnet := range failureDomain.Subnets {
pcSubnet := machinev1.NutanixResourceIdentifier{
Name: fdSubnet.Name,
UUID: fdSubnet.UUID,
}

switch fdSubnet.Type {
case configv1.NutanixIdentifierName:
pcSubnet.Type = machinev1.NutanixIdentifierName
case configv1.NutanixIdentifierUUID:
pcSubnet.Type = machinev1.NutanixIdentifierUUID
default:
}

providerConfig.Subnets = append(providerConfig.Subnets, pcSubnet)
}
}

return providerConfig
}

// BuildRawExtension builds a new Nutanix machine config based on the configuration provided.
func (n *NutanixMachineProviderConfigBuilder) BuildRawExtension() *runtime.RawExtension {
providerConfig := n.Build()

raw, err := json.Marshal(providerConfig)
if err != nil {
// As we are building the input to json.Marshal, this should never happen.
panic(err)
}

return &runtime.RawExtension{
Raw: raw,
}
}

// WithFailureDomains sets the failureDomains field with the input value.
func (n *NutanixMachineProviderConfigBuilder) WithFailureDomains(failureDomains []configv1.NutanixFailureDomain) *NutanixMachineProviderConfigBuilder {
n.failureDomains = failureDomains
return n
}

// WithFailureDomainName sets the failureDomainName field with the input value.
func (n *NutanixMachineProviderConfigBuilder) WithFailureDomainName(failureDomainName string) *NutanixMachineProviderConfigBuilder {
n.failureDomainName = failureDomainName
return n
}
Loading