Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPLAT-1976: Add vSphere VM Host Zonal updates to testutils #373

Merged
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 testutils/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/golangci/golangci-lint v1.61.0
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/openshift/api v0.0.0-20240924155631-232984653385
github.com/openshift/api v0.0.0-20250106182855-361e35fd82e5
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.0
Expand Down
4 changes: 2 additions & 2 deletions testutils/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/openshift/api v0.0.0-20240924155631-232984653385 h1:P6O191HwBj0ahEfea2wkvxhmW2fzXhvCh8hwHDvUozM=
github.com/openshift/api v0.0.0-20240924155631-232984653385/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
github.com/openshift/api v0.0.0-20250106182855-361e35fd82e5 h1:sCuu1GPr/NFMrQt95plJ455BnssYfxycOSEl1oYOexs=
github.com/openshift/api v0.0.0-20250106182855-361e35fd82e5/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
Expand Down
38 changes: 37 additions & 1 deletion testutils/resourcebuilder/config/v1/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ limitations under the License.
package v1

import (
configv1 "github.com/openshift/api/config/v1"
"fmt"
"path"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

configv1 "github.com/openshift/api/config/v1"
)

// Infrastructure creates a new infrastructure builder.
Expand Down Expand Up @@ -348,6 +352,38 @@ func (i InfrastructureBuilder) AsVSphereWithFailureDomains(name string, failureD
return i
}

func (i InfrastructureBuilder) WithVSphereVMHostZonal() InfrastructureBuilder {
infraBuilder := i

for n := range infraBuilder.spec.PlatformSpec.VSphere.FailureDomains {
datacenter := "test-dc1"
cluster := "test-cluster-1"
datastore := "test-datastore-1"

fdName := infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].Name

infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].Topology.Datacenter = datacenter
infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].Topology.ComputeCluster = path.Join("/", datacenter, "host", cluster)
infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].Topology.Datastore = path.Join("/", datacenter, "datastore", datastore)
infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].Topology.ResourcePool = path.Join("/", datacenter, "host", cluster, "Resources")

infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].ZoneAffinity = &configv1.VSphereFailureDomainZoneAffinity{
Type: configv1.HostGroupFailureDomainZone,
HostGroup: &configv1.VSphereFailureDomainHostGroup{
VMGroup: fmt.Sprintf("%s-vm-group", fdName),
HostGroup: fmt.Sprintf("%s-host-group", fdName),
VMHostRule: fmt.Sprintf("%s-vm-host-rule", fdName),
},
}

infraBuilder.spec.PlatformSpec.VSphere.FailureDomains[n].RegionAffinity = &configv1.VSphereFailureDomainRegionAffinity{Type: configv1.ComputeClusterFailureDomainRegion}
}

i.spec = infraBuilder.spec

return i
}

// AsPowerVS sets the Status for the infrastructure builder.
func (i InfrastructureBuilder) AsPowerVS(name string) InfrastructureBuilder {
i.spec = &configv1.InfrastructureSpec{
Expand Down
48 changes: 26 additions & 22 deletions testutils/resourcebuilder/machine/v1beta1/vsphere_provider_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ 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"

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"
)

// VSphereProviderSpec creates a new VSphere machine config builder.
Expand Down Expand Up @@ -79,26 +80,29 @@ func (v VSphereProviderSpecBuilder) Build() *machinev1beta1.VSphereMachineProvid

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/Resources",
vSphereFailureDomain.Topology.ComputeCluster),
}
networkDevices[0].NetworkName = vSphereFailureDomain.Topology.Networks[0]
template = v.template

break
switch {
case v.cpmsProviderSpec && len(failureDomains) != 0:
workspace = &machinev1beta1.Workspace{}
networkDevices = nil
template = ""
case !v.cpmsProviderSpec && len(failureDomains) != 0:
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/Resources",
vSphereFailureDomain.Topology.ComputeCluster),
}
networkDevices[0].NetworkName = vSphereFailureDomain.Topology.Networks[0]
template = v.template

if vSphereFailureDomain.ZoneAffinity != nil && vSphereFailureDomain.ZoneAffinity.HostGroup != nil {
workspace.VMGroup = vSphereFailureDomain.ZoneAffinity.HostGroup.VMGroup
}

break
}
}
}
Expand Down

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

55 changes: 26 additions & 29 deletions testutils/vendor/github.com/openshift/api/config/v1/types.go

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

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

Loading