diff --git a/.golangci-kal.yml b/.golangci-kal.yml index aeea6bb77de1..606cb2359983 100644 --- a/.golangci-kal.yml +++ b/.golangci-kal.yml @@ -43,7 +43,7 @@ linters: lintersConfig: conditions: isFirstField: Warn # Require conditions to be the first field in the status struct. - usePatchStrategy: Forbid # Require conditions to be the first field in the status struct. + usePatchStrategy: Forbid # Forbid patchStrategy markers on the Conditions field. useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. optionalfields: pointers: @@ -171,11 +171,15 @@ linters: linters: - kubeapilinter - path: "api/core/v1beta2/cluster_types.go" - text: "optionalfields: field (ControlPlaneEndpoint|ControlPlane|Metadata) is optional and should (be a pointer|have the omitempty tag)" + text: "optionalfields: field (ClusterNetwork|Services|Pods|ControlPlaneEndpoint|ControlPlane|Workers|Metadata|Variables|Strategy) is optional and should (be a pointer|have the omitempty tag)" linters: - kubeapilinter - path: "api/core/v1beta2/clusterclass_types.go" - text: "optionalfields: field (Workers|Metadata|ControlPlane|Infrastructure|DeprecatedV1Beta1Metadata) is optional and should (be a pointer|have the omitempty tag)" + text: "optionalfields: field (Workers|Metadata|ControlPlane|Strategy|Infrastructure|DeprecatedV1Beta1Metadata) is optional and should (be a pointer|have the omitempty tag)" + linters: + - kubeapilinter + - path: "api/core/v1beta2/machinedeployment_types.go" + text: "optionalfields: field (Strategy|RollingUpdate|Remediation) is optional and should (be a pointer|have the omitempty tag)" linters: - kubeapilinter - path: "api/ipam/v1beta2/ipaddressclaim_types.go" @@ -184,7 +188,7 @@ linters: - kubeapilinter # KAL does not handle enum markers on enum types yet: https://github.com/kubernetes-sigs/kube-api-linter/issues/113 - path: ".*" - text: "optionalfields: field (Format|Encoding|Type|DeletePolicy|FailurePolicy) is optional and (should be a pointer|has a valid zero value)" + text: "optionalfields: field (Polarity|Format|Encoding|Type|DeletePolicy|FailurePolicy) is optional and (should be a pointer|has a valid zero value)" linters: - kubeapilinter diff --git a/api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go b/api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go index 6d9d8b1eda7a..8e969f3c2220 100644 --- a/api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go +++ b/api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go @@ -498,6 +498,7 @@ type KubeadmControlPlaneMachineTemplate struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []clusterv1.MachineReadinessGate `json:"readinessGates,omitempty"` diff --git a/api/core/v1beta1/conversion.go b/api/core/v1beta1/conversion.go index 679c0fc3c583..9a65233039ed 100644 --- a/api/core/v1beta1/conversion.go +++ b/api/core/v1beta1/conversion.go @@ -109,6 +109,11 @@ func (dst *Cluster) ConvertFrom(srcRaw conversion.Hub) error { dst.Spec.ControlPlaneRef = controlPlaneRef } + if dst.Spec.ClusterNetwork != nil && dst.Spec.ClusterNetwork.APIServerPort != nil && + *dst.Spec.ClusterNetwork.APIServerPort == 0 { + dst.Spec.ClusterNetwork.APIServerPort = nil + } + if dst.Spec.Topology != nil { if dst.Spec.Topology.ControlPlane.MachineHealthCheck != nil && dst.Spec.Topology.ControlPlane.MachineHealthCheck.RemediationTemplate != nil { dst.Spec.Topology.ControlPlane.MachineHealthCheck.RemediationTemplate.Namespace = dst.Namespace @@ -727,6 +732,11 @@ func Convert_v1beta1_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(in *Co if err := autoConvert_v1beta1_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(in, out, s); err != nil { return err } + if in.Variables != nil { + if err := autoConvert_v1beta1_ControlPlaneVariables_To_v1beta2_ControlPlaneVariables(in.Variables, &out.Variables, s); err != nil { + return err + } + } out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout) out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout) out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout) @@ -737,6 +747,12 @@ func Convert_v1beta2_ControlPlaneTopology_To_v1beta1_ControlPlaneTopology(in *cl if err := autoConvert_v1beta2_ControlPlaneTopology_To_v1beta1_ControlPlaneTopology(in, out, s); err != nil { return err } + if !reflect.DeepEqual(in.Variables, clusterv1.ControlPlaneVariables{}) { + out.Variables = &ControlPlaneVariables{} + if err := autoConvert_v1beta2_ControlPlaneVariables_To_v1beta1_ControlPlaneVariables(&in.Variables, out.Variables, s); err != nil { + return err + } + } out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds) out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds) out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds) @@ -747,6 +763,20 @@ func Convert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in if err := autoConvert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in, out, s); err != nil { return err } + if err := Convert_v1beta1_ObjectMeta_To_v1beta2_ObjectMeta(&in.Template.Metadata, &out.Metadata, s); err != nil { + return err + } + if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassBootstrapTemplate(&in.Template.Bootstrap, &out.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassInfrastructureTemplate(&in.Template.Infrastructure, &out.Infrastructure, s); err != nil { + return err + } + if in.Strategy != nil { + if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in.Strategy, &out.Strategy, s); err != nil { + return err + } + } out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout) out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout) out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout) @@ -757,6 +787,21 @@ func Convert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in if err := autoConvert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in, out, s); err != nil { return err } + if err := Convert_v1beta2_ObjectMeta_To_v1beta1_ObjectMeta(&in.Metadata, &out.Template.Metadata, s); err != nil { + return err + } + if err := Convert_v1beta2_MachineDeploymentClassBootstrapTemplate_To_v1beta1_LocalObjectTemplate(&in.Bootstrap, &out.Template.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1beta2_MachineDeploymentClassInfrastructureTemplate_To_v1beta1_LocalObjectTemplate(&in.Infrastructure, &out.Template.Infrastructure, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Strategy, clusterv1.MachineDeploymentStrategy{}) { + out.Strategy = &MachineDeploymentStrategy{} + if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(&in.Strategy, out.Strategy, s); err != nil { + return err + } + } out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds) out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds) out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds) @@ -767,6 +812,16 @@ func Convert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopol if err := autoConvert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopology(in, out, s); err != nil { return err } + if in.Variables != nil { + if err := autoConvert_v1beta1_MachineDeploymentVariables_To_v1beta2_MachineDeploymentVariables(in.Variables, &out.Variables, s); err != nil { + return err + } + } + if in.Strategy != nil { + if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in.Strategy, &out.Strategy, s); err != nil { + return err + } + } out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout) out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout) out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout) @@ -777,6 +832,18 @@ func Convert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopol if err := autoConvert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopology(in, out, s); err != nil { return err } + if !reflect.DeepEqual(in.Variables, clusterv1.MachineDeploymentVariables{}) { + out.Variables = &MachineDeploymentVariables{} + if err := autoConvert_v1beta2_MachineDeploymentVariables_To_v1beta1_MachineDeploymentVariables(&in.Variables, out.Variables, s); err != nil { + return err + } + } + if !reflect.DeepEqual(in.Strategy, clusterv1.MachineDeploymentStrategy{}) { + out.Strategy = &MachineDeploymentStrategy{} + if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(&in.Strategy, out.Strategy, s); err != nil { + return err + } + } out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds) out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds) out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds) @@ -787,6 +854,15 @@ func Convert_v1beta1_MachinePoolClass_To_v1beta2_MachinePoolClass(in *MachinePoo if err := autoConvert_v1beta1_MachinePoolClass_To_v1beta2_MachinePoolClass(in, out, s); err != nil { return err } + if err := Convert_v1beta1_ObjectMeta_To_v1beta2_ObjectMeta(&in.Template.Metadata, &out.Metadata, s); err != nil { + return err + } + if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachinePoolClassBootstrapTemplate(&in.Template.Bootstrap, &out.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachinePoolClassInfrastructureTemplate(&in.Template.Infrastructure, &out.Infrastructure, s); err != nil { + return err + } out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout) out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout) out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout) @@ -797,6 +873,15 @@ func Convert_v1beta2_MachinePoolClass_To_v1beta1_MachinePoolClass(in *clusterv1. if err := autoConvert_v1beta2_MachinePoolClass_To_v1beta1_MachinePoolClass(in, out, s); err != nil { return err } + if err := Convert_v1beta2_ObjectMeta_To_v1beta1_ObjectMeta(&in.Metadata, &out.Template.Metadata, s); err != nil { + return err + } + if err := Convert_v1beta2_MachinePoolClassBootstrapTemplate_To_v1beta1_LocalObjectTemplate(&in.Bootstrap, &out.Template.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1beta2_MachinePoolClassInfrastructureTemplate_To_v1beta1_LocalObjectTemplate(&in.Infrastructure, &out.Template.Infrastructure, s); err != nil { + return err + } out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds) out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds) out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds) @@ -807,6 +892,11 @@ func Convert_v1beta1_MachinePoolTopology_To_v1beta2_MachinePoolTopology(in *Mach if err := autoConvert_v1beta1_MachinePoolTopology_To_v1beta2_MachinePoolTopology(in, out, s); err != nil { return err } + if in.Variables != nil { + if err := autoConvert_v1beta1_MachinePoolVariables_To_v1beta2_MachinePoolVariables(in.Variables, &out.Variables, s); err != nil { + return err + } + } out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout) out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout) out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout) @@ -817,6 +907,12 @@ func Convert_v1beta2_MachinePoolTopology_To_v1beta1_MachinePoolTopology(in *clus if err := autoConvert_v1beta2_MachinePoolTopology_To_v1beta1_MachinePoolTopology(in, out, s); err != nil { return err } + if !reflect.DeepEqual(in.Variables, clusterv1.MachinePoolVariables{}) { + out.Variables = &MachinePoolVariables{} + if err := autoConvert_v1beta2_MachinePoolVariables_To_v1beta1_MachinePoolVariables(&in.Variables, out.Variables, s); err != nil { + return err + } + } out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds) out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds) out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds) @@ -953,7 +1049,11 @@ func Convert_v1beta1_Topology_To_v1beta2_Topology(in *Topology, out *clusterv1.T if err := autoConvert_v1beta1_Topology_To_v1beta2_Topology(in, out, s); err != nil { return err } - + if in.Workers != nil { + if err := autoConvert_v1beta1_WorkersTopology_To_v1beta2_WorkersTopology(in.Workers, &out.Workers, s); err != nil { + return err + } + } out.ClassRef.Name = in.Class out.ClassRef.Namespace = in.ClassNamespace return nil @@ -1031,17 +1131,17 @@ func Convert_v1beta2_Topology_To_v1beta1_Topology(in *clusterv1.Topology, out *T if err := autoConvert_v1beta2_Topology_To_v1beta1_Topology(in, out, s); err != nil { return err } - + if !reflect.DeepEqual(in.Workers, clusterv1.WorkersTopology{}) { + out.Workers = &WorkersTopology{} + if err := autoConvert_v1beta2_WorkersTopology_To_v1beta1_WorkersTopology(&in.Workers, out.Workers, s); err != nil { + return err + } + } out.Class = in.ClassRef.Name out.ClassNamespace = in.ClassRef.Namespace return nil } -func Convert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in *MachineDeploymentSpec, out *clusterv1.MachineDeploymentSpec, s apimachineryconversion.Scope) error { - // NOTE: v1beta2 MachineDeploymentSpec does not have ProgressDeadlineSeconds anymore. But it's fine to just lose this field it was never used. - return autoConvert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s) -} - func Convert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, out *MachineDeploymentStatus, s apimachineryconversion.Scope) error { if err := autoConvert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in, out, s); err != nil { return err @@ -1646,26 +1746,156 @@ func Convert_v1beta2_ClusterClassTemplateReference_To_v1beta1_LocalObjectTemplat } } -func Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *clusterv1.MachineRollingUpdateDeployment, s apimachineryconversion.Scope) error { - if err := autoConvert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in, out, s); err != nil { - return err - } +func Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in *MachineRollingUpdateDeployment, out *clusterv1.MachineDeploymentStrategyRollingUpdate, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge if in.DeletePolicy != nil { out.DeletePolicy = clusterv1.MachineSetDeletePolicy(*in.DeletePolicy) } return nil } -func Convert_v1beta2_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(in *clusterv1.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s apimachineryconversion.Scope) error { - if err := autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(in, out, s); err != nil { - return err - } +func Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1beta1_MachineRollingUpdateDeployment(in *clusterv1.MachineDeploymentStrategyRollingUpdate, out *MachineRollingUpdateDeployment, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge if in.DeletePolicy != "" { out.DeletePolicy = ptr.To(string(in.DeletePolicy)) } return nil } +func Convert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *clusterv1.ClusterSpec, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s); err != nil { + return err + } + if in.ClusterNetwork != nil { + if err := Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in.ClusterNetwork, &out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in *clusterv1.ClusterSpec, out *ClusterSpec, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.ClusterNetwork, clusterv1.ClusterNetwork{}) { + out.ClusterNetwork = &ClusterNetwork{} + if err := Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(&in.ClusterNetwork, out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *clusterv1.ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s); err != nil { + return err + } + if in.Services != nil { + if err := autoConvert_v1beta1_NetworkRanges_To_v1beta2_NetworkRanges(in.Services, &out.Services, s); err != nil { + return err + } + } + if in.Pods != nil { + if err := autoConvert_v1beta1_NetworkRanges_To_v1beta2_NetworkRanges(in.Pods, &out.Pods, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(in *clusterv1.ClusterNetwork, out *ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Services, clusterv1.NetworkRanges{}) { + out.Services = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1beta1_NetworkRanges(&in.Services, out.Services, s); err != nil { + return err + } + } + + if !reflect.DeepEqual(in.Pods, clusterv1.NetworkRanges{}) { + out.Pods = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1beta1_NetworkRanges(&in.Pods, out.Pods, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in *MachineDeploymentSpec, out *clusterv1.MachineDeploymentSpec, s apimachineryconversion.Scope) error { + // NOTE: v1beta2 MachineDeploymentSpec does not have ProgressDeadlineSeconds anymore. But it's fine to just lose this field it was never used. + if err := autoConvert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if in.Strategy != nil { + if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in.Strategy, &out.Strategy, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(in *clusterv1.MachineDeploymentSpec, out *MachineDeploymentSpec, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Strategy, clusterv1.MachineDeploymentStrategy{}) { + out.Strategy = &MachineDeploymentStrategy{} + if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(&in.Strategy, out.Strategy, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *clusterv1.MachineDeploymentStrategy, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if in.RollingUpdate != nil { + if err := Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in.RollingUpdate, &out.RollingUpdate, s); err != nil { + return err + } + } + if in.Remediation != nil { + if err := Convert_v1beta1_RemediationStrategy_To_v1beta2_RemediationStrategy(in.Remediation, &out.Remediation, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(in *clusterv1.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.RollingUpdate, clusterv1.MachineDeploymentStrategyRollingUpdate{}) { + out.RollingUpdate = &MachineRollingUpdateDeployment{} + if err := Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1beta1_MachineRollingUpdateDeployment(&in.RollingUpdate, out.RollingUpdate, s); err != nil { + return err + } + } + if !reflect.DeepEqual(in.Remediation, clusterv1.RemediationStrategy{}) { + out.Remediation = &RemediationStrategy{} + if err := Convert_v1beta2_RemediationStrategy_To_v1beta1_RemediationStrategy(&in.Remediation, out.Remediation, s); err != nil { + return err + } + } + + return nil +} + func convertMachineSpecToContractVersionedObjectReference(src *MachineSpec, dst *clusterv1.MachineSpec) error { infraRef, err := convertToContractVersionedObjectReference(&src.InfrastructureRef) if err != nil { diff --git a/api/core/v1beta1/conversion_test.go b/api/core/v1beta1/conversion_test.go index eacb30d60ff3..dc774f23bc7c 100644 --- a/api/core/v1beta1/conversion_test.go +++ b/api/core/v1beta1/conversion_test.go @@ -195,13 +195,15 @@ func spokeCluster(in *Cluster, c randfill.Continue) { dropEmptyStringsCluster(in) - if in.Spec.Topology != nil && in.Spec.Topology.Workers != nil { - for _, md := range in.Spec.Topology.Workers.MachineDeployments { - if md.Strategy != nil && md.Strategy.RollingUpdate != nil && - md.Strategy.RollingUpdate.DeletePolicy != nil && *md.Strategy.RollingUpdate.DeletePolicy == "" { - // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. - md.Strategy.RollingUpdate.DeletePolicy = nil - } + if in.Spec.ClusterNetwork != nil { + if in.Spec.ClusterNetwork.Services != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Services, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Services = nil + } + if in.Spec.ClusterNetwork.Pods != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Pods, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Pods = nil + } + if reflect.DeepEqual(in.Spec.ClusterNetwork, &ClusterNetwork{}) { + in.Spec.ClusterNetwork = nil } } } @@ -211,6 +213,10 @@ func spokeClusterTopology(in *Topology, c randfill.Continue) { // RolloutAfter was unused and has been removed in v1beta2. in.RolloutAfter = nil + + if in.Workers != nil && reflect.DeepEqual(in.Workers, &WorkersTopology{}) { + in.Workers = nil + } } func spokeClusterStatus(in *ClusterStatus, c randfill.Continue) { @@ -326,14 +332,6 @@ func spokeClusterClass(in *ClusterClass, c randfill.Continue) { in.Namespace = "foo" dropEmptyStringsClusterClass(in) - - for _, md := range in.Spec.Workers.MachineDeployments { - if md.Strategy != nil && md.Strategy.RollingUpdate != nil && - md.Strategy.RollingUpdate.DeletePolicy != nil && *md.Strategy.RollingUpdate.DeletePolicy == "" { - // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. - md.Strategy.RollingUpdate.DeletePolicy = nil - } - } } func spokeClusterClassStatus(in *ClusterClassStatus, c randfill.Continue) { @@ -589,12 +587,6 @@ func spokeMachineDeployment(in *MachineDeployment, c randfill.Continue) { fillMachineSpec(&in.Spec.Template.Spec, c, in.Namespace) dropEmptyStringsMachineSpec(&in.Spec.Template.Spec) - - if in.Spec.Strategy != nil && in.Spec.Strategy.RollingUpdate != nil && - in.Spec.Strategy.RollingUpdate.DeletePolicy != nil && *in.Spec.Strategy.RollingUpdate.DeletePolicy == "" { - // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. - in.Spec.Strategy.RollingUpdate.DeletePolicy = nil - } } func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue) { @@ -605,6 +597,24 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue) // Drop RevisionHistoryLimit as we intentionally don't preserve it. in.RevisionHistoryLimit = nil + + if in.Strategy != nil { + if in.Strategy.RollingUpdate != nil { + if in.Strategy.RollingUpdate.DeletePolicy != nil && *in.Strategy.RollingUpdate.DeletePolicy == "" { + // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. + in.Strategy.RollingUpdate.DeletePolicy = nil + } + if reflect.DeepEqual(in.Strategy.RollingUpdate, &MachineRollingUpdateDeployment{}) { + in.Strategy.RollingUpdate = nil + } + } + if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) { + in.Strategy.Remediation = nil + } + if reflect.DeepEqual(in.Strategy, &MachineDeploymentStrategy{}) { + in.Strategy = nil + } + } } func spokeMachineDeploymentStatus(in *MachineDeploymentStatus, c randfill.Continue) { @@ -726,6 +736,10 @@ func spokeControlPlaneTopology(in *ControlPlaneTopology, c randfill.Continue) { if in.NodeDeletionTimeout != nil { in.NodeDeletionTimeout = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31()) * time.Second}) } + + if in.Variables != nil && reflect.DeepEqual(in.Variables, &ControlPlaneVariables{}) { + in.Variables = nil + } } func spokeMachineDeploymentTopology(in *MachineDeploymentTopology, c randfill.Continue) { @@ -740,6 +754,26 @@ func spokeMachineDeploymentTopology(in *MachineDeploymentTopology, c randfill.Co if in.NodeDeletionTimeout != nil { in.NodeDeletionTimeout = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31()) * time.Second}) } + if in.Variables != nil && reflect.DeepEqual(in.Variables, &MachineDeploymentVariables{}) { + in.Variables = nil + } + if in.Strategy != nil { + if in.Strategy.RollingUpdate != nil { + if in.Strategy.RollingUpdate.DeletePolicy != nil && *in.Strategy.RollingUpdate.DeletePolicy == "" { + // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. + in.Strategy.RollingUpdate.DeletePolicy = nil + } + if reflect.DeepEqual(in.Strategy.RollingUpdate, &MachineRollingUpdateDeployment{}) { + in.Strategy.RollingUpdate = nil + } + } + if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) { + in.Strategy.Remediation = nil + } + if reflect.DeepEqual(in.Strategy, &MachineDeploymentStrategy{}) { + in.Strategy = nil + } + } } func spokeMachinePoolTopology(in *MachinePoolTopology, c randfill.Continue) { @@ -754,6 +788,9 @@ func spokeMachinePoolTopology(in *MachinePoolTopology, c randfill.Continue) { if in.NodeDeletionTimeout != nil { in.NodeDeletionTimeout = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31()) * time.Second}) } + if in.Variables != nil && reflect.DeepEqual(in.Variables, &MachinePoolVariables{}) { + in.Variables = nil + } } func spokeMachineHealthCheckClass(in *MachineHealthCheckClass, c randfill.Continue) { @@ -790,6 +827,23 @@ func spokeMachineDeploymentClass(in *MachineDeploymentClass, c randfill.Continue if in.NodeDeletionTimeout != nil { in.NodeDeletionTimeout = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31()) * time.Second}) } + if in.Strategy != nil { + if in.Strategy.RollingUpdate != nil { + if in.Strategy.RollingUpdate.DeletePolicy != nil && *in.Strategy.RollingUpdate.DeletePolicy == "" { + // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. + in.Strategy.RollingUpdate.DeletePolicy = nil + } + if reflect.DeepEqual(in.Strategy.RollingUpdate, &MachineRollingUpdateDeployment{}) { + in.Strategy.RollingUpdate = nil + } + } + if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) { + in.Strategy.Remediation = nil + } + if reflect.DeepEqual(in.Strategy, &MachineDeploymentStrategy{}) { + in.Strategy = nil + } + } } func spokeMachinePoolClass(in *MachinePoolClass, c randfill.Continue) { diff --git a/api/core/v1beta1/zz_generated.conversion.go b/api/core/v1beta1/zz_generated.conversion.go index ae2800f6e841..b275acf137e5 100644 --- a/api/core/v1beta1/zz_generated.conversion.go +++ b/api/core/v1beta1/zz_generated.conversion.go @@ -145,26 +145,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.ClusterSpec)(nil), (*ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(a.(*v1beta2.ClusterSpec), b.(*ClusterSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*v1beta2.ClusterVariable)(nil), (*ClusterVariable)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_ClusterVariable_To_v1beta1_ClusterVariable(a.(*v1beta2.ClusterVariable), b.(*ClusterVariable), scope) }); err != nil { @@ -275,16 +255,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentClassTemplate)(nil), (*v1beta2.MachineDeploymentClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(a.(*MachineDeploymentClassTemplate), b.(*v1beta2.MachineDeploymentClassTemplate), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.MachineDeploymentClassTemplate)(nil), (*MachineDeploymentClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate(a.(*v1beta2.MachineDeploymentClassTemplate), b.(*MachineDeploymentClassTemplate), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineDeploymentList)(nil), (*v1beta2.MachineDeploymentList)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_MachineDeploymentList_To_v1beta2_MachineDeploymentList(a.(*MachineDeploymentList), b.(*v1beta2.MachineDeploymentList), scope) }); err != nil { @@ -295,21 +265,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta2.MachineDeploymentSpec)(nil), (*MachineDeploymentSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(a.(*v1beta2.MachineDeploymentSpec), b.(*MachineDeploymentSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.MachineDeploymentStrategy)(nil), (*MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(a.(*v1beta2.MachineDeploymentStrategy), b.(*MachineDeploymentStrategy), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineDeploymentVariables)(nil), (*v1beta2.MachineDeploymentVariables)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_MachineDeploymentVariables_To_v1beta2_MachineDeploymentVariables(a.(*MachineDeploymentVariables), b.(*v1beta2.MachineDeploymentVariables), scope) }); err != nil { @@ -450,16 +405,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachinePoolClassTemplate)(nil), (*v1beta2.MachinePoolClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate(a.(*MachinePoolClassTemplate), b.(*v1beta2.MachinePoolClassTemplate), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.MachinePoolClassTemplate)(nil), (*MachinePoolClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate(a.(*v1beta2.MachinePoolClassTemplate), b.(*MachinePoolClassTemplate), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachinePoolList)(nil), (*v1beta2.MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_MachinePoolList_To_v1beta2_MachinePoolList(a.(*MachinePoolList), b.(*v1beta2.MachinePoolList), scope) }); err != nil { @@ -710,6 +655,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*ClusterStatus)(nil), (*v1beta2.ClusterStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(a.(*ClusterStatus), b.(*v1beta2.ClusterStatus), scope) }); err != nil { @@ -790,6 +745,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineDeploymentTopology)(nil), (*v1beta2.MachineDeploymentTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopology(a.(*MachineDeploymentTopology), b.(*v1beta2.MachineDeploymentTopology), scope) }); err != nil { @@ -830,8 +790,8 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineRollingUpdateDeployment), scope) + if err := s.AddConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineDeploymentStrategyRollingUpdate), scope) }); err != nil { return err } @@ -885,6 +845,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*v1beta2.ClusterSpec)(nil), (*ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(a.(*v1beta2.ClusterSpec), b.(*ClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.ClusterStatus)(nil), (*ClusterStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_ClusterStatus_To_v1beta1_ClusterStatus(a.(*v1beta2.ClusterStatus), b.(*ClusterStatus), scope) }); err != nil { @@ -935,11 +905,26 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.MachineDeploymentSpec)(nil), (*MachineDeploymentSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(a.(*v1beta2.MachineDeploymentSpec), b.(*MachineDeploymentSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStatus)(nil), (*MachineDeploymentStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(a.(*v1beta2.MachineDeploymentStatus), b.(*MachineDeploymentStatus), scope) }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1beta1_MachineRollingUpdateDeployment(a.(*v1beta2.MachineDeploymentStrategyRollingUpdate), b.(*MachineRollingUpdateDeployment), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategy)(nil), (*MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(a.(*v1beta2.MachineDeploymentStrategy), b.(*MachineDeploymentStrategy), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.MachineDeploymentTopology)(nil), (*MachineDeploymentTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopology(a.(*v1beta2.MachineDeploymentTopology), b.(*MachineDeploymentTopology), scope) }); err != nil { @@ -995,11 +980,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta2.MachineRollingUpdateDeployment)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(a.(*v1beta2.MachineRollingUpdateDeployment), b.(*MachineRollingUpdateDeployment), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*v1beta2.MachineSetStatus)(nil), (*MachineSetStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineSetStatus_To_v1beta1_MachineSetStatus(a.(*v1beta2.MachineSetStatus), b.(*MachineSetStatus), scope) }); err != nil { @@ -1584,36 +1564,30 @@ func Convert_v1beta2_ClusterList_To_v1beta1_ClusterList(in *v1beta2.ClusterList, } func autoConvert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_Pointer_int32_To_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork is an autogenerated conversion function. -func Convert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1beta1_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s) -} - func autoConvert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_int32_To_Pointer_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/api/core/v1beta1.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/api/core/v1beta1.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork is an autogenerated conversion function. -func Convert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1beta2_ClusterNetwork_To_v1beta1_ClusterNetwork(in, out, s) -} - func autoConvert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { if err := v1.Convert_bool_To_Pointer_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*v1beta2.ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.ClusterNetwork vs sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork) if err := Convert_v1beta1_APIEndpoint_To_v1beta2_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -1648,16 +1622,11 @@ func autoConvert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out return nil } -// Convert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec is an autogenerated conversion function. -func Convert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { - return autoConvert_v1beta1_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s) -} - func autoConvert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in *v1beta2.ClusterSpec, out *ClusterSpec, s conversion.Scope) error { if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork vs *sigs.k8s.io/cluster-api/api/core/v1beta1.ClusterNetwork) if err := Convert_v1beta2_APIEndpoint_To_v1beta1_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -1692,11 +1661,6 @@ func autoConvert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in *v1beta2.ClusterS return nil } -// Convert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec is an autogenerated conversion function. -func Convert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in *v1beta2.ClusterSpec, out *ClusterSpec, s conversion.Scope) error { - return autoConvert_v1beta2_ClusterSpec_To_v1beta1_ClusterSpec(in, out, s) -} - func autoConvert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, out *v1beta2.ClusterStatus, s conversion.Scope) error { // WARNING: in.FailureDomains requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta1.FailureDomains vs []sigs.k8s.io/cluster-api/api/core/v1beta2.FailureDomain) // WARNING: in.FailureReason requires manual conversion: does not exist in peer-type @@ -1910,15 +1874,7 @@ func autoConvert_v1beta1_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(in // WARNING: in.NodeVolumeDetachTimeout requires manual conversion: does not exist in peer-type // WARNING: in.NodeDeletionTimeout requires manual conversion: does not exist in peer-type out.ReadinessGates = *(*[]v1beta2.MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(v1beta2.ControlPlaneVariables) - if err := Convert_v1beta1_ControlPlaneVariables_To_v1beta2_ControlPlaneVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Variables requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.ControlPlaneVariables vs sigs.k8s.io/cluster-api/api/core/v1beta2.ControlPlaneVariables) return nil } @@ -1940,15 +1896,7 @@ func autoConvert_v1beta2_ControlPlaneTopology_To_v1beta1_ControlPlaneTopology(in // WARNING: in.NodeVolumeDetachTimeoutSeconds requires manual conversion: does not exist in peer-type // WARNING: in.NodeDeletionTimeoutSeconds requires manual conversion: does not exist in peer-type out.ReadinessGates = *(*[]MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(ControlPlaneVariables) - if err := Convert_v1beta2_ControlPlaneVariables_To_v1beta1_ControlPlaneVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Variables requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.ControlPlaneVariables vs *sigs.k8s.io/cluster-api/api/core/v1beta1.ControlPlaneVariables) return nil } @@ -2419,9 +2367,7 @@ func Convert_v1beta2_MachineDeployment_To_v1beta1_MachineDeployment(in *v1beta2. func autoConvert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in *MachineDeploymentClass, out *v1beta2.MachineDeploymentClass, s conversion.Scope) error { out.Class = in.Class - if err := Convert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Template requires manual conversion: does not exist in peer-type if in.MachineHealthCheck != nil { in, out := &in.MachineHealthCheck, &out.MachineHealthCheck *out = new(v1beta2.MachineHealthCheckClass) @@ -2448,23 +2394,15 @@ func autoConvert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClas // WARNING: in.NodeDeletionTimeout requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.ReadinessGates = *(*[]v1beta2.MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(v1beta2.MachineDeploymentStrategy) - if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy) return nil } func autoConvert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in *v1beta2.MachineDeploymentClass, out *MachineDeploymentClass, s conversion.Scope) error { + // WARNING: in.Metadata requires manual conversion: does not exist in peer-type out.Class = in.Class - if err := Convert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Bootstrap requires manual conversion: does not exist in peer-type + // WARNING: in.Infrastructure requires manual conversion: does not exist in peer-type if in.MachineHealthCheck != nil { in, out := &in.MachineHealthCheck, &out.MachineHealthCheck *out = new(MachineHealthCheckClass) @@ -2491,15 +2429,7 @@ func autoConvert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClas // WARNING: in.NodeDeletionTimeoutSeconds requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.ReadinessGates = *(*[]MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy) return nil } @@ -2527,42 +2457,6 @@ func Convert_v1beta2_MachineDeploymentClassNamingStrategy_To_v1beta1_MachineDepl return autoConvert_v1beta2_MachineDeploymentClassNamingStrategy_To_v1beta1_MachineDeploymentClassNamingStrategy(in, out, s) } -func autoConvert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in *MachineDeploymentClassTemplate, out *v1beta2.MachineDeploymentClassTemplate, s conversion.Scope) error { - if err := Convert_v1beta1_ObjectMeta_To_v1beta2_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassBootstrapTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassInfrastructureTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate is an autogenerated conversion function. -func Convert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in *MachineDeploymentClassTemplate, out *v1beta2.MachineDeploymentClassTemplate, s conversion.Scope) error { - return autoConvert_v1beta1_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in, out, s) -} - -func autoConvert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate(in *v1beta2.MachineDeploymentClassTemplate, out *MachineDeploymentClassTemplate, s conversion.Scope) error { - if err := Convert_v1beta2_ObjectMeta_To_v1beta1_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1beta2_MachineDeploymentClassBootstrapTemplate_To_v1beta1_LocalObjectTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1beta2_MachineDeploymentClassInfrastructureTemplate_To_v1beta1_LocalObjectTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate is an autogenerated conversion function. -func Convert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate(in *v1beta2.MachineDeploymentClassTemplate, out *MachineDeploymentClassTemplate, s conversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentClassTemplate_To_v1beta1_MachineDeploymentClassTemplate(in, out, s) -} - func autoConvert_v1beta1_MachineDeploymentList_To_v1beta2_MachineDeploymentList(in *MachineDeploymentList, out *v1beta2.MachineDeploymentList, s conversion.Scope) error { out.ListMeta = in.ListMeta if in.Items != nil { @@ -2613,15 +2507,7 @@ func autoConvert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec( if err := Convert_v1beta1_MachineTemplateSpec_To_v1beta2_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(v1beta2.MachineDeploymentStrategy) - if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy) out.MachineNamingStrategy = (*v1beta2.MachineNamingStrategy)(unsafe.Pointer(in.MachineNamingStrategy)) // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type @@ -2640,15 +2526,7 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec( if err := Convert_v1beta2_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy) out.MachineNamingStrategy = (*MachineNamingStrategy)(unsafe.Pointer(in.MachineNamingStrategy)) if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err @@ -2656,11 +2534,6 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec( return nil } -// Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec is an autogenerated conversion function. -func Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(in *v1beta2.MachineDeploymentSpec, out *MachineDeploymentSpec, s conversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(in, out, s) -} - func autoConvert_v1beta1_MachineDeploymentStatus_To_v1beta2_MachineDeploymentStatus(in *MachineDeploymentStatus, out *v1beta2.MachineDeploymentStatus, s conversion.Scope) error { out.ObservedGeneration = in.ObservedGeneration out.Selector = in.Selector @@ -2722,44 +2595,18 @@ func autoConvert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentSta func autoConvert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { out.Type = v1beta2.MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(v1beta2.MachineRollingUpdateDeployment) - if err := Convert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } - out.Remediation = (*v1beta2.RemediationStrategy)(unsafe.Pointer(in.Remediation)) + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachineRollingUpdateDeployment vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate) + // WARNING: in.Remediation requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.RemediationStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.RemediationStrategy) return nil } -// Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy is an autogenerated conversion function. -func Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { - return autoConvert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s) -} - func autoConvert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(in *v1beta2.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s conversion.Scope) error { out.Type = MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(MachineRollingUpdateDeployment) - if err := Convert_v1beta2_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } - out.Remediation = (*RemediationStrategy)(unsafe.Pointer(in.Remediation)) + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachineRollingUpdateDeployment) + // WARNING: in.Remediation requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.RemediationStrategy vs *sigs.k8s.io/cluster-api/api/core/v1beta1.RemediationStrategy) return nil } -// Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy is an autogenerated conversion function. -func Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(in *v1beta2.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s conversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(in, out, s) -} - func autoConvert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopology(in *MachineDeploymentTopology, out *v1beta2.MachineDeploymentTopology, s conversion.Scope) error { if err := Convert_v1beta1_ObjectMeta_To_v1beta2_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { return err @@ -2784,24 +2631,8 @@ func autoConvert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentT // WARNING: in.NodeDeletionTimeout requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.ReadinessGates = *(*[]v1beta2.MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(v1beta2.MachineDeploymentStrategy) - if err := Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(v1beta2.MachineDeploymentVariables) - if err := Convert_v1beta1_MachineDeploymentVariables_To_v1beta2_MachineDeploymentVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy) + // WARNING: in.Variables requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentVariables vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentVariables) return nil } @@ -2829,24 +2660,8 @@ func autoConvert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentT // WARNING: in.NodeDeletionTimeoutSeconds requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.ReadinessGates = *(*[]MachineReadinessGate)(unsafe.Pointer(&in.ReadinessGates)) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(MachineDeploymentVariables) - if err := Convert_v1beta2_MachineDeploymentVariables_To_v1beta1_MachineDeploymentVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentStrategy) + // WARNING: in.Variables requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentVariables vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachineDeploymentVariables) return nil } @@ -3362,9 +3177,7 @@ func Convert_v1beta2_MachinePool_To_v1beta1_MachinePool(in *v1beta2.MachinePool, func autoConvert_v1beta1_MachinePoolClass_To_v1beta2_MachinePoolClass(in *MachinePoolClass, out *v1beta2.MachinePoolClass, s conversion.Scope) error { out.Class = in.Class - if err := Convert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Template requires manual conversion: does not exist in peer-type out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) if in.NamingStrategy != nil { in, out := &in.NamingStrategy, &out.NamingStrategy @@ -3383,10 +3196,10 @@ func autoConvert_v1beta1_MachinePoolClass_To_v1beta2_MachinePoolClass(in *Machin } func autoConvert_v1beta2_MachinePoolClass_To_v1beta1_MachinePoolClass(in *v1beta2.MachinePoolClass, out *MachinePoolClass, s conversion.Scope) error { + // WARNING: in.Metadata requires manual conversion: does not exist in peer-type out.Class = in.Class - if err := Convert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Bootstrap requires manual conversion: does not exist in peer-type + // WARNING: in.Infrastructure requires manual conversion: does not exist in peer-type out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) if in.NamingStrategy != nil { in, out := &in.NamingStrategy, &out.NamingStrategy @@ -3428,42 +3241,6 @@ func Convert_v1beta2_MachinePoolClassNamingStrategy_To_v1beta1_MachinePoolClassN return autoConvert_v1beta2_MachinePoolClassNamingStrategy_To_v1beta1_MachinePoolClassNamingStrategy(in, out, s) } -func autoConvert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate(in *MachinePoolClassTemplate, out *v1beta2.MachinePoolClassTemplate, s conversion.Scope) error { - if err := Convert_v1beta1_ObjectMeta_To_v1beta2_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachinePoolClassBootstrapTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1beta1_LocalObjectTemplate_To_v1beta2_MachinePoolClassInfrastructureTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate(in *MachinePoolClassTemplate, out *v1beta2.MachinePoolClassTemplate, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolClassTemplate_To_v1beta2_MachinePoolClassTemplate(in, out, s) -} - -func autoConvert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate(in *v1beta2.MachinePoolClassTemplate, out *MachinePoolClassTemplate, s conversion.Scope) error { - if err := Convert_v1beta2_ObjectMeta_To_v1beta1_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1beta2_MachinePoolClassBootstrapTemplate_To_v1beta1_LocalObjectTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1beta2_MachinePoolClassInfrastructureTemplate_To_v1beta1_LocalObjectTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate is an autogenerated conversion function. -func Convert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate(in *v1beta2.MachinePoolClassTemplate, out *MachinePoolClassTemplate, s conversion.Scope) error { - return autoConvert_v1beta2_MachinePoolClassTemplate_To_v1beta1_MachinePoolClassTemplate(in, out, s) -} - func autoConvert_v1beta1_MachinePoolList_To_v1beta2_MachinePoolList(in *MachinePoolList, out *v1beta2.MachinePoolList, s conversion.Scope) error { out.ListMeta = in.ListMeta if in.Items != nil { @@ -3609,15 +3386,7 @@ func autoConvert_v1beta1_MachinePoolTopology_To_v1beta2_MachinePoolTopology(in * // WARNING: in.NodeDeletionTimeout requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(v1beta2.MachinePoolVariables) - if err := Convert_v1beta1_MachinePoolVariables_To_v1beta2_MachinePoolVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Variables requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.MachinePoolVariables vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolVariables) return nil } @@ -3633,15 +3402,7 @@ func autoConvert_v1beta2_MachinePoolTopology_To_v1beta1_MachinePoolTopology(in * // WARNING: in.NodeDeletionTimeoutSeconds requires manual conversion: does not exist in peer-type out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(MachinePoolVariables) - if err := Convert_v1beta2_MachinePoolVariables_To_v1beta1_MachinePoolVariables(*in, *out, s); err != nil { - return err - } - } else { - out.Variables = nil - } + // WARNING: in.Variables requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolVariables vs *sigs.k8s.io/cluster-api/api/core/v1beta1.MachinePoolVariables) return nil } @@ -3707,20 +3468,6 @@ func Convert_v1beta2_MachineReadinessGate_To_v1beta1_MachineReadinessGate(in *v1 return autoConvert_v1beta2_MachineReadinessGate_To_v1beta1_MachineReadinessGate(in, out, s) } -func autoConvert_v1beta1_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta2.MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - // WARNING: in.DeletePolicy requires manual conversion: inconvertible types (*string vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetDeletePolicy) - return nil -} - -func autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(in *v1beta2.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - // WARNING: in.DeletePolicy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetDeletePolicy vs *string) - return nil -} - func autoConvert_v1beta1_MachineSet_To_v1beta2_MachineSet(in *MachineSet, out *v1beta2.MachineSet, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1beta1_MachineSetSpec_To_v1beta2_MachineSetSpec(&in.Spec, &out.Spec, s); err != nil { @@ -4249,15 +3996,7 @@ func autoConvert_v1beta1_Topology_To_v1beta2_Topology(in *Topology, out *v1beta2 if err := Convert_v1beta1_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(&in.ControlPlane, &out.ControlPlane, s); err != nil { return err } - if in.Workers != nil { - in, out := &in.Workers, &out.Workers - *out = new(v1beta2.WorkersTopology) - if err := Convert_v1beta1_WorkersTopology_To_v1beta2_WorkersTopology(*in, *out, s); err != nil { - return err - } - } else { - out.Workers = nil - } + // WARNING: in.Workers requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/api/core/v1beta1.WorkersTopology vs sigs.k8s.io/cluster-api/api/core/v1beta2.WorkersTopology) if in.Variables != nil { in, out := &in.Variables, &out.Variables *out = make([]v1beta2.ClusterVariable, len(*in)) @@ -4278,15 +4017,7 @@ func autoConvert_v1beta2_Topology_To_v1beta1_Topology(in *v1beta2.Topology, out if err := Convert_v1beta2_ControlPlaneTopology_To_v1beta1_ControlPlaneTopology(&in.ControlPlane, &out.ControlPlane, s); err != nil { return err } - if in.Workers != nil { - in, out := &in.Workers, &out.Workers - *out = new(WorkersTopology) - if err := Convert_v1beta2_WorkersTopology_To_v1beta1_WorkersTopology(*in, *out, s); err != nil { - return err - } - } else { - out.Workers = nil - } + // WARNING: in.Workers requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.WorkersTopology vs *sigs.k8s.io/cluster-api/api/core/v1beta1.WorkersTopology) if in.Variables != nil { in, out := &in.Variables, &out.Variables *out = make([]ClusterVariable, len(*in)) diff --git a/api/core/v1beta2/cluster_types.go b/api/core/v1beta2/cluster_types.go index ac3e6f68ae4f..26ca0a8d4587 100644 --- a/api/core/v1beta2/cluster_types.go +++ b/api/core/v1beta2/cluster_types.go @@ -466,7 +466,7 @@ type ClusterSpec struct { // clusterNetwork represents the cluster network configuration. // +optional - ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"` + ClusterNetwork ClusterNetwork `json:"clusterNetwork,omitempty,omitzero"` // controlPlaneEndpoint represents the endpoint used to communicate with the control plane. // +optional @@ -497,11 +497,13 @@ type ClusterSpec struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 AvailabilityGates []ClusterAvailabilityGate `json:"availabilityGates,omitempty"` } // ConditionPolarity defines the polarity for a metav1.Condition. +// +kubebuilder:validation:Enum=Positive;Negative type ConditionPolarity string const ( @@ -530,7 +532,6 @@ type ClusterAvailabilityGate struct { // When omitted, the default behaviour will be Positive. // A positive polarity means that the condition should report a true status under normal conditions. // A negative polarity means that the condition should report a false status under normal conditions. - // +kubebuilder:validation:Enum=Positive;Negative // +optional Polarity ConditionPolarity `json:"polarity,omitempty"` } @@ -554,7 +555,7 @@ type Topology struct { // workers encapsulates the different constructs that form the worker nodes // for the cluster. // +optional - Workers *WorkersTopology `json:"workers,omitempty"` + Workers WorkersTopology `json:"workers,omitempty,omitzero"` // variables can be used to customize the Cluster through // patches. They must comply to the corresponding @@ -562,6 +563,7 @@ type Topology struct { // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=1000 Variables []ClusterVariable `json:"variables,omitempty"` } @@ -601,7 +603,7 @@ type ControlPlaneTopology struct { Metadata ObjectMeta `json:"metadata,omitempty,omitzero"` // replicas is the number of control plane nodes. - // If the value is nil, the ControlPlane object is created without the number of Replicas + // If the value is not set, the ControlPlane object is created without the number of Replicas // and it's assumed that the control plane controller does not implement support for this field. // When specified against a control plane provider that lacks support for this field, this value will be ignored. // +optional @@ -644,20 +646,23 @@ type ControlPlaneTopology struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"` // variables can be used to customize the ControlPlane through patches. // +optional - Variables *ControlPlaneVariables `json:"variables,omitempty"` + Variables ControlPlaneVariables `json:"variables,omitempty,omitzero"` } // WorkersTopology represents the different sets of worker nodes in the cluster. +// +kubebuilder:validation:MinProperties=1 type WorkersTopology struct { // machineDeployments is a list of machine deployments in the cluster. // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=2000 MachineDeployments []MachineDeploymentTopology `json:"machineDeployments,omitempty"` @@ -665,6 +670,7 @@ type WorkersTopology struct { // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=2000 MachinePools []MachinePoolTopology `json:"machinePools,omitempty"` } @@ -751,20 +757,22 @@ type MachineDeploymentTopology struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"` // strategy is the deployment strategy to use to replace existing machines with // new ones. // +optional - Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"` + Strategy MachineDeploymentStrategy `json:"strategy,omitempty,omitzero"` // variables can be used to customize the MachineDeployment through patches. // +optional - Variables *MachineDeploymentVariables `json:"variables,omitempty"` + Variables MachineDeploymentVariables `json:"variables,omitempty,omitzero"` } // MachineHealthCheckTopology defines a MachineHealthCheck for a group of machines. +// +kubebuilder:validation:MinProperties=1 type MachineHealthCheckTopology struct { // enable controls if a MachineHealthCheck should be created for the target machines. // @@ -812,6 +820,7 @@ type MachinePoolTopology struct { // Must match a key in the FailureDomains map stored on the cluster object. // +optional // +listType=atomic + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=100 // +kubebuilder:validation:items:MinLength=1 // +kubebuilder:validation:items:MaxLength=256 @@ -854,7 +863,7 @@ type MachinePoolTopology struct { // variables can be used to customize the MachinePool through patches. // +optional - Variables *MachinePoolVariables `json:"variables,omitempty"` + Variables MachinePoolVariables `json:"variables,omitempty,omitzero"` } // ClusterVariable can be used to customize the Cluster through patches. Each ClusterVariable is associated with a @@ -878,31 +887,37 @@ type ClusterVariable struct { } // ControlPlaneVariables can be used to provide variables for the ControlPlane. +// +kubebuilder:validation:MinProperties=1 type ControlPlaneVariables struct { // overrides can be used to override Cluster level variables. // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=1000 Overrides []ClusterVariable `json:"overrides,omitempty"` } // MachineDeploymentVariables can be used to provide variables for a specific MachineDeployment. +// +kubebuilder:validation:MinProperties=1 type MachineDeploymentVariables struct { // overrides can be used to override Cluster level variables. // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=1000 Overrides []ClusterVariable `json:"overrides,omitempty"` } // MachinePoolVariables can be used to provide variables for a specific MachinePool. +// +kubebuilder:validation:MinProperties=1 type MachinePoolVariables struct { // overrides can be used to override Cluster level variables. // +optional // +listType=map // +listMapKey=name + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=1000 Overrides []ClusterVariable `json:"overrides,omitempty"` } @@ -913,19 +928,22 @@ type MachinePoolVariables struct { // ClusterNetwork specifies the different networking // parameters for a cluster. +// +kubebuilder:validation:MinProperties=1 type ClusterNetwork struct { // apiServerPort specifies the port the API Server should bind to. // Defaults to 6443. // +optional - APIServerPort *int32 `json:"apiServerPort,omitempty"` + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=65535 + APIServerPort int32 `json:"apiServerPort,omitempty"` // services is the network ranges from which service VIPs are allocated. // +optional - Services *NetworkRanges `json:"services,omitempty"` + Services NetworkRanges `json:"services,omitempty,omitzero"` // pods is the network ranges from which Pod networks are allocated. // +optional - Pods *NetworkRanges `json:"pods,omitempty"` + Pods NetworkRanges `json:"pods,omitempty,omitzero"` // serviceDomain is the domain name for services. // +optional diff --git a/api/core/v1beta2/clusterclass_types.go b/api/core/v1beta2/clusterclass_types.go index 8b777601297b..6ff78faea3b5 100644 --- a/api/core/v1beta2/clusterclass_types.go +++ b/api/core/v1beta2/clusterclass_types.go @@ -97,6 +97,7 @@ type ClusterClassSpec struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 AvailabilityGates []ClusterAvailabilityGate `json:"availabilityGates,omitempty"` @@ -213,6 +214,7 @@ type ControlPlaneClass struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"` } @@ -270,6 +272,11 @@ type WorkersClass struct { // MachineDeploymentClass serves as a template to define a set of worker nodes of the cluster // provisioned using the `ClusterClass`. type MachineDeploymentClass struct { + // metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. + // At runtime this metadata is merged with the corresponding metadata from the topology. + // +optional + Metadata ObjectMeta `json:"metadata,omitempty,omitzero"` + // class denotes a type of worker node present in the cluster, // this name MUST be unique within a ClusterClass and can be referenced // in the Cluster to create a managed MachineDeployment. @@ -278,10 +285,15 @@ type MachineDeploymentClass struct { // +kubebuilder:validation:MaxLength=256 Class string `json:"class"` - // template is a local struct containing a collection of templates for creation of - // MachineDeployment objects representing a set of worker nodes. + // bootstrap contains the bootstrap template reference to be used + // for the creation of worker Machines. // +required - Template MachineDeploymentClassTemplate `json:"template"` + Bootstrap MachineDeploymentClassBootstrapTemplate `json:"bootstrap"` + + // infrastructure contains the infrastructure template reference to be used + // for the creation of worker Machines. + // +required + Infrastructure MachineDeploymentClassInfrastructureTemplate `json:"infrastructure"` // machineHealthCheck defines a MachineHealthCheck for this MachineDeploymentClass. // +optional @@ -341,6 +353,7 @@ type MachineDeploymentClass struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"` @@ -348,26 +361,7 @@ type MachineDeploymentClass struct { // new ones. // NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass. // +optional - Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"` -} - -// MachineDeploymentClassTemplate defines how a MachineDeployment generated from a MachineDeploymentClass -// should look like. -type MachineDeploymentClassTemplate struct { - // metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. - // At runtime this metadata is merged with the corresponding metadata from the topology. - // +optional - Metadata ObjectMeta `json:"metadata,omitempty,omitzero"` - - // bootstrap contains the bootstrap template reference to be used - // for the creation of worker Machines. - // +required - Bootstrap MachineDeploymentClassBootstrapTemplate `json:"bootstrap"` - - // infrastructure contains the infrastructure template reference to be used - // for the creation of worker Machines. - // +required - Infrastructure MachineDeploymentClassInfrastructureTemplate `json:"infrastructure"` + Strategy MachineDeploymentStrategy `json:"strategy,omitempty,omitzero"` } // MachineDeploymentClassNamingStrategy defines the naming strategy for machine deployment objects. @@ -387,6 +381,7 @@ type MachineDeploymentClassNamingStrategy struct { } // MachineHealthCheckClass defines a MachineHealthCheck for a group of Machines. +// +kubebuilder:validation:MinProperties=1 type MachineHealthCheckClass struct { // unhealthyNodeConditions contains a list of conditions that determine // whether a node is considered unhealthy. The conditions are combined in a @@ -394,6 +389,7 @@ type MachineHealthCheckClass struct { // // +optional // +listType=atomic + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=100 UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"` @@ -444,6 +440,11 @@ type MachineHealthCheckClass struct { // MachinePoolClass serves as a template to define a pool of worker nodes of the cluster // provisioned using `ClusterClass`. type MachinePoolClass struct { + // metadata is the metadata applied to the MachinePool. + // At runtime this metadata is merged with the corresponding metadata from the topology. + // +optional + Metadata ObjectMeta `json:"metadata,omitempty,omitzero"` + // class denotes a type of machine pool present in the cluster, // this name MUST be unique within a ClusterClass and can be referenced // in the Cluster to create a managed MachinePool. @@ -452,10 +453,15 @@ type MachinePoolClass struct { // +kubebuilder:validation:MaxLength=256 Class string `json:"class"` - // template is a local struct containing a collection of templates for creation of - // MachinePools objects representing a pool of worker nodes. + // bootstrap contains the bootstrap template reference to be used + // for the creation of the Machines in the MachinePool. // +required - Template MachinePoolClassTemplate `json:"template"` + Bootstrap MachinePoolClassBootstrapTemplate `json:"bootstrap"` + + // infrastructure contains the infrastructure template reference to be used + // for the creation of the MachinePool. + // +required + Infrastructure MachinePoolClassInfrastructureTemplate `json:"infrastructure"` // failureDomains is the list of failure domains the MachinePool should be attached to. // Must match a key in the FailureDomains map stored on the cluster object. @@ -504,25 +510,6 @@ type MachinePoolClass struct { MinReadySeconds *int32 `json:"minReadySeconds,omitempty"` } -// MachinePoolClassTemplate defines how a MachinePool generated from a MachinePoolClass -// should look like. -type MachinePoolClassTemplate struct { - // metadata is the metadata applied to the MachinePool. - // At runtime this metadata is merged with the corresponding metadata from the topology. - // +optional - Metadata ObjectMeta `json:"metadata,omitempty,omitzero"` - - // bootstrap contains the bootstrap template reference to be used - // for the creation of the Machines in the MachinePool. - // +required - Bootstrap MachinePoolClassBootstrapTemplate `json:"bootstrap"` - - // infrastructure contains the infrastructure template reference to be used - // for the creation of the MachinePool. - // +required - Infrastructure MachinePoolClassInfrastructureTemplate `json:"infrastructure"` -} - // MachinePoolClassNamingStrategy defines the naming strategy for machine pool objects. type MachinePoolClassNamingStrategy struct { // template defines the template to use for generating the name of the MachinePool object. diff --git a/api/core/v1beta2/machine_types.go b/api/core/v1beta2/machine_types.go index 612af19d51bc..8358d8a6a291 100644 --- a/api/core/v1beta2/machine_types.go +++ b/api/core/v1beta2/machine_types.go @@ -446,6 +446,7 @@ type MachineSpec struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"` @@ -486,7 +487,6 @@ type MachineReadinessGate struct { // When omitted, the default behaviour will be Positive. // A positive polarity means that the condition should report a true status under normal conditions. // A negative polarity means that the condition should report a false status under normal conditions. - // +kubebuilder:validation:Enum=Positive;Negative // +optional Polarity ConditionPolarity `json:"polarity,omitempty"` } diff --git a/api/core/v1beta2/machinedeployment_types.go b/api/core/v1beta2/machinedeployment_types.go index 3ec979a45bdc..e0d8caf14050 100644 --- a/api/core/v1beta2/machinedeployment_types.go +++ b/api/core/v1beta2/machinedeployment_types.go @@ -32,6 +32,7 @@ const ( ) // MachineDeploymentStrategyType defines the type of MachineDeployment rollout strategies. +// +kubebuilder:validation:Enum=RollingUpdate;OnDelete type MachineDeploymentStrategyType string const ( @@ -283,7 +284,7 @@ type MachineDeploymentSpec struct { // strategy is the deployment strategy to use to replace existing machines with // new ones. // +optional - Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"` + Strategy MachineDeploymentStrategy `json:"strategy,omitempty,omitzero"` // machineNamingStrategy allows changing the naming pattern used when creating Machines. // Note: InfraMachines & BootstrapConfigs will use the same name as the corresponding Machines. @@ -301,30 +302,31 @@ type MachineDeploymentSpec struct { // MachineDeploymentStrategy describes how to replace existing machines // with new ones. +// +kubebuilder:validation:MinProperties=1 type MachineDeploymentStrategy struct { // type of deployment. Allowed values are RollingUpdate and OnDelete. // The default is RollingUpdate. - // +kubebuilder:validation:Enum=RollingUpdate;OnDelete // +optional Type MachineDeploymentStrategyType `json:"type,omitempty"` // rollingUpdate is the rolling update config params. Present only if // MachineDeploymentStrategyType = RollingUpdate. // +optional - RollingUpdate *MachineRollingUpdateDeployment `json:"rollingUpdate,omitempty"` + RollingUpdate MachineDeploymentStrategyRollingUpdate `json:"rollingUpdate,omitempty,omitzero"` // remediation controls the strategy of remediating unhealthy machines // and how remediating operations should occur during the lifecycle of the dependant MachineSets. // +optional - Remediation *RemediationStrategy `json:"remediation,omitempty"` + Remediation RemediationStrategy `json:"remediation,omitempty,omitzero"` } // ANCHOR_END: MachineDeploymentStrategy -// ANCHOR: MachineRollingUpdateDeployment +// ANCHOR: MachineDeploymentStrategyRollingUpdate -// MachineRollingUpdateDeployment is used to control the desired behavior of rolling update. -type MachineRollingUpdateDeployment struct { +// MachineDeploymentStrategyRollingUpdate is used to control the desired behavior of rolling update. +// +kubebuilder:validation:MinProperties=1 +type MachineDeploymentStrategyRollingUpdate struct { // maxUnavailable is the maximum number of machines that can be unavailable during the update. // Value can be an absolute number (ex: 5) or a percentage of desired // machines (ex: 10%). @@ -363,11 +365,12 @@ type MachineRollingUpdateDeployment struct { DeletePolicy MachineSetDeletePolicy `json:"deletePolicy,omitempty"` } -// ANCHOR_END: MachineRollingUpdateDeployment +// ANCHOR_END: MachineDeploymentStrategyRollingUpdate // ANCHOR: RemediationStrategy // RemediationStrategy allows to define how the MachineSet can control scaling operations. +// +kubebuilder:validation:MinProperties=1 type RemediationStrategy struct { // maxInFlight determines how many in flight remediations should happen at the same time. // diff --git a/api/core/v1beta2/machinehealthcheck_types.go b/api/core/v1beta2/machinehealthcheck_types.go index c264255229d8..2278495e1731 100644 --- a/api/core/v1beta2/machinehealthcheck_types.go +++ b/api/core/v1beta2/machinehealthcheck_types.go @@ -66,6 +66,7 @@ type MachineHealthCheckSpec struct { // // +optional // +listType=atomic + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=100 UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"` diff --git a/api/core/v1beta2/zz_generated.deepcopy.go b/api/core/v1beta2/zz_generated.deepcopy.go index f2a9dd54a68c..f89f39e07b79 100644 --- a/api/core/v1beta2/zz_generated.deepcopy.go +++ b/api/core/v1beta2/zz_generated.deepcopy.go @@ -550,21 +550,8 @@ func (in *ClusterList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterNetwork) DeepCopyInto(out *ClusterNetwork) { *out = *in - if in.APIServerPort != nil { - in, out := &in.APIServerPort, &out.APIServerPort - *out = new(int32) - **out = **in - } - if in.Services != nil { - in, out := &in.Services, &out.Services - *out = new(NetworkRanges) - (*in).DeepCopyInto(*out) - } - if in.Pods != nil { - in, out := &in.Pods, &out.Pods - *out = new(NetworkRanges) - (*in).DeepCopyInto(*out) - } + in.Services.DeepCopyInto(&out.Services) + in.Pods.DeepCopyInto(&out.Pods) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterNetwork. @@ -585,11 +572,7 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { *out = new(bool) **out = **in } - if in.ClusterNetwork != nil { - in, out := &in.ClusterNetwork, &out.ClusterNetwork - *out = new(ClusterNetwork) - (*in).DeepCopyInto(*out) - } + in.ClusterNetwork.DeepCopyInto(&out.ClusterNetwork) out.ControlPlaneEndpoint = in.ControlPlaneEndpoint if in.ControlPlaneRef != nil { in, out := &in.ControlPlaneRef, &out.ControlPlaneRef @@ -885,11 +868,7 @@ func (in *ControlPlaneTopology) DeepCopyInto(out *ControlPlaneTopology) { *out = make([]MachineReadinessGate, len(*in)) copy(*out, *in) } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(ControlPlaneVariables) - (*in).DeepCopyInto(*out) - } + in.Variables.DeepCopyInto(&out.Variables) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneTopology. @@ -1318,7 +1297,9 @@ func (in *MachineDeployment) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineDeploymentClass) DeepCopyInto(out *MachineDeploymentClass) { *out = *in - in.Template.DeepCopyInto(&out.Template) + in.Metadata.DeepCopyInto(&out.Metadata) + out.Bootstrap = in.Bootstrap + out.Infrastructure = in.Infrastructure if in.MachineHealthCheck != nil { in, out := &in.MachineHealthCheck, &out.MachineHealthCheck *out = new(MachineHealthCheckClass) @@ -1354,11 +1335,7 @@ func (in *MachineDeploymentClass) DeepCopyInto(out *MachineDeploymentClass) { *out = make([]MachineReadinessGate, len(*in)) copy(*out, *in) } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - (*in).DeepCopyInto(*out) - } + in.Strategy.DeepCopyInto(&out.Strategy) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentClass. @@ -1418,24 +1395,6 @@ func (in *MachineDeploymentClassNamingStrategy) DeepCopy() *MachineDeploymentCla return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachineDeploymentClassTemplate) DeepCopyInto(out *MachineDeploymentClassTemplate) { - *out = *in - in.Metadata.DeepCopyInto(&out.Metadata) - out.Bootstrap = in.Bootstrap - out.Infrastructure = in.Infrastructure -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentClassTemplate. -func (in *MachineDeploymentClassTemplate) DeepCopy() *MachineDeploymentClassTemplate { - if in == nil { - return nil - } - out := new(MachineDeploymentClassTemplate) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineDeploymentDeprecatedStatus) DeepCopyInto(out *MachineDeploymentDeprecatedStatus) { *out = *in @@ -1502,11 +1461,7 @@ func (in *MachineDeploymentSpec) DeepCopyInto(out *MachineDeploymentSpec) { } in.Selector.DeepCopyInto(&out.Selector) in.Template.DeepCopyInto(&out.Template) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - (*in).DeepCopyInto(*out) - } + in.Strategy.DeepCopyInto(&out.Strategy) if in.MachineNamingStrategy != nil { in, out := &in.MachineNamingStrategy, &out.MachineNamingStrategy *out = new(MachineNamingStrategy) @@ -1579,16 +1534,8 @@ func (in *MachineDeploymentStatus) DeepCopy() *MachineDeploymentStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineDeploymentStrategy) DeepCopyInto(out *MachineDeploymentStrategy) { *out = *in - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(MachineRollingUpdateDeployment) - (*in).DeepCopyInto(*out) - } - if in.Remediation != nil { - in, out := &in.Remediation, &out.Remediation - *out = new(RemediationStrategy) - (*in).DeepCopyInto(*out) - } + in.RollingUpdate.DeepCopyInto(&out.RollingUpdate) + in.Remediation.DeepCopyInto(&out.Remediation) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentStrategy. @@ -1601,6 +1548,31 @@ func (in *MachineDeploymentStrategy) DeepCopy() *MachineDeploymentStrategy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineDeploymentStrategyRollingUpdate) DeepCopyInto(out *MachineDeploymentStrategyRollingUpdate) { + *out = *in + if in.MaxUnavailable != nil { + in, out := &in.MaxUnavailable, &out.MaxUnavailable + *out = new(intstr.IntOrString) + **out = **in + } + if in.MaxSurge != nil { + in, out := &in.MaxSurge, &out.MaxSurge + *out = new(intstr.IntOrString) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentStrategyRollingUpdate. +func (in *MachineDeploymentStrategyRollingUpdate) DeepCopy() *MachineDeploymentStrategyRollingUpdate { + if in == nil { + return nil + } + out := new(MachineDeploymentStrategyRollingUpdate) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineDeploymentTopology) DeepCopyInto(out *MachineDeploymentTopology) { *out = *in @@ -1640,16 +1612,8 @@ func (in *MachineDeploymentTopology) DeepCopyInto(out *MachineDeploymentTopology *out = make([]MachineReadinessGate, len(*in)) copy(*out, *in) } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - (*in).DeepCopyInto(*out) - } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(MachineDeploymentVariables) - (*in).DeepCopyInto(*out) - } + in.Strategy.DeepCopyInto(&out.Strategy) + in.Variables.DeepCopyInto(&out.Variables) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentTopology. @@ -2256,7 +2220,9 @@ func (in *MachinePool) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachinePoolClass) DeepCopyInto(out *MachinePoolClass) { *out = *in - in.Template.DeepCopyInto(&out.Template) + in.Metadata.DeepCopyInto(&out.Metadata) + out.Bootstrap = in.Bootstrap + out.Infrastructure = in.Infrastructure if in.FailureDomains != nil { in, out := &in.FailureDomains, &out.FailureDomains *out = make([]string, len(*in)) @@ -2346,24 +2312,6 @@ func (in *MachinePoolClassNamingStrategy) DeepCopy() *MachinePoolClassNamingStra return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolClassTemplate) DeepCopyInto(out *MachinePoolClassTemplate) { - *out = *in - in.Metadata.DeepCopyInto(&out.Metadata) - out.Bootstrap = in.Bootstrap - out.Infrastructure = in.Infrastructure -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolClassTemplate. -func (in *MachinePoolClassTemplate) DeepCopy() *MachinePoolClassTemplate { - if in == nil { - return nil - } - out := new(MachinePoolClassTemplate) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachinePoolDeprecatedStatus) DeepCopyInto(out *MachinePoolDeprecatedStatus) { *out = *in @@ -2559,11 +2507,7 @@ func (in *MachinePoolTopology) DeepCopyInto(out *MachinePoolTopology) { *out = new(int32) **out = **in } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = new(MachinePoolVariables) - (*in).DeepCopyInto(*out) - } + in.Variables.DeepCopyInto(&out.Variables) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolTopology. @@ -2645,31 +2589,6 @@ func (in *MachineReadinessGate) DeepCopy() *MachineReadinessGate { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachineRollingUpdateDeployment) DeepCopyInto(out *MachineRollingUpdateDeployment) { - *out = *in - if in.MaxUnavailable != nil { - in, out := &in.MaxUnavailable, &out.MaxUnavailable - *out = new(intstr.IntOrString) - **out = **in - } - if in.MaxSurge != nil { - in, out := &in.MaxSurge, &out.MaxSurge - *out = new(intstr.IntOrString) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineRollingUpdateDeployment. -func (in *MachineRollingUpdateDeployment) DeepCopy() *MachineRollingUpdateDeployment { - if in == nil { - return nil - } - out := new(MachineRollingUpdateDeployment) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineSet) DeepCopyInto(out *MachineSet) { *out = *in @@ -3190,11 +3109,7 @@ func (in *Topology) DeepCopyInto(out *Topology) { *out = *in out.ClassRef = in.ClassRef in.ControlPlane.DeepCopyInto(&out.ControlPlane) - if in.Workers != nil { - in, out := &in.Workers, &out.Workers - *out = new(WorkersTopology) - (*in).DeepCopyInto(*out) - } + in.Workers.DeepCopyInto(&out.Workers) if in.Variables != nil { in, out := &in.Variables, &out.Variables *out = make([]ClusterVariable, len(*in)) diff --git a/api/core/v1beta2/zz_generated.openapi.go b/api/core/v1beta2/zz_generated.openapi.go index e33bb509db39..bfaace019b24 100644 --- a/api/core/v1beta2/zz_generated.openapi.go +++ b/api/core/v1beta2/zz_generated.openapi.go @@ -76,12 +76,12 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassBootstrapTemplate": schema_cluster_api_api_core_v1beta2_MachineDeploymentClassBootstrapTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassInfrastructureTemplate": schema_cluster_api_api_core_v1beta2_MachineDeploymentClassInfrastructureTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassNamingStrategy": schema_cluster_api_api_core_v1beta2_MachineDeploymentClassNamingStrategy(ref), - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassTemplate": schema_cluster_api_api_core_v1beta2_MachineDeploymentClassTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentDeprecatedStatus": schema_cluster_api_api_core_v1beta2_MachineDeploymentDeprecatedStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentList": schema_cluster_api_api_core_v1beta2_MachineDeploymentList(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentSpec": schema_cluster_api_api_core_v1beta2_MachineDeploymentSpec(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStatus": schema_cluster_api_api_core_v1beta2_MachineDeploymentStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy": schema_cluster_api_api_core_v1beta2_MachineDeploymentStrategy(ref), + "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate": schema_cluster_api_api_core_v1beta2_MachineDeploymentStrategyRollingUpdate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentTopology": schema_cluster_api_api_core_v1beta2_MachineDeploymentTopology(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentV1Beta1DeprecatedStatus": schema_cluster_api_api_core_v1beta2_MachineDeploymentV1Beta1DeprecatedStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentVariables": schema_cluster_api_api_core_v1beta2_MachineDeploymentVariables(ref), @@ -110,7 +110,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassBootstrapTemplate": schema_cluster_api_api_core_v1beta2_MachinePoolClassBootstrapTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassInfrastructureTemplate": schema_cluster_api_api_core_v1beta2_MachinePoolClassInfrastructureTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassNamingStrategy": schema_cluster_api_api_core_v1beta2_MachinePoolClassNamingStrategy(ref), - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassTemplate": schema_cluster_api_api_core_v1beta2_MachinePoolClassTemplate(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolDeprecatedStatus": schema_cluster_api_api_core_v1beta2_MachinePoolDeprecatedStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolInitializationStatus": schema_cluster_api_api_core_v1beta2_MachinePoolInitializationStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolList": schema_cluster_api_api_core_v1beta2_MachinePoolList(ref), @@ -120,7 +119,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolV1Beta1DeprecatedStatus": schema_cluster_api_api_core_v1beta2_MachinePoolV1Beta1DeprecatedStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolVariables": schema_cluster_api_api_core_v1beta2_MachinePoolVariables(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineReadinessGate": schema_cluster_api_api_core_v1beta2_MachineReadinessGate(ref), - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineRollingUpdateDeployment": schema_cluster_api_api_core_v1beta2_MachineRollingUpdateDeployment(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSet": schema_cluster_api_api_core_v1beta2_MachineSet(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetDeprecatedStatus": schema_cluster_api_api_core_v1beta2_MachineSetDeprecatedStatus(ref), "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetList": schema_cluster_api_api_core_v1beta2_MachineSetList(ref), @@ -1084,12 +1082,14 @@ func schema_cluster_api_api_core_v1beta2_ClusterNetwork(ref common.ReferenceCall "services": { SchemaProps: spec.SchemaProps{ Description: "services is the network ranges from which service VIPs are allocated.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges"), }, }, "pods": { SchemaProps: spec.SchemaProps{ Description: "pods is the network ranges from which Pod networks are allocated.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges"), }, }, @@ -1125,6 +1125,7 @@ func schema_cluster_api_api_core_v1beta2_ClusterSpec(ref common.ReferenceCallbac "clusterNetwork": { SchemaProps: spec.SchemaProps{ Description: "clusterNetwork represents the cluster network configuration.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork"), }, }, @@ -1601,7 +1602,7 @@ func schema_cluster_api_api_core_v1beta2_ControlPlaneTopology(ref common.Referen }, "replicas": { SchemaProps: spec.SchemaProps{ - Description: "replicas is the number of control plane nodes. If the value is nil, the ControlPlane object is created without the number of Replicas and it's assumed that the control plane controller does not implement support for this field. When specified against a control plane provider that lacks support for this field, this value will be ignored.", + Description: "replicas is the number of control plane nodes. If the value is not set, the ControlPlane object is created without the number of Replicas and it's assumed that the control plane controller does not implement support for this field. When specified against a control plane provider that lacks support for this field, this value will be ignored.", Type: []string{"integer"}, Format: "int32", }, @@ -1658,6 +1659,7 @@ func schema_cluster_api_api_core_v1beta2_ControlPlaneTopology(ref common.Referen "variables": { SchemaProps: spec.SchemaProps{ Description: "variables can be used to customize the ControlPlane through patches.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ControlPlaneVariables"), }, }, @@ -2374,6 +2376,13 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentClass(ref common.Refer Description: "MachineDeploymentClass serves as a template to define a set of worker nodes of the cluster provisioned using the `ClusterClass`.", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. At runtime this metadata is merged with the corresponding metadata from the topology.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"), + }, + }, "class": { SchemaProps: spec.SchemaProps{ Description: "class denotes a type of worker node present in the cluster, this name MUST be unique within a ClusterClass and can be referenced in the Cluster to create a managed MachineDeployment.", @@ -2382,11 +2391,18 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentClass(ref common.Refer Format: "", }, }, - "template": { + "bootstrap": { SchemaProps: spec.SchemaProps{ - Description: "template is a local struct containing a collection of templates for creation of MachineDeployment objects representing a set of worker nodes.", + Description: "bootstrap contains the bootstrap template reference to be used for the creation of worker Machines.", Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassTemplate"), + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassBootstrapTemplate"), + }, + }, + "infrastructure": { + SchemaProps: spec.SchemaProps{ + Description: "infrastructure contains the infrastructure template reference to be used for the creation of worker Machines.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassInfrastructureTemplate"), }, }, "machineHealthCheck": { @@ -2461,15 +2477,16 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentClass(ref common.Refer "strategy": { SchemaProps: spec.SchemaProps{ Description: "strategy is the deployment strategy to use to replace existing machines with new ones. NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy"), }, }, }, - Required: []string{"class", "template"}, + Required: []string{"class", "bootstrap", "infrastructure"}, }, }, Dependencies: []string{ - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassNamingStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineHealthCheckClass", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineReadinessGate"}, + "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassBootstrapTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassInfrastructureTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassNamingStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineHealthCheckClass", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineReadinessGate", "sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"}, } } @@ -2539,43 +2556,6 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentClassNamingStrategy(re } } -func schema_cluster_api_api_core_v1beta2_MachineDeploymentClassTemplate(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MachineDeploymentClassTemplate defines how a MachineDeployment generated from a MachineDeploymentClass should look like.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "metadata": { - SchemaProps: spec.SchemaProps{ - Description: "metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. At runtime this metadata is merged with the corresponding metadata from the topology.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"), - }, - }, - "bootstrap": { - SchemaProps: spec.SchemaProps{ - Description: "bootstrap contains the bootstrap template reference to be used for the creation of worker Machines.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassBootstrapTemplate"), - }, - }, - "infrastructure": { - SchemaProps: spec.SchemaProps{ - Description: "infrastructure contains the infrastructure template reference to be used for the creation of worker Machines.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassInfrastructureTemplate"), - }, - }, - }, - Required: []string{"bootstrap", "infrastructure"}, - }, - }, - Dependencies: []string{ - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassBootstrapTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentClassInfrastructureTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"}, - } -} - func schema_cluster_api_api_core_v1beta2_MachineDeploymentDeprecatedStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2693,6 +2673,7 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentSpec(ref common.Refere "strategy": { SchemaProps: spec.SchemaProps{ Description: "strategy is the deployment strategy to use to replace existing machines with new ones.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy"), }, }, @@ -2827,12 +2808,14 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentStrategy(ref common.Re "rollingUpdate": { SchemaProps: spec.SchemaProps{ Description: "rollingUpdate is the rolling update config params. Present only if MachineDeploymentStrategyType = RollingUpdate.", - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineRollingUpdateDeployment"), + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate"), }, }, "remediation": { SchemaProps: spec.SchemaProps{ Description: "remediation controls the strategy of remediating unhealthy machines and how remediating operations should occur during the lifecycle of the dependant MachineSets.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.RemediationStrategy"), }, }, @@ -2840,7 +2823,41 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentStrategy(ref common.Re }, }, Dependencies: []string{ - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineRollingUpdateDeployment", "sigs.k8s.io/cluster-api/api/core/v1beta2.RemediationStrategy"}, + "sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate", "sigs.k8s.io/cluster-api/api/core/v1beta2.RemediationStrategy"}, + } +} + +func schema_cluster_api_api_core_v1beta2_MachineDeploymentStrategyRollingUpdate(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MachineDeploymentStrategyRollingUpdate is used to control the desired behavior of rolling update.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "maxUnavailable": { + SchemaProps: spec.SchemaProps{ + Description: "maxUnavailable is the maximum number of machines that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired machines (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 0. Example: when this is set to 30%, the old MachineSet can be scaled down to 70% of desired machines immediately when the rolling update starts. Once new machines are ready, old MachineSet can be scaled down further, followed by scaling up the new MachineSet, ensuring that the total number of machines available at all times during the update is at least 70% of desired machines.", + Ref: ref("k8s.io/apimachinery/pkg/util/intstr.IntOrString"), + }, + }, + "maxSurge": { + SchemaProps: spec.SchemaProps{ + Description: "maxSurge is the maximum number of machines that can be scheduled above the desired number of machines. Value can be an absolute number (ex: 5) or a percentage of desired machines (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 1. Example: when this is set to 30%, the new MachineSet can be scaled up immediately when the rolling update starts, such that the total number of old and new machines do not exceed 130% of desired machines. Once old machines have been killed, new MachineSet can be scaled up further, ensuring that total number of machines running at any time during the update is at most 130% of desired machines.", + Ref: ref("k8s.io/apimachinery/pkg/util/intstr.IntOrString"), + }, + }, + "deletePolicy": { + SchemaProps: spec.SchemaProps{ + Description: "deletePolicy defines the policy used by the MachineDeployment to identify nodes to delete when downscaling. Valid values are \"Random, \"Newest\", \"Oldest\" When no value is supplied, the default DeletePolicy of MachineSet is used", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/util/intstr.IntOrString"}, } } @@ -2947,12 +2964,14 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentTopology(ref common.Re "strategy": { SchemaProps: spec.SchemaProps{ Description: "strategy is the deployment strategy to use to replace existing machines with new ones.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy"), }, }, "variables": { SchemaProps: spec.SchemaProps{ Description: "variables can be used to customize the MachineDeployment through patches.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentVariables"), }, }, @@ -3985,6 +4004,13 @@ func schema_cluster_api_api_core_v1beta2_MachinePoolClass(ref common.ReferenceCa Description: "MachinePoolClass serves as a template to define a pool of worker nodes of the cluster provisioned using `ClusterClass`.", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "metadata is the metadata applied to the MachinePool. At runtime this metadata is merged with the corresponding metadata from the topology.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"), + }, + }, "class": { SchemaProps: spec.SchemaProps{ Description: "class denotes a type of machine pool present in the cluster, this name MUST be unique within a ClusterClass and can be referenced in the Cluster to create a managed MachinePool.", @@ -3993,11 +4019,18 @@ func schema_cluster_api_api_core_v1beta2_MachinePoolClass(ref common.ReferenceCa Format: "", }, }, - "template": { + "bootstrap": { SchemaProps: spec.SchemaProps{ - Description: "template is a local struct containing a collection of templates for creation of MachinePools objects representing a pool of worker nodes.", + Description: "bootstrap contains the bootstrap template reference to be used for the creation of the Machines in the MachinePool.", Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassTemplate"), + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassBootstrapTemplate"), + }, + }, + "infrastructure": { + SchemaProps: spec.SchemaProps{ + Description: "infrastructure contains the infrastructure template reference to be used for the creation of the MachinePool.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassInfrastructureTemplate"), }, }, "failureDomains": { @@ -4055,11 +4088,11 @@ func schema_cluster_api_api_core_v1beta2_MachinePoolClass(ref common.ReferenceCa }, }, }, - Required: []string{"class", "template"}, + Required: []string{"class", "bootstrap", "infrastructure"}, }, }, Dependencies: []string{ - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassNamingStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassTemplate"}, + "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassBootstrapTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassInfrastructureTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassNamingStrategy", "sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"}, } } @@ -4129,43 +4162,6 @@ func schema_cluster_api_api_core_v1beta2_MachinePoolClassNamingStrategy(ref comm } } -func schema_cluster_api_api_core_v1beta2_MachinePoolClassTemplate(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MachinePoolClassTemplate defines how a MachinePool generated from a MachinePoolClass should look like.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "metadata": { - SchemaProps: spec.SchemaProps{ - Description: "metadata is the metadata applied to the MachinePool. At runtime this metadata is merged with the corresponding metadata from the topology.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"), - }, - }, - "bootstrap": { - SchemaProps: spec.SchemaProps{ - Description: "bootstrap contains the bootstrap template reference to be used for the creation of the Machines in the MachinePool.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassBootstrapTemplate"), - }, - }, - "infrastructure": { - SchemaProps: spec.SchemaProps{ - Description: "infrastructure contains the infrastructure template reference to be used for the creation of the MachinePool.", - Default: map[string]interface{}{}, - Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassInfrastructureTemplate"), - }, - }, - }, - Required: []string{"bootstrap", "infrastructure"}, - }, - }, - Dependencies: []string{ - "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassBootstrapTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolClassInfrastructureTemplate", "sigs.k8s.io/cluster-api/api/core/v1beta2.ObjectMeta"}, - } -} - func schema_cluster_api_api_core_v1beta2_MachinePoolDeprecatedStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -4542,6 +4538,7 @@ func schema_cluster_api_api_core_v1beta2_MachinePoolTopology(ref common.Referenc "variables": { SchemaProps: spec.SchemaProps{ Description: "variables can be used to customize the MachinePool through patches.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachinePoolVariables"), }, }, @@ -4684,40 +4681,6 @@ func schema_cluster_api_api_core_v1beta2_MachineReadinessGate(ref common.Referen } } -func schema_cluster_api_api_core_v1beta2_MachineRollingUpdateDeployment(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MachineRollingUpdateDeployment is used to control the desired behavior of rolling update.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "maxUnavailable": { - SchemaProps: spec.SchemaProps{ - Description: "maxUnavailable is the maximum number of machines that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired machines (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 0. Example: when this is set to 30%, the old MachineSet can be scaled down to 70% of desired machines immediately when the rolling update starts. Once new machines are ready, old MachineSet can be scaled down further, followed by scaling up the new MachineSet, ensuring that the total number of machines available at all times during the update is at least 70% of desired machines.", - Ref: ref("k8s.io/apimachinery/pkg/util/intstr.IntOrString"), - }, - }, - "maxSurge": { - SchemaProps: spec.SchemaProps{ - Description: "maxSurge is the maximum number of machines that can be scheduled above the desired number of machines. Value can be an absolute number (ex: 5) or a percentage of desired machines (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 1. Example: when this is set to 30%, the new MachineSet can be scaled up immediately when the rolling update starts, such that the total number of old and new machines do not exceed 130% of desired machines. Once old machines have been killed, new MachineSet can be scaled up further, ensuring that total number of machines running at any time during the update is at most 130% of desired machines.", - Ref: ref("k8s.io/apimachinery/pkg/util/intstr.IntOrString"), - }, - }, - "deletePolicy": { - SchemaProps: spec.SchemaProps{ - Description: "deletePolicy defines the policy used by the MachineDeployment to identify nodes to delete when downscaling. Valid values are \"Random, \"Newest\", \"Oldest\" When no value is supplied, the default DeletePolicy of MachineSet is used", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - Dependencies: []string{ - "k8s.io/apimachinery/pkg/util/intstr.IntOrString"}, - } -} - func schema_cluster_api_api_core_v1beta2_MachineSet(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -5661,6 +5624,7 @@ func schema_cluster_api_api_core_v1beta2_Topology(ref common.ReferenceCallback) "workers": { SchemaProps: spec.SchemaProps{ Description: "workers encapsulates the different constructs that form the worker nodes for the cluster.", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.WorkersTopology"), }, }, diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index 50f79a4a9a28..ebcfb53e6717 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -1326,18 +1326,14 @@ func (r *KubeadmConfigReconciler) computeClusterConfigurationAndAdditionalData(c data.ClusterName = ptr.To(cluster.Name) // Use ClusterNetwork settings, if defined - if cluster.Spec.ClusterNetwork != nil { - if cluster.Spec.ClusterNetwork.ServiceDomain != "" { - data.DNSDomain = ptr.To(cluster.Spec.ClusterNetwork.ServiceDomain) - } - if cluster.Spec.ClusterNetwork.Services != nil && - len(cluster.Spec.ClusterNetwork.Services.CIDRBlocks) > 0 { - data.ServiceSubnet = ptr.To(cluster.Spec.ClusterNetwork.Services.String()) - } - if cluster.Spec.ClusterNetwork.Pods != nil && - len(cluster.Spec.ClusterNetwork.Pods.CIDRBlocks) > 0 { - data.PodSubnet = ptr.To(cluster.Spec.ClusterNetwork.Pods.String()) - } + if cluster.Spec.ClusterNetwork.ServiceDomain != "" { + data.DNSDomain = ptr.To(cluster.Spec.ClusterNetwork.ServiceDomain) + } + if len(cluster.Spec.ClusterNetwork.Services.CIDRBlocks) > 0 { + data.ServiceSubnet = ptr.To(cluster.Spec.ClusterNetwork.Services.String()) + } + if len(cluster.Spec.ClusterNetwork.Pods.CIDRBlocks) > 0 { + data.PodSubnet = ptr.To(cluster.Spec.ClusterNetwork.Pods.String()) } // Use Version from machine, if defined diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go index 01425afb8f2c..d4da446cdde8 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go @@ -1831,9 +1831,9 @@ func TestKubeadmConfigReconciler_computeClusterConfigurationAndAdditionalData(t Name: "mycluster", }, Spec: clusterv1.ClusterSpec{ - ClusterNetwork: &clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{CIDRBlocks: []string{"myServiceSubnet"}}, - Pods: &clusterv1.NetworkRanges{CIDRBlocks: []string{"myPodSubnet"}}, + ClusterNetwork: clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{CIDRBlocks: []string{"myServiceSubnet"}}, + Pods: clusterv1.NetworkRanges{CIDRBlocks: []string{"myPodSubnet"}}, ServiceDomain: "myDNSDomain", }, ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "myControlPlaneEndpoint", Port: 6443}, diff --git a/cmd/clusterctl/client/cluster/objectgraph.go b/cmd/clusterctl/client/cluster/objectgraph.go index 0113eba5ff9c..22efc6c9d010 100644 --- a/cmd/clusterctl/client/cluster/objectgraph.go +++ b/cmd/clusterctl/client/cluster/objectgraph.go @@ -532,16 +532,16 @@ func (o *objectGraph) Discovery(ctx context.Context, namespace string) error { } for _, mdClass := range cc.Spec.Workers.MachineDeployments { - _, err = o.fetchRef(ctx, discoveryBackoff, mdClass.Template.Infrastructure.TemplateRef.ToObjectReference(cc.Namespace)) + _, err = o.fetchRef(ctx, discoveryBackoff, mdClass.Infrastructure.TemplateRef.ToObjectReference(cc.Namespace)) errs = append(errs, err) - _, err = o.fetchRef(ctx, discoveryBackoff, mdClass.Template.Bootstrap.TemplateRef.ToObjectReference(cc.Namespace)) + _, err = o.fetchRef(ctx, discoveryBackoff, mdClass.Bootstrap.TemplateRef.ToObjectReference(cc.Namespace)) errs = append(errs, err) } for _, mpClass := range cc.Spec.Workers.MachinePools { - _, err = o.fetchRef(ctx, discoveryBackoff, mpClass.Template.Infrastructure.TemplateRef.ToObjectReference(cc.Namespace)) + _, err = o.fetchRef(ctx, discoveryBackoff, mpClass.Infrastructure.TemplateRef.ToObjectReference(cc.Namespace)) errs = append(errs, err) - _, err = o.fetchRef(ctx, discoveryBackoff, mpClass.Template.Bootstrap.TemplateRef.ToObjectReference(cc.Namespace)) + _, err = o.fetchRef(ctx, discoveryBackoff, mpClass.Bootstrap.TemplateRef.ToObjectReference(cc.Namespace)) errs = append(errs, err) } diff --git a/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml b/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml index 327a2e48c6ea..32f68c175b4e 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml @@ -2882,6 +2882,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType @@ -2896,6 +2897,7 @@ spec: machineHealthCheck defines a MachineHealthCheck for this ControlPlaneClass. This field is supported if and only if the ControlPlane provider template referenced above is Machine based and supports setting replicas. + minProperties: 1 properties: maxUnhealthy: anyOf: @@ -2997,6 +2999,7 @@ spec: - type type: object maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic unhealthyRange: @@ -3168,6 +3171,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType @@ -3920,6 +3924,47 @@ spec: MachineDeploymentClass serves as a template to define a set of worker nodes of the cluster provisioned using the `ClusterClass`. properties: + bootstrap: + description: |- + bootstrap contains the bootstrap template reference to be used + for the creation of worker Machines. + properties: + templateRef: + description: templateRef is a required reference to + the BootstrapTemplate for a MachineDeployment. + properties: + apiVersion: + description: |- + apiVersion of the template. + apiVersion must be fully qualified domain name followed by / and a version. + maxLength: 317 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ + type: string + kind: + description: |- + kind of the template. + kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: |- + name of the template. + name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + maxLength: 253 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + required: + - apiVersion + - kind + - name + type: object + required: + - templateRef + type: object class: description: |- class denotes a type of worker node present in the cluster, @@ -3936,9 +3981,51 @@ spec: maxLength: 256 minLength: 1 type: string + infrastructure: + description: |- + infrastructure contains the infrastructure template reference to be used + for the creation of worker Machines. + properties: + templateRef: + description: templateRef is a required reference to + the InfrastructureTemplate for a MachineDeployment. + properties: + apiVersion: + description: |- + apiVersion of the template. + apiVersion must be fully qualified domain name followed by / and a version. + maxLength: 317 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ + type: string + kind: + description: |- + kind of the template. + kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: |- + name of the template. + name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + maxLength: 253 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + required: + - apiVersion + - kind + - name + type: object + required: + - templateRef + type: object machineHealthCheck: description: machineHealthCheck defines a MachineHealthCheck for this MachineDeploymentClass. + minProperties: 1 properties: maxUnhealthy: anyOf: @@ -4040,6 +4127,7 @@ spec: - type type: object maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic unhealthyRange: @@ -4055,6 +4143,31 @@ spec: pattern: ^\[[0-9]+-[0-9]+\]$ type: string type: object + metadata: + description: |- + metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. + At runtime this metadata is merged with the corresponding metadata from the topology. + minProperties: 1 + properties: + annotations: + additionalProperties: + type: string + description: |- + annotations is an unstructured key value map stored with a resource that may be + set by external tools to store and retrieve arbitrary metadata. They are not + queryable and should be preserved when modifying objects. + More info: http://kubernetes.io/docs/user-guide/annotations + type: object + labels: + additionalProperties: + type: string + description: |- + labels is a map of string keys and values that can be used to organize and categorize + (scope and select) objects. May match selectors of replication controllers + and services. + More info: http://kubernetes.io/docs/user-guide/labels + type: object + type: object minReadySeconds: description: |- minReadySeconds is the minimum number of seconds for which a newly created machine should @@ -4146,6 +4259,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType @@ -4155,11 +4269,13 @@ spec: strategy is the deployment strategy to use to replace existing machines with new ones. NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass. + minProperties: 1 properties: remediation: description: |- remediation controls the strategy of remediating unhealthy machines and how remediating operations should occur during the lifecycle of the dependant MachineSets. + minProperties: 1 properties: maxInFlight: anyOf: @@ -4186,6 +4302,7 @@ spec: description: |- rollingUpdate is the rolling update config params. Present only if MachineDeploymentStrategyType = RollingUpdate. + minProperties: 1 properties: deletePolicy: description: |- @@ -4244,125 +4361,10 @@ spec: - OnDelete type: string type: object - template: - description: |- - template is a local struct containing a collection of templates for creation of - MachineDeployment objects representing a set of worker nodes. - properties: - bootstrap: - description: |- - bootstrap contains the bootstrap template reference to be used - for the creation of worker Machines. - properties: - templateRef: - description: templateRef is a required reference - to the BootstrapTemplate for a MachineDeployment. - properties: - apiVersion: - description: |- - apiVersion of the template. - apiVersion must be fully qualified domain name followed by / and a version. - maxLength: 317 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ - type: string - kind: - description: |- - kind of the template. - kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. - maxLength: 63 - minLength: 1 - pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ - type: string - name: - description: |- - name of the template. - name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - maxLength: 253 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - type: string - required: - - apiVersion - - kind - - name - type: object - required: - - templateRef - type: object - infrastructure: - description: |- - infrastructure contains the infrastructure template reference to be used - for the creation of worker Machines. - properties: - templateRef: - description: templateRef is a required reference - to the InfrastructureTemplate for a MachineDeployment. - properties: - apiVersion: - description: |- - apiVersion of the template. - apiVersion must be fully qualified domain name followed by / and a version. - maxLength: 317 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ - type: string - kind: - description: |- - kind of the template. - kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. - maxLength: 63 - minLength: 1 - pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ - type: string - name: - description: |- - name of the template. - name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - maxLength: 253 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - type: string - required: - - apiVersion - - kind - - name - type: object - required: - - templateRef - type: object - metadata: - description: |- - metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment. - At runtime this metadata is merged with the corresponding metadata from the topology. - minProperties: 1 - properties: - annotations: - additionalProperties: - type: string - description: |- - annotations is an unstructured key value map stored with a resource that may be - set by external tools to store and retrieve arbitrary metadata. They are not - queryable and should be preserved when modifying objects. - More info: http://kubernetes.io/docs/user-guide/annotations - type: object - labels: - additionalProperties: - type: string - description: |- - labels is a map of string keys and values that can be used to organize and categorize - (scope and select) objects. May match selectors of replication controllers - and services. - More info: http://kubernetes.io/docs/user-guide/labels - type: object - type: object - required: - - bootstrap - - infrastructure - type: object required: + - bootstrap - class - - template + - infrastructure type: object maxItems: 100 type: array @@ -4378,6 +4380,47 @@ spec: MachinePoolClass serves as a template to define a pool of worker nodes of the cluster provisioned using `ClusterClass`. properties: + bootstrap: + description: |- + bootstrap contains the bootstrap template reference to be used + for the creation of the Machines in the MachinePool. + properties: + templateRef: + description: templateRef is a required reference to + the BootstrapTemplate for a MachinePool. + properties: + apiVersion: + description: |- + apiVersion of the template. + apiVersion must be fully qualified domain name followed by / and a version. + maxLength: 317 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ + type: string + kind: + description: |- + kind of the template. + kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: |- + name of the template. + name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + maxLength: 253 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + required: + - apiVersion + - kind + - name + type: object + required: + - templateRef + type: object class: description: |- class denotes a type of machine pool present in the cluster, @@ -4398,6 +4441,72 @@ spec: maxItems: 100 type: array x-kubernetes-list-type: atomic + infrastructure: + description: |- + infrastructure contains the infrastructure template reference to be used + for the creation of the MachinePool. + properties: + templateRef: + description: templateRef is a required reference to + the InfrastructureTemplate for a MachinePool. + properties: + apiVersion: + description: |- + apiVersion of the template. + apiVersion must be fully qualified domain name followed by / and a version. + maxLength: 317 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ + type: string + kind: + description: |- + kind of the template. + kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: |- + name of the template. + name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + maxLength: 253 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + required: + - apiVersion + - kind + - name + type: object + required: + - templateRef + type: object + metadata: + description: |- + metadata is the metadata applied to the MachinePool. + At runtime this metadata is merged with the corresponding metadata from the topology. + minProperties: 1 + properties: + annotations: + additionalProperties: + type: string + description: |- + annotations is an unstructured key value map stored with a resource that may be + set by external tools to store and retrieve arbitrary metadata. They are not + queryable and should be preserved when modifying objects. + More info: http://kubernetes.io/docs/user-guide/annotations + type: object + labels: + additionalProperties: + type: string + description: |- + labels is a map of string keys and values that can be used to organize and categorize + (scope and select) objects. May match selectors of replication controllers + and services. + More info: http://kubernetes.io/docs/user-guide/labels + type: object + type: object minReadySeconds: description: |- minReadySeconds is the minimum number of seconds for which a newly created machine pool should @@ -4452,125 +4561,10 @@ spec: format: int32 minimum: 0 type: integer - template: - description: |- - template is a local struct containing a collection of templates for creation of - MachinePools objects representing a pool of worker nodes. - properties: - bootstrap: - description: |- - bootstrap contains the bootstrap template reference to be used - for the creation of the Machines in the MachinePool. - properties: - templateRef: - description: templateRef is a required reference - to the BootstrapTemplate for a MachinePool. - properties: - apiVersion: - description: |- - apiVersion of the template. - apiVersion must be fully qualified domain name followed by / and a version. - maxLength: 317 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ - type: string - kind: - description: |- - kind of the template. - kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. - maxLength: 63 - minLength: 1 - pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ - type: string - name: - description: |- - name of the template. - name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - maxLength: 253 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - type: string - required: - - apiVersion - - kind - - name - type: object - required: - - templateRef - type: object - infrastructure: - description: |- - infrastructure contains the infrastructure template reference to be used - for the creation of the MachinePool. - properties: - templateRef: - description: templateRef is a required reference - to the InfrastructureTemplate for a MachinePool. - properties: - apiVersion: - description: |- - apiVersion of the template. - apiVersion must be fully qualified domain name followed by / and a version. - maxLength: 317 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[a-z]([-a-z0-9]*[a-z0-9])?$ - type: string - kind: - description: |- - kind of the template. - kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character. - maxLength: 63 - minLength: 1 - pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ - type: string - name: - description: |- - name of the template. - name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - maxLength: 253 - minLength: 1 - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - type: string - required: - - apiVersion - - kind - - name - type: object - required: - - templateRef - type: object - metadata: - description: |- - metadata is the metadata applied to the MachinePool. - At runtime this metadata is merged with the corresponding metadata from the topology. - minProperties: 1 - properties: - annotations: - additionalProperties: - type: string - description: |- - annotations is an unstructured key value map stored with a resource that may be - set by external tools to store and retrieve arbitrary metadata. They are not - queryable and should be preserved when modifying objects. - More info: http://kubernetes.io/docs/user-guide/annotations - type: object - labels: - additionalProperties: - type: string - description: |- - labels is a map of string keys and values that can be used to organize and categorize - (scope and select) objects. May match selectors of replication controllers - and services. - More info: http://kubernetes.io/docs/user-guide/labels - type: object - type: object - required: - - bootstrap - - infrastructure - type: object required: + - bootstrap - class - - template + - infrastructure type: object maxItems: 100 type: array diff --git a/config/crd/bases/cluster.x-k8s.io_clusters.yaml b/config/crd/bases/cluster.x-k8s.io_clusters.yaml index 5db29ec18189..d0d307df2e5f 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusters.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusters.yaml @@ -2224,18 +2224,22 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType x-kubernetes-list-type: map clusterNetwork: description: clusterNetwork represents the cluster network configuration. + minProperties: 1 properties: apiServerPort: description: |- apiServerPort specifies the port the API Server should bind to. Defaults to 6443. format: int32 + maximum: 65535 + minimum: 1 type: integer pods: description: pods is the network ranges from which Pod networks @@ -2408,6 +2412,9 @@ spec: minProperties: 1 properties: machineHealthCheck: + allOf: + - minProperties: 1 + - minProperties: 1 description: |- machineHealthCheck allows to enable, disable and override the MachineHealthCheck configuration in the ClusterClass for this control plane. @@ -2524,6 +2531,7 @@ spec: - type type: object maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic unhealthyRange: @@ -2628,6 +2636,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType @@ -2635,7 +2644,7 @@ spec: replicas: description: |- replicas is the number of control plane nodes. - If the value is nil, the ControlPlane object is created without the number of Replicas + If the value is not set, the ControlPlane object is created without the number of Replicas and it's assumed that the control plane controller does not implement support for this field. When specified against a control plane provider that lacks support for this field, this value will be ignored. format: int32 @@ -2643,6 +2652,7 @@ spec: variables: description: variables can be used to customize the ControlPlane through patches. + minProperties: 1 properties: overrides: description: overrides can be used to override Cluster @@ -2672,6 +2682,7 @@ spec: - value type: object maxItems: 1000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name @@ -2708,6 +2719,7 @@ spec: - value type: object maxItems: 1000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name @@ -2721,6 +2733,7 @@ spec: description: |- workers encapsulates the different constructs that form the worker nodes for the cluster. + minProperties: 1 properties: machineDeployments: description: machineDeployments is a list of machine deployments @@ -2746,6 +2759,9 @@ spec: minLength: 1 type: string machineHealthCheck: + allOf: + - minProperties: 1 + - minProperties: 1 description: |- machineHealthCheck allows to enable, disable and override the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment. @@ -2862,6 +2878,7 @@ spec: - type type: object maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic unhealthyRange: @@ -2980,6 +2997,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType @@ -2996,11 +3014,13 @@ spec: description: |- strategy is the deployment strategy to use to replace existing machines with new ones. + minProperties: 1 properties: remediation: description: |- remediation controls the strategy of remediating unhealthy machines and how remediating operations should occur during the lifecycle of the dependant MachineSets. + minProperties: 1 properties: maxInFlight: anyOf: @@ -3027,6 +3047,7 @@ spec: description: |- rollingUpdate is the rolling update config params. Present only if MachineDeploymentStrategyType = RollingUpdate. + minProperties: 1 properties: deletePolicy: description: |- @@ -3088,6 +3109,7 @@ spec: variables: description: variables can be used to customize the MachineDeployment through patches. + minProperties: 1 properties: overrides: description: overrides can be used to override Cluster @@ -3117,6 +3139,7 @@ spec: - value type: object maxItems: 1000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name @@ -3127,6 +3150,7 @@ spec: - name type: object maxItems: 2000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name @@ -3156,6 +3180,7 @@ spec: minLength: 1 type: string maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic metadata: @@ -3235,6 +3260,7 @@ spec: variables: description: variables can be used to customize the MachinePool through patches. + minProperties: 1 properties: overrides: description: overrides can be used to override Cluster @@ -3264,6 +3290,7 @@ spec: - value type: object maxItems: 1000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name @@ -3274,6 +3301,7 @@ spec: - name type: object maxItems: 2000 + minItems: 1 type: array x-kubernetes-list-map-keys: - name diff --git a/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml b/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml index 4404804c30d2..211d14e026f4 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml @@ -1996,11 +1996,13 @@ spec: description: |- strategy is the deployment strategy to use to replace existing machines with new ones. + minProperties: 1 properties: remediation: description: |- remediation controls the strategy of remediating unhealthy machines and how remediating operations should occur during the lifecycle of the dependant MachineSets. + minProperties: 1 properties: maxInFlight: anyOf: @@ -2027,6 +2029,7 @@ spec: description: |- rollingUpdate is the rolling update config params. Present only if MachineDeploymentStrategyType = RollingUpdate. + minProperties: 1 properties: deletePolicy: description: |- @@ -2306,6 +2309,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType diff --git a/config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml b/config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml index 73a706df40f3..144343a72beb 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml @@ -1189,6 +1189,7 @@ spec: - type type: object maxItems: 100 + minItems: 1 type: array x-kubernetes-list-type: atomic unhealthyRange: diff --git a/config/crd/bases/cluster.x-k8s.io_machinepools.yaml b/config/crd/bases/cluster.x-k8s.io_machinepools.yaml index b049eb9af09e..e16a00791e48 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinepools.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinepools.yaml @@ -1917,6 +1917,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType diff --git a/config/crd/bases/cluster.x-k8s.io_machines.yaml b/config/crd/bases/cluster.x-k8s.io_machines.yaml index 345edafea329..5274c3f64253 100644 --- a/config/crd/bases/cluster.x-k8s.io_machines.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machines.yaml @@ -1710,6 +1710,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType diff --git a/config/crd/bases/cluster.x-k8s.io_machinesets.yaml b/config/crd/bases/cluster.x-k8s.io_machinesets.yaml index e7242cfffd60..f089735e424c 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinesets.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinesets.yaml @@ -1970,6 +1970,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index 1ad62578f272..e6522d7f5a39 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -7295,6 +7295,7 @@ spec: - conditionType type: object maxItems: 32 + minItems: 1 type: array x-kubernetes-list-map-keys: - conditionType diff --git a/docs/book/src/developer/providers/contracts/control-plane.md b/docs/book/src/developer/providers/contracts/control-plane.md index 0a9bdd6c9390..79ede02fcce8 100644 --- a/docs/book/src/developer/providers/contracts/control-plane.md +++ b/docs/book/src/developer/providers/contracts/control-plane.md @@ -507,6 +507,7 @@ type FooControlPlaneMachineTemplate struct { // +optional // +listType=map // +listMapKey=conditionType + // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=32 ReadinessGates []clusterv1.MachineReadinessGate `json:"readinessGates,omitempty"` diff --git a/exp/topology/desiredstate/desired_state.go b/exp/topology/desiredstate/desired_state.go index 1b9ddfb3ede0..d51b82381a64 100644 --- a/exp/topology/desiredstate/desired_state.go +++ b/exp/topology/desiredstate/desired_state.go @@ -21,6 +21,7 @@ import ( "context" "fmt" "maps" + "reflect" "slices" "strings" "time" @@ -795,7 +796,7 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope } strategy := machineDeploymentClass.Strategy - if machineDeploymentTopology.Strategy != nil { + if !reflect.DeepEqual(machineDeploymentTopology.Strategy, clusterv1.MachineDeploymentStrategy{}) { strategy = machineDeploymentTopology.Strategy } diff --git a/exp/topology/desiredstate/desired_state_test.go b/exp/topology/desiredstate/desired_state_test.go index 49c91a69bb05..ff94d7d846e4 100644 --- a/exp/topology/desiredstate/desired_state_test.go +++ b/exp/topology/desiredstate/desired_state_test.go @@ -1718,7 +1718,7 @@ func TestComputeMachineDeployment(t *testing.T) { var clusterClassMinReadySeconds int32 = 20 clusterClassStrategy := clusterv1.MachineDeploymentStrategy{ Type: clusterv1.OnDeleteMachineDeploymentStrategyType, - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: ptr.To(intstr.FromInt32(5)), }, } @@ -1740,7 +1740,7 @@ func TestComputeMachineDeployment(t *testing.T) { WithNodeVolumeDetachTimeout(&clusterClassDuration). WithNodeDeletionTimeout(&clusterClassDuration). WithMinReadySeconds(&clusterClassMinReadySeconds). - WithStrategy(&clusterClassStrategy). + WithStrategy(clusterClassStrategy). Build() mcds := []clusterv1.MachineDeploymentClass{*md1} fakeClass := builder.ClusterClass(metav1.NamespaceDefault, "class1"). @@ -1785,7 +1785,7 @@ func TestComputeMachineDeployment(t *testing.T) { var topologyMinReadySeconds int32 = 10 topologyStrategy := clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: ptr.To(intstr.FromInt32(5)), }, } @@ -1816,7 +1816,7 @@ func TestComputeMachineDeployment(t *testing.T) { NodeVolumeDetachTimeoutSeconds: &topologyDuration, NodeDeletionTimeoutSeconds: &topologyDuration, MinReadySeconds: &topologyMinReadySeconds, - Strategy: &topologyStrategy, + Strategy: topologyStrategy, } t.Run("Generates the machine deployment and the referenced templates", func(t *testing.T) { @@ -1845,7 +1845,7 @@ func TestComputeMachineDeployment(t *testing.T) { actualMd := actual.Object g.Expect(*actualMd.Spec.Replicas).To(Equal(replicas)) - g.Expect(*actualMd.Spec.Strategy).To(BeComparableTo(topologyStrategy)) + g.Expect(actualMd.Spec.Strategy).To(BeComparableTo(topologyStrategy)) g.Expect(actualMd.Spec.Template.Spec.MinReadySeconds).To(HaveValue(Equal(topologyMinReadySeconds))) g.Expect(actualMd.Spec.Template.Spec.FailureDomain).To(Equal(topologyFailureDomain)) g.Expect(*actualMd.Spec.Template.Spec.NodeDrainTimeoutSeconds).To(Equal(topologyDuration)) @@ -1856,13 +1856,13 @@ func TestComputeMachineDeployment(t *testing.T) { g.Expect(actualMd.Name).To(ContainSubstring("cluster1")) g.Expect(actualMd.Name).To(ContainSubstring("big-pool-of-machines")) - expectedAnnotations := util.MergeMap(mdTopology.Metadata.Annotations, md1.Template.Metadata.Annotations) + expectedAnnotations := util.MergeMap(mdTopology.Metadata.Annotations, md1.Metadata.Annotations) delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation) delete(expectedAnnotations, clusterv1.ClusterTopologyDeferUpgradeAnnotation) g.Expect(actualMd.Annotations).To(Equal(expectedAnnotations)) g.Expect(actualMd.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations)) - g.Expect(actualMd.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMd.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", @@ -1872,7 +1872,7 @@ func TestComputeMachineDeployment(t *testing.T) { clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", })) - g.Expect(actualMd.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMd.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", @@ -1903,7 +1903,7 @@ func TestComputeMachineDeployment(t *testing.T) { // checking only values from CC defaults actualMd := actual.Object - g.Expect(*actualMd.Spec.Strategy).To(BeComparableTo(clusterClassStrategy)) + g.Expect(actualMd.Spec.Strategy).To(BeComparableTo(clusterClassStrategy)) g.Expect(actualMd.Spec.Template.Spec.MinReadySeconds).To(HaveValue(Equal(clusterClassMinReadySeconds))) g.Expect(actualMd.Spec.Template.Spec.FailureDomain).To(Equal(clusterClassFailureDomain)) g.Expect(actualMd.Spec.Template.Spec.ReadinessGates).To(Equal(clusterClassReadinessGates)) @@ -2002,13 +2002,13 @@ func TestComputeMachineDeployment(t *testing.T) { g.Expect(actualMd.Spec.Template.Spec.FailureDomain).To(Equal(topologyFailureDomain)) g.Expect(actualMd.Name).To(Equal("existing-deployment-1")) - expectedAnnotations := util.MergeMap(mdTopology.Metadata.Annotations, md1.Template.Metadata.Annotations) + expectedAnnotations := util.MergeMap(mdTopology.Metadata.Annotations, md1.Metadata.Annotations) delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation) delete(expectedAnnotations, clusterv1.ClusterTopologyDeferUpgradeAnnotation) g.Expect(actualMd.Annotations).To(Equal(expectedAnnotations)) g.Expect(actualMd.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations)) - g.Expect(actualMd.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMd.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", @@ -2018,7 +2018,7 @@ func TestComputeMachineDeployment(t *testing.T) { clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", })) - g.Expect(actualMd.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMd.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mdTopology.Metadata.Labels, md1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachineDeploymentNameLabel: "big-pool-of-machines", @@ -2121,7 +2121,7 @@ func TestComputeMachineDeployment(t *testing.T) { s.Blueprint.Topology.ControlPlane = clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](2), } - s.Blueprint.Topology.Workers = &clusterv1.WorkersTopology{} + s.Blueprint.Topology.Workers = clusterv1.WorkersTopology{} mdsState := scope.MachineDeploymentsStateMap{} if tt.currentMDVersion != nil { @@ -2315,18 +2315,18 @@ func TestComputeMachinePool(t *testing.T) { g.Expect(actualMp.Name).To(ContainSubstring("cluster1")) g.Expect(actualMp.Name).To(ContainSubstring("big-pool-of-machines")) - expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Template.Metadata.Annotations) + expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Metadata.Annotations) delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation) delete(expectedAnnotations, clusterv1.ClusterTopologyDeferUpgradeAnnotation) g.Expect(actualMp.Annotations).To(Equal(expectedAnnotations)) g.Expect(actualMp.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations)) - g.Expect(actualMp.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMp.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines", }))) - g.Expect(actualMp.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMp.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines", @@ -2406,18 +2406,18 @@ func TestComputeMachinePool(t *testing.T) { g.Expect(actualMp.Spec.FailureDomains).To(Equal(topologyFailureDomains)) g.Expect(actualMp.Name).To(Equal("existing-pool-1")) - expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Template.Metadata.Annotations) + expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Metadata.Annotations) delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation) delete(expectedAnnotations, clusterv1.ClusterTopologyDeferUpgradeAnnotation) g.Expect(actualMp.Annotations).To(Equal(expectedAnnotations)) g.Expect(actualMp.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations)) - g.Expect(actualMp.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMp.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines", }))) - g.Expect(actualMp.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{ + g.Expect(actualMp.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Metadata.Labels, map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines", @@ -2520,7 +2520,7 @@ func TestComputeMachinePool(t *testing.T) { s.Blueprint.Topology.ControlPlane = clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](2), } - s.Blueprint.Topology.Workers = &clusterv1.WorkersTopology{} + s.Blueprint.Topology.Workers = clusterv1.WorkersTopology{} mpsState := scope.MachinePoolsStateMap{} if tt.currentMPVersion != nil { @@ -2692,7 +2692,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) { ControlPlane: clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](2), }, - Workers: &clusterv1.WorkersTopology{}, + Workers: clusterv1.WorkersTopology{}, }}, Current: &scope.ClusterState{ ControlPlane: &scope.ControlPlaneState{Object: controlPlaneObj}, @@ -2861,7 +2861,7 @@ func TestComputeMachinePoolVersion(t *testing.T) { ControlPlane: clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](2), }, - Workers: &clusterv1.WorkersTopology{}, + Workers: clusterv1.WorkersTopology{}, }}, Current: &scope.ClusterState{ ControlPlane: &scope.ControlPlaneState{Object: controlPlaneObj}, @@ -2907,7 +2907,7 @@ func TestComputeMachinePoolVersion(t *testing.T) { func TestIsMachineDeploymentDeferred(t *testing.T) { clusterTopology := &clusterv1.Topology{ - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Name: "md-with-defer-upgrade", @@ -2990,7 +2990,7 @@ func TestIsMachineDeploymentDeferred(t *testing.T) { func TestIsMachinePoolDeferred(t *testing.T) { clusterTopology := &clusterv1.Topology{ - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachinePools: []clusterv1.MachinePoolTopology{ { Name: "mp-with-defer-upgrade", diff --git a/exp/topology/scope/blueprint.go b/exp/topology/scope/blueprint.go index f8e01566ea3e..402ae827af62 100644 --- a/exp/topology/scope/blueprint.go +++ b/exp/topology/scope/blueprint.go @@ -153,10 +153,10 @@ func (b *ClusterBlueprint) MachineDeploymentMachineHealthCheckClass(md *clusterv // HasMachineDeployments checks whether the topology has MachineDeployments. func (b *ClusterBlueprint) HasMachineDeployments() bool { - return b.Topology.Workers != nil && len(b.Topology.Workers.MachineDeployments) > 0 + return len(b.Topology.Workers.MachineDeployments) > 0 } // HasMachinePools checks whether the topology has MachinePools. func (b *ClusterBlueprint) HasMachinePools() bool { - return b.Topology.Workers != nil && len(b.Topology.Workers.MachinePools) > 0 + return len(b.Topology.Workers.MachinePools) > 0 } diff --git a/internal/api/core/v1alpha3/conversion.go b/internal/api/core/v1alpha3/conversion.go index 766120e8f971..2d1832a06df2 100644 --- a/internal/api/core/v1alpha3/conversion.go +++ b/internal/api/core/v1alpha3/conversion.go @@ -163,6 +163,11 @@ func (dst *Cluster) ConvertFrom(srcRaw conversion.Hub) error { dst.Spec.ControlPlaneRef = controlPlaneRef } + if dst.Spec.ClusterNetwork != nil && dst.Spec.ClusterNetwork.APIServerPort != nil && + *dst.Spec.ClusterNetwork.APIServerPort == 0 { + dst.Spec.ClusterNetwork.APIServerPort = nil + } + // Reset conditions from autogenerated conversions // NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1alpha3). dst.Status.Conditions = nil @@ -420,18 +425,8 @@ func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error { // Recover other values if ok { - if restored.Spec.Strategy != nil { - if dst.Spec.Strategy == nil { - dst.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{} - } - if restored.Spec.Strategy.RollingUpdate != nil { - if dst.Spec.Strategy.RollingUpdate == nil { - dst.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{} - } - dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy - } - dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation - } + dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy + dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation if restored.Spec.MachineNamingStrategy != nil { dst.Spec.MachineNamingStrategy = restored.Spec.MachineNamingStrategy @@ -674,10 +669,72 @@ func Convert_v1beta2_MachineSetStatus_To_v1alpha3_MachineSetStatus(in *clusterv1 return autoConvert_v1beta2_MachineSetStatus_To_v1alpha3_MachineSetStatus(in, out, nil) } +func Convert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *clusterv1.ClusterSpec, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s); err != nil { + return err + } + if in.ClusterNetwork != nil { + if err := Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in.ClusterNetwork, &out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + func Convert_v1beta2_ClusterSpec_To_v1alpha3_ClusterSpec(in *clusterv1.ClusterSpec, out *ClusterSpec, s apimachineryconversion.Scope) error { // NOTE: custom conversion func is required because spec.Topology does not exist in v1alpha3 - // AvailabilityGates was added in v1beta1 - return autoConvert_v1beta2_ClusterSpec_To_v1alpha3_ClusterSpec(in, out, s) + // AvailabilityGates was added in v1alpha3 + if err := autoConvert_v1beta2_ClusterSpec_To_v1alpha3_ClusterSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.ClusterNetwork, clusterv1.ClusterNetwork{}) { + out.ClusterNetwork = &ClusterNetwork{} + if err := Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(&in.ClusterNetwork, out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *clusterv1.ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s); err != nil { + return err + } + if in.Services != nil { + if err := autoConvert_v1alpha3_NetworkRanges_To_v1beta2_NetworkRanges(in.Services, &out.Services, s); err != nil { + return err + } + } + if in.Pods != nil { + if err := autoConvert_v1alpha3_NetworkRanges_To_v1beta2_NetworkRanges(in.Pods, &out.Pods, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(in *clusterv1.ClusterNetwork, out *ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Services, clusterv1.NetworkRanges{}) { + out.Services = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1alpha3_NetworkRanges(&in.Services, out.Services, s); err != nil { + return err + } + } + + if !reflect.DeepEqual(in.Pods, clusterv1.NetworkRanges{}) { + out.Pods = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1alpha3_NetworkRanges(&in.Pods, out.Pods, s); err != nil { + return err + } + } + + return nil } func Convert_v1beta2_ClusterStatus_To_v1alpha3_ClusterStatus(in *clusterv1.ClusterStatus, out *ClusterStatus, s apimachineryconversion.Scope) error { @@ -704,8 +761,28 @@ func Convert_v1alpha3_Bootstrap_To_v1beta2_Bootstrap(in *Bootstrap, out *cluster return autoConvert_v1alpha3_Bootstrap_To_v1beta2_Bootstrap(in, out, s) } -func Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(in *clusterv1.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s apimachineryconversion.Scope) error { - return autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(in, out, s) +func Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in *MachineRollingUpdateDeployment, out *clusterv1.MachineDeploymentStrategyRollingUpdate, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge + return nil +} + +func Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha3_MachineRollingUpdateDeployment(in *clusterv1.MachineDeploymentStrategyRollingUpdate, out *MachineRollingUpdateDeployment, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge + return nil +} + +func Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *clusterv1.MachineDeploymentStrategy, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if in.RollingUpdate != nil { + if err := Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in.RollingUpdate, &out.RollingUpdate, s); err != nil { + return err + } + } + return nil } func Convert_v1alpha3_MachineHealthCheckSpec_To_v1beta2_MachineHealthCheckSpec(in *MachineHealthCheckSpec, out *clusterv1.MachineHealthCheckSpec, s apimachineryconversion.Scope) error { @@ -790,7 +867,17 @@ func Convert_v1beta2_MachineSpec_To_v1alpha3_MachineSpec(in *clusterv1.MachineSp } func Convert_v1beta2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec(in *clusterv1.MachineDeploymentSpec, out *MachineDeploymentSpec, s apimachineryconversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec(in, out, s) + if err := autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Strategy, clusterv1.MachineDeploymentStrategy{}) { + out.Strategy = &MachineDeploymentStrategy{} + if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(&in.Strategy, out.Strategy, s); err != nil { + return err + } + } + + return nil } func Convert_v1beta2_MachineDeploymentStatus_To_v1alpha3_MachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, out *MachineDeploymentStatus, s apimachineryconversion.Scope) error { @@ -805,7 +892,16 @@ func Convert_v1alpha3_MachineStatus_To_v1beta2_MachineStatus(in *MachineStatus, } func Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in *clusterv1.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s apimachineryconversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in, out, s) + if err := autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.RollingUpdate, clusterv1.MachineDeploymentStrategyRollingUpdate{}) { + out.RollingUpdate = &MachineRollingUpdateDeployment{} + if err := Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha3_MachineRollingUpdateDeployment(&in.RollingUpdate, out.RollingUpdate, s); err != nil { + return err + } + } + return nil } func Convert_v1beta2_MachineSetSpec_To_v1alpha3_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apimachineryconversion.Scope) error { @@ -814,7 +910,16 @@ func Convert_v1beta2_MachineSetSpec_To_v1alpha3_MachineSetSpec(in *clusterv1.Mac func Convert_v1alpha3_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in *MachineDeploymentSpec, out *clusterv1.MachineDeploymentSpec, s apimachineryconversion.Scope) error { // NOTE: v1beta2 MachineDeploymentSpec does not have ProgressDeadlineSeconds anymore. But it's fine to just lose this field it was never used. - return autoConvert_v1alpha3_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s) + if err := autoConvert_v1alpha3_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if in.Strategy != nil { + if err := Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in.Strategy, &out.Strategy, s); err != nil { + return err + } + } + + return nil } func Convert_v1alpha3_MachineDeploymentStatus_To_v1beta2_MachineDeploymentStatus(in *MachineDeploymentStatus, out *clusterv1.MachineDeploymentStatus, s apimachineryconversion.Scope) error { diff --git a/internal/api/core/v1alpha3/conversion_test.go b/internal/api/core/v1alpha3/conversion_test.go index d5f3b5fa5d97..dc3c577f0a92 100644 --- a/internal/api/core/v1alpha3/conversion_test.go +++ b/internal/api/core/v1alpha3/conversion_test.go @@ -261,6 +261,17 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue) // Drop RevisionHistoryLimit as we intentionally don't preserve it. in.RevisionHistoryLimit = nil + + if in.Strategy != nil { + if in.Strategy.RollingUpdate != nil { + if reflect.DeepEqual(in.Strategy.RollingUpdate, &MachineRollingUpdateDeployment{}) { + in.Strategy.RollingUpdate = nil + } + } + if reflect.DeepEqual(in.Strategy, &MachineDeploymentStrategy{}) { + in.Strategy = nil + } + } } func spokeObjectMeta(in *ObjectMeta, c randfill.Continue) { @@ -386,6 +397,18 @@ func spokeCluster(in *Cluster, c randfill.Continue) { in.Spec.InfrastructureRef.ResourceVersion = "" in.Spec.InfrastructureRef.FieldPath = "" } + + if in.Spec.ClusterNetwork != nil { + if in.Spec.ClusterNetwork.Services != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Services, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Services = nil + } + if in.Spec.ClusterNetwork.Pods != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Pods, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Pods = nil + } + if reflect.DeepEqual(in.Spec.ClusterNetwork, &ClusterNetwork{}) { + in.Spec.ClusterNetwork = nil + } + } } func MachineHealthCheckFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} { diff --git a/internal/api/core/v1alpha3/zz_generated.conversion.go b/internal/api/core/v1alpha3/zz_generated.conversion.go index 8fe97eccb346..e04b5f8df017 100644 --- a/internal/api/core/v1alpha3/zz_generated.conversion.go +++ b/internal/api/core/v1alpha3/zz_generated.conversion.go @@ -75,21 +75,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*Condition)(nil), (*v1beta2.Condition)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_Condition_To_v1beta2_Condition(a.(*Condition), b.(*v1beta2.Condition), scope) }); err != nil { @@ -140,11 +125,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineHealthCheck)(nil), (*v1beta2.MachineHealthCheck)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineHealthCheck_To_v1beta2_MachineHealthCheck(a.(*MachineHealthCheck), b.(*v1beta2.MachineHealthCheck), scope) }); err != nil { @@ -195,11 +175,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineRollingUpdateDeployment), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineSet)(nil), (*v1beta2.MachineSet)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineSet_To_v1beta2_MachineSet(a.(*MachineSet), b.(*v1beta2.MachineSet), scope) }); err != nil { @@ -255,6 +230,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*ClusterStatus)(nil), (*v1beta2.ClusterStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_ClusterStatus_To_v1beta2_ClusterStatus(a.(*ClusterStatus), b.(*v1beta2.ClusterStatus), scope) }); err != nil { @@ -275,6 +260,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineHealthCheckSpec)(nil), (*v1beta2.MachineHealthCheckSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineHealthCheckSpec_To_v1beta2_MachineHealthCheckSpec(a.(*MachineHealthCheckSpec), b.(*v1beta2.MachineHealthCheckSpec), scope) }); err != nil { @@ -295,6 +285,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineDeploymentStrategyRollingUpdate), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineSetSpec)(nil), (*v1beta2.MachineSetSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineSetSpec_To_v1beta2_MachineSetSpec(a.(*MachineSetSpec), b.(*v1beta2.MachineSetSpec), scope) }); err != nil { @@ -320,6 +315,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.ClusterSpec)(nil), (*ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_ClusterSpec_To_v1alpha3_ClusterSpec(a.(*v1beta2.ClusterSpec), b.(*ClusterSpec), scope) }); err != nil { @@ -340,6 +340,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha3_MachineRollingUpdateDeployment(a.(*v1beta2.MachineDeploymentStrategyRollingUpdate), b.(*MachineRollingUpdateDeployment), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategy)(nil), (*MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(a.(*v1beta2.MachineDeploymentStrategy), b.(*MachineDeploymentStrategy), scope) }); err != nil { @@ -365,11 +370,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta2.MachineRollingUpdateDeployment)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(a.(*v1beta2.MachineRollingUpdateDeployment), b.(*MachineRollingUpdateDeployment), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*v1beta2.MachineSetSpec)(nil), (*MachineSetSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineSetSpec_To_v1alpha3_MachineSetSpec(a.(*v1beta2.MachineSetSpec), b.(*MachineSetSpec), scope) }); err != nil { @@ -524,36 +524,30 @@ func Convert_v1beta2_ClusterList_To_v1alpha3_ClusterList(in *v1beta2.ClusterList } func autoConvert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_Pointer_int32_To_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork is an autogenerated conversion function. -func Convert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1alpha3_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s) -} - func autoConvert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_int32_To_Pointer_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork is an autogenerated conversion function. -func Convert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1beta2_ClusterNetwork_To_v1alpha3_ClusterNetwork(in, out, s) -} - func autoConvert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { if err := v1.Convert_bool_To_Pointer_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*v1beta2.ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.ClusterNetwork vs sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork) if err := Convert_v1alpha3_APIEndpoint_To_v1beta2_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -578,16 +572,11 @@ func autoConvert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, ou return nil } -// Convert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec is an autogenerated conversion function. -func Convert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { - return autoConvert_v1alpha3_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s) -} - func autoConvert_v1beta2_ClusterSpec_To_v1alpha3_ClusterSpec(in *v1beta2.ClusterSpec, out *ClusterSpec, s conversion.Scope) error { if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.ClusterNetwork) if err := Convert_v1beta2_APIEndpoint_To_v1alpha3_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -824,15 +813,7 @@ func autoConvert_v1alpha3_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec if err := Convert_v1alpha3_MachineTemplateSpec_To_v1beta2_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(v1beta2.MachineDeploymentStrategy) - if err := Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.MachineDeploymentStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy) // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type if err := v1.Convert_bool_To_Pointer_bool(&in.Paused, &out.Paused, s); err != nil { @@ -850,15 +831,7 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec if err := Convert_v1beta2_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.MachineDeploymentStrategy) // WARNING: in.MachineNamingStrategy requires manual conversion: does not exist in peer-type if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err @@ -905,34 +878,13 @@ func autoConvert_v1beta2_MachineDeploymentStatus_To_v1alpha3_MachineDeploymentSt func autoConvert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { out.Type = v1beta2.MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(v1beta2.MachineRollingUpdateDeployment) - if err := Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.MachineRollingUpdateDeployment vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate) return nil } -// Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy is an autogenerated conversion function. -func Convert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { - return autoConvert_v1alpha3_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s) -} - func autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in *v1beta2.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s conversion.Scope) error { out.Type = MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(MachineRollingUpdateDeployment) - if err := Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha3.MachineRollingUpdateDeployment) // WARNING: in.Remediation requires manual conversion: does not exist in peer-type return nil } @@ -1303,24 +1255,6 @@ func autoConvert_v1beta2_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in *v1b return nil } -func autoConvert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta2.MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - return nil -} - -// Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment is an autogenerated conversion function. -func Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta2.MachineRollingUpdateDeployment, s conversion.Scope) error { - return autoConvert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in, out, s) -} - -func autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(in *v1beta2.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - // WARNING: in.DeletePolicy requires manual conversion: does not exist in peer-type - return nil -} - func autoConvert_v1alpha3_MachineSet_To_v1beta2_MachineSet(in *MachineSet, out *v1beta2.MachineSet, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha3_MachineSetSpec_To_v1beta2_MachineSetSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/internal/api/core/v1alpha4/conversion.go b/internal/api/core/v1alpha4/conversion.go index 1a2a810cadfa..6de5085f3732 100644 --- a/internal/api/core/v1alpha4/conversion.go +++ b/internal/api/core/v1alpha4/conversion.go @@ -147,24 +147,19 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.Topology.ControlPlane.ReadinessGates = restored.Spec.Topology.ControlPlane.ReadinessGates - if restored.Spec.Topology.Workers != nil { - if dst.Spec.Topology.Workers == nil { - dst.Spec.Topology.Workers = &clusterv1.WorkersTopology{} - } - for i := range restored.Spec.Topology.Workers.MachineDeployments { - dst.Spec.Topology.Workers.MachineDeployments[i].FailureDomain = restored.Spec.Topology.Workers.MachineDeployments[i].FailureDomain - dst.Spec.Topology.Workers.MachineDeployments[i].Variables = restored.Spec.Topology.Workers.MachineDeployments[i].Variables - dst.Spec.Topology.Workers.MachineDeployments[i].ReadinessGates = restored.Spec.Topology.Workers.MachineDeployments[i].ReadinessGates - dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeoutSeconds - dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeoutSeconds - dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeoutSeconds - dst.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds = restored.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds - dst.Spec.Topology.Workers.MachineDeployments[i].Strategy = restored.Spec.Topology.Workers.MachineDeployments[i].Strategy - dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck - } - - dst.Spec.Topology.Workers.MachinePools = restored.Spec.Topology.Workers.MachinePools + for i := range restored.Spec.Topology.Workers.MachineDeployments { + dst.Spec.Topology.Workers.MachineDeployments[i].FailureDomain = restored.Spec.Topology.Workers.MachineDeployments[i].FailureDomain + dst.Spec.Topology.Workers.MachineDeployments[i].Variables = restored.Spec.Topology.Workers.MachineDeployments[i].Variables + dst.Spec.Topology.Workers.MachineDeployments[i].ReadinessGates = restored.Spec.Topology.Workers.MachineDeployments[i].ReadinessGates + dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeoutSeconds + dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeoutSeconds + dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeoutSeconds = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeoutSeconds + dst.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds = restored.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds + dst.Spec.Topology.Workers.MachineDeployments[i].Strategy = restored.Spec.Topology.Workers.MachineDeployments[i].Strategy + dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck } + + dst.Spec.Topology.Workers.MachinePools = restored.Spec.Topology.Workers.MachinePools } dst.Status.Conditions = restored.Status.Conditions dst.Status.ControlPlane = restored.Status.ControlPlane @@ -197,6 +192,11 @@ func (dst *Cluster) ConvertFrom(srcRaw conversion.Hub) error { dst.Spec.ControlPlaneRef = controlPlaneRef } + if dst.Spec.ClusterNetwork != nil && dst.Spec.ClusterNetwork.APIServerPort != nil && + *dst.Spec.ClusterNetwork.APIServerPort == 0 { + dst.Spec.ClusterNetwork.APIServerPort = nil + } + // Reset conditions from autogenerated conversions // NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1alpha4). dst.Status.Conditions = nil @@ -521,13 +521,7 @@ func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.Template.Spec.NodeDeletionTimeoutSeconds = restored.Spec.Template.Spec.NodeDeletionTimeoutSeconds dst.Spec.Template.Spec.NodeVolumeDetachTimeoutSeconds = restored.Spec.Template.Spec.NodeVolumeDetachTimeoutSeconds dst.Spec.RolloutAfter = restored.Spec.RolloutAfter - - if restored.Spec.Strategy != nil { - if dst.Spec.Strategy == nil { - dst.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{} - } - dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation - } + dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation if restored.Spec.MachineNamingStrategy != nil { dst.Spec.MachineNamingStrategy = restored.Spec.MachineNamingStrategy @@ -803,12 +797,83 @@ func Convert_v1beta2_MachineSpec_To_v1alpha4_MachineSpec(in *clusterv1.MachineSp } func Convert_v1beta2_MachineDeploymentSpec_To_v1alpha4_MachineDeploymentSpec(in *clusterv1.MachineDeploymentSpec, out *MachineDeploymentSpec, s apimachineryconversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha4_MachineDeploymentSpec(in, out, s) + if err := autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha4_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Strategy, clusterv1.MachineDeploymentStrategy{}) { + out.Strategy = &MachineDeploymentStrategy{} + if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(&in.Strategy, out.Strategy, s); err != nil { + return err + } + } + + return nil } -func Convert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(in *clusterv1.ClusterSpec, out *ClusterSpec, s apimachineryconversion.Scope) error { - // AvailabilityGates was added in v1beta1. - return autoConvert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(in, out, s) +func Convert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *clusterv1.ClusterSpec, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s); err != nil { + return err + } + if in.ClusterNetwork != nil { + if err := Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in.ClusterNetwork, &out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(in *clusterv1.ClusterSpec, out *ClusterSpec, s apimachineryconversion.Scope) error { // AvailabilityGates was added in v1alpha4. + if err := autoConvert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.ClusterNetwork, clusterv1.ClusterNetwork{}) { + out.ClusterNetwork = &ClusterNetwork{} + if err := Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(&in.ClusterNetwork, out.ClusterNetwork, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *clusterv1.ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s); err != nil { + return err + } + if in.Services != nil { + if err := autoConvert_v1alpha4_NetworkRanges_To_v1beta2_NetworkRanges(in.Services, &out.Services, s); err != nil { + return err + } + } + if in.Pods != nil { + if err := autoConvert_v1alpha4_NetworkRanges_To_v1beta2_NetworkRanges(in.Pods, &out.Pods, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(in *clusterv1.ClusterNetwork, out *ClusterNetwork, s apimachineryconversion.Scope) error { + if err := autoConvert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.Services, clusterv1.NetworkRanges{}) { + out.Services = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1alpha4_NetworkRanges(&in.Services, out.Services, s); err != nil { + return err + } + } + + if !reflect.DeepEqual(in.Pods, clusterv1.NetworkRanges{}) { + out.Pods = &NetworkRanges{} + if err := autoConvert_v1beta2_NetworkRanges_To_v1alpha4_NetworkRanges(&in.Pods, out.Pods, s); err != nil { + return err + } + } + + return nil } func Convert_v1beta2_ClusterStatus_To_v1alpha4_ClusterStatus(in *clusterv1.ClusterStatus, out *ClusterStatus, s apimachineryconversion.Scope) error { @@ -836,7 +901,12 @@ func Convert_v1beta2_Topology_To_v1alpha4_Topology(in *clusterv1.Topology, out * if err := autoConvert_v1beta2_Topology_To_v1alpha4_Topology(in, out, s); err != nil { return err } - + if !reflect.DeepEqual(in.Workers, clusterv1.WorkersTopology{}) { + out.Workers = &WorkersTopology{} + if err := autoConvert_v1beta2_WorkersTopology_To_v1alpha4_WorkersTopology(&in.Workers, out.Workers, s); err != nil { + return err + } + } out.Class = in.ClassRef.Name return nil } @@ -847,9 +917,37 @@ func Convert_v1beta2_MachineDeploymentTopology_To_v1alpha4_MachineDeploymentTopo return autoConvert_v1beta2_MachineDeploymentTopology_To_v1alpha4_MachineDeploymentTopology(in, out, s) } +func Convert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in *MachineDeploymentClass, out *clusterv1.MachineDeploymentClass, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in, out, s); err != nil { + return err + } + if err := Convert_v1alpha4_ObjectMeta_To_v1beta2_ObjectMeta(&in.Template.Metadata, &out.Metadata, s); err != nil { + return err + } + if err := Convert_v1alpha4_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassBootstrapTemplate(&in.Template.Bootstrap, &out.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1alpha4_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassInfrastructureTemplate(&in.Template.Infrastructure, &out.Infrastructure, s); err != nil { + return err + } + return nil +} + func Convert_v1beta2_MachineDeploymentClass_To_v1alpha4_MachineDeploymentClass(in *clusterv1.MachineDeploymentClass, out *MachineDeploymentClass, s apimachineryconversion.Scope) error { // machineDeploymentClass.machineHealthCheck has been added with v1beta1. - return autoConvert_v1beta2_MachineDeploymentClass_To_v1alpha4_MachineDeploymentClass(in, out, s) + if err := autoConvert_v1beta2_MachineDeploymentClass_To_v1alpha4_MachineDeploymentClass(in, out, s); err != nil { + return err + } + if err := Convert_v1beta2_ObjectMeta_To_v1alpha4_ObjectMeta(&in.Metadata, &out.Template.Metadata, s); err != nil { + return err + } + if err := Convert_v1beta2_MachineDeploymentClassBootstrapTemplate_To_v1alpha4_LocalObjectTemplate(&in.Bootstrap, &out.Template.Bootstrap, s); err != nil { + return err + } + if err := Convert_v1beta2_MachineDeploymentClassInfrastructureTemplate_To_v1alpha4_LocalObjectTemplate(&in.Infrastructure, &out.Template.Infrastructure, s); err != nil { + return err + } + return nil } func Convert_v1beta2_ControlPlaneClass_To_v1alpha4_ControlPlaneClass(in *clusterv1.ControlPlaneClass, out *ControlPlaneClass, s apimachineryconversion.Scope) error { @@ -865,7 +963,11 @@ func Convert_v1alpha4_Topology_To_v1beta2_Topology(in *Topology, out *clusterv1. if err := autoConvert_v1alpha4_Topology_To_v1beta2_Topology(in, out, s); err != nil { return err } - + if in.Workers != nil { + if err := autoConvert_v1alpha4_WorkersTopology_To_v1beta2_WorkersTopology(in.Workers, &out.Workers, s); err != nil { + return err + } + } out.ClassRef.Name = in.Class return nil } @@ -917,7 +1019,30 @@ func Convert_v1beta2_WorkersTopology_To_v1alpha4_WorkersTopology(in *clusterv1.W } func Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(in *clusterv1.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s apimachineryconversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(in, out, s) + if err := autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if !reflect.DeepEqual(in.RollingUpdate, clusterv1.MachineDeploymentStrategyRollingUpdate{}) { + out.RollingUpdate = &MachineRollingUpdateDeployment{} + if err := Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha4_MachineRollingUpdateDeployment(&in.RollingUpdate, out.RollingUpdate, s); err != nil { + return err + } + } + + return nil +} + +func Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *clusterv1.MachineDeploymentStrategy, s apimachineryconversion.Scope) error { + if err := autoConvert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s); err != nil { + return err + } + if in.RollingUpdate != nil { + if err := Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in.RollingUpdate, &out.RollingUpdate, s); err != nil { + return err + } + } + + return nil } func Convert_v1beta2_MachineSetSpec_To_v1alpha4_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apimachineryconversion.Scope) error { @@ -998,7 +1123,16 @@ func Convert_v1alpha4_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, func Convert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in *MachineDeploymentSpec, out *clusterv1.MachineDeploymentSpec, s apimachineryconversion.Scope) error { // NOTE: v1beta2 MachineDeploymentSpec does not have ProgressDeadlineSeconds anymore. But it's fine to just lose this field it was never used. - return autoConvert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s) + if err := autoConvert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in, out, s); err != nil { + return err + } + if in.Strategy != nil { + if err := Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in.Strategy, &out.Strategy, s); err != nil { + return err + } + } + + return nil } func Convert_v1alpha4_MachineDeploymentStatus_To_v1beta2_MachineDeploymentStatus(in *MachineDeploymentStatus, out *clusterv1.MachineDeploymentStatus, s apimachineryconversion.Scope) error { @@ -1112,20 +1246,18 @@ func Convert_v1alpha4_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in *MachinePool return autoConvert_v1alpha4_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in, out, s) } -func Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *clusterv1.MachineRollingUpdateDeployment, s apimachineryconversion.Scope) error { - if err := autoConvert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in, out, s); err != nil { - return err - } +func Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(in *MachineRollingUpdateDeployment, out *clusterv1.MachineDeploymentStrategyRollingUpdate, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge if in.DeletePolicy != nil { out.DeletePolicy = clusterv1.MachineSetDeletePolicy(*in.DeletePolicy) } return nil } -func Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha4_MachineRollingUpdateDeployment(in *clusterv1.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s apimachineryconversion.Scope) error { - if err := autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha4_MachineRollingUpdateDeployment(in, out, s); err != nil { - return err - } +func Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha4_MachineRollingUpdateDeployment(in *clusterv1.MachineDeploymentStrategyRollingUpdate, out *MachineRollingUpdateDeployment, _ apimachineryconversion.Scope) error { + out.MaxUnavailable = in.MaxUnavailable + out.MaxSurge = in.MaxSurge if in.DeletePolicy != "" { out.DeletePolicy = ptr.To(string(in.DeletePolicy)) } diff --git a/internal/api/core/v1alpha4/conversion_test.go b/internal/api/core/v1alpha4/conversion_test.go index 9b0f84632cec..c138ca560bbc 100644 --- a/internal/api/core/v1alpha4/conversion_test.go +++ b/internal/api/core/v1alpha4/conversion_test.go @@ -264,6 +264,18 @@ func spokeCluster(in *Cluster, c randfill.Continue) { in.Spec.InfrastructureRef.ResourceVersion = "" in.Spec.InfrastructureRef.FieldPath = "" } + + if in.Spec.ClusterNetwork != nil { + if in.Spec.ClusterNetwork.Services != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Services, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Services = nil + } + if in.Spec.ClusterNetwork.Pods != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Pods, &NetworkRanges{}) { + in.Spec.ClusterNetwork.Pods = nil + } + if reflect.DeepEqual(in.Spec.ClusterNetwork, &ClusterNetwork{}) { + in.Spec.ClusterNetwork = nil + } + } } func spokeClusterTopology(in *Topology, c randfill.Continue) { @@ -271,6 +283,10 @@ func spokeClusterTopology(in *Topology, c randfill.Continue) { // RolloutAfter was unused and has been removed in v1beta2. in.RolloutAfter = nil + + if in.Workers != nil && reflect.DeepEqual(in.Workers, &WorkersTopology{}) { + in.Workers = nil + } } func ClusterClassFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} { @@ -433,12 +449,6 @@ func spokeMachineDeployment(in *MachineDeployment, c randfill.Continue) { fillMachineSpec(&in.Spec.Template.Spec, c, in.Namespace) dropEmptyStringsMachineSpec(&in.Spec.Template.Spec) - - if in.Spec.Strategy != nil && in.Spec.Strategy.RollingUpdate != nil && - in.Spec.Strategy.RollingUpdate.DeletePolicy != nil && *in.Spec.Strategy.RollingUpdate.DeletePolicy == "" { - // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. - in.Spec.Strategy.RollingUpdate.DeletePolicy = nil - } } func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue) { @@ -449,6 +459,21 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue) // Drop RevisionHistoryLimit as we intentionally don't preserve it. in.RevisionHistoryLimit = nil + + if in.Strategy != nil { + if in.Strategy.RollingUpdate != nil { + if in.Strategy.RollingUpdate.DeletePolicy != nil && *in.Strategy.RollingUpdate.DeletePolicy == "" { + // &"" Is not a valid value for DeletePolicy as the enum validation enforces an enum value if DeletePolicy is set. + in.Strategy.RollingUpdate.DeletePolicy = nil + } + if reflect.DeepEqual(in.Strategy.RollingUpdate, &MachineRollingUpdateDeployment{}) { + in.Strategy.RollingUpdate = nil + } + } + if reflect.DeepEqual(in.Strategy, &MachineDeploymentStrategy{}) { + in.Strategy = nil + } + } } func MachineHealthCheckFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} { diff --git a/internal/api/core/v1alpha4/zz_generated.conversion.go b/internal/api/core/v1alpha4/zz_generated.conversion.go index c04054aa6a34..84640206784e 100644 --- a/internal/api/core/v1alpha4/zz_generated.conversion.go +++ b/internal/api/core/v1alpha4/zz_generated.conversion.go @@ -100,21 +100,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*Condition)(nil), (*v1beta2.Condition)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_Condition_To_v1beta2_Condition(a.(*Condition), b.(*v1beta2.Condition), scope) }); err != nil { @@ -160,21 +145,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentClass)(nil), (*v1beta2.MachineDeploymentClass)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(a.(*MachineDeploymentClass), b.(*v1beta2.MachineDeploymentClass), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentClassTemplate)(nil), (*v1beta2.MachineDeploymentClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(a.(*MachineDeploymentClassTemplate), b.(*v1beta2.MachineDeploymentClassTemplate), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta2.MachineDeploymentClassTemplate)(nil), (*MachineDeploymentClassTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate(a.(*v1beta2.MachineDeploymentClassTemplate), b.(*MachineDeploymentClassTemplate), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineDeploymentList)(nil), (*v1beta2.MachineDeploymentList)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_MachineDeploymentList_To_v1beta2_MachineDeploymentList(a.(*MachineDeploymentList), b.(*v1beta2.MachineDeploymentList), scope) }); err != nil { @@ -185,11 +155,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MachineDeploymentTopology)(nil), (*v1beta2.MachineDeploymentTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopology(a.(*MachineDeploymentTopology), b.(*v1beta2.MachineDeploymentTopology), scope) }); err != nil { @@ -320,6 +285,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*ClusterNetwork)(nil), (*v1beta2.ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(a.(*ClusterNetwork), b.(*v1beta2.ClusterNetwork), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*ClusterSpec)(nil), (*v1beta2.ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(a.(*ClusterSpec), b.(*v1beta2.ClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*ClusterStatus)(nil), (*v1beta2.ClusterStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_ClusterStatus_To_v1beta2_ClusterStatus(a.(*ClusterStatus), b.(*v1beta2.ClusterStatus), scope) }); err != nil { @@ -355,6 +330,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineDeploymentClass)(nil), (*v1beta2.MachineDeploymentClass)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(a.(*MachineDeploymentClass), b.(*v1beta2.MachineDeploymentClass), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineDeploymentSpec)(nil), (*v1beta2.MachineDeploymentSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(a.(*MachineDeploymentSpec), b.(*v1beta2.MachineDeploymentSpec), scope) }); err != nil { @@ -365,6 +345,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineDeploymentStrategy)(nil), (*v1beta2.MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(a.(*MachineDeploymentStrategy), b.(*v1beta2.MachineDeploymentStrategy), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineHealthCheckSpec)(nil), (*v1beta2.MachineHealthCheckSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_MachineHealthCheckSpec_To_v1beta2_MachineHealthCheckSpec(a.(*MachineHealthCheckSpec), b.(*v1beta2.MachineHealthCheckSpec), scope) }); err != nil { @@ -380,8 +365,8 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineRollingUpdateDeployment), scope) + if err := s.AddConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineDeploymentStrategyRollingUpdate(a.(*MachineRollingUpdateDeployment), b.(*v1beta2.MachineDeploymentStrategyRollingUpdate), scope) }); err != nil { return err } @@ -420,6 +405,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.ClusterNetwork)(nil), (*ClusterNetwork)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(a.(*v1beta2.ClusterNetwork), b.(*ClusterNetwork), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.ClusterSpec)(nil), (*ClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(a.(*v1beta2.ClusterSpec), b.(*ClusterSpec), scope) }); err != nil { @@ -475,6 +465,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategyRollingUpdate)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta2_MachineDeploymentStrategyRollingUpdate_To_v1alpha4_MachineRollingUpdateDeployment(a.(*v1beta2.MachineDeploymentStrategyRollingUpdate), b.(*MachineRollingUpdateDeployment), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta2.MachineDeploymentStrategy)(nil), (*MachineDeploymentStrategy)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(a.(*v1beta2.MachineDeploymentStrategy), b.(*MachineDeploymentStrategy), scope) }); err != nil { @@ -500,11 +495,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta2.MachineRollingUpdateDeployment)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha4_MachineRollingUpdateDeployment(a.(*v1beta2.MachineRollingUpdateDeployment), b.(*MachineRollingUpdateDeployment), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*v1beta2.MachineSetSpec)(nil), (*MachineSetSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta2_MachineSetSpec_To_v1alpha4_MachineSetSpec(a.(*v1beta2.MachineSetSpec), b.(*MachineSetSpec), scope) }); err != nil { @@ -776,36 +766,30 @@ func Convert_v1beta2_ClusterList_To_v1alpha4_ClusterList(in *v1beta2.ClusterList } func autoConvert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*v1beta2.NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_Pointer_int32_To_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.NetworkRanges vs sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork is an autogenerated conversion function. -func Convert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in *ClusterNetwork, out *v1beta2.ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1alpha4_ClusterNetwork_To_v1beta2_ClusterNetwork(in, out, s) -} - func autoConvert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - out.APIServerPort = (*int32)(unsafe.Pointer(in.APIServerPort)) - out.Services = (*NetworkRanges)(unsafe.Pointer(in.Services)) - out.Pods = (*NetworkRanges)(unsafe.Pointer(in.Pods)) + if err := v1.Convert_int32_To_Pointer_int32(&in.APIServerPort, &out.APIServerPort, s); err != nil { + return err + } + // WARNING: in.Services requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.NetworkRanges) + // WARNING: in.Pods requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.NetworkRanges vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.NetworkRanges) out.ServiceDomain = in.ServiceDomain return nil } -// Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork is an autogenerated conversion function. -func Convert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(in *v1beta2.ClusterNetwork, out *ClusterNetwork, s conversion.Scope) error { - return autoConvert_v1beta2_ClusterNetwork_To_v1alpha4_ClusterNetwork(in, out, s) -} - func autoConvert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { if err := v1.Convert_bool_To_Pointer_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*v1beta2.ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.ClusterNetwork vs sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork) if err := Convert_v1alpha4_APIEndpoint_To_v1beta2_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -839,16 +823,11 @@ func autoConvert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, ou return nil } -// Convert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec is an autogenerated conversion function. -func Convert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in *ClusterSpec, out *v1beta2.ClusterSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_ClusterSpec_To_v1beta2_ClusterSpec(in, out, s) -} - func autoConvert_v1beta2_ClusterSpec_To_v1alpha4_ClusterSpec(in *v1beta2.ClusterSpec, out *ClusterSpec, s conversion.Scope) error { if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err } - out.ClusterNetwork = (*ClusterNetwork)(unsafe.Pointer(in.ClusterNetwork)) + // WARNING: in.ClusterNetwork requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.ClusterNetwork vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.ClusterNetwork) if err := Convert_v1beta2_APIEndpoint_To_v1alpha4_APIEndpoint(&in.ControlPlaneEndpoint, &out.ControlPlaneEndpoint, s); err != nil { return err } @@ -1112,22 +1091,15 @@ func Convert_v1beta2_MachineDeployment_To_v1alpha4_MachineDeployment(in *v1beta2 func autoConvert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in *MachineDeploymentClass, out *v1beta2.MachineDeploymentClass, s conversion.Scope) error { out.Class = in.Class - if err := Convert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Template requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass is an autogenerated conversion function. -func Convert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in *MachineDeploymentClass, out *v1beta2.MachineDeploymentClass, s conversion.Scope) error { - return autoConvert_v1alpha4_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in, out, s) -} - func autoConvert_v1beta2_MachineDeploymentClass_To_v1alpha4_MachineDeploymentClass(in *v1beta2.MachineDeploymentClass, out *MachineDeploymentClass, s conversion.Scope) error { + // WARNING: in.Metadata requires manual conversion: does not exist in peer-type out.Class = in.Class - if err := Convert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate(&in.Template, &out.Template, s); err != nil { - return err - } + // WARNING: in.Bootstrap requires manual conversion: does not exist in peer-type + // WARNING: in.Infrastructure requires manual conversion: does not exist in peer-type // WARNING: in.MachineHealthCheck requires manual conversion: does not exist in peer-type // WARNING: in.FailureDomain requires manual conversion: does not exist in peer-type // WARNING: in.NamingStrategy requires manual conversion: does not exist in peer-type @@ -1140,42 +1112,6 @@ func autoConvert_v1beta2_MachineDeploymentClass_To_v1alpha4_MachineDeploymentCla return nil } -func autoConvert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in *MachineDeploymentClassTemplate, out *v1beta2.MachineDeploymentClassTemplate, s conversion.Scope) error { - if err := Convert_v1alpha4_ObjectMeta_To_v1beta2_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1alpha4_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassBootstrapTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1alpha4_LocalObjectTemplate_To_v1beta2_MachineDeploymentClassInfrastructureTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate is an autogenerated conversion function. -func Convert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in *MachineDeploymentClassTemplate, out *v1beta2.MachineDeploymentClassTemplate, s conversion.Scope) error { - return autoConvert_v1alpha4_MachineDeploymentClassTemplate_To_v1beta2_MachineDeploymentClassTemplate(in, out, s) -} - -func autoConvert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate(in *v1beta2.MachineDeploymentClassTemplate, out *MachineDeploymentClassTemplate, s conversion.Scope) error { - if err := Convert_v1beta2_ObjectMeta_To_v1alpha4_ObjectMeta(&in.Metadata, &out.Metadata, s); err != nil { - return err - } - if err := Convert_v1beta2_MachineDeploymentClassBootstrapTemplate_To_v1alpha4_LocalObjectTemplate(&in.Bootstrap, &out.Bootstrap, s); err != nil { - return err - } - if err := Convert_v1beta2_MachineDeploymentClassInfrastructureTemplate_To_v1alpha4_LocalObjectTemplate(&in.Infrastructure, &out.Infrastructure, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate is an autogenerated conversion function. -func Convert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate(in *v1beta2.MachineDeploymentClassTemplate, out *MachineDeploymentClassTemplate, s conversion.Scope) error { - return autoConvert_v1beta2_MachineDeploymentClassTemplate_To_v1alpha4_MachineDeploymentClassTemplate(in, out, s) -} - func autoConvert_v1alpha4_MachineDeploymentList_To_v1beta2_MachineDeploymentList(in *MachineDeploymentList, out *v1beta2.MachineDeploymentList, s conversion.Scope) error { out.ListMeta = in.ListMeta if in.Items != nil { @@ -1225,15 +1161,7 @@ func autoConvert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec if err := Convert_v1alpha4_MachineTemplateSpec_To_v1beta2_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(v1beta2.MachineDeploymentStrategy) - if err := Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.MachineDeploymentStrategy vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy) // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type if err := v1.Convert_bool_To_Pointer_bool(&in.Paused, &out.Paused, s); err != nil { @@ -1251,15 +1179,7 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha4_MachineDeploymentSpec if err := Convert_v1beta2_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(MachineDeploymentStrategy) - if err := Convert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(*in, *out, s); err != nil { - return err - } - } else { - out.Strategy = nil - } + // WARNING: in.Strategy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategy vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.MachineDeploymentStrategy) // WARNING: in.MachineNamingStrategy requires manual conversion: does not exist in peer-type if err := v1.Convert_Pointer_bool_To_bool(&in.Paused, &out.Paused, s); err != nil { return err @@ -1327,34 +1247,13 @@ func autoConvert_v1beta2_MachineDeploymentStatus_To_v1alpha4_MachineDeploymentSt func autoConvert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { out.Type = v1beta2.MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(v1beta2.MachineRollingUpdateDeployment) - if err := Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.MachineRollingUpdateDeployment vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate) return nil } -// Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy is an autogenerated conversion function. -func Convert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in *MachineDeploymentStrategy, out *v1beta2.MachineDeploymentStrategy, s conversion.Scope) error { - return autoConvert_v1alpha4_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrategy(in, out, s) -} - func autoConvert_v1beta2_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStrategy(in *v1beta2.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s conversion.Scope) error { out.Type = MachineDeploymentStrategyType(in.Type) - if in.RollingUpdate != nil { - in, out := &in.RollingUpdate, &out.RollingUpdate - *out = new(MachineRollingUpdateDeployment) - if err := Convert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha4_MachineRollingUpdateDeployment(*in, *out, s); err != nil { - return err - } - } else { - out.RollingUpdate = nil - } + // WARNING: in.RollingUpdate requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineDeploymentStrategyRollingUpdate vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.MachineRollingUpdateDeployment) // WARNING: in.Remediation requires manual conversion: does not exist in peer-type return nil } @@ -1773,20 +1672,6 @@ func autoConvert_v1beta2_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in *v1b return nil } -func autoConvert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta2_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta2.MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - // WARNING: in.DeletePolicy requires manual conversion: inconvertible types (*string vs sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetDeletePolicy) - return nil -} - -func autoConvert_v1beta2_MachineRollingUpdateDeployment_To_v1alpha4_MachineRollingUpdateDeployment(in *v1beta2.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s conversion.Scope) error { - out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) - out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) - // WARNING: in.DeletePolicy requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.MachineSetDeletePolicy vs *string) - return nil -} - func autoConvert_v1alpha4_MachineSet_To_v1beta2_MachineSet(in *MachineSet, out *v1beta2.MachineSet, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha4_MachineSetSpec_To_v1beta2_MachineSetSpec(&in.Spec, &out.Spec, s); err != nil { @@ -2134,15 +2019,7 @@ func autoConvert_v1alpha4_Topology_To_v1beta2_Topology(in *Topology, out *v1beta if err := Convert_v1alpha4_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(&in.ControlPlane, &out.ControlPlane, s); err != nil { return err } - if in.Workers != nil { - in, out := &in.Workers, &out.Workers - *out = new(v1beta2.WorkersTopology) - if err := Convert_v1alpha4_WorkersTopology_To_v1beta2_WorkersTopology(*in, *out, s); err != nil { - return err - } - } else { - out.Workers = nil - } + // WARNING: in.Workers requires manual conversion: inconvertible types (*sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.WorkersTopology vs sigs.k8s.io/cluster-api/api/core/v1beta2.WorkersTopology) return nil } @@ -2152,15 +2029,7 @@ func autoConvert_v1beta2_Topology_To_v1alpha4_Topology(in *v1beta2.Topology, out if err := Convert_v1beta2_ControlPlaneTopology_To_v1alpha4_ControlPlaneTopology(&in.ControlPlane, &out.ControlPlane, s); err != nil { return err } - if in.Workers != nil { - in, out := &in.Workers, &out.Workers - *out = new(WorkersTopology) - if err := Convert_v1beta2_WorkersTopology_To_v1alpha4_WorkersTopology(*in, *out, s); err != nil { - return err - } - } else { - out.Workers = nil - } + // WARNING: in.Workers requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api/api/core/v1beta2.WorkersTopology vs *sigs.k8s.io/cluster-api/internal/api/core/v1alpha4.WorkersTopology) // WARNING: in.Variables requires manual conversion: does not exist in peer-type return nil } diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index 295c3416590c..8672cefa0ce5 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -222,10 +222,10 @@ func (r *Reconciler) reconcileExternalReferences(ctx context.Context, s *scope) refs = append(refs, clusterClass.Spec.ControlPlane.MachineInfrastructure.TemplateRef) } for _, mdClass := range clusterClass.Spec.Workers.MachineDeployments { - refs = append(refs, mdClass.Template.Bootstrap.TemplateRef, mdClass.Template.Infrastructure.TemplateRef) + refs = append(refs, mdClass.Bootstrap.TemplateRef, mdClass.Infrastructure.TemplateRef) } for _, mpClass := range clusterClass.Spec.Workers.MachinePools { - refs = append(refs, mpClass.Template.Bootstrap.TemplateRef, mpClass.Template.Infrastructure.TemplateRef) + refs = append(refs, mpClass.Bootstrap.TemplateRef, mpClass.Infrastructure.TemplateRef) } // Ensure all referenced objects are owned by the ClusterClass. diff --git a/internal/controllers/clusterclass/clusterclass_controller_test.go b/internal/controllers/clusterclass/clusterclass_controller_test.go index ddc904ec03e1..d3cf1956e3df 100644 --- a/internal/controllers/clusterclass/clusterclass_controller_test.go +++ b/internal/controllers/clusterclass/clusterclass_controller_test.go @@ -295,7 +295,7 @@ func assertMachineDeploymentClass(ctx context.Context, actualClusterClass *clust actualInfrastructureMachineTemplate := builder.InfrastructureMachineTemplate("", "").Build() actualInfrastructureMachineTemplateKey := client.ObjectKey{ Namespace: ns.Name, - Name: mdClass.Template.Infrastructure.TemplateRef.Name, + Name: mdClass.Infrastructure.TemplateRef.Name, } if err := env.Get(ctx, actualInfrastructureMachineTemplateKey, actualInfrastructureMachineTemplate); err != nil { return err @@ -305,7 +305,7 @@ func assertMachineDeploymentClass(ctx context.Context, actualClusterClass *clust } // Assert the MachineDeploymentClass has the expected APIVersion and Kind to the infrastructure machine template - if err := referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Infrastructure.TemplateRef, + if err := referenceExistsWithCorrectKindAndAPIVersion(mdClass.Infrastructure.TemplateRef, builder.GenericInfrastructureMachineTemplateKind, builder.InfrastructureGroupVersion); err != nil { return err @@ -315,7 +315,7 @@ func assertMachineDeploymentClass(ctx context.Context, actualClusterClass *clust actualBootstrapTemplate := builder.BootstrapTemplate("", "").Build() actualBootstrapTemplateKey := client.ObjectKey{ Namespace: ns.Name, - Name: mdClass.Template.Bootstrap.TemplateRef.Name, + Name: mdClass.Bootstrap.TemplateRef.Name, } if err := env.Get(ctx, actualBootstrapTemplateKey, actualBootstrapTemplate); err != nil { return err @@ -325,7 +325,7 @@ func assertMachineDeploymentClass(ctx context.Context, actualClusterClass *clust } // Assert the MachineDeploymentClass has the expected APIVersion and Kind to the bootstrap template - return referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.TemplateRef, + return referenceExistsWithCorrectKindAndAPIVersion(mdClass.Bootstrap.TemplateRef, builder.GenericBootstrapConfigTemplateKind, builder.BootstrapGroupVersion) } @@ -344,7 +344,7 @@ func assertMachinePoolClass(ctx context.Context, actualClusterClass *clusterv1.C actualInfrastructureMachinePoolTemplate := builder.InfrastructureMachinePoolTemplate("", "").Build() actualInfrastructureMachinePoolTemplateKey := client.ObjectKey{ Namespace: ns.Name, - Name: mpClass.Template.Infrastructure.TemplateRef.Name, + Name: mpClass.Infrastructure.TemplateRef.Name, } if err := env.Get(ctx, actualInfrastructureMachinePoolTemplateKey, actualInfrastructureMachinePoolTemplate); err != nil { return err @@ -354,7 +354,7 @@ func assertMachinePoolClass(ctx context.Context, actualClusterClass *clusterv1.C } // Assert the MachinePoolClass has the expected APIVersion and Kind to the infrastructure machinepool template - if err := referenceExistsWithCorrectKindAndAPIVersion(mpClass.Template.Infrastructure.TemplateRef, + if err := referenceExistsWithCorrectKindAndAPIVersion(mpClass.Infrastructure.TemplateRef, builder.GenericInfrastructureMachinePoolTemplateKind, builder.InfrastructureGroupVersion); err != nil { return err @@ -364,7 +364,7 @@ func assertMachinePoolClass(ctx context.Context, actualClusterClass *clusterv1.C actualBootstrapTemplate := builder.BootstrapTemplate("", "").Build() actualBootstrapTemplateKey := client.ObjectKey{ Namespace: ns.Name, - Name: mpClass.Template.Bootstrap.TemplateRef.Name, + Name: mpClass.Bootstrap.TemplateRef.Name, } if err := env.Get(ctx, actualBootstrapTemplateKey, actualBootstrapTemplate); err != nil { return err @@ -374,7 +374,7 @@ func assertMachinePoolClass(ctx context.Context, actualClusterClass *clusterv1.C } // Assert the MachinePoolClass has the expected APIVersion and Kind to the bootstrap template - return referenceExistsWithCorrectKindAndAPIVersion(mpClass.Template.Bootstrap.TemplateRef, + return referenceExistsWithCorrectKindAndAPIVersion(mpClass.Bootstrap.TemplateRef, builder.GenericBootstrapConfigTemplateKind, builder.BootstrapGroupVersion) } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 974e51d3f0d7..3ccf17372284 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -305,14 +305,7 @@ func (r *Reconciler) reconcile(ctx context.Context, s *scope) error { return r.sync(ctx, md, s.machineSets, templateExists) } - if md.Spec.Strategy == nil { - return errors.Errorf("missing MachineDeployment strategy") - } - if md.Spec.Strategy.Type == clusterv1.RollingUpdateMachineDeploymentStrategyType { - if md.Spec.Strategy.RollingUpdate == nil { - return errors.Errorf("missing MachineDeployment settings for strategy type: %s", md.Spec.Strategy.Type) - } return r.rolloutRolling(ctx, md, s.machineSets, templateExists) } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/machinedeployment/machinedeployment_controller_test.go index 7d2bc35c5076..adf111188319 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller_test.go @@ -125,9 +125,9 @@ func TestMachineDeploymentReconciler(t *testing.T) { // verify that all original MachineSets have been deleted. MatchLabels: labels, }, - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(1), DeletePolicy: clusterv1.OldestMachineSetDeletePolicy, @@ -560,9 +560,9 @@ func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption(t *testi // We're using the same labels for spec.selector and spec.template.labels. MatchLabels: labels, }, - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(1), DeletePolicy: clusterv1.OldestMachineSetDeletePolicy, diff --git a/internal/controllers/machinedeployment/machinedeployment_rolling_test.go b/internal/controllers/machinedeployment/machinedeployment_rolling_test.go index 285b0680c67e..f8c5d63deacf 100644 --- a/internal/controllers/machinedeployment/machinedeployment_rolling_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_rolling_test.go @@ -79,9 +79,9 @@ func TestReconcileNewMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -108,9 +108,9 @@ func TestReconcileNewMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -137,9 +137,9 @@ func TestReconcileNewMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -181,9 +181,9 @@ func TestReconcileNewMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(0), }, @@ -225,9 +225,9 @@ func TestReconcileNewMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(0), }, @@ -348,9 +348,9 @@ func TestReconcileOldMachineSets(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(1), MaxSurge: intOrStrPtr(3), }, @@ -406,9 +406,9 @@ func TestReconcileOldMachineSets(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(2), MaxSurge: intOrStrPtr(3), }, diff --git a/internal/controllers/machinedeployment/machinedeployment_status.go b/internal/controllers/machinedeployment/machinedeployment_status.go index d625ee83b041..485f4f082036 100644 --- a/internal/controllers/machinedeployment/machinedeployment_status.go +++ b/internal/controllers/machinedeployment/machinedeployment_status.go @@ -172,7 +172,7 @@ func setAvailableCondition(_ context.Context, machineDeployment *clusterv1.Machi } message := fmt.Sprintf("%d available replicas, at least %d required", *machineDeployment.Status.AvailableReplicas, minReplicasNeeded) - if machineDeployment.Spec.Strategy != nil && mdutil.IsRollingUpdate(machineDeployment) && machineDeployment.Spec.Strategy.RollingUpdate != nil { + if mdutil.IsRollingUpdate(machineDeployment) { message += fmt.Sprintf(" (spec.strategy.rollout.maxUnavailable is %s, spec.replicas is %d)", machineDeployment.Spec.Strategy.RollingUpdate.MaxUnavailable, *machineDeployment.Spec.Replicas) } diff --git a/internal/controllers/machinedeployment/machinedeployment_status_test.go b/internal/controllers/machinedeployment/machinedeployment_status_test.go index 5b6fdefb78fa..b8ece18692fc 100644 --- a/internal/controllers/machinedeployment/machinedeployment_status_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_status_test.go @@ -131,9 +131,9 @@ func Test_setAvailableCondition(t *testing.T) { machineDeployment: &clusterv1.MachineDeployment{ Spec: clusterv1.MachineDeploymentSpec{ Replicas: ptr.To(int32(5)), - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: ptr.To(intstr.FromInt32(1)), MaxUnavailable: ptr.To(intstr.FromInt32(0)), }, @@ -153,9 +153,9 @@ func Test_setAvailableCondition(t *testing.T) { machineDeployment: &clusterv1.MachineDeployment{ Spec: clusterv1.MachineDeploymentSpec{ Replicas: ptr.To(int32(5)), - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: ptr.To(intstr.FromInt32(1)), MaxUnavailable: ptr.To(intstr.FromInt32(1)), }, @@ -175,9 +175,9 @@ func Test_setAvailableCondition(t *testing.T) { machineDeployment: &clusterv1.MachineDeployment{ Spec: clusterv1.MachineDeploymentSpec{ Replicas: ptr.To(int32(5)), - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: ptr.To(intstr.FromInt32(1)), MaxUnavailable: ptr.To(intstr.FromInt32(1)), }, @@ -201,9 +201,9 @@ func Test_setAvailableCondition(t *testing.T) { }, Spec: clusterv1.MachineDeploymentSpec{ Replicas: ptr.To(int32(5)), - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: ptr.To(intstr.FromInt32(1)), MaxUnavailable: ptr.To(intstr.FromInt32(1)), }, diff --git a/internal/controllers/machinedeployment/machinedeployment_sync.go b/internal/controllers/machinedeployment/machinedeployment_sync.go index c6798d98f5e5..bbc6a177c551 100644 --- a/internal/controllers/machinedeployment/machinedeployment_sync.go +++ b/internal/controllers/machinedeployment/machinedeployment_sync.go @@ -321,11 +321,7 @@ func (r *Reconciler) computeDesiredMachineSet(ctx context.Context, deployment *c // Set all other in-place mutable fields. desiredMS.Spec.Template.Spec.MinReadySeconds = deployment.Spec.Template.Spec.MinReadySeconds - if deployment.Spec.Strategy != nil && deployment.Spec.Strategy.RollingUpdate != nil { - desiredMS.Spec.DeletePolicy = deployment.Spec.Strategy.RollingUpdate.DeletePolicy - } else { - desiredMS.Spec.DeletePolicy = "" - } + desiredMS.Spec.DeletePolicy = deployment.Spec.Strategy.RollingUpdate.DeletePolicy desiredMS.Spec.Template.Spec.ReadinessGates = deployment.Spec.Template.Spec.ReadinessGates desiredMS.Spec.Template.Spec.NodeDrainTimeoutSeconds = deployment.Spec.Template.Spec.NodeDrainTimeoutSeconds desiredMS.Spec.Template.Spec.NodeDeletionTimeoutSeconds = deployment.Spec.Template.Spec.NodeDeletionTimeoutSeconds diff --git a/internal/controllers/machinedeployment/machinedeployment_sync_test.go b/internal/controllers/machinedeployment/machinedeployment_sync_test.go index 4a72af4b927a..19b2211e954f 100644 --- a/internal/controllers/machinedeployment/machinedeployment_sync_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_sync_test.go @@ -264,9 +264,9 @@ func TestScaleMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -293,9 +293,9 @@ func TestScaleMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -322,9 +322,9 @@ func TestScaleMachineSet(t *testing.T) { Name: "bar", }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(2), }, @@ -388,9 +388,9 @@ func newTestMachineDeployment(replicas, statusReplicas, upToDateReplicas, availa }, Spec: clusterv1.MachineDeploymentSpec{ Replicas: &replicas, - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: intOrStrPtr(0), MaxSurge: intOrStrPtr(1), DeletePolicy: clusterv1.OldestMachineSetDeletePolicy, @@ -540,9 +540,9 @@ func TestComputeDesiredMachineSet(t *testing.T) { Spec: clusterv1.MachineDeploymentSpec{ ClusterName: "test-cluster", Replicas: ptr.To[int32](3), - Strategy: &clusterv1.MachineDeploymentStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: intOrStrPtr(1), DeletePolicy: clusterv1.RandomMachineSetDeletePolicy, MaxUnavailable: intOrStrPtr(0), @@ -707,9 +707,9 @@ func TestComputeDesiredMachineSet(t *testing.T) { t.Run("should compute the updated MachineSet when no old MachineSets exists (", func(t *testing.T) { // Set rollout strategy to "OnDelete". deployment := deployment.DeepCopy() - deployment.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{ + deployment.Spec.Strategy = clusterv1.MachineDeploymentStrategy{ Type: clusterv1.OnDeleteMachineDeploymentStrategyType, - RollingUpdate: nil, + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{}, } uniqueID := apirand.String(5) diff --git a/internal/controllers/machinedeployment/mdutil/util_test.go b/internal/controllers/machinedeployment/mdutil/util_test.go index 3d377cd23643..b2d77bd788da 100644 --- a/internal/controllers/machinedeployment/mdutil/util_test.go +++ b/internal/controllers/machinedeployment/mdutil/util_test.go @@ -743,8 +743,8 @@ func TestNewMSNewReplicas(t *testing.T) { g := NewWithT(t) *(newDeployment.Spec.Replicas) = test.depReplicas - newDeployment.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{Type: test.strategyType} - newDeployment.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{ + newDeployment.Spec.Strategy.Type = test.strategyType + newDeployment.Spec.Strategy.RollingUpdate = clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: ptr.To(intstr.FromInt32(1)), MaxSurge: ptr.To(intstr.FromInt32(test.maxSurge)), } @@ -761,8 +761,8 @@ func TestDeploymentComplete(t *testing.T) { return &clusterv1.MachineDeployment{ Spec: clusterv1.MachineDeploymentSpec{ Replicas: &desired, - Strategy: &clusterv1.MachineDeploymentStrategy{ - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + Strategy: clusterv1.MachineDeploymentStrategy{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: ptr.To(intstr.FromInt32(maxUnavailable)), MaxSurge: ptr.To(intstr.FromInt32(maxSurge)), }, @@ -839,8 +839,8 @@ func TestMaxUnavailable(t *testing.T) { return clusterv1.MachineDeployment{ Spec: clusterv1.MachineDeploymentSpec{ Replicas: func(i int32) *int32 { return &i }(replicas), - Strategy: &clusterv1.MachineDeploymentStrategy{ - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + Strategy: clusterv1.MachineDeploymentStrategy{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: ptr.To(intstr.FromInt32(1)), MaxUnavailable: &maxUnavailable, }, @@ -934,9 +934,9 @@ func TestComputeMachineSetAnnotations(t *testing.T) { deployment.Spec.Replicas = ptr.To[int32](3) maxSurge := intstr.FromInt32(1) maxUnavailable := intstr.FromInt32(0) - deployment.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{ + deployment.Spec.Strategy = clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxSurge: &maxSurge, MaxUnavailable: &maxUnavailable, }, diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index a4f5564c1f3f..bdc69a2f1c97 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -1387,16 +1387,14 @@ func (r *Reconciler) reconcileUnhealthyMachines(ctx context.Context, s *scope) ( return ctrl.Result{}, nil } - if owner.Spec.Strategy != nil && owner.Spec.Strategy.Remediation != nil { - if owner.Spec.Strategy.Remediation.MaxInFlight != nil { - var err error - replicas := int(ptr.Deref(owner.Spec.Replicas, 1)) - maxInFlight, err = intstr.GetScaledValueFromIntOrPercent(owner.Spec.Strategy.Remediation.MaxInFlight, replicas, true) - if err != nil { - return ctrl.Result{}, fmt.Errorf("failed to calculate maxInFlight to remediate machines: %v", err) - } - log = log.WithValues("maxInFlight", maxInFlight, "replicas", replicas) + if owner.Spec.Strategy.Remediation.MaxInFlight != nil { + var err error + replicas := int(ptr.Deref(owner.Spec.Replicas, 1)) + maxInFlight, err = intstr.GetScaledValueFromIntOrPercent(owner.Spec.Strategy.Remediation.MaxInFlight, replicas, true) + if err != nil { + return ctrl.Result{}, fmt.Errorf("failed to calculate maxInFlight to remediate machines: %v", err) } + log = log.WithValues("maxInFlight", maxInFlight, "replicas", replicas) } } diff --git a/internal/controllers/machineset/machineset_controller_test.go b/internal/controllers/machineset/machineset_controller_test.go index d158945a0ae4..36a5db65fd55 100644 --- a/internal/controllers/machineset/machineset_controller_test.go +++ b/internal/controllers/machineset/machineset_controller_test.go @@ -1942,8 +1942,8 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) { }, Spec: clusterv1.MachineDeploymentSpec{ ClusterName: "test-cluster", - Strategy: &clusterv1.MachineDeploymentStrategy{ - Remediation: &clusterv1.RemediationStrategy{ + Strategy: clusterv1.MachineDeploymentStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: ptr.To(intstr.FromInt32(int32(maxInFlight))), }, }, diff --git a/internal/controllers/topology/cluster/blueprint.go b/internal/controllers/topology/cluster/blueprint.go index 14fbc9c32728..5a00369eeded 100644 --- a/internal/controllers/topology/cluster/blueprint.go +++ b/internal/controllers/topology/cluster/blueprint.go @@ -72,16 +72,16 @@ func (r *Reconciler) getBlueprint(ctx context.Context, cluster *clusterv1.Cluste // Make sure to copy the metadata from the blueprint, which is later layered // with the additional metadata defined in the Cluster's topology section // for the MachineDeployment that is created or updated. - machineDeploymentClass.Template.Metadata.DeepCopyInto(&machineDeploymentBlueprint.Metadata) + machineDeploymentClass.Metadata.DeepCopyInto(&machineDeploymentBlueprint.Metadata) // Get the infrastructure machine template. - machineDeploymentBlueprint.InfrastructureMachineTemplate, err = r.getReference(ctx, machineDeploymentClass.Template.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) + machineDeploymentBlueprint.InfrastructureMachineTemplate, err = r.getReference(ctx, machineDeploymentClass.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) if err != nil { return nil, errors.Wrapf(err, "failed to get infrastructure machine template for ClusterClass %s, MachineDeployment class %q", klog.KObj(blueprint.ClusterClass), machineDeploymentClass.Class) } // Get the bootstrap config template. - machineDeploymentBlueprint.BootstrapTemplate, err = r.getReference(ctx, machineDeploymentClass.Template.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) + machineDeploymentBlueprint.BootstrapTemplate, err = r.getReference(ctx, machineDeploymentClass.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) if err != nil { return nil, errors.Wrapf(err, "failed to get bootstrap config template for ClusterClass %s, MachineDeployment class %q", klog.KObj(blueprint.ClusterClass), machineDeploymentClass.Class) } @@ -101,16 +101,16 @@ func (r *Reconciler) getBlueprint(ctx context.Context, cluster *clusterv1.Cluste // Make sure to copy the metadata from the blueprint, which is later layered // with the additional metadata defined in the Cluster's topology section // for the MachinePool that is created or updated. - machinePoolClass.Template.Metadata.DeepCopyInto(&machinePoolBlueprint.Metadata) + machinePoolClass.Metadata.DeepCopyInto(&machinePoolBlueprint.Metadata) // Get the InfrastructureMachinePoolTemplate. - machinePoolBlueprint.InfrastructureMachinePoolTemplate, err = r.getReference(ctx, machinePoolClass.Template.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) + machinePoolBlueprint.InfrastructureMachinePoolTemplate, err = r.getReference(ctx, machinePoolClass.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) if err != nil { return nil, errors.Wrapf(err, "failed to get InfrastructureMachinePoolTemplate for ClusterClass %s, MachinePool class %q", klog.KObj(blueprint.ClusterClass), machinePoolClass.Class) } // Get the bootstrap config template. - machinePoolBlueprint.BootstrapTemplate, err = r.getReference(ctx, machinePoolClass.Template.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) + machinePoolBlueprint.BootstrapTemplate, err = r.getReference(ctx, machinePoolClass.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) if err != nil { return nil, errors.Wrapf(err, "failed to get bootstrap config for ClusterClass %s, MachinePool class %q", klog.KObj(blueprint.ClusterClass), machinePoolClass.Class) } diff --git a/internal/controllers/topology/cluster/cluster_controller_test.go b/internal/controllers/topology/cluster/cluster_controller_test.go index f5cd458a4187..e43609c1ca37 100644 --- a/internal/controllers/topology/cluster/cluster_controller_test.go +++ b/internal/controllers/topology/cluster/cluster_controller_test.go @@ -312,9 +312,9 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { patchHelper, err := patch.NewHelper(clusterClass, env.Client) g.Expect(err).ToNot(HaveOccurred()) // Change the infrastructureMachineTemplateName for the first of our MachineDeployments and update in the API. - clusterClass.Spec.Workers.MachineDeployments[0].Template.Infrastructure.TemplateRef.Name = infrastructureMachineTemplateName2 + clusterClass.Spec.Workers.MachineDeployments[0].Infrastructure.TemplateRef.Name = infrastructureMachineTemplateName2 // Change the infrastructureMachinePoolTemplateName for the first of our MachinePools and update in the API. - clusterClass.Spec.Workers.MachinePools[0].Template.Infrastructure.TemplateRef.Name = infrastructureMachinePoolTemplateName2 + clusterClass.Spec.Workers.MachinePools[0].Infrastructure.TemplateRef.Name = infrastructureMachinePoolTemplateName2 g.Expect(patchHelper.Patch(ctx, clusterClass)).To(Succeed()) g.Eventually(func(g Gomega) error { @@ -322,8 +322,8 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { // This is necessary as sometimes the cache can take a little time to update. class := &clusterv1.ClusterClass{} g.Expect(env.Get(ctx, actualCluster.GetClassKey(), class)).To(Succeed()) - g.Expect(class.Spec.Workers.MachineDeployments[0].Template.Infrastructure.TemplateRef.Name).To(Equal(infrastructureMachineTemplateName2)) - g.Expect(class.Spec.Workers.MachinePools[0].Template.Infrastructure.TemplateRef.Name).To(Equal(infrastructureMachinePoolTemplateName2)) + g.Expect(class.Spec.Workers.MachineDeployments[0].Infrastructure.TemplateRef.Name).To(Equal(infrastructureMachineTemplateName2)) + g.Expect(class.Spec.Workers.MachinePools[0].Infrastructure.TemplateRef.Name).To(Equal(infrastructureMachinePoolTemplateName2)) // For each cluster check that the clusterClass changes have been correctly reconciled. for _, name := range []string{clusterName1, clusterName2} { diff --git a/internal/controllers/topology/cluster/current_state.go b/internal/controllers/topology/cluster/current_state.go index a8a0b481442b..63b897ec7c37 100644 --- a/internal/controllers/topology/cluster/current_state.go +++ b/internal/controllers/topology/cluster/current_state.go @@ -459,10 +459,6 @@ func alignRefAPIVersion(ctx context.Context, c client.Reader, templateFromCluste // getMDClassName retrieves the MDClass name by looking up the MDTopology in the Cluster. func getMDClassName(cluster *clusterv1.Cluster, mdTopologyName string) (bool, string) { - if cluster.Spec.Topology.Workers == nil { - return false, "" - } - for _, mdTopology := range cluster.Spec.Topology.Workers.MachineDeployments { if mdTopology.Name == mdTopologyName { return true, mdTopology.Class @@ -473,10 +469,6 @@ func getMDClassName(cluster *clusterv1.Cluster, mdTopologyName string) (bool, st // getMPClassName retrieves the MPClass name by looking up the MPTopology in the Cluster. func getMPClassName(cluster *clusterv1.Cluster, mpTopologyName string) (bool, string) { - if cluster.Spec.Topology.Workers == nil { - return false, "" - } - for _, mpTopology := range cluster.Spec.Topology.Workers.MachinePools { if mpTopology.Name == mpTopologyName { return true, mpTopology.Class diff --git a/internal/controllers/topology/cluster/patches/engine_test.go b/internal/controllers/topology/cluster/patches/engine_test.go index 9cd7ae20d5e3..cbdb953c16f9 100644 --- a/internal/controllers/topology/cluster/patches/engine_test.go +++ b/internal/controllers/topology/cluster/patches/engine_test.go @@ -1085,12 +1085,12 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) { }, Spec: clusterv1.ClusterSpec{ Paused: ptr.To(false), - ClusterNetwork: &clusterv1.ClusterNetwork{ - APIServerPort: ptr.To[int32](8), - Services: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + APIServerPort: 8, + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.1/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"11.10.10.1/24"}, }, ServiceDomain: "lark", @@ -1104,7 +1104,7 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) { }, ControlPlane: clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](3), - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "controlPlaneVariable", @@ -1134,13 +1134,13 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) { Value: apiextensionsv1.JSON{Raw: []byte(`"default-mp-cluster-wide-value"`)}, }, }, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Metadata: clusterv1.ObjectMeta{Labels: map[string]string{"foo": "bar"}, Annotations: map[string]string{"fizz": "buzz"}}, Class: "default-worker", Name: "default-worker-topo1", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "defaultMDWorkerVariable", @@ -1161,7 +1161,7 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) { Metadata: clusterv1.ObjectMeta{Labels: map[string]string{"foo": "bar"}, Annotations: map[string]string{"fizz": "buzz"}}, Class: "default-mp-worker", Name: "default-mp-worker-topo1", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "defaultMPWorkerVariable", diff --git a/internal/controllers/topology/cluster/patches/variables/variables.go b/internal/controllers/topology/cluster/patches/variables/variables.go index 2ee4aa783b7c..41d44e2a88eb 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables.go +++ b/internal/controllers/topology/cluster/patches/variables/variables.go @@ -74,25 +74,23 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster, pat Annotations: cleanupAnnotations(cluster.Annotations), } } - if cluster.Spec.ClusterNetwork != nil { - if cluster.Spec.ClusterNetwork.ServiceDomain != "" { - if builtin.Cluster.Network == nil { - builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} - } - builtin.Cluster.Network.ServiceDomain = &cluster.Spec.ClusterNetwork.ServiceDomain + if cluster.Spec.ClusterNetwork.ServiceDomain != "" { + if builtin.Cluster.Network == nil { + builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} } - if cluster.Spec.ClusterNetwork.Services != nil && cluster.Spec.ClusterNetwork.Services.CIDRBlocks != nil { - if builtin.Cluster.Network == nil { - builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} - } - builtin.Cluster.Network.Services = cluster.Spec.ClusterNetwork.Services.CIDRBlocks + builtin.Cluster.Network.ServiceDomain = &cluster.Spec.ClusterNetwork.ServiceDomain + } + if cluster.Spec.ClusterNetwork.Services.CIDRBlocks != nil { + if builtin.Cluster.Network == nil { + builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} } - if cluster.Spec.ClusterNetwork.Pods != nil && cluster.Spec.ClusterNetwork.Pods.CIDRBlocks != nil { - if builtin.Cluster.Network == nil { - builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} - } - builtin.Cluster.Network.Pods = cluster.Spec.ClusterNetwork.Pods.CIDRBlocks + builtin.Cluster.Network.Services = cluster.Spec.ClusterNetwork.Services.CIDRBlocks + } + if cluster.Spec.ClusterNetwork.Pods.CIDRBlocks != nil { + if builtin.Cluster.Network == nil { + builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{} } + builtin.Cluster.Network.Pods = cluster.Spec.ClusterNetwork.Pods.CIDRBlocks } // Add builtin variables derived from the cluster object. @@ -110,12 +108,10 @@ func ControlPlane(cpTopology *clusterv1.ControlPlaneTopology, cp, cpInfrastructu variables := []runtimehooksv1.Variable{} // Add variables overrides for the ControlPlane. - if cpTopology.Variables != nil { - for _, variable := range cpTopology.Variables.Overrides { - // Add the variable if it has a definition from this patch in the ClusterClass. - if _, ok := patchVariableDefinitions[variable.Name]; ok { - variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) - } + for _, variable := range cpTopology.Variables.Overrides { + // Add the variable if it has a definition from this patch in the ClusterClass. + if _, ok := patchVariableDefinitions[variable.Name]; ok { + variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) } } @@ -172,12 +168,10 @@ func MachineDeployment(mdTopology *clusterv1.MachineDeploymentTopology, md *clus variables := []runtimehooksv1.Variable{} // Add variables overrides for the MachineDeployment. - if mdTopology.Variables != nil { - for _, variable := range mdTopology.Variables.Overrides { - // Add the variable if it has a definition from this patch in the ClusterClass. - if _, ok := patchVariableDefinitions[variable.Name]; ok { - variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) - } + for _, variable := range mdTopology.Variables.Overrides { + // Add the variable if it has a definition from this patch in the ClusterClass. + if _, ok := patchVariableDefinitions[variable.Name]; ok { + variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) } } @@ -228,12 +222,10 @@ func MachinePool(mpTopology *clusterv1.MachinePoolTopology, mp *clusterv1.Machin variables := []runtimehooksv1.Variable{} // Add variables overrides for the MachinePool. - if mpTopology.Variables != nil { - for _, variable := range mpTopology.Variables.Overrides { - // Add the variable if it has a definition from this patch in the ClusterClass. - if _, ok := patchVariableDefinitions[variable.Name]; ok { - variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) - } + for _, variable := range mpTopology.Variables.Overrides { + // Add the variable if it has a definition from this patch in the ClusterClass. + if _, ok := patchVariableDefinitions[variable.Name]; ok { + variables = append(variables, runtimehooksv1.Variable{Name: variable.Name, Value: variable.Value}) } } diff --git a/internal/controllers/topology/cluster/patches/variables/variables_test.go b/internal/controllers/topology/cluster/patches/variables/variables_test.go index be143e74a797..ecfeceb717d8 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables_test.go +++ b/internal/controllers/topology/cluster/patches/variables/variables_test.go @@ -84,11 +84,11 @@ func TestGlobal(t *testing.T) { }, Version: "v1.21.1", }, - ClusterNetwork: &clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.1/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"11.10.10.1/24"}, }, ServiceDomain: "cluster.local", @@ -163,11 +163,11 @@ func TestGlobal(t *testing.T) { }, Version: "v1.21.1", }, - ClusterNetwork: &clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.1/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"11.10.10.1/24"}, }, ServiceDomain: "cluster.local", @@ -242,11 +242,11 @@ func TestGlobal(t *testing.T) { }, Version: "v1.21.1", }, - ClusterNetwork: &clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.1/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"11.10.10.1/24"}, }, }, @@ -319,9 +319,9 @@ func TestGlobal(t *testing.T) { }, Version: "v1.21.1", }, - ClusterNetwork: &clusterv1.ClusterNetwork{ - Services: nil, - Pods: &clusterv1.NetworkRanges{}, + ClusterNetwork: clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{}, + Pods: clusterv1.NetworkRanges{}, ServiceDomain: "cluster.local", }, }, @@ -392,7 +392,7 @@ func TestGlobal(t *testing.T) { }, Version: "v1.21.1", }, - ClusterNetwork: nil, + ClusterNetwork: clusterv1.ClusterNetwork{}, }, }, want: []runtimehooksv1.Variable{ @@ -450,7 +450,7 @@ func TestControlPlane(t *testing.T) { variableDefinitionsForPatch: map[string]bool{"location": true, "cpu": true}, controlPlaneTopology: &clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](3), - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -499,7 +499,7 @@ func TestControlPlane(t *testing.T) { variableDefinitionsForPatch: map[string]bool{"location": true, "cpu": true}, controlPlaneTopology: &clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](3), - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -569,7 +569,7 @@ func TestControlPlane(t *testing.T) { name: "Should calculate ControlPlane variables, replicas not set", variableDefinitionsForPatch: map[string]bool{"location": true, "cpu": true}, controlPlaneTopology: &clusterv1.ControlPlaneTopology{ - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -609,7 +609,7 @@ func TestControlPlane(t *testing.T) { variableDefinitionsForPatch: map[string]bool{"location": true, "cpu": true}, controlPlaneTopology: &clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](3), - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -682,7 +682,7 @@ func TestMachineDeployment(t *testing.T) { Replicas: ptr.To[int32](3), Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -738,7 +738,7 @@ func TestMachineDeployment(t *testing.T) { Replicas: ptr.To[int32](3), Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -814,7 +814,7 @@ func TestMachineDeployment(t *testing.T) { mdTopology: &clusterv1.MachineDeploymentTopology{ Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -858,7 +858,7 @@ func TestMachineDeployment(t *testing.T) { Replicas: ptr.To[int32](3), Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -910,7 +910,7 @@ func TestMachineDeployment(t *testing.T) { Replicas: ptr.To[int32](3), Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -960,7 +960,7 @@ func TestMachineDeployment(t *testing.T) { Replicas: ptr.To[int32](3), Name: "md-topology", Class: "md-class", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1038,7 +1038,7 @@ func TestMachinePool(t *testing.T) { Replicas: ptr.To[int32](3), Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1094,7 +1094,7 @@ func TestMachinePool(t *testing.T) { Replicas: ptr.To[int32](3), Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1170,7 +1170,7 @@ func TestMachinePool(t *testing.T) { mpTopology: &clusterv1.MachinePoolTopology{ Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1214,7 +1214,7 @@ func TestMachinePool(t *testing.T) { Replicas: ptr.To[int32](3), Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1266,7 +1266,7 @@ func TestMachinePool(t *testing.T) { Replicas: ptr.To[int32](3), Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", @@ -1316,7 +1316,7 @@ func TestMachinePool(t *testing.T) { Replicas: ptr.To[int32](3), Name: "mp-topology", Class: "mp-class", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "location", diff --git a/internal/topology/check/compatibility.go b/internal/topology/check/compatibility.go index 4a093e58d249..f391b5bdd7cb 100644 --- a/internal/topology/check/compatibility.go +++ b/internal/topology/check/compatibility.go @@ -208,7 +208,7 @@ func MachineDeploymentClassesAreCompatible(current, desired *clusterv1.ClusterCl // class.Template.Bootstrap is ensured syntactically correct by LocalObjectTemplateIsValid. // Validates class.Template.Infrastructure template changes in a compatible way - allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Template.Infrastructure.TemplateRef, class.Template.Infrastructure.TemplateRef, + allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Infrastructure.TemplateRef, class.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machineDeployments").Index(i))...) } } @@ -249,7 +249,7 @@ func MachinePoolClassesAreCompatible(current, desired *clusterv1.ClusterClass) f // class.Template.Bootstrap is ensured syntactically correct by LocalObjectTemplateIsValid. // Validates class.Template.Infrastructure template changes in a compatible way - allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Template.Infrastructure.TemplateRef, class.Template.Infrastructure.TemplateRef, + allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Infrastructure.TemplateRef, class.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machinePools").Index(i))...) } } @@ -280,9 +280,6 @@ func MachinePoolClassesAreUnique(clusterClass *clusterv1.ClusterClass) field.Err // and unique, and each class in use is defined in ClusterClass.spec.Workers.MachineDeployments. func MachineDeploymentTopologiesAreValidAndDefinedInClusterClass(desired *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass) field.ErrorList { var allErrs field.ErrorList - if desired.Spec.Topology.Workers == nil { - return nil - } if len(desired.Spec.Topology.Workers.MachineDeployments) == 0 { return nil } @@ -344,9 +341,6 @@ func MachineDeploymentTopologiesAreValidAndDefinedInClusterClass(desired *cluste // and unique, and each class in use is defined in ClusterClass.spec.Workers.MachinePools. func MachinePoolTopologiesAreValidAndDefinedInClusterClass(desired *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass) field.ErrorList { var allErrs field.ErrorList - if desired.Spec.Topology.Workers == nil { - return nil - } if len(desired.Spec.Topology.Workers.MachinePools) == 0 { return nil } @@ -416,14 +410,14 @@ func ClusterClassTemplatesAreValid(clusterClass *clusterv1.ClusterClass) field.E for i := range clusterClass.Spec.Workers.MachineDeployments { mdc := clusterClass.Spec.Workers.MachineDeployments[i] - allErrs = append(allErrs, ClusterClassTemplateIsValid(mdc.Template.Bootstrap.TemplateRef, field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "bootstrap"))...) - allErrs = append(allErrs, ClusterClassTemplateIsValid(mdc.Template.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "infrastructure"))...) + allErrs = append(allErrs, ClusterClassTemplateIsValid(mdc.Bootstrap.TemplateRef, field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "bootstrap"))...) + allErrs = append(allErrs, ClusterClassTemplateIsValid(mdc.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "infrastructure"))...) } for i := range clusterClass.Spec.Workers.MachinePools { mpc := clusterClass.Spec.Workers.MachinePools[i] - allErrs = append(allErrs, ClusterClassTemplateIsValid(mpc.Template.Bootstrap.TemplateRef, field.NewPath("spec", "workers", "machinePools").Index(i).Child("template", "bootstrap"))...) - allErrs = append(allErrs, ClusterClassTemplateIsValid(mpc.Template.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machinePools").Index(i).Child("template", "infrastructure"))...) + allErrs = append(allErrs, ClusterClassTemplateIsValid(mpc.Bootstrap.TemplateRef, field.NewPath("spec", "workers", "machinePools").Index(i).Child("template", "bootstrap"))...) + allErrs = append(allErrs, ClusterClassTemplateIsValid(mpc.Infrastructure.TemplateRef, field.NewPath("spec", "workers", "machinePools").Index(i).Child("template", "infrastructure"))...) } return allErrs diff --git a/internal/topology/upgrade/clusterctl_upgrade_test.go b/internal/topology/upgrade/clusterctl_upgrade_test.go index e7523eeae59a..d57cfc8dc59e 100644 --- a/internal/topology/upgrade/clusterctl_upgrade_test.go +++ b/internal/topology/upgrade/clusterctl_upgrade_test.go @@ -348,20 +348,18 @@ func createT1ClusterClass(g *WithT, ns *corev1.Namespace, ct1 client.Client) *cl machineDeploymentClass1 := clusterv1.MachineDeploymentClass{ Class: "md-class1", - Template: clusterv1.MachineDeploymentClassTemplate{ - Infrastructure: clusterv1.MachineDeploymentClassInfrastructureTemplate{ - TemplateRef: clusterv1.ClusterClassTemplateReference{ - Kind: "TestResourceTemplate", - Name: infrastructureMachineTemplate1.Name, - APIVersion: testt1v1beta1.GroupVersion.String(), - }, + Infrastructure: clusterv1.MachineDeploymentClassInfrastructureTemplate{ + TemplateRef: clusterv1.ClusterClassTemplateReference{ + Kind: "TestResourceTemplate", + Name: infrastructureMachineTemplate1.Name, + APIVersion: testt1v1beta1.GroupVersion.String(), }, - Bootstrap: clusterv1.MachineDeploymentClassBootstrapTemplate{ - TemplateRef: clusterv1.ClusterClassTemplateReference{ - Kind: "TestResourceTemplate", - Name: bootstrapTemplate.Name, - APIVersion: testt1v1beta1.GroupVersion.String(), - }, + }, + Bootstrap: clusterv1.MachineDeploymentClassBootstrapTemplate{ + TemplateRef: clusterv1.ClusterClassTemplateReference{ + Kind: "TestResourceTemplate", + Name: bootstrapTemplate.Name, + APIVersion: testt1v1beta1.GroupVersion.String(), }, }, } @@ -543,20 +541,18 @@ func createT2ClusterClass(g *WithT, ns *corev1.Namespace, ct2 client.Client) *cl machineDeploymentClass1 := clusterv1.MachineDeploymentClass{ Class: "md-class1", - Template: clusterv1.MachineDeploymentClassTemplate{ - Infrastructure: clusterv1.MachineDeploymentClassInfrastructureTemplate{ - TemplateRef: clusterv1.ClusterClassTemplateReference{ - Kind: "TestResourceTemplate", - Name: infrastructureMachineTemplate1.Name, - APIVersion: testt2v1beta2.GroupVersion.String(), - }, + Infrastructure: clusterv1.MachineDeploymentClassInfrastructureTemplate{ + TemplateRef: clusterv1.ClusterClassTemplateReference{ + Kind: "TestResourceTemplate", + Name: infrastructureMachineTemplate1.Name, + APIVersion: testt2v1beta2.GroupVersion.String(), }, - Bootstrap: clusterv1.MachineDeploymentClassBootstrapTemplate{ - TemplateRef: clusterv1.ClusterClassTemplateReference{ - Kind: "TestResourceTemplate", - Name: bootstrapTemplate.Name, - APIVersion: testt2v1beta2.GroupVersion.String(), - }, + }, + Bootstrap: clusterv1.MachineDeploymentClassBootstrapTemplate{ + TemplateRef: clusterv1.ClusterClassTemplateReference{ + Kind: "TestResourceTemplate", + Name: bootstrapTemplate.Name, + APIVersion: testt2v1beta2.GroupVersion.String(), }, }, } diff --git a/internal/webhooks/cluster.go b/internal/webhooks/cluster.go index 8ccfd34faad9..ddd984f28ba2 100644 --- a/internal/webhooks/cluster.go +++ b/internal/webhooks/cluster.go @@ -216,18 +216,11 @@ func (webhook *Cluster) validate(ctx context.Context, oldCluster, newCluster *cl ) } - if newCluster.Spec.ClusterNetwork != nil { - // Ensure that the CIDR blocks defined under ClusterNetwork are valid. - if newCluster.Spec.ClusterNetwork.Pods != nil { - allErrs = append(allErrs, validateCIDRBlocks(specPath.Child("clusterNetwork", "pods", "cidrBlocks"), - newCluster.Spec.ClusterNetwork.Pods.CIDRBlocks)...) - } - - if newCluster.Spec.ClusterNetwork.Services != nil { - allErrs = append(allErrs, validateCIDRBlocks(specPath.Child("clusterNetwork", "services", "cidrBlocks"), - newCluster.Spec.ClusterNetwork.Services.CIDRBlocks)...) - } - } + // Ensure that the CIDR blocks defined under ClusterNetwork are valid. + allErrs = append(allErrs, validateCIDRBlocks(specPath.Child("clusterNetwork", "pods", "cidrBlocks"), + newCluster.Spec.ClusterNetwork.Pods.CIDRBlocks)...) + allErrs = append(allErrs, validateCIDRBlocks(specPath.Child("clusterNetwork", "services", "cidrBlocks"), + newCluster.Spec.ClusterNetwork.Services.CIDRBlocks)...) topologyPath := specPath.Child("topology") @@ -675,32 +668,30 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust } } - if cluster.Spec.Topology.Workers != nil { - for i := range cluster.Spec.Topology.Workers.MachineDeployments { - md := cluster.Spec.Topology.Workers.MachineDeployments[i] - if md.MachineHealthCheck != nil { - fldPath := field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("machineHealthCheck") + for i := range cluster.Spec.Topology.Workers.MachineDeployments { + md := cluster.Spec.Topology.Workers.MachineDeployments[i] + if md.MachineHealthCheck != nil { + fldPath := field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("machineHealthCheck") - // Validate the MachineDeployment MachineHealthCheck if defined. - if !md.MachineHealthCheck.IsZero() { - allErrs = append(allErrs, validateMachineHealthCheckClass(fldPath, cluster.Namespace, - &md.MachineHealthCheck.MachineHealthCheckClass)...) - } + // Validate the MachineDeployment MachineHealthCheck if defined. + if !md.MachineHealthCheck.IsZero() { + allErrs = append(allErrs, validateMachineHealthCheckClass(fldPath, cluster.Namespace, + &md.MachineHealthCheck.MachineHealthCheckClass)...) + } - // If MachineHealthCheck is explicitly enabled then make sure that a MachineHealthCheck definition is - // available either in the Cluster topology or in the ClusterClass. - // (One of these definitions will be used in the controller to create the MachineHealthCheck) - mdClass := machineDeploymentClassOfName(clusterClass, md.Class) - if mdClass != nil { // Note: we skip handling the nil case here as it is already handled in previous validations. - // Check if the machineHealthCheck is explicitly enabled in the machineDeploymentTopology. - if md.MachineHealthCheck.Enable != nil && *md.MachineHealthCheck.Enable { - // Ensure the MHC is defined in at least one of the MachineDeploymentTopology of the Cluster or the MachineDeploymentClass of the ClusterClass. - if md.MachineHealthCheck.IsZero() && mdClass.MachineHealthCheck == nil { - allErrs = append(allErrs, field.Forbidden( - fldPath.Child("enable"), - fmt.Sprintf("cannot be set to %t as MachineHealthCheck definition is not available in the Cluster topology or the ClusterClass", *md.MachineHealthCheck.Enable), - )) - } + // If MachineHealthCheck is explicitly enabled then make sure that a MachineHealthCheck definition is + // available either in the Cluster topology or in the ClusterClass. + // (One of these definitions will be used in the controller to create the MachineHealthCheck) + mdClass := machineDeploymentClassOfName(clusterClass, md.Class) + if mdClass != nil { // Note: we skip handling the nil case here as it is already handled in previous validations. + // Check if the machineHealthCheck is explicitly enabled in the machineDeploymentTopology. + if md.MachineHealthCheck.Enable != nil && *md.MachineHealthCheck.Enable { + // Ensure the MHC is defined in at least one of the MachineDeploymentTopology of the Cluster or the MachineDeploymentClass of the ClusterClass. + if md.MachineHealthCheck.IsZero() && mdClass.MachineHealthCheck == nil { + allErrs = append(allErrs, field.Forbidden( + fldPath.Child("enable"), + fmt.Sprintf("cannot be set to %t as MachineHealthCheck definition is not available in the Cluster topology or the ClusterClass", *md.MachineHealthCheck.Enable), + )) } } } @@ -751,24 +742,16 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust ) if oldCluster != nil { oldClusterVariables = oldCluster.Spec.Topology.Variables - if oldCluster.Spec.Topology.ControlPlane.Variables != nil { - oldCPOverrides = oldCluster.Spec.Topology.ControlPlane.Variables.Overrides - } + oldCPOverrides = oldCluster.Spec.Topology.ControlPlane.Variables.Overrides - if oldCluster.Spec.Topology.Workers != nil { - oldMDVariables = make(map[string][]clusterv1.ClusterVariable, len(oldCluster.Spec.Topology.Workers.MachineDeployments)) - for _, md := range oldCluster.Spec.Topology.Workers.MachineDeployments { - if md.Variables != nil { - oldMDVariables[md.Name] = md.Variables.Overrides - } - } + oldMDVariables = make(map[string][]clusterv1.ClusterVariable, len(oldCluster.Spec.Topology.Workers.MachineDeployments)) + for _, md := range oldCluster.Spec.Topology.Workers.MachineDeployments { + oldMDVariables[md.Name] = md.Variables.Overrides + } - oldMPVariables = make(map[string][]clusterv1.ClusterVariable, len(oldCluster.Spec.Topology.Workers.MachinePools)) - for _, mp := range oldCluster.Spec.Topology.Workers.MachinePools { - if mp.Variables != nil { - oldMPVariables[mp.Name] = mp.Variables.Overrides - } - } + oldMPVariables = make(map[string][]clusterv1.ClusterVariable, len(oldCluster.Spec.Topology.Workers.MachinePools)) + for _, mp := range oldCluster.Spec.Topology.Workers.MachinePools { + oldMPVariables[mp.Name] = mp.Variables.Overrides } } @@ -784,7 +767,7 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust field.NewPath("spec", "topology", "variables"))...) // Validate ControlPlane variable overrides. - if cluster.Spec.Topology.ControlPlane.Variables != nil && len(cluster.Spec.Topology.ControlPlane.Variables.Overrides) > 0 { + if len(cluster.Spec.Topology.ControlPlane.Variables.Overrides) > 0 { allErrs = append(allErrs, variables.ValidateControlPlaneVariables( ctx, cluster.Spec.Topology.ControlPlane.Variables.Overrides, @@ -794,36 +777,34 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust ) } - if cluster.Spec.Topology.Workers != nil { - // Validate MachineDeployment variable overrides. - for _, md := range cluster.Spec.Topology.Workers.MachineDeployments { - // Continue if there are no variable overrides. - if md.Variables == nil || len(md.Variables.Overrides) == 0 { - continue - } - allErrs = append(allErrs, variables.ValidateMachineVariables( - ctx, - md.Variables.Overrides, - oldMDVariables[md.Name], - clusterClass.Status.Variables, - field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("variables", "overrides"))..., - ) + // Validate MachineDeployment variable overrides. + for _, md := range cluster.Spec.Topology.Workers.MachineDeployments { + // Continue if there are no variable overrides. + if len(md.Variables.Overrides) == 0 { + continue } + allErrs = append(allErrs, variables.ValidateMachineVariables( + ctx, + md.Variables.Overrides, + oldMDVariables[md.Name], + clusterClass.Status.Variables, + field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("variables", "overrides"))..., + ) + } - // Validate MachinePool variable overrides. - for _, mp := range cluster.Spec.Topology.Workers.MachinePools { - // Continue if there are no variable overrides. - if mp.Variables == nil || len(mp.Variables.Overrides) == 0 { - continue - } - allErrs = append(allErrs, variables.ValidateMachineVariables( - ctx, - mp.Variables.Overrides, - oldMPVariables[mp.Name], - clusterClass.Status.Variables, - field.NewPath("spec", "topology", "workers", "machinePools").Key(mp.Name).Child("variables", "overrides"))..., - ) + // Validate MachinePool variable overrides. + for _, mp := range cluster.Spec.Topology.Workers.MachinePools { + // Continue if there are no variable overrides. + if len(mp.Variables.Overrides) == 0 { + continue } + allErrs = append(allErrs, variables.ValidateMachineVariables( + ctx, + mp.Variables.Overrides, + oldMPVariables[mp.Name], + clusterClass.Status.Variables, + field.NewPath("spec", "topology", "workers", "machinePools").Key(mp.Name).Child("variables", "overrides"))..., + ) } return allErrs } @@ -848,7 +829,7 @@ func DefaultVariables(cluster *clusterv1.Cluster, clusterClass *clusterv1.Cluste } // Default ControlPlane variable overrides. - if cluster.Spec.Topology.ControlPlane.Variables != nil && len(cluster.Spec.Topology.ControlPlane.Variables.Overrides) > 0 { + if len(cluster.Spec.Topology.ControlPlane.Variables.Overrides) > 0 { defaultedVariables, errs := variables.DefaultMachineVariables(cluster.Spec.Topology.ControlPlane.Variables.Overrides, clusterClass.Status.Variables, field.NewPath("spec", "topology", "controlPlane", "variables", "overrides")) if len(errs) > 0 { @@ -858,35 +839,33 @@ func DefaultVariables(cluster *clusterv1.Cluster, clusterClass *clusterv1.Cluste } } - if cluster.Spec.Topology.Workers != nil { - // Default MachineDeployment variable overrides. - for _, md := range cluster.Spec.Topology.Workers.MachineDeployments { - // Continue if there are no variable overrides. - if md.Variables == nil || len(md.Variables.Overrides) == 0 { - continue - } - defaultedVariables, errs := variables.DefaultMachineVariables(md.Variables.Overrides, clusterClass.Status.Variables, - field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("variables", "overrides")) - if len(errs) > 0 { - allErrs = append(allErrs, errs...) - } else { - md.Variables.Overrides = defaultedVariables - } + // Default MachineDeployment variable overrides. + for i, md := range cluster.Spec.Topology.Workers.MachineDeployments { + // Continue if there are no variable overrides. + if len(md.Variables.Overrides) == 0 { + continue + } + defaultedVariables, errs := variables.DefaultMachineVariables(md.Variables.Overrides, clusterClass.Status.Variables, + field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("variables", "overrides")) + if len(errs) > 0 { + allErrs = append(allErrs, errs...) + } else { + cluster.Spec.Topology.Workers.MachineDeployments[i].Variables.Overrides = defaultedVariables } + } - // Default MachinePool variable overrides. - for _, mp := range cluster.Spec.Topology.Workers.MachinePools { - // Continue if there are no variable overrides. - if mp.Variables == nil || len(mp.Variables.Overrides) == 0 { - continue - } - defaultedVariables, errs := variables.DefaultMachineVariables(mp.Variables.Overrides, clusterClass.Status.Variables, - field.NewPath("spec", "topology", "workers", "machinePools").Key(mp.Name).Child("variables", "overrides")) - if len(errs) > 0 { - allErrs = append(allErrs, errs...) - } else { - mp.Variables.Overrides = defaultedVariables - } + // Default MachinePool variable overrides. + for i, mp := range cluster.Spec.Topology.Workers.MachinePools { + // Continue if there are no variable overrides. + if len(mp.Variables.Overrides) == 0 { + continue + } + defaultedVariables, errs := variables.DefaultMachineVariables(mp.Variables.Overrides, clusterClass.Status.Variables, + field.NewPath("spec", "topology", "workers", "machinePools").Key(mp.Name).Child("variables", "overrides")) + if len(errs) > 0 { + allErrs = append(allErrs, errs...) + } else { + cluster.Spec.Topology.Workers.MachinePools[i].Variables.Overrides = defaultedVariables } } return allErrs @@ -983,17 +962,15 @@ func clusterClassIsReconciled(clusterClass *clusterv1.ClusterClass) error { func validateTopologyMetadata(topology *clusterv1.Topology, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList allErrs = append(allErrs, topology.ControlPlane.Metadata.Validate(fldPath.Child("controlPlane", "metadata"))...) - if topology.Workers != nil { - for _, md := range topology.Workers.MachineDeployments { - allErrs = append(allErrs, md.Metadata.Validate( - fldPath.Child("workers", "machineDeployments").Key(md.Name).Child("metadata"), - )...) - } - for _, mp := range topology.Workers.MachinePools { - allErrs = append(allErrs, mp.Metadata.Validate( - fldPath.Child("workers", "machinePools").Key(mp.Name).Child("metadata"), - )...) - } + for _, md := range topology.Workers.MachineDeployments { + allErrs = append(allErrs, md.Metadata.Validate( + fldPath.Child("workers", "machineDeployments").Key(md.Name).Child("metadata"), + )...) + } + for _, mp := range topology.Workers.MachinePools { + allErrs = append(allErrs, mp.Metadata.Validate( + fldPath.Child("workers", "machinePools").Key(mp.Name).Child("metadata"), + )...) } return allErrs } @@ -1004,7 +981,7 @@ func validateTopologyMetadata(topology *clusterv1.Topology, fldPath *field.Path) func validateAutoscalerAnnotationsForCluster(cluster *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass) field.ErrorList { var allErrs field.ErrorList - if cluster.Spec.Topology == nil || cluster.Spec.Topology.Workers == nil { + if cluster.Spec.Topology == nil { return allErrs } @@ -1037,7 +1014,7 @@ func validateAutoscalerAnnotationsForCluster(cluster *clusterv1.Cluster, cluster if mdc.Class != mdt.Class { continue } - for k := range mdc.Template.Metadata.Annotations { + for k := range mdc.Metadata.Annotations { if k == clusterv1.AutoscalerMinSizeAnnotation || k == clusterv1.AutoscalerMaxSizeAnnotation { allErrs = append( allErrs, diff --git a/internal/webhooks/cluster_test.go b/internal/webhooks/cluster_test.go index 6731dd5c1f02..7ec27b2a2662 100644 --- a/internal/webhooks/cluster_test.go +++ b/internal/webhooks/cluster_test.go @@ -277,7 +277,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { Build(), topology: &clusterv1.Topology{ ControlPlane: clusterv1.ControlPlaneTopology{}, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Class: "default-worker", @@ -296,7 +296,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { ControlPlane: clusterv1.ControlPlaneTopology{ // "location" has not been added to .variables.overrides. }, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Class: "default-worker", @@ -357,7 +357,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { Build(), topology: &clusterv1.Topology{ ControlPlane: clusterv1.ControlPlaneTopology{ - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -366,12 +366,12 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Class: "default-worker", Name: "md-1", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -385,7 +385,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { { Class: "default-worker", Name: "md-1", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -405,7 +405,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, expect: &clusterv1.Topology{ ControlPlane: clusterv1.ControlPlaneTopology{ - Variables: &clusterv1.ControlPlaneVariables{ + Variables: clusterv1.ControlPlaneVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -415,12 +415,12 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Class: "default-worker", Name: "md-1", - Variables: &clusterv1.MachineDeploymentVariables{ + Variables: clusterv1.MachineDeploymentVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -435,7 +435,7 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { { Class: "default-worker", Name: "md-1", - Variables: &clusterv1.MachinePoolVariables{ + Variables: clusterv1.MachinePoolVariables{ Overrides: []clusterv1.ClusterVariable{ { Name: "httpProxy", @@ -1438,11 +1438,11 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{}, }, }). @@ -1454,11 +1454,11 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: nil, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: nil, }, }). @@ -1470,11 +1470,11 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.10/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.10/24"}, }, }). @@ -1486,11 +1486,11 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}, }, }). @@ -1502,11 +1502,11 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}, }, - Pods: &clusterv1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}, }, }). @@ -1518,8 +1518,8 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24"}, }, }). @@ -1531,8 +1531,8 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"2002::1234:abcd:ffff:c0a8:101/64", "2004::1234:abcd:ffff:c0a8:101/64"}, }, }). @@ -1544,8 +1544,8 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24", "12.12.12.12/24"}, }, }). @@ -1558,8 +1558,8 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Services: clusterv1.NetworkRanges{ // Invalid ranges: missing network suffix CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}, }, @@ -1573,8 +1573,8 @@ func TestClusterValidation(t *testing.T) { in: builder.Cluster("fooNamespace", "cluster1"). WithControlPlane( builder.ControlPlane("fooNamespace", "cp1").Build()). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ + WithClusterNetwork(clusterv1.ClusterNetwork{ + Pods: clusterv1.NetworkRanges{ // Invalid ranges: missing network suffix CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}, }, diff --git a/internal/webhooks/clusterclass.go b/internal/webhooks/clusterclass.go index cc3da15ef946..bf9685cfb59e 100644 --- a/internal/webhooks/clusterclass.go +++ b/internal/webhooks/clusterclass.go @@ -218,9 +218,6 @@ func validateUpdatesToMachineHealthCheckClasses(clusters []clusterv1.Cluster, ol if oldMdClass.MachineHealthCheck != nil && newMdClass.MachineHealthCheck == nil { clustersUsingMHC := []string{} for _, cluster := range clusters { - if cluster.Spec.Topology.Workers == nil { - continue - } for _, mdTopology := range cluster.Spec.Topology.Workers.MachineDeployments { if mdTopology.Class == newMdClass.Class { if mdTopology.MachineHealthCheck != nil && @@ -492,10 +489,10 @@ func validateClusterClassMetadata(clusterClass *clusterv1.ClusterClass) field.Er var allErrs field.ErrorList allErrs = append(allErrs, clusterClass.Spec.ControlPlane.Metadata.Validate(field.NewPath("spec", "controlPlane", "metadata"))...) for _, m := range clusterClass.Spec.Workers.MachineDeployments { - allErrs = append(allErrs, m.Template.Metadata.Validate(field.NewPath("spec", "workers", "machineDeployments").Key(m.Class).Child("template", "metadata"))...) + allErrs = append(allErrs, m.Metadata.Validate(field.NewPath("spec", "workers", "machineDeployments").Key(m.Class).Child("template", "metadata"))...) } for _, m := range clusterClass.Spec.Workers.MachinePools { - allErrs = append(allErrs, m.Template.Metadata.Validate(field.NewPath("spec", "workers", "machinePools").Key(m.Class).Child("template", "metadata"))...) + allErrs = append(allErrs, m.Metadata.Validate(field.NewPath("spec", "workers", "machinePools").Key(m.Class).Child("template", "metadata"))...) } return allErrs } diff --git a/internal/webhooks/machinedeployment.go b/internal/webhooks/machinedeployment.go index 8b948127132d..1be645da1257 100644 --- a/internal/webhooks/machinedeployment.go +++ b/internal/webhooks/machinedeployment.go @@ -104,10 +104,6 @@ func (webhook *MachineDeployment) Default(ctx context.Context, obj runtime.Objec m.Spec.Selector.MatchLabels = make(map[string]string) } - if m.Spec.Strategy == nil { - m.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{} - } - if m.Spec.Strategy.Type == "" { m.Spec.Strategy.Type = clusterv1.RollingUpdateMachineDeploymentStrategyType } @@ -118,9 +114,6 @@ func (webhook *MachineDeployment) Default(ctx context.Context, obj runtime.Objec // Default RollingUpdate strategy only if strategy type is RollingUpdate. if m.Spec.Strategy.Type == clusterv1.RollingUpdateMachineDeploymentStrategyType { - if m.Spec.Strategy.RollingUpdate == nil { - m.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{} - } if m.Spec.Strategy.RollingUpdate.MaxSurge == nil { ios1 := intstr.FromInt32(1) m.Spec.Strategy.RollingUpdate.MaxSurge = &ios1 @@ -252,47 +245,38 @@ func (webhook *MachineDeployment) validate(oldMD, newMD *clusterv1.MachineDeploy ) } - if newMD.Spec.Strategy != nil && newMD.Spec.Strategy.RollingUpdate != nil { - total := 1 - if newMD.Spec.Replicas != nil { - total = int(*newMD.Spec.Replicas) - } - - if newMD.Spec.Strategy.RollingUpdate.MaxSurge != nil { - if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.RollingUpdate.MaxSurge, total, true); err != nil { - allErrs = append( - allErrs, - field.Invalid(specPath.Child("strategy", "rollingUpdate", "maxSurge"), - newMD.Spec.Strategy.RollingUpdate.MaxSurge, fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), - ) - } - } + total := 1 + if newMD.Spec.Replicas != nil { + total = int(*newMD.Spec.Replicas) + } - if newMD.Spec.Strategy.RollingUpdate.MaxUnavailable != nil { - if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.RollingUpdate.MaxUnavailable, total, true); err != nil { - allErrs = append( - allErrs, - field.Invalid(specPath.Child("strategy", "rollingUpdate", "maxUnavailable"), - newMD.Spec.Strategy.RollingUpdate.MaxUnavailable, fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), - ) - } + if newMD.Spec.Strategy.RollingUpdate.MaxSurge != nil { + if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.RollingUpdate.MaxSurge, total, true); err != nil { + allErrs = append( + allErrs, + field.Invalid(specPath.Child("strategy", "rollingUpdate", "maxSurge"), + newMD.Spec.Strategy.RollingUpdate.MaxSurge, fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), + ) } } - if newMD.Spec.Strategy != nil && newMD.Spec.Strategy.Remediation != nil { - total := 1 - if newMD.Spec.Replicas != nil { - total = int(*newMD.Spec.Replicas) + if newMD.Spec.Strategy.RollingUpdate.MaxUnavailable != nil { + if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.RollingUpdate.MaxUnavailable, total, true); err != nil { + allErrs = append( + allErrs, + field.Invalid(specPath.Child("strategy", "rollingUpdate", "maxUnavailable"), + newMD.Spec.Strategy.RollingUpdate.MaxUnavailable, fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), + ) } + } - if newMD.Spec.Strategy.Remediation.MaxInFlight != nil { - if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.Remediation.MaxInFlight, total, true); err != nil { - allErrs = append( - allErrs, - field.Invalid(specPath.Child("strategy", "remediation", "maxInFlight"), - newMD.Spec.Strategy.Remediation.MaxInFlight.String(), fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), - ) - } + if newMD.Spec.Strategy.Remediation.MaxInFlight != nil { + if _, err := intstr.GetScaledValueFromIntOrPercent(newMD.Spec.Strategy.Remediation.MaxInFlight, total, true); err != nil { + allErrs = append( + allErrs, + field.Invalid(specPath.Child("strategy", "remediation", "maxInFlight"), + newMD.Spec.Strategy.Remediation.MaxInFlight.String(), fmt.Sprintf("must be either an int or a percentage: %v", err.Error())), + ) } } diff --git a/internal/webhooks/machinedeployment_test.go b/internal/webhooks/machinedeployment_test.go index aa3d04f484e4..94f6391a15a5 100644 --- a/internal/webhooks/machinedeployment_test.go +++ b/internal/webhooks/machinedeployment_test.go @@ -71,7 +71,6 @@ func TestMachineDeploymentDefault(t *testing.T) { g.Expect(md.Labels[clusterv1.ClusterNameLabel]).To(Equal(md.Spec.ClusterName)) g.Expect(md.Spec.Replicas).To(Equal(ptr.To[int32](1))) - g.Expect(md.Spec.Strategy).ToNot(BeNil()) g.Expect(md.Spec.Selector.MatchLabels).To(HaveKeyWithValue(clusterv1.MachineDeploymentNameLabel, "test-md")) g.Expect(md.Spec.Template.Labels).To(HaveKeyWithValue(clusterv1.MachineDeploymentNameLabel, "test-md")) @@ -79,7 +78,6 @@ func TestMachineDeploymentDefault(t *testing.T) { g.Expect(md.Spec.Template.Labels).To(HaveKeyWithValue(clusterv1.ClusterNameLabel, "test-cluster")) g.Expect(md.Spec.Strategy.Type).To(Equal(clusterv1.RollingUpdateMachineDeploymentStrategyType)) - g.Expect(md.Spec.Strategy.RollingUpdate).ToNot(BeNil()) g.Expect(md.Spec.Strategy.RollingUpdate.MaxSurge.IntValue()).To(Equal(1)) g.Expect(md.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue()).To(Equal(0)) @@ -433,7 +431,7 @@ func TestMachineDeploymentValidation(t *testing.T) { labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: &goodMaxUnavailableInt, MaxSurge: &badMaxSurge, }, @@ -446,7 +444,7 @@ func TestMachineDeploymentValidation(t *testing.T) { labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: &badMaxUnavailable, MaxSurge: &goodMaxSurgeInt, }, @@ -458,7 +456,7 @@ func TestMachineDeploymentValidation(t *testing.T) { selectors: map[string]string{"foo": "bar"}, labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: &badMaxInFlight, }, }, @@ -469,7 +467,7 @@ func TestMachineDeploymentValidation(t *testing.T) { selectors: map[string]string{"foo": "bar"}, labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: &goodMaxInFlightPercentage, }, }, @@ -480,7 +478,7 @@ func TestMachineDeploymentValidation(t *testing.T) { selectors: map[string]string{"foo": "bar"}, labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: &goodMaxInFlightInt, }, }, @@ -492,7 +490,7 @@ func TestMachineDeploymentValidation(t *testing.T) { labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: &goodMaxUnavailableInt, MaxSurge: &goodMaxSurgeInt, }, @@ -505,7 +503,7 @@ func TestMachineDeploymentValidation(t *testing.T) { labels: map[string]string{"foo": "bar"}, strategy: clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: &goodMaxUnavailablePercentage, MaxSurge: &goodMaxSurgePercentage, }, @@ -544,7 +542,7 @@ func TestMachineDeploymentValidation(t *testing.T) { Name: tt.mdName, }, Spec: clusterv1.MachineDeploymentSpec{ - Strategy: &tt.strategy, + Strategy: tt.strategy, Selector: metav1.LabelSelector{ MatchLabels: tt.selectors, }, diff --git a/internal/webhooks/patch_validation.go b/internal/webhooks/patch_validation.go index 10773fcaf05f..d25daa53d875 100644 --- a/internal/webhooks/patch_validation.go +++ b/internal/webhooks/patch_validation.go @@ -224,8 +224,8 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste } if matches { - if selectorMatchTemplate(selector, md.Template.Infrastructure.TemplateRef) || - selectorMatchTemplate(selector, md.Template.Bootstrap.TemplateRef) { + if selectorMatchTemplate(selector, md.Infrastructure.TemplateRef) || + selectorMatchTemplate(selector, md.Bootstrap.TemplateRef) { match = true break } @@ -260,8 +260,8 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste } if matches { - if selectorMatchTemplate(selector, mp.Template.Infrastructure.TemplateRef) || - selectorMatchTemplate(selector, mp.Template.Bootstrap.TemplateRef) { + if selectorMatchTemplate(selector, mp.Infrastructure.TemplateRef) || + selectorMatchTemplate(selector, mp.Bootstrap.TemplateRef) { match = true break } diff --git a/test/e2e/clusterclass_changes.go b/test/e2e/clusterclass_changes.go index a4d095dd7d94..418672a0eb25 100644 --- a/test/e2e/clusterclass_changes.go +++ b/test/e2e/clusterclass_changes.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "path/filepath" + "reflect" "strings" "time" @@ -454,7 +455,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo log.Logf("Modifying the BootstrapConfigTemplate of MachineDeploymentClass %q of ClusterClass %s", mdClass.Class, klog.KObj(input.ClusterClass)) // Retrieve BootstrapConfigTemplate object. - bootstrapConfigTemplateRef := mdClass.Template.Bootstrap.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) + bootstrapConfigTemplateRef := mdClass.Bootstrap.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new BootstrapConfigTemplate object with a new name and ModifyBootstrapConfigTemplateFields set. @@ -470,7 +471,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo log.Logf("Modifying the InfrastructureMachineTemplate of MachineDeploymentClass %q of ClusterClass %s", mdClass.Class, klog.KObj(input.ClusterClass)) // Retrieve InfrastructureMachineTemplate object. - infrastructureMachineTemplateRef := mdClass.Template.Infrastructure.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) + infrastructureMachineTemplateRef := mdClass.Infrastructure.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachineTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new InfrastructureMachineTemplate object with a new name and ModifyInfrastructureMachineTemplateFields set. @@ -486,8 +487,8 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo // Patch the refs of the MachineDeploymentClass to reference the new templates. patchHelper, err := patch.NewHelper(input.ClusterClass, mgmtClient) Expect(err).ToNot(HaveOccurred()) - input.ClusterClass.Spec.Workers.MachineDeployments[i].Template.Bootstrap.TemplateRef.Name = newBootstrapConfigTemplateName - input.ClusterClass.Spec.Workers.MachineDeployments[i].Template.Infrastructure.TemplateRef.Name = newInfrastructureMachineTemplateName + input.ClusterClass.Spec.Workers.MachineDeployments[i].Bootstrap.TemplateRef.Name = newBootstrapConfigTemplateName + input.ClusterClass.Spec.Workers.MachineDeployments[i].Infrastructure.TemplateRef.Name = newInfrastructureMachineTemplateName Expect(patchHelper.Patch(ctx, input.ClusterClass)).To(Succeed()) log.Logf("Waiting for MachineDeployment rollout for MachineDeploymentClass %q to complete.", mdClass.Class) @@ -570,7 +571,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa log.Logf("Modifying the BootstrapConfigTemplate of MachinePoolClass %q of ClusterClass %s", mpClass.Class, klog.KObj(input.ClusterClass)) // Retrieve BootstrapConfigTemplate object. - bootstrapConfigTemplateRef := mpClass.Template.Bootstrap.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) + bootstrapConfigTemplateRef := mpClass.Bootstrap.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new BootstrapConfigTemplate object with a new name and ModifyBootstrapConfigTemplateFields set. @@ -586,7 +587,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa log.Logf("Modifying the InfrastructureMachinePoolTemplate of MachinePoolClass %q of ClusterClass %s", mpClass.Class, klog.KObj(input.ClusterClass)) // Retrieve InfrastructureMachineTemplate object. - infrastructureMachinePoolTemplateRef := mpClass.Template.Infrastructure.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) + infrastructureMachinePoolTemplateRef := mpClass.Infrastructure.TemplateRef.ToObjectReference(input.ClusterClass.Namespace) infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachinePoolTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new InfrastructureMachinePoolTemplate object with a new name and ModifyInfrastructureMachinePoolTemplateFields set. @@ -602,8 +603,8 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa // Patch the refs of the MachinePoolClass to reference the new templates. patchHelper, err := patch.NewHelper(input.ClusterClass, mgmtClient) Expect(err).ToNot(HaveOccurred()) - input.ClusterClass.Spec.Workers.MachinePools[i].Template.Bootstrap.TemplateRef.Name = newBootstrapConfigTemplateName - input.ClusterClass.Spec.Workers.MachinePools[i].Template.Infrastructure.TemplateRef.Name = newInfrastructureMachinePoolTemplateName + input.ClusterClass.Spec.Workers.MachinePools[i].Bootstrap.TemplateRef.Name = newBootstrapConfigTemplateName + input.ClusterClass.Spec.Workers.MachinePools[i].Infrastructure.TemplateRef.Name = newInfrastructureMachinePoolTemplateName Expect(patchHelper.Patch(ctx, input.ClusterClass)).To(Succeed()) log.Logf("Waiting for MachinePool rollout for MachinePoolClass %q to complete.", mpClass.Class) @@ -691,7 +692,7 @@ func assertMachineDeploymentTopologyFields(g Gomega, md clusterv1.MachineDeploym g.Expect(md.Spec.Template.Spec.MinReadySeconds).To(Equal(mdTopology.MinReadySeconds)) } - if mdTopology.Strategy != nil { + if !reflect.DeepEqual(mdTopology.Strategy, clusterv1.MachineDeploymentStrategy{}) { g.Expect(md.Spec.Strategy).To(BeComparableTo(mdTopology.Strategy)) } @@ -772,23 +773,23 @@ func rebaseClusterClassAndWait(ctx context.Context, input rebaseClusterClassAndW newClusterClass.SetResourceVersion("") for i, mdClass := range newClusterClass.Spec.Workers.MachineDeployments { - if mdClass.Template.Metadata.Labels == nil { - mdClass.Template.Metadata.Labels = map[string]string{} + if mdClass.Metadata.Labels == nil { + mdClass.Metadata.Labels = map[string]string{} } - mdClass.Template.Metadata.Labels[testWorkerLabelName] = mdClass.Class + mdClass.Metadata.Labels[testWorkerLabelName] = mdClass.Class newClusterClass.Spec.Workers.MachineDeployments[i] = mdClass } // Copy ClusterClass templates to the new namespace for i, mdClass := range newClusterClass.Spec.Workers.MachineDeployments { - cloneTemplateAndUpdateRef(ctx, mgmtClient, &mdClass.Template.Infrastructure.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) - cloneTemplateAndUpdateRef(ctx, mgmtClient, &mdClass.Template.Bootstrap.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) + cloneTemplateAndUpdateRef(ctx, mgmtClient, &mdClass.Infrastructure.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) + cloneTemplateAndUpdateRef(ctx, mgmtClient, &mdClass.Bootstrap.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) newClusterClass.Spec.Workers.MachineDeployments[i] = mdClass } for i, mpClass := range newClusterClass.Spec.Workers.MachinePools { - cloneTemplateAndUpdateRef(ctx, mgmtClient, &mpClass.Template.Infrastructure.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) - cloneTemplateAndUpdateRef(ctx, mgmtClient, &mpClass.Template.Bootstrap.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) + cloneTemplateAndUpdateRef(ctx, mgmtClient, &mpClass.Infrastructure.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) + cloneTemplateAndUpdateRef(ctx, mgmtClient, &mpClass.Bootstrap.TemplateRef, input.ClusterClass.Namespace, input.ClusterClassNamespace) newClusterClass.Spec.Workers.MachinePools[i] = mpClass } diff --git a/test/e2e/clusterclass_rollout.go b/test/e2e/clusterclass_rollout.go index 984bb1ae502b..86c43b503846 100644 --- a/test/e2e/clusterclass_rollout.go +++ b/test/e2e/clusterclass_rollout.go @@ -193,14 +193,14 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas topology.NodeDeletionTimeoutSeconds = ptr.To(rand.Int31n(20)) //nolint:gosec topology.NodeVolumeDetachTimeoutSeconds = ptr.To(rand.Int31n(20)) //nolint:gosec topology.MinReadySeconds = ptr.To[int32](rand.Int31n(20)) //nolint:gosec - topology.Strategy = &clusterv1.MachineDeploymentStrategy{ + topology.Strategy = clusterv1.MachineDeploymentStrategy{ Type: clusterv1.RollingUpdateMachineDeploymentStrategyType, - RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{ + RollingUpdate: clusterv1.MachineDeploymentStrategyRollingUpdate{ MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0}, MaxSurge: &intstr.IntOrString{Type: intstr.Int, IntVal: 5 + rand.Int31n(20)}, //nolint:gosec DeletePolicy: clusterv1.NewestMachineSetDeletePolicy, }, - Remediation: &clusterv1.RemediationStrategy{ + Remediation: clusterv1.RemediationStrategy{ MaxInFlight: &intstr.IntOrString{Type: intstr.Int, IntVal: 2 + rand.Int31n(20)}, //nolint:gosec }, } @@ -563,7 +563,7 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects, clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name, }, mdTopology.Metadata.Labels, - mdClass.Template.Metadata.Labels, + mdClass.Metadata.Labels, ), ) expectMapsToBeEquivalent(g, @@ -572,7 +572,7 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects, ).without(g, clusterv1.RevisionAnnotation), union( mdTopology.Metadata.Annotations, - mdClass.Template.Metadata.Annotations, + mdClass.Metadata.Annotations, ), ) @@ -595,13 +595,13 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects, clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name, }, mdTopology.Metadata.Labels, - mdClass.Template.Metadata.Labels, + mdClass.Metadata.Labels, ), ) expectMapsToBeEquivalent(g, machineDeployment.Spec.Template.Annotations, union( mdTopology.Metadata.Annotations, - mdClass.Template.Metadata.Annotations, + mdClass.Metadata.Annotations, ), ) @@ -623,8 +623,8 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects, expectMapsToBeEquivalent(g, infrastructureMachineTemplate.GetAnnotations(), union( map[string]string{ - clusterv1.TemplateClonedFromGroupKindAnnotation: mdClass.Template.Infrastructure.TemplateRef.GroupVersionKind().GroupKind().String(), - clusterv1.TemplateClonedFromNameAnnotation: mdClass.Template.Infrastructure.TemplateRef.Name, + clusterv1.TemplateClonedFromGroupKindAnnotation: mdClass.Infrastructure.TemplateRef.GroupVersionKind().GroupKind().String(), + clusterv1.TemplateClonedFromNameAnnotation: mdClass.Infrastructure.TemplateRef.Name, }, ccInfrastructureMachineTemplate.GetAnnotations(), ), @@ -655,8 +655,8 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects, expectMapsToBeEquivalent(g, bootstrapConfigTemplate.GetAnnotations(), union( map[string]string{ - clusterv1.TemplateClonedFromGroupKindAnnotation: mdClass.Template.Bootstrap.TemplateRef.GroupVersionKind().GroupKind().String(), - clusterv1.TemplateClonedFromNameAnnotation: mdClass.Template.Bootstrap.TemplateRef.Name, + clusterv1.TemplateClonedFromGroupKindAnnotation: mdClass.Bootstrap.TemplateRef.GroupVersionKind().GroupKind().String(), + clusterv1.TemplateClonedFromNameAnnotation: mdClass.Bootstrap.TemplateRef.Name, }, ccBootstrapConfigTemplate.GetAnnotations(), ), @@ -688,13 +688,13 @@ func assertMachinePools(g Gomega, clusterClassObjects clusterClassObjects, clust clusterv1.ClusterTopologyMachinePoolNameLabel: mpTopology.Name, }, mpTopology.Metadata.Labels, - mpClass.Template.Metadata.Labels, + mpClass.Metadata.Labels, ), ) expectMapsToBeEquivalent(g, machinePool.Annotations, union( mpTopology.Metadata.Annotations, - mpClass.Template.Metadata.Annotations, + mpClass.Metadata.Annotations, ), ) @@ -707,13 +707,13 @@ func assertMachinePools(g Gomega, clusterClassObjects clusterClassObjects, clust clusterv1.ClusterTopologyMachinePoolNameLabel: mpTopology.Name, }, mpTopology.Metadata.Labels, - mpClass.Template.Metadata.Labels, + mpClass.Metadata.Labels, ), ) expectMapsToBeEquivalent(g, machinePool.Spec.Template.Annotations, union( mpTopology.Metadata.Annotations, - mpClass.Template.Metadata.Annotations, + mpClass.Metadata.Annotations, ), ) @@ -734,8 +734,8 @@ func assertMachinePools(g Gomega, clusterClassObjects clusterClassObjects, clust expectMapsToBeEquivalent(g, infrastructureMachinePool.GetAnnotations(), union( map[string]string{ - clusterv1.TemplateClonedFromGroupKindAnnotation: mpClass.Template.Infrastructure.TemplateRef.GroupVersionKind().GroupKind().String(), - clusterv1.TemplateClonedFromNameAnnotation: mpClass.Template.Infrastructure.TemplateRef.Name, + clusterv1.TemplateClonedFromGroupKindAnnotation: mpClass.Infrastructure.TemplateRef.GroupVersionKind().GroupKind().String(), + clusterv1.TemplateClonedFromNameAnnotation: mpClass.Infrastructure.TemplateRef.Name, }, ccInfrastructureMachinePoolTemplateTemplateMetadata.Annotations, ), @@ -758,8 +758,8 @@ func assertMachinePools(g Gomega, clusterClassObjects clusterClassObjects, clust expectMapsToBeEquivalent(g, bootstrapConfig.GetAnnotations(), union( map[string]string{ - clusterv1.TemplateClonedFromGroupKindAnnotation: mpClass.Template.Bootstrap.TemplateRef.GroupVersionKind().GroupKind().String(), - clusterv1.TemplateClonedFromNameAnnotation: mpClass.Template.Bootstrap.TemplateRef.Name, + clusterv1.TemplateClonedFromGroupKindAnnotation: mpClass.Bootstrap.TemplateRef.GroupVersionKind().GroupKind().String(), + clusterv1.TemplateClonedFromNameAnnotation: mpClass.Bootstrap.TemplateRef.Name, }, ccBootstrapConfigTemplateTemplateMetadata.Annotations, ), @@ -1068,21 +1068,21 @@ func getClusterClassObjects(ctx context.Context, g Gomega, clusterProxy framewor g.Expect(err).ToNot(HaveOccurred()) for _, mdClass := range clusterClass.Spec.Workers.MachineDeployments { - infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) + infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, mdClass.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachineTemplateByMachineDeploymentClass[mdClass.Class] = infrastructureMachineTemplate - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigTemplateByMachineDeploymentClass[mdClass.Class] = bootstrapConfigTemplate } for _, mpClass := range clusterClass.Spec.Workers.MachinePools { - infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) + infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, mpClass.Infrastructure.TemplateRef.ToObjectReference(clusterClass.Namespace)) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachinePoolTemplateByMachinePoolClass[mpClass.Class] = infrastructureMachinePoolTemplate - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mpClass.Bootstrap.TemplateRef.ToObjectReference(clusterClass.Namespace)) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigTemplateByMachinePoolClass[mpClass.Class] = bootstrapConfigTemplate } diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 3659225c6cfe..be69b1e0ceee 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -973,13 +973,11 @@ func calculateExpectedMachineDeploymentMachineCount(ctx context.Context, c clien Expect(apiruntime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCluster.Object, cluster)).To(Succeed()) if cluster.Spec.Topology != nil { - if cluster.Spec.Topology.Workers != nil { - for _, md := range cluster.Spec.Topology.Workers.MachineDeployments { - if md.Replicas == nil { - continue - } - expectedMachineDeploymentWorkerCount += int64(*md.Replicas) + for _, md := range cluster.Spec.Topology.Workers.MachineDeployments { + if md.Replicas == nil { + continue } + expectedMachineDeploymentWorkerCount += int64(*md.Replicas) } return expectedMachineDeploymentWorkerCount } @@ -1062,13 +1060,11 @@ func calculateExpectedMachinePoolNodeCount(ctx context.Context, c client.Client, Expect(apiruntime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCluster.Object, cluster)).To(Succeed()) if cluster.Spec.Topology != nil { - if cluster.Spec.Topology.Workers != nil { - for _, mp := range cluster.Spec.Topology.Workers.MachinePools { - if mp.Replicas == nil { - continue - } - expectedMachinePoolWorkerCount += int64(*mp.Replicas) + for _, mp := range cluster.Spec.Topology.Workers.MachinePools { + if mp.Replicas == nil { + continue } + expectedMachinePoolWorkerCount += int64(*mp.Replicas) } return expectedMachinePoolWorkerCount } diff --git a/test/e2e/data/infrastructure-docker/main/clusterclass-in-memory.yaml b/test/e2e/data/infrastructure-docker/main/clusterclass-in-memory.yaml index abd2743258be..996464eab95d 100644 --- a/test/e2e/data/infrastructure-docker/main/clusterclass-in-memory.yaml +++ b/test/e2e/data/infrastructure-docker/main/clusterclass-in-memory.yaml @@ -118,7 +118,7 @@ spec: kind: KubeadmControlPlaneTemplate name: in-memory-control-plane machineHealthCheck: - unhealthyConditions: + unhealthyNodeConditions: - type: Ready status: "Unknown" timeoutSeconds: 300 @@ -133,19 +133,18 @@ spec: workers: machineDeployments: - class: default-worker - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: in-memory-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DevMachineTemplate - name: in-memory-default-worker-machinetemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: in-memory-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DevMachineTemplate + name: in-memory-default-worker-machinetemplate machineHealthCheck: - unhealthyConditions: + unhealthyNodeConditions: - type: Ready status: "Unknown" timeoutSeconds: 300 diff --git a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml index 35bcb59eb66d..af075cdfaca6 100644 --- a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml +++ b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml @@ -27,32 +27,30 @@ spec: - class: default-worker namingStrategy: template: "{{ .cluster.name }}-md-{{ .machineDeployment.topologyName }}-{{ .random }}" - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachineTemplate - name: quick-start-default-worker-machinetemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachineTemplate + name: quick-start-default-worker-machinetemplate machinePools: - class: default-worker namingStrategy: template: "{{ .cluster.name }}-mp-{{ .machinePool.topologyName }}-{{ .random }}" - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachinePoolTemplate - name: quick-start-default-worker-machinepooltemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachinePoolTemplate + name: quick-start-default-worker-machinepooltemplate patches: - name: test-patch external: diff --git a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml index 92742205c4df..6399a4cb6bfa 100644 --- a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml +++ b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml @@ -31,41 +31,39 @@ spec: workers: machineDeployments: - class: default-worker - template: - metadata: - labels: - ClusterClass.machineDeployment.label: "ClusterClass.machineDeployment.labelValue" - annotations: - ClusterClass.machineDeployment.annotation: "ClusterClass.machineDeployment.annotationValue" - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-md-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachineTemplate - name: quick-start-default-worker-machinetemplate - # We are intentionally not setting the 'unhealthyConditions' here to test that the field is optional. + metadata: + labels: + ClusterClass.machineDeployment.label: "ClusterClass.machineDeployment.labelValue" + annotations: + ClusterClass.machineDeployment.annotation: "ClusterClass.machineDeployment.annotationValue" + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-md-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachineTemplate + name: quick-start-default-worker-machinetemplate + # We are intentionally not setting the 'unhealthyNodeConditions' here to test that the field is optional. machinePools: - class: default-worker - template: - metadata: - labels: - ClusterClass.machinePool.label: "ClusterClass.machinePool.labelValue" - annotations: - ClusterClass.machinePool.annotation: "ClusterClass.machinePool.annotationValue" - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-mp-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachinePoolTemplate - name: quick-start-default-worker-machinepooltemplate + metadata: + labels: + ClusterClass.machinePool.label: "ClusterClass.machinePool.labelValue" + annotations: + ClusterClass.machinePool.annotation: "ClusterClass.machinePool.annotationValue" + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-mp-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachinePoolTemplate + name: quick-start-default-worker-machinepooltemplate variables: - name: lbImageRepository required: true diff --git a/test/e2e/scale.go b/test/e2e/scale.go index f298d2e3be18..ab0335d4c444 100644 --- a/test/e2e/scale.go +++ b/test/e2e/scale.go @@ -958,7 +958,6 @@ func modifyMachineDeployments(baseClusterTemplateYAML []byte, count int64) []byt // Verify the Cluster Topology. Expect(cluster.Spec.Topology).NotTo(BeNil(), "Should be a ClusterClass based Cluster") - Expect(cluster.Spec.Topology.Workers).NotTo(BeNil(), "ClusterTopology should have exactly one MachineDeployment. Cannot be empty") Expect(cluster.Spec.Topology.Workers.MachineDeployments).To(HaveLen(1), "ClusterTopology should have exactly one MachineDeployment") baseMD := cluster.Spec.Topology.Workers.MachineDeployments[0] diff --git a/test/extension/handlers/topologymutation/handler_integration_test.go b/test/extension/handlers/topologymutation/handler_integration_test.go index c95a91b0b930..47f886030781 100644 --- a/test/extension/handlers/topologymutation/handler_integration_test.go +++ b/test/extension/handlers/topologymutation/handler_integration_test.go @@ -153,8 +153,8 @@ func getCluster() *clusterv1.Cluster { Namespace: "namespace-name-test", }, Spec: clusterv1.ClusterSpec{ - ClusterNetwork: &clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"192.168.0.0/16"}, }, }, @@ -167,7 +167,7 @@ func getCluster() *clusterv1.Cluster { ControlPlane: clusterv1.ControlPlaneTopology{ Replicas: ptr.To[int32](1), }, - Workers: &clusterv1.WorkersTopology{ + Workers: clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Name: "md-test1", @@ -288,9 +288,9 @@ func getScope(cluster *clusterv1.Cluster, clusterClassFile string) (*scope.Scope // MachineDeployments. for _, machineDeploymentClass := range s.Blueprint.ClusterClass.Spec.Workers.MachineDeployments { machineDeploymentBlueprint := &scope.MachineDeploymentBlueprint{} - machineDeploymentClass.Template.Metadata.DeepCopyInto(&machineDeploymentBlueprint.Metadata) - machineDeploymentBlueprint.InfrastructureMachineTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machineDeploymentClass.Template.Infrastructure.TemplateRef)) - machineDeploymentBlueprint.BootstrapTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machineDeploymentClass.Template.Bootstrap.TemplateRef)) + machineDeploymentClass.Metadata.DeepCopyInto(&machineDeploymentBlueprint.Metadata) + machineDeploymentBlueprint.InfrastructureMachineTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machineDeploymentClass.Infrastructure.TemplateRef)) + machineDeploymentBlueprint.BootstrapTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machineDeploymentClass.Bootstrap.TemplateRef)) if machineDeploymentClass.MachineHealthCheck != nil { machineDeploymentBlueprint.MachineHealthCheck = machineDeploymentClass.MachineHealthCheck } @@ -300,9 +300,9 @@ func getScope(cluster *clusterv1.Cluster, clusterClassFile string) (*scope.Scope // MachinePools. for _, machinePoolClass := range s.Blueprint.ClusterClass.Spec.Workers.MachinePools { machinePoolBlueprint := &scope.MachinePoolBlueprint{} - machinePoolClass.Template.Metadata.DeepCopyInto(&machinePoolBlueprint.Metadata) - machinePoolBlueprint.InfrastructureMachinePoolTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machinePoolClass.Template.Infrastructure.TemplateRef)) - machinePoolBlueprint.BootstrapTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machinePoolClass.Template.Bootstrap.TemplateRef)) + machinePoolClass.Metadata.DeepCopyInto(&machinePoolBlueprint.Metadata) + machinePoolBlueprint.InfrastructureMachinePoolTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machinePoolClass.Infrastructure.TemplateRef)) + machinePoolBlueprint.BootstrapTemplate = mustFind(findObject[*unstructured.Unstructured](parsedObjects, machinePoolClass.Bootstrap.TemplateRef)) s.Blueprint.MachinePools[machinePoolClass.Class] = machinePoolBlueprint } diff --git a/test/extension/handlers/topologymutation/testdata/clusterclass-quick-start-runtimesdk.yaml b/test/extension/handlers/topologymutation/testdata/clusterclass-quick-start-runtimesdk.yaml index 5211ddbe596a..7db928791f4d 100644 --- a/test/extension/handlers/topologymutation/testdata/clusterclass-quick-start-runtimesdk.yaml +++ b/test/extension/handlers/topologymutation/testdata/clusterclass-quick-start-runtimesdk.yaml @@ -25,32 +25,30 @@ spec: - class: default-worker namingStrategy: template: "{{ .cluster.name }}-md-{{ .machineDeployment.topologyName }}-{{ .random }}" - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachineTemplate - name: quick-start-default-worker-machinetemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachineTemplate + name: quick-start-default-worker-machinetemplate machinePools: - class: default-worker namingStrategy: template: "{{ .cluster.name }}-mp-{{ .machinePool.topologyName }}-{{ .random }}" - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachinePoolTemplate - name: quick-start-default-worker-machinepooltemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachinePoolTemplate + name: quick-start-default-worker-machinepooltemplate patches: - name: test-patch external: diff --git a/test/framework/machinedeployment_helpers.go b/test/framework/machinedeployment_helpers.go index 461625cabd83..51ea7b1c4b61 100644 --- a/test/framework/machinedeployment_helpers.go +++ b/test/framework/machinedeployment_helpers.go @@ -632,7 +632,6 @@ func ScaleAndWaitMachineDeploymentTopology(ctx context.Context, input ScaleAndWa Expect(ctx).NotTo(BeNil(), "ctx is required for ScaleAndWaitMachineDeployment") Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling ScaleAndWaitMachineDeployment") Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling ScaleAndWaitMachineDeployment") - Expect(input.Cluster.Spec.Topology.Workers).ToNot(BeNil(), "Invalid argument. input.Cluster must have MachineDeployment topologies") Expect(input.Cluster.Spec.Topology.Workers.MachineDeployments).NotTo(BeEmpty(), "Invalid argument. input.Cluster must have at least one MachineDeployment topology") mdTopology := input.Cluster.Spec.Topology.Workers.MachineDeployments[0] diff --git a/test/framework/machinepool_helpers.go b/test/framework/machinepool_helpers.go index b396e94572e2..429add84730b 100644 --- a/test/framework/machinepool_helpers.go +++ b/test/framework/machinepool_helpers.go @@ -219,7 +219,6 @@ func ScaleMachinePoolTopologyAndWait(ctx context.Context, input ScaleMachinePool Expect(ctx).NotTo(BeNil(), "ctx is required for ScaleMachinePoolTopologyAndWait") Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling ScaleMachinePoolTopologyAndWait") Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling ScaleMachinePoolTopologyAndWait") - Expect(input.Cluster.Spec.Topology.Workers).ToNot(BeNil(), "Invalid argument. input.Cluster must have MachinePool topologies") Expect(input.Cluster.Spec.Topology.Workers.MachinePools).NotTo(BeEmpty(), "Invalid argument. input.Cluster must have at least one MachinePool topology") mpTopology := input.Cluster.Spec.Topology.Workers.MachinePools[0] diff --git a/test/infrastructure/container/interface.go b/test/infrastructure/container/interface.go index a0eef8a08a05..80869607f2d1 100644 --- a/test/infrastructure/container/interface.go +++ b/test/infrastructure/container/interface.go @@ -162,15 +162,8 @@ func RuntimeInto(ctx context.Context, runtime Runtime) context.Context { // GetClusterIPFamily returns a ClusterIPFamily based on the Cluster provided. func GetClusterIPFamily(c *clusterv1.Cluster) (ClusterIPFamily, error) { - var podCIDRs, serviceCIDRs []string - if c.Spec.ClusterNetwork != nil { - if c.Spec.ClusterNetwork.Pods != nil { - podCIDRs = c.Spec.ClusterNetwork.Pods.CIDRBlocks - } - if c.Spec.ClusterNetwork.Services != nil { - serviceCIDRs = c.Spec.ClusterNetwork.Services.CIDRBlocks - } - } + podCIDRs := c.Spec.ClusterNetwork.Pods.CIDRBlocks + serviceCIDRs := c.Spec.ClusterNetwork.Services.CIDRBlocks if len(podCIDRs) == 0 && len(serviceCIDRs) == 0 { return IPv4IPFamily, nil } diff --git a/test/infrastructure/container/interface_test.go b/test/infrastructure/container/interface_test.go index 55d660f3f89d..6a03458c3bad 100644 --- a/test/infrastructure/container/interface_test.go +++ b/test/infrastructure/container/interface_test.go @@ -77,11 +77,11 @@ func TestGetClusterIPFamily(t *testing.T) { clusterWithNetwork := func(podCIDRs, serviceCIDRs []string) *clusterv1.Cluster { return &clusterv1.Cluster{ Spec: clusterv1.ClusterSpec{ - ClusterNetwork: &clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ + ClusterNetwork: clusterv1.ClusterNetwork{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: podCIDRs, }, - Services: &clusterv1.NetworkRanges{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: serviceCIDRs, }, }, diff --git a/test/infrastructure/docker/templates/clusterclass-in-memory.yaml b/test/infrastructure/docker/templates/clusterclass-in-memory.yaml index 2ceab8339a58..d0bb3f35e0be 100644 --- a/test/infrastructure/docker/templates/clusterclass-in-memory.yaml +++ b/test/infrastructure/docker/templates/clusterclass-in-memory.yaml @@ -133,17 +133,16 @@ spec: workers: machineDeployments: - class: default-worker - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: in-memory-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DevMachineTemplate - name: in-memory-default-worker-machinetemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: in-memory-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DevMachineTemplate + name: in-memory-default-worker-machinetemplate machineHealthCheck: unhealthyNodeConditions: - type: Ready diff --git a/test/infrastructure/docker/templates/clusterclass-quick-start.yaml b/test/infrastructure/docker/templates/clusterclass-quick-start.yaml index 6610c9ed6843..3a287efdeb37 100644 --- a/test/infrastructure/docker/templates/clusterclass-quick-start.yaml +++ b/test/infrastructure/docker/templates/clusterclass-quick-start.yaml @@ -29,17 +29,16 @@ spec: workers: machineDeployments: - class: default-worker - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachineTemplate - name: quick-start-default-worker-machinetemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachineTemplate + name: quick-start-default-worker-machinetemplate machineHealthCheck: unhealthyNodeConditions: - type: Ready @@ -50,17 +49,16 @@ spec: timeoutSeconds: 300 machinePools: - class: default-worker - template: - bootstrap: - templateRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 - kind: KubeadmConfigTemplate - name: quick-start-default-worker-bootstraptemplate - infrastructure: - templateRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: DockerMachinePoolTemplate - name: quick-start-default-worker-machinepooltemplate + bootstrap: + templateRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + templateRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: DockerMachinePoolTemplate + name: quick-start-default-worker-machinepooltemplate variables: - name: imageRepository required: true diff --git a/util/test/builder/builders.go b/util/test/builder/builders.go index 12af33744627..d21c470fa9dc 100644 --- a/util/test/builder/builders.go +++ b/util/test/builder/builders.go @@ -39,7 +39,7 @@ type ClusterBuilder struct { topology *clusterv1.Topology infrastructureCluster *unstructured.Unstructured controlPlane *unstructured.Unstructured - network *clusterv1.ClusterNetwork + network clusterv1.ClusterNetwork } // Cluster returns a ClusterBuilder with the given name and namespace. @@ -51,7 +51,7 @@ func Cluster(namespace, name string) *ClusterBuilder { } // WithClusterNetwork sets the ClusterNetwork for the ClusterBuilder. -func (c *ClusterBuilder) WithClusterNetwork(clusterNetwork *clusterv1.ClusterNetwork) *ClusterBuilder { +func (c *ClusterBuilder) WithClusterNetwork(clusterNetwork clusterv1.ClusterNetwork) *ClusterBuilder { c.network = clusterNetwork return c } @@ -116,7 +116,7 @@ func (c *ClusterBuilder) Build() *clusterv1.Cluster { // ClusterTopologyBuilder contains the fields needed to build a testable ClusterTopology. type ClusterTopologyBuilder struct { class, classNamespace string - workers *clusterv1.WorkersTopology + workers clusterv1.WorkersTopology version string controlPlaneReplicas int32 controlPlaneMHC *clusterv1.MachineHealthCheckTopology @@ -127,7 +127,7 @@ type ClusterTopologyBuilder struct { // ClusterTopology returns a ClusterTopologyBuilder. func ClusterTopology() *ClusterTopologyBuilder { return &ClusterTopologyBuilder{ - workers: &clusterv1.WorkersTopology{}, + workers: clusterv1.WorkersTopology{}, } } @@ -202,7 +202,7 @@ func (c *ClusterTopologyBuilder) Build() *clusterv1.Topology { } if len(c.controlPlaneVariables) > 0 { - t.ControlPlane.Variables = &clusterv1.ControlPlaneVariables{ + t.ControlPlane.Variables = clusterv1.ControlPlaneVariables{ Overrides: c.controlPlaneVariables, } } @@ -270,7 +270,7 @@ func (m *MachineDeploymentTopologyBuilder) Build() clusterv1.MachineDeploymentTo } if len(m.variables) > 0 { - md.Variables = &clusterv1.MachineDeploymentVariables{ + md.Variables = clusterv1.MachineDeploymentVariables{ Overrides: m.variables, } } @@ -328,7 +328,7 @@ func (m *MachinePoolTopologyBuilder) Build() clusterv1.MachinePoolTopology { } if len(m.variables) > 0 { - mp.Variables = &clusterv1.MachinePoolVariables{ + mp.Variables = clusterv1.MachinePoolVariables{ Overrides: m.variables, } } @@ -555,7 +555,7 @@ type MachineDeploymentClassBuilder struct { nodeVolumeDetachTimeout *int32 nodeDeletionTimeout *int32 minReadySeconds *int32 - strategy *clusterv1.MachineDeploymentStrategy + strategy clusterv1.MachineDeploymentStrategy namingStrategy *clusterv1.MachineDeploymentClassNamingStrategy } @@ -633,7 +633,7 @@ func (m *MachineDeploymentClassBuilder) WithMinReadySeconds(t *int32) *MachineDe } // WithStrategy sets the Strategy for the MachineDeploymentClassBuilder. -func (m *MachineDeploymentClassBuilder) WithStrategy(s *clusterv1.MachineDeploymentStrategy) *MachineDeploymentClassBuilder { +func (m *MachineDeploymentClassBuilder) WithStrategy(s clusterv1.MachineDeploymentStrategy) *MachineDeploymentClassBuilder { m.strategy = s return m } @@ -648,18 +648,16 @@ func (m *MachineDeploymentClassBuilder) WithNamingStrategy(n *clusterv1.MachineD func (m *MachineDeploymentClassBuilder) Build() *clusterv1.MachineDeploymentClass { obj := &clusterv1.MachineDeploymentClass{ Class: m.class, - Template: clusterv1.MachineDeploymentClassTemplate{ - Metadata: clusterv1.ObjectMeta{ - Labels: m.labels, - Annotations: m.annotations, - }, + Metadata: clusterv1.ObjectMeta{ + Labels: m.labels, + Annotations: m.annotations, }, } if m.bootstrapTemplate != nil { - obj.Template.Bootstrap.TemplateRef = objToClusterClassTemplateRef(m.bootstrapTemplate) + obj.Bootstrap.TemplateRef = objToClusterClassTemplateRef(m.bootstrapTemplate) } if m.infrastructureMachineTemplate != nil { - obj.Template.Infrastructure.TemplateRef = objToClusterClassTemplateRef(m.infrastructureMachineTemplate) + obj.Infrastructure.TemplateRef = objToClusterClassTemplateRef(m.infrastructureMachineTemplate) } if m.machineHealthCheckClass != nil { obj.MachineHealthCheck = m.machineHealthCheckClass @@ -682,9 +680,7 @@ func (m *MachineDeploymentClassBuilder) Build() *clusterv1.MachineDeploymentClas if m.minReadySeconds != nil { obj.MinReadySeconds = m.minReadySeconds } - if m.strategy != nil { - obj.Strategy = m.strategy - } + obj.Strategy = m.strategy if m.namingStrategy != nil { obj.NamingStrategy = m.namingStrategy } @@ -777,18 +773,16 @@ func (m *MachinePoolClassBuilder) WithNamingStrategy(n *clusterv1.MachinePoolCla func (m *MachinePoolClassBuilder) Build() *clusterv1.MachinePoolClass { obj := &clusterv1.MachinePoolClass{ Class: m.class, - Template: clusterv1.MachinePoolClassTemplate{ - Metadata: clusterv1.ObjectMeta{ - Labels: m.labels, - Annotations: m.annotations, - }, + Metadata: clusterv1.ObjectMeta{ + Labels: m.labels, + Annotations: m.annotations, }, } if m.bootstrapTemplate != nil { - obj.Template.Bootstrap.TemplateRef = objToClusterClassTemplateRef(m.bootstrapTemplate) + obj.Bootstrap.TemplateRef = objToClusterClassTemplateRef(m.bootstrapTemplate) } if m.infrastructureMachinePoolTemplate != nil { - obj.Template.Infrastructure.TemplateRef = objToClusterClassTemplateRef(m.infrastructureMachinePoolTemplate) + obj.Infrastructure.TemplateRef = objToClusterClassTemplateRef(m.infrastructureMachinePoolTemplate) } if m.failureDomains != nil { obj.FailureDomains = m.failureDomains diff --git a/util/test/builder/zz_generated.deepcopy.go b/util/test/builder/zz_generated.deepcopy.go index 20546dca045f..4aa8b545c627 100644 --- a/util/test/builder/zz_generated.deepcopy.go +++ b/util/test/builder/zz_generated.deepcopy.go @@ -95,11 +95,7 @@ func (in *ClusterBuilder) DeepCopyInto(out *ClusterBuilder) { in, out := &in.controlPlane, &out.controlPlane *out = (*in).DeepCopy() } - if in.network != nil { - in, out := &in.network, &out.network - *out = new(v1beta2.ClusterNetwork) - (*in).DeepCopyInto(*out) - } + in.network.DeepCopyInto(&out.network) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterBuilder. @@ -224,11 +220,7 @@ func (in *ClusterClassBuilder) DeepCopy() *ClusterClassBuilder { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTopologyBuilder) DeepCopyInto(out *ClusterTopologyBuilder) { *out = *in - if in.workers != nil { - in, out := &in.workers, &out.workers - *out = new(v1beta2.WorkersTopology) - (*in).DeepCopyInto(*out) - } + in.workers.DeepCopyInto(&out.workers) if in.controlPlaneMHC != nil { in, out := &in.controlPlaneMHC, &out.controlPlaneMHC *out = new(v1beta2.MachineHealthCheckTopology) @@ -574,11 +566,7 @@ func (in *MachineDeploymentClassBuilder) DeepCopyInto(out *MachineDeploymentClas *out = new(int32) **out = **in } - if in.strategy != nil { - in, out := &in.strategy, &out.strategy - *out = new(v1beta2.MachineDeploymentStrategy) - (*in).DeepCopyInto(*out) - } + in.strategy.DeepCopyInto(&out.strategy) if in.namingStrategy != nil { in, out := &in.namingStrategy, &out.namingStrategy *out = new(v1beta2.MachineDeploymentClassNamingStrategy)