Skip to content

Commit

Permalink
Fix panics in conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer authored and k8s-infra-cherrypick-robot committed Feb 16, 2022
1 parent 3f68d67 commit a5829fb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
}

if restored.Spec.Topology != nil {
if dst.Spec.Topology == nil {
dst.Spec.Topology = &clusterv1.Topology{}
}
dst.Spec.Topology.Variables = restored.Spec.Topology.Variables
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
Expand Down
12 changes: 12 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.Ignition = restored.Spec.Ignition
if restored.Spec.InitConfiguration != nil {
if dst.Spec.InitConfiguration == nil {
dst.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.InitConfiguration.Patches = restored.Spec.InitConfiguration.Patches
}
if restored.Spec.JoinConfiguration != nil {
if dst.Spec.JoinConfiguration == nil {
dst.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.JoinConfiguration.Patches = restored.Spec.JoinConfiguration.Patches
}

Expand Down Expand Up @@ -119,9 +125,15 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
if restored.Spec.Template.Spec.InitConfiguration != nil {
if dst.Spec.Template.Spec.InitConfiguration == nil {
dst.Spec.Template.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.Template.Spec.InitConfiguration.Patches = restored.Spec.Template.Spec.InitConfiguration.Patches
}
if restored.Spec.Template.Spec.JoinConfiguration != nil {
if dst.Spec.Template.Spec.JoinConfiguration == nil {
dst.Spec.Template.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.Template.Spec.JoinConfiguration.Patches = restored.Spec.Template.Spec.JoinConfiguration.Patches
}

Expand Down
12 changes: 12 additions & 0 deletions bootstrap/kubeadm/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.Ignition = restored.Spec.Ignition
if restored.Spec.InitConfiguration != nil {
if dst.Spec.InitConfiguration == nil {
dst.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.InitConfiguration.Patches = restored.Spec.InitConfiguration.Patches
}
if restored.Spec.JoinConfiguration != nil {
if dst.Spec.JoinConfiguration == nil {
dst.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.JoinConfiguration.Patches = restored.Spec.JoinConfiguration.Patches
}

Expand Down Expand Up @@ -85,9 +91,15 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
if restored.Spec.Template.Spec.InitConfiguration != nil {
if dst.Spec.Template.Spec.InitConfiguration == nil {
dst.Spec.Template.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.Template.Spec.InitConfiguration.Patches = restored.Spec.Template.Spec.InitConfiguration.Patches
}
if restored.Spec.Template.Spec.JoinConfiguration != nil {
if dst.Spec.Template.Spec.JoinConfiguration == nil {
dst.Spec.Template.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.Template.Spec.JoinConfiguration.Patches = restored.Spec.Template.Spec.JoinConfiguration.Patches
}

Expand Down
6 changes: 6 additions & 0 deletions controlplane/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ func (src *KubeadmControlPlane) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.KubeadmConfigSpec.Ignition = restored.Spec.KubeadmConfigSpec.Ignition
if restored.Spec.KubeadmConfigSpec.InitConfiguration != nil {
if dst.Spec.KubeadmConfigSpec.InitConfiguration == nil {
dst.Spec.KubeadmConfigSpec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.KubeadmConfigSpec.InitConfiguration.Patches = restored.Spec.KubeadmConfigSpec.InitConfiguration.Patches
}
if restored.Spec.KubeadmConfigSpec.JoinConfiguration != nil {
if dst.Spec.KubeadmConfigSpec.JoinConfiguration == nil {
dst.Spec.KubeadmConfigSpec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.KubeadmConfigSpec.JoinConfiguration.Patches = restored.Spec.KubeadmConfigSpec.JoinConfiguration.Patches
}

Expand Down
13 changes: 13 additions & 0 deletions controlplane/kubeadm/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

bootstrapv1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)
Expand All @@ -40,9 +41,15 @@ func (src *KubeadmControlPlane) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.KubeadmConfigSpec.Ignition = restored.Spec.KubeadmConfigSpec.Ignition
if restored.Spec.KubeadmConfigSpec.InitConfiguration != nil {
if dst.Spec.KubeadmConfigSpec.InitConfiguration == nil {
dst.Spec.KubeadmConfigSpec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.KubeadmConfigSpec.InitConfiguration.Patches = restored.Spec.KubeadmConfigSpec.InitConfiguration.Patches
}
if restored.Spec.KubeadmConfigSpec.JoinConfiguration != nil {
if dst.Spec.KubeadmConfigSpec.JoinConfiguration == nil {
dst.Spec.KubeadmConfigSpec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.KubeadmConfigSpec.JoinConfiguration.Patches = restored.Spec.KubeadmConfigSpec.JoinConfiguration.Patches
}

Expand Down Expand Up @@ -88,9 +95,15 @@ func (src *KubeadmControlPlaneTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.KubeadmConfigSpec.Ignition = restored.Spec.Template.Spec.KubeadmConfigSpec.Ignition
dst.Spec.Template.Spec.MachineTemplate = restored.Spec.Template.Spec.MachineTemplate
if restored.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration != nil {
if dst.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration == nil {
dst.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.Patches = restored.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.Patches
}
if restored.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration != nil {
if dst.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration == nil {
dst.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.Patches = restored.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.Patches
}

Expand Down

0 comments on commit a5829fb

Please sign in to comment.