Skip to content

Commit 4b8978c

Browse files
committed
fix
1 parent cc001db commit 4b8978c

File tree

5 files changed

+14
-30
lines changed

5 files changed

+14
-30
lines changed

apis/v1beta1/vspherefailuredomain_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ type Topology struct {
8585
// NetworkConfigurations is a list of network configurations within this failure domain.
8686
// +optional
8787
// +listType=map
88-
// +listMapKey=name
89-
NetworkConfigurations []NetworkConfiguration `json:"networkConfigs,omitempty"`
88+
// +listMapKey=networkName
89+
NetworkConfigurations []NetworkConfiguration `json:"networkConfigurations,omitempty"`
9090

9191
// Datastore is the name or inventory path of the datastore in which the
9292
// virtual machine is created/located.
@@ -99,7 +99,7 @@ type Topology struct {
9999
type NetworkConfiguration struct {
100100
// NetworkName is the network name for this machine's VM.
101101
// +kubebuilder:validation:Required
102-
NetworkName string `json:"name"`
102+
NetworkName string `json:"networkName"`
103103

104104
// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4.
105105
// +optional

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ spec:
365365
- hostGroupName
366366
- vmGroupName
367367
type: object
368-
networkConfigs:
368+
networkConfigurations:
369369
description: NetworkConfigurations is a list of network configurations
370370
within this failure domain.
371371
items:
@@ -523,10 +523,6 @@ spec:
523523
in the routing table.
524524
type: string
525525
type: object
526-
name:
527-
description: NetworkName is the network name for this machine's
528-
VM.
529-
type: string
530526
nameservers:
531527
description: |-
532528
Nameservers is a list of IPv4 and/or IPv6 addresses used as DNS
@@ -535,6 +531,10 @@ spec:
535531
items:
536532
type: string
537533
type: array
534+
networkName:
535+
description: NetworkName is the network name for this machine's
536+
VM.
537+
type: string
538538
searchDomains:
539539
description: |-
540540
SearchDomains is a list of search domains used when resolving IP
@@ -543,11 +543,11 @@ spec:
543543
type: string
544544
type: array
545545
required:
546-
- name
546+
- networkName
547547
type: object
548548
type: array
549549
x-kubernetes-list-map-keys:
550-
- name
550+
- networkName
551551
x-kubernetes-list-type: map
552552
networks:
553553
description: Networks is the list of networks within this failure

internal/webhooks/vspherefailuredomain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ func (webhook *VSphereFailureDomainWebhook) ValidateCreate(_ context.Context, ra
7878
}
7979

8080
if len(obj.Spec.Topology.NetworkConfigurations) != 0 && len(obj.Spec.Topology.Networks) != 0 {
81-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "topology", "networks"), "cannot be set if spec.topology.networkConfigs is already set"))
81+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "topology", "networks"), "cannot be set if spec.topology.networkConfigurations is already set"))
8282
}
8383

8484
for i, networkConfig := range obj.Spec.Topology.NetworkConfigurations {
8585
if networkConfig.NetworkName == "" {
86-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "topology", "networkConfigurations", fmt.Sprint(i), "name"), "cannot be empty"))
86+
allErrs = append(allErrs, field.Required(field.NewPath("spec", "topology", "networkConfigurations").Index(i).Child("networkName"), "cannot be empty"))
8787
}
8888
}
8989

pkg/services/vimmachine.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/types"
3030
kerrors "k8s.io/apimachinery/pkg/util/errors"
3131
"k8s.io/klog/v2"
32-
"k8s.io/utils/integer"
3332
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3433
clusterutilv1 "sigs.k8s.io/cluster-api/util"
3534
"sigs.k8s.io/cluster-api/util/conditions"
@@ -453,7 +452,7 @@ func (v *VimMachineService) generateOverrideFunc(ctx context.Context, vimMachine
453452
func overrideNetworkDeviceSpecs[T any](deviceSpecs []infrav1.NetworkDeviceSpec, networks []T, mergeFunc func(device *infrav1.NetworkDeviceSpec, network T)) []infrav1.NetworkDeviceSpec {
454453
index, length := 0, len(networks)
455454

456-
devices := make([]infrav1.NetworkDeviceSpec, 0, integer.IntMax(length, len(deviceSpecs)))
455+
devices := make([]infrav1.NetworkDeviceSpec, 0, max(length, len(deviceSpecs)))
457456
// override the networks on the VM spec with placement constraint network definitions
458457
for i := range deviceSpecs {
459458
vmNetworkDeviceSpec := deviceSpecs[i]
@@ -478,9 +477,6 @@ func mergeFailureDomainNetworkName(device *infrav1.NetworkDeviceSpec, network st
478477
}
479478

480479
func mergeNetworkConfigurationInNetworkDeviceSpec(device *infrav1.NetworkDeviceSpec, nc infrav1.NetworkConfiguration) {
481-
if device == nil {
482-
return
483-
}
484480
if nc.NetworkName != "" {
485481
device.NetworkName = nc.NetworkName
486482
}

pkg/services/vimmachine_test.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) {
7272
Topology: infrav1.Topology{
7373
Datacenter: fmt.Sprintf("dc-%s", suffix),
7474
Datastore: fmt.Sprintf("ds-%s", suffix),
75-
Networks: []string{fmt.Sprintf("nw-%s", suffix), "another-nw"},
7675
NetworkConfigurations: []infrav1.NetworkConfiguration{
7776
{
7877
NetworkName: fmt.Sprintf("nw-%s", suffix),
@@ -316,18 +315,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) {
316315
}
317316

318317
func Test_mergeNetworkConfigurationToNetworkDeviceSpec(t *testing.T) {
319-
t.Run("device is nil", func(t *testing.T) {
320-
g := NewWithT(t)
321-
322-
var device *infrav1.NetworkDeviceSpec
323-
mergeNetworkConfigurationInNetworkDeviceSpec(device, infrav1.NetworkConfiguration{
324-
NetworkName: "ignored",
325-
})
326-
327-
g.Expect(device).To(BeNil())
328-
})
329-
330-
t.Run("all fields from NetworkConfiguration are overrided", func(t *testing.T) {
318+
t.Run("all fields from NetworkConfiguration are overridden", func(t *testing.T) {
331319
g := NewWithT(t)
332320

333321
device := infrav1.NetworkDeviceSpec{}

0 commit comments

Comments
 (0)