From b6e9a99106e5bfc610ee4f3fe218d72faf2ee556 Mon Sep 17 00:00:00 2001 From: Efim Smykov Date: Thu, 18 Jul 2024 15:42:09 +0300 Subject: [PATCH] fix comments --- apis/v1alpha3/topology_conversion.go | 9 +--- .../vspherefailuredomainspec_conversion.go | 35 ---------------- apis/v1alpha3/zz_generated.conversion.go | 15 ++++--- apis/v1alpha4/topology_conversion.go | 9 +--- .../vspherefailuredomainspec_conversion.go | 35 ---------------- apis/v1alpha4/zz_generated.conversion.go | 15 ++++--- apis/v1beta1/vspherefailuredomain_types.go | 6 +-- ...luster.x-k8s.io_vspherefailuredomains.yaml | 8 ++-- ...vspheredeploymentzone_controller_domain.go | 4 +- pkg/services/vimmachine.go | 42 +++++++++---------- pkg/services/vimmachine_test.go | 6 +-- 11 files changed, 55 insertions(+), 129 deletions(-) delete mode 100644 apis/v1alpha3/vspherefailuredomainspec_conversion.go delete mode 100644 apis/v1alpha4/vspherefailuredomainspec_conversion.go diff --git a/apis/v1alpha3/topology_conversion.go b/apis/v1alpha3/topology_conversion.go index aded5d63da..6fe140b1e6 100644 --- a/apis/v1alpha3/topology_conversion.go +++ b/apis/v1alpha3/topology_conversion.go @@ -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) } diff --git a/apis/v1alpha3/vspherefailuredomainspec_conversion.go b/apis/v1alpha3/vspherefailuredomainspec_conversion.go deleted file mode 100644 index 03890dddb2..0000000000 --- a/apis/v1alpha3/vspherefailuredomainspec_conversion.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -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 v1alpha3 - -import ( - conversion "k8s.io/apimachinery/pkg/conversion" - v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" -) - -func Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec(in *v1beta1.VSphereFailureDomainSpec, out *VSphereFailureDomainSpec, s conversion.Scope) error { - if err := Convert_v1beta1_FailureDomain_To_v1alpha3_FailureDomain(&in.Region, &out.Region, s); err != nil { - return err - } - if err := Convert_v1beta1_FailureDomain_To_v1alpha3_FailureDomain(&in.Zone, &out.Zone, s); err != nil { - return err - } - if err := Convert_v1beta1_Topology_To_v1alpha3_Topology(&in.Topology, &out.Topology, s); err != nil { - return err - } - return nil -} diff --git a/apis/v1alpha3/zz_generated.conversion.go b/apis/v1alpha3/zz_generated.conversion.go index a99972e6f2..a3223189ae 100644 --- a/apis/v1alpha3/zz_generated.conversion.go +++ b/apis/v1alpha3/zz_generated.conversion.go @@ -285,6 +285,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1beta1.VSphereFailureDomainSpec)(nil), (*VSphereFailureDomainSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec(a.(*v1beta1.VSphereFailureDomainSpec), b.(*VSphereFailureDomainSpec), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*VSphereIdentityReference)(nil), (*v1beta1.VSphereIdentityReference)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_VSphereIdentityReference_To_v1beta1_VSphereIdentityReference(a.(*VSphereIdentityReference), b.(*v1beta1.VSphereIdentityReference), scope) }); err != nil { @@ -465,11 +470,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta1.VSphereFailureDomainSpec)(nil), (*VSphereFailureDomainSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec(a.(*v1beta1.VSphereFailureDomainSpec), b.(*VSphereFailureDomainSpec), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*v1beta1.VSphereMachineSpec)(nil), (*VSphereMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_VSphereMachineSpec_To_v1alpha3_VSphereMachineSpec(a.(*v1beta1.VSphereMachineSpec), b.(*VSphereMachineSpec), scope) }); err != nil { @@ -1286,6 +1286,11 @@ func autoConvert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDoma return nil } +// Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec is an autogenerated conversion function. +func Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec(in *v1beta1.VSphereFailureDomainSpec, out *VSphereFailureDomainSpec, s conversion.Scope) error { + return autoConvert_v1beta1_VSphereFailureDomainSpec_To_v1alpha3_VSphereFailureDomainSpec(in, out, s) +} + func autoConvert_v1alpha3_VSphereIdentityReference_To_v1beta1_VSphereIdentityReference(in *VSphereIdentityReference, out *v1beta1.VSphereIdentityReference, s conversion.Scope) error { out.Kind = v1beta1.VSphereIdentityKind(in.Kind) out.Name = in.Name diff --git a/apis/v1alpha4/topology_conversion.go b/apis/v1alpha4/topology_conversion.go index 758c18646c..fa5f515940 100644 --- a/apis/v1alpha4/topology_conversion.go +++ b/apis/v1alpha4/topology_conversion.go @@ -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) } diff --git a/apis/v1alpha4/vspherefailuredomainspec_conversion.go b/apis/v1alpha4/vspherefailuredomainspec_conversion.go deleted file mode 100644 index 5eeccad973..0000000000 --- a/apis/v1alpha4/vspherefailuredomainspec_conversion.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -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 v1alpha4 - -import ( - conversion "k8s.io/apimachinery/pkg/conversion" - v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" -) - -func Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec(in *v1beta1.VSphereFailureDomainSpec, out *VSphereFailureDomainSpec, s conversion.Scope) error { - if err := Convert_v1beta1_FailureDomain_To_v1alpha4_FailureDomain(&in.Region, &out.Region, s); err != nil { - return err - } - if err := Convert_v1beta1_FailureDomain_To_v1alpha4_FailureDomain(&in.Zone, &out.Zone, s); err != nil { - return err - } - if err := Convert_v1beta1_Topology_To_v1alpha4_Topology(&in.Topology, &out.Topology, s); err != nil { - return err - } - return nil -} diff --git a/apis/v1alpha4/zz_generated.conversion.go b/apis/v1alpha4/zz_generated.conversion.go index c0eee66d30..a348b92c47 100644 --- a/apis/v1alpha4/zz_generated.conversion.go +++ b/apis/v1alpha4/zz_generated.conversion.go @@ -330,6 +330,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1beta1.VSphereFailureDomainSpec)(nil), (*VSphereFailureDomainSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec(a.(*v1beta1.VSphereFailureDomainSpec), b.(*VSphereFailureDomainSpec), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*VSphereIdentityReference)(nil), (*v1beta1.VSphereIdentityReference)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_VSphereIdentityReference_To_v1beta1_VSphereIdentityReference(a.(*VSphereIdentityReference), b.(*v1beta1.VSphereIdentityReference), scope) }); err != nil { @@ -505,11 +510,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta1.VSphereFailureDomainSpec)(nil), (*VSphereFailureDomainSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec(a.(*v1beta1.VSphereFailureDomainSpec), b.(*VSphereFailureDomainSpec), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*v1beta1.VSphereMachineSpec)(nil), (*VSphereMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_VSphereMachineSpec_To_v1alpha4_VSphereMachineSpec(a.(*v1beta1.VSphereMachineSpec), b.(*VSphereMachineSpec), scope) }); err != nil { @@ -1440,6 +1440,11 @@ func autoConvert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDoma return nil } +// Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec is an autogenerated conversion function. +func Convert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec(in *v1beta1.VSphereFailureDomainSpec, out *VSphereFailureDomainSpec, s conversion.Scope) error { + return autoConvert_v1beta1_VSphereFailureDomainSpec_To_v1alpha4_VSphereFailureDomainSpec(in, out, s) +} + func autoConvert_v1alpha4_VSphereIdentityReference_To_v1beta1_VSphereIdentityReference(in *VSphereIdentityReference, out *v1beta1.VSphereIdentityReference, s conversion.Scope) error { out.Kind = v1beta1.VSphereIdentityKind(in.Kind) out.Name = in.Name diff --git a/apis/v1beta1/vspherefailuredomain_types.go b/apis/v1beta1/vspherefailuredomain_types.go index 8fe7f3e9d6..e3f10786c2 100644 --- a/apis/v1beta1/vspherefailuredomain_types.go +++ b/apis/v1beta1/vspherefailuredomain_types.go @@ -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"` @@ -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"` diff --git a/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml b/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml index 11af6ee782..4dfe3521f8 100644 --- a/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml +++ b/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml @@ -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 @@ -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: |- @@ -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: |- diff --git a/controllers/vspheredeploymentzone_controller_domain.go b/controllers/vspheredeploymentzone_controller_domain.go index 117955f20e..8940dcb490 100644 --- a/controllers/vspheredeploymentzone_controller_domain.go +++ b/controllers/vspheredeploymentzone_controller_domain.go @@ -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) } } @@ -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) } } diff --git a/pkg/services/vimmachine.go b/pkg/services/vimmachine.go index 22e29bc401..0da86f6a25 100644 --- a/pkg/services/vimmachine.go +++ b/pkg/services/vimmachine.go @@ -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) } } return overrideWithFailureDomainFunc, true @@ -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) } } diff --git a/pkg/services/vimmachine_test.go b/pkg/services/vimmachine_test.go index f1371c9678..fd617489b0 100644 --- a/pkg/services/vimmachine_test.go +++ b/pkg/services/vimmachine_test.go @@ -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{ NetworkName: "ignored", }) @@ -332,7 +332,7 @@ func Test_mergeFailureDomainNetSpecToNetworkDeviceSpec(t *testing.T) { device := infrav1.NetworkDeviceSpec{} - mergeFailureDomainNetSpecToNetworkDeviceSpec(&device, infrav1.NetworkConfiguration{ + mergeNetworkConfigurationToNetworkDeviceSpec(&device, infrav1.NetworkConfiguration{ NetworkName: "nw-name", DHCP4: ptr.To(true), DHCP6: ptr.To(false),