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-20231002140248-174e989c9ee1
github.com/openshift/api v0.0.0-20231025170628-b8a18fdc040d
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-20231002140248-174e989c9ee1 h1:a50eFxcKkdrH+tVjou4zOKH0RgSRmeeNdzucSqJlJ4I=
github.com/openshift/api v0.0.0-20231002140248-174e989c9ee1/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
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/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
90 changes: 90 additions & 0 deletions testutils/resourcebuilder/config/v1/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,96 @@ func (i InfrastructureBuilder) AsOpenStack(name string) InfrastructureBuilder {
return i
}

// AsVSphere sets the Status for the infrastructure builder.
func (i InfrastructureBuilder) AsVSphere(name string) InfrastructureBuilder {
i.spec = &configv1.InfrastructureSpec{
PlatformSpec: configv1.PlatformSpec{
Type: configv1.VSpherePlatformType,
VSphere: &configv1.VSpherePlatformSpec{},
},
}
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.VSpherePlatformType,
VSphere: &configv1.VSpherePlatformStatus{
APIServerInternalIPs: []string{"10.0.0.5"},
IngressIPs: []string{"10.0.0.7"},
},
},
}

return i
}

// AsVSphereWithFailureDomains returns a VSphere infrastructure resource with failure domains.
// if failureDomains = nil, default failure domains will be applied to the resource which are
// compatible with machinev1beta1resourcebuilder default failure domain names.
func (i InfrastructureBuilder) AsVSphereWithFailureDomains(name string, failureDomains *[]configv1.VSpherePlatformFailureDomainSpec) InfrastructureBuilder {
infraBuilder := i.AsVSphere(name)
if failureDomains != nil {
infraBuilder.spec.PlatformSpec.VSphere.FailureDomains = *failureDomains
} else {
infraBuilder.spec.PlatformSpec.VSphere.FailureDomains = []configv1.VSpherePlatformFailureDomainSpec{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to use the failure domain builder here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i think it might. i'll take a look at that.

{
Name: "us-central1-a",
Region: "us-central",
Zone: "1-a",
Server: "vcenter.test.com",
Topology: configv1.VSpherePlatformTopology{
Datacenter: "test-dc1",
ComputeCluster: "test-cluster-1",
Networks: []string{
"test-network-1",
},
Datastore: "/test-dc1/datastore/test-datastore-1",
ResourcePool: "/test-dc1/hosts/test-cluster-1/resources",
},
},
{
Name: "us-central1-b",
Region: "us-central",
Zone: "1-b",
Server: "vcenter.test.com",
Topology: configv1.VSpherePlatformTopology{
Datacenter: "test-dc2",
ComputeCluster: "test-cluster-2",
Networks: []string{
"test-network-2",
},
Datastore: "/test-dc2/datastore/test-datastore-2",
ResourcePool: "/test-dc2/hosts/test-cluster-2/resources",
},
},
{
Name: "us-central1-c",
Region: "us-central",
Zone: "1-c",
Server: "vcenter.test.com",
Topology: configv1.VSpherePlatformTopology{
Datacenter: "test-dc3",
ComputeCluster: "test-cluster-3",
Networks: []string{
"test-network-3",
},
Datastore: "/test-dc3/datastore/test-datastore-3",
ResourcePool: "/test-dc3/hosts/test-cluster-3/resources",
},
},
}
}

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

return i
}

