Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutrymaco committed Jul 18, 2024
1 parent bb6223c commit b6e9a99
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 129 deletions.
9 changes: 1 addition & 8 deletions apis/v1alpha3/topology_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,5 @@ import (
)

func Convert_v1beta1_Topology_To_v1alpha3_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
if len(in.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[i].NetworkName
}
out.Networks = networks
}
return nil
return autoConvert_v1beta1_Topology_To_v1alpha3_Topology(in, out, s)
}
35 changes: 0 additions & 35 deletions apis/v1alpha3/vspherefailuredomainspec_conversion.go

This file was deleted.

15 changes: 10 additions & 5 deletions apis/v1alpha3/zz_generated.conversion.go

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

9 changes: 1 addition & 8 deletions apis/v1alpha4/topology_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,5 @@ import (
)

func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
if len(in.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[i].NetworkName
}
out.Networks = networks
}
return nil
return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s)
}
35 changes: 0 additions & 35 deletions apis/v1alpha4/vspherefailuredomainspec_conversion.go

This file was deleted.

15 changes: 10 additions & 5 deletions apis/v1alpha4/zz_generated.conversion.go

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

6 changes: 3 additions & 3 deletions apis/v1beta1/vspherefailuredomain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Topology struct {
// +optional
Networks []string `json:"networks,omitempty"`

// NetworkConfigurations is a list with new network configurations within this failure domain
// NetworkConfigurations is a list of network configurations within this failure domain.
// +optional
NetworkConfigurations []NetworkConfiguration `json:"networkConfigs,omitempty"`

Expand All @@ -98,11 +98,11 @@ type NetworkConfiguration struct {
// NetworkName is the network name for this machine's VM.
NetworkName string `json:"name,omitempty"`

// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4
// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4.
// +optional
DHCP4 *bool `json:"dhcp4,omitempty"`

// DHCP6 is a flag that indicates whether or not to use DHCP for IPv6
// DHCP6 is a flag that indicates whether or not to use DHCP for IPv6.
// +optional
DHCP6 *bool `json:"dhcp6,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ spec:
- vmGroupName
type: object
networkConfigs:
description: NetworkConfigurations is a list with new network
configurations within this failure domain
description: NetworkConfigurations is a list of network configurations
within this failure domain.
items:
description: |-
NetworkConfiguration defines a network configuration that should be used when consuming
Expand Down Expand Up @@ -403,7 +403,7 @@ spec:
type: array
dhcp4:
description: DHCP4 is a flag that indicates whether or not
to use DHCP for IPv4
to use DHCP for IPv4.
type: boolean
dhcp4Overrides:
description: |-
Expand Down Expand Up @@ -464,7 +464,7 @@ spec:
type: object
dhcp6:
description: DHCP6 is a flag that indicates whether or not
to use DHCP for IPv6
to use DHCP for IPv6.
type: boolean
dhcp6Overrides:
description: |-
Expand Down
4 changes: 2 additions & 2 deletions controllers/vspheredeploymentzone_controller_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r vsphereDeploymentZoneReconciler) reconcileTopology(ctx context.Context,

for _, network := range topology.Networks {
if _, err := deploymentZoneCtx.AuthSession.Finder.Network(ctx, network); err != nil {
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition, infrav1.NetworkNotFoundReason, clusterv1.ConditionSeverityError, "network %s is misconfigured", network)
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition, infrav1.NetworkNotFoundReason, clusterv1.ConditionSeverityError, "network %s is not found", network)
return errors.Wrapf(err, "unable to find network %s", network)
}
}
Expand All @@ -105,7 +105,7 @@ func (r vsphereDeploymentZoneReconciler) reconcileTopology(ctx context.Context,
continue
}
if _, err := deploymentZoneCtx.AuthSession.Finder.Network(ctx, networkConfig.NetworkName); err != nil {
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition, infrav1.NetworkNotFoundReason, clusterv1.ConditionSeverityError, "network %s is misconfigured", networkConfig.NetworkName)
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition, infrav1.NetworkNotFoundReason, clusterv1.ConditionSeverityError, "network %s is not found", networkConfig.NetworkName)
return errors.Wrapf(err, "unable to find network %s", networkConfig.NetworkName)
}
}
Expand Down
42 changes: 21 additions & 21 deletions pkg/services/vimmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (v *VimMachineService) generateOverrideFunc(ctx context.Context, vimMachine
vm.Spec.Network.Devices = overrideNetworkDeviceSpecs(vm.Spec.Network.Devices, vsphereFailureDomain.Spec.Topology.Networks, mergeFailureDomainNetworkName)
}
if len(vsphereFailureDomain.Spec.Topology.NetworkConfigurations) > 0 {
vm.Spec.Network.Devices = overrideNetworkDeviceSpecs(vm.Spec.Network.Devices, vsphereFailureDomain.Spec.Topology.NetworkConfigurations, mergeFailureDomainNetSpecToNetworkDeviceSpec)
vm.Spec.Network.Devices = overrideNetworkDeviceSpecs(vm.Spec.Network.Devices, vsphereFailureDomain.Spec.Topology.NetworkConfigurations, mergeNetworkConfigurationToNetworkDeviceSpec)

Check failure on line 443 in pkg/services/vimmachine.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec) (typecheck)

Check failure on line 443 in pkg/services/vimmachine.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec) (typecheck)

Check failure on line 443 in pkg/services/vimmachine.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec) (typecheck)

Check failure on line 443 in pkg/services/vimmachine.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec
}
}
return overrideWithFailureDomainFunc, true
Expand Down Expand Up @@ -477,39 +477,39 @@ func mergeFailureDomainNetworkName(device *infrav1.NetworkDeviceSpec, network st
device.NetworkName = network
}

func mergeFailureDomainNetSpecToNetworkDeviceSpec(device *infrav1.NetworkDeviceSpec, fd infrav1.NetworkConfiguration) {
func mergeNetworkConfigurationInNetworkDeviceSpec(device *infrav1.NetworkDeviceSpec, nc infrav1.NetworkConfiguration) {
if device == nil {
return
}
if fd.NetworkName != "" {
device.NetworkName = fd.NetworkName
if nc.NetworkName != "" {
device.NetworkName = nc.NetworkName
}
if fd.DHCP4 != nil {
device.DHCP4 = *fd.DHCP4
if nc.DHCP4 != nil {
device.DHCP4 = *nc.DHCP4
}
if fd.DHCP6 != nil {
device.DHCP6 = *fd.DHCP6
if nc.DHCP6 != nil {
device.DHCP6 = *nc.DHCP6
}
if len(fd.Nameservers) > 0 {
device.Nameservers = make([]string, len(fd.Nameservers))
copy(device.Nameservers, fd.Nameservers)
if len(nc.Nameservers) > 0 {
device.Nameservers = make([]string, len(nc.Nameservers))
copy(device.Nameservers, nc.Nameservers)
}

if len(fd.SearchDomains) > 0 {
device.SearchDomains = make([]string, len(fd.SearchDomains))
copy(device.SearchDomains, fd.SearchDomains)
if len(nc.SearchDomains) > 0 {
device.SearchDomains = make([]string, len(nc.SearchDomains))
copy(device.SearchDomains, nc.SearchDomains)
}

if fd.DHCP4Overrides != nil {
device.DHCP4Overrides = fd.DHCP4Overrides.DeepCopy()
if nc.DHCP4Overrides != nil {
device.DHCP4Overrides = nc.DHCP4Overrides.DeepCopy()
}

if fd.DHCP6Overrides != nil {
device.DHCP6Overrides = fd.DHCP6Overrides.DeepCopy()
if nc.DHCP6Overrides != nil {
device.DHCP6Overrides = nc.DHCP6Overrides.DeepCopy()
}

if len(fd.AddressesFromPools) > 0 {
device.AddressesFromPools = make([]corev1.TypedLocalObjectReference, len(fd.AddressesFromPools))
copy(device.AddressesFromPools, fd.AddressesFromPools)
if len(nc.AddressesFromPools) > 0 {
device.AddressesFromPools = make([]corev1.TypedLocalObjectReference, len(nc.AddressesFromPools))
copy(device.AddressesFromPools, nc.AddressesFromPools)
}
}
6 changes: 3 additions & 3 deletions pkg/services/vimmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) {
})
}

func Test_mergeFailureDomainNetSpecToNetworkDeviceSpec(t *testing.T) {
func Test_mergeNetworkConfigurationToNetworkDeviceSpec(t *testing.T) {
t.Run("device is nil", func(t *testing.T) {
g := NewWithT(t)

var device *infrav1.NetworkDeviceSpec
mergeFailureDomainNetSpecToNetworkDeviceSpec(device, infrav1.NetworkConfiguration{
mergeNetworkConfigurationToNetworkDeviceSpec(device, infrav1.NetworkConfiguration{

Check failure on line 323 in pkg/services/vimmachine_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec
NetworkName: "ignored",
})

Expand All @@ -332,7 +332,7 @@ func Test_mergeFailureDomainNetSpecToNetworkDeviceSpec(t *testing.T) {

device := infrav1.NetworkDeviceSpec{}

mergeFailureDomainNetSpecToNetworkDeviceSpec(&device, infrav1.NetworkConfiguration{
mergeNetworkConfigurationToNetworkDeviceSpec(&device, infrav1.NetworkConfiguration{

Check failure on line 335 in pkg/services/vimmachine_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mergeNetworkConfigurationToNetworkDeviceSpec (typecheck)
NetworkName: "nw-name",
DHCP4: ptr.To(true),
DHCP6: ptr.To(false),
Expand Down

0 comments on commit b6e9a99

Please sign in to comment.