// WithGenerateName sets the generateName for the infrastructure builder.
func (i InfrastructureBuilder) WithGenerateName(generateName string) InfrastructureBuilder {
i.generateName = generateName
Expand Down
89 changes: 89 additions & 0 deletions testutils/resourcebuilder/machine/v1/vsphere_failure_domains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
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.
*/

// Linter warns about duplicated code with OpenStack, VSphere, and Azure FailureDomains builders.
// While the builders are almost identical, we need to keep them separate because they build different objects.
//
//nolint:dupl
package v1

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

// VSphereFailureDomains creates a new failure domains builder for VSphere.
func VSphereFailureDomains() VSphereFailureDomainsBuilder {
return VSphereFailureDomainsBuilder{[]VSphereFailureDomainBuilder{
VSphereFailureDomain().WithZone("us-central1-a"),
VSphereFailureDomain().WithZone("us-central1-b"),
VSphereFailureDomain().WithZone("us-central1-c"),
}}
}

// VSphereFailureDomainsBuilder is used to build a failuredomains.
type VSphereFailureDomainsBuilder struct {
failureDomainsBuilders []VSphereFailureDomainBuilder
}

// BuildFailureDomains builds a failuredomains from the configuration.
func (g VSphereFailureDomainsBuilder) BuildFailureDomains() machinev1.FailureDomains {
fds := machinev1.FailureDomains{
Platform: configv1.VSpherePlatformType,
VSphere: []machinev1.VSphereFailureDomain{},
}

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

return fds
}

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

// WithFailureDomainBuilders replaces the failure domains builder's builders with the given builders.
func (g VSphereFailureDomainsBuilder) WithFailureDomainBuilders(fdbuilders ...VSphereFailureDomainBuilder) VSphereFailureDomainsBuilder {
g.failureDomainsBuilders = fdbuilders
return g
}

// VSphereFailureDomain creates a new VSphere failure domain builder for VSphere.
func VSphereFailureDomain() VSphereFailureDomainBuilder {
return VSphereFailureDomainBuilder{}
}

// VSphereFailureDomainBuilder is used to build a VSphere failuredomain.
type VSphereFailureDomainBuilder struct {
Name string
}

// Build builds a VSphere failuredomain from the configuration.
func (g VSphereFailureDomainBuilder) Build() machinev1.VSphereFailureDomain {
return machinev1.VSphereFailureDomain{
Name: g.Name,
}
}

// WithZone sets the zone for the VSphere failuredomain builder.
func (g VSphereFailureDomainBuilder) WithZone(name string) VSphereFailureDomainBuilder {
g.Name = name
return g
}
106 changes: 98 additions & 8 deletions testutils/resourcebuilder/machine/v1beta1/vsphere_provider_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ package v1beta1

import (
"encoding/json"
"fmt"

configv1 "github.com/openshift/api/config/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
configv1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/config/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -34,11 +37,74 @@ func VSphereProviderSpec() VSphereProviderSpecBuilder {

// VSphereProviderSpecBuilder is used to build out a VSphere machine config object.
type VSphereProviderSpecBuilder struct {
template string
template string
cpmsProviderSpec bool
failureDomainName string
infrastructure *configv1.Infrastructure
ippool bool
}

// Build builds a new VSphere machine config based on the configuration provided.
func (v VSphereProviderSpecBuilder) Build() *machinev1beta1.VSphereMachineProviderSpec {
var networkDevices []machinev1beta1.NetworkDeviceSpec

if v.infrastructure == nil {
v.infrastructure = configv1resourcebuilder.Infrastructure().AsVSphereWithFailureDomains("vsphere-test", nil).Build()
}

failureDomains := v.infrastructure.Spec.PlatformSpec.VSphere.FailureDomains

workspace := &machinev1beta1.Workspace{
Server: "test-vcenter",
Datacenter: "test-datacenter",
Datastore: "test-datastore",
ResourcePool: "/test-datacenter/hosts/test-cluster/resources",
}
networkDevices = []machinev1beta1.NetworkDeviceSpec{
{
NetworkName: "test-network",
},
}

if v.ippool {
networkDevices[0].AddressesFromPools = []machinev1beta1.AddressesFromPool{
{
Group: "test",
Resource: "IPpool",
Name: "test",
},
}
}

template := v.template

if len(failureDomains) > 0 {
if v.cpmsProviderSpec {
workspace = &machinev1beta1.Workspace{}
networkDevices = nil
template = ""
} else {
for _, vSphereFailureDomain := range failureDomains {
if vSphereFailureDomain.Name == v.failureDomainName {
workspace = &machinev1beta1.Workspace{
Server: vSphereFailureDomain.Server,
Datacenter: vSphereFailureDomain.Topology.Datacenter,
Datastore: vSphereFailureDomain.Topology.Datastore,
ResourcePool: fmt.Sprintf("/%s/hosts/%s/resources",
vSphereFailureDomain.Topology.Datacenter,
vSphereFailureDomain.Topology.ComputeCluster),
}
networkDevices = []machinev1beta1.NetworkDeviceSpec{
{
NetworkName: vSphereFailureDomain.Topology.Networks[0],
},
}
template = v.template
}
}
}
}

return &machinev1beta1.VSphereMachineProviderSpec{
TypeMeta: metav1.TypeMeta{
Kind: "VSphereMachineProviderSpec",
Expand All @@ -54,14 +120,11 @@ func (v VSphereProviderSpecBuilder) Build() *machinev1beta1.VSphereMachineProvid
Name: "vsphere-cloud-credentials",
},
Network: machinev1beta1.NetworkSpec{
Devices: []machinev1beta1.NetworkDeviceSpec{
{
NetworkName: "test-segment-01",
},
},
Devices: networkDevices,
},
NumCPUs: 4,
Template: v.template,
Workspace: workspace,
NumCPUs: 4,
Template: template,
}
}

Expand All @@ -80,8 +143,35 @@ func (v VSphereProviderSpecBuilder) BuildRawExtension() *runtime.RawExtension {
}
}

// AsControlPlaneMachineSetProviderSpec the control plane machine set providerConfig is derived from the
// infrastructure spec. when failure domains are used to populate the provider spec of descendant machines,
// the cpms provider spec workspace, template, and network are left uninitialized to prevent ambiguity as
// the provider spec is not used to populate the workspace, template, and network.
func (v VSphereProviderSpecBuilder) AsControlPlaneMachineSetProviderSpec() VSphereProviderSpecBuilder {
v.cpmsProviderSpec = true
return v
}

// WithInfrastructure sets the template for the VSphere machine config builder.
func (v VSphereProviderSpecBuilder) WithInfrastructure(infrastructure configv1.Infrastructure) VSphereProviderSpecBuilder {
v.infrastructure = &infrastructure
return v
}

// WithTemplate sets the template for the VSphere machine config builder.
func (v VSphereProviderSpecBuilder) WithTemplate(template string) VSphereProviderSpecBuilder {
v.template = template
return v
}

// WithZone sets the zone for the VSphere machine config builder.
func (v VSphereProviderSpecBuilder) WithZone(zone string) VSphereProviderSpecBuilder {
v.failureDomainName = zone
return v
}

// WithIPPool sets the ippool for the VSphere machine config builder.
func (v VSphereProviderSpecBuilder) WithIPPool() VSphereProviderSpecBuilder {
v.ippool = true
return v
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading