-
Notifications
You must be signed in to change notification settings - Fork 1.4k
⚠️ Align CAPD conversion to conversion of other providers #12481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sivchari
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
sivchari:align-conversions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−157
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package v1alpha3 | |
|
||
import ( | ||
"maps" | ||
"reflect" | ||
"slices" | ||
"sort" | ||
|
||
|
@@ -41,26 +42,46 @@ func (src *DockerCluster) ConvertTo(dstRaw conversion.Hub) error { | |
|
||
// Manually restore data. | ||
restored := &infrav1.DockerCluster{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
ok, err := utilconversion.UnmarshalData(src, restored) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if restored.Spec.LoadBalancer.ImageRepository != "" { | ||
dst.Spec.LoadBalancer.ImageRepository = restored.Spec.LoadBalancer.ImageRepository | ||
// Recover intent for bool values converted to *bool. | ||
initialization := infrav1.DockerClusterInitializationStatus{} | ||
restoredDockerClusterProvisioned := restored.Status.Initialization.Provisioned | ||
clusterv1.Convert_bool_To_Pointer_bool(src.Status.Ready, ok, restoredDockerClusterProvisioned, &initialization.Provisioned) | ||
if !reflect.DeepEqual(initialization, infrav1.DockerClusterInitializationStatus{}) { | ||
dst.Status.Initialization = initialization | ||
} | ||
|
||
if restored.Spec.LoadBalancer.ImageTag != "" { | ||
dst.Spec.LoadBalancer.ImageTag = restored.Spec.LoadBalancer.ImageTag | ||
if ok { | ||
RestoreDockerClusterSpec(&restored.Spec, &dst.Spec) | ||
} | ||
|
||
if restored.Spec.LoadBalancer.CustomHAProxyConfigTemplateRef != nil { | ||
dst.Spec.LoadBalancer.CustomHAProxyConfigTemplateRef = restored.Spec.LoadBalancer.CustomHAProxyConfigTemplateRef | ||
RestoreDockerClusterStatus(&restored.Status, &dst.Status) | ||
|
||
return nil | ||
} | ||
|
||
func RestoreDockerClusterSpec(restored *infrav1.DockerClusterSpec, dst *infrav1.DockerClusterSpec) { | ||
// Restore fields added in v1beta2. | ||
if restored.LoadBalancer.ImageRepository != "" { | ||
dst.LoadBalancer.ImageRepository = restored.LoadBalancer.ImageRepository | ||
} | ||
|
||
if restored.LoadBalancer.ImageTag != "" { | ||
dst.LoadBalancer.ImageTag = restored.LoadBalancer.ImageTag | ||
} | ||
|
||
dst.Status.Conditions = restored.Status.Conditions | ||
dst.Status.Initialization = restored.Status.Initialization | ||
if restored.LoadBalancer.CustomHAProxyConfigTemplateRef != nil { | ||
dst.LoadBalancer.CustomHAProxyConfigTemplateRef = restored.LoadBalancer.CustomHAProxyConfigTemplateRef | ||
} | ||
} | ||
|
||
return nil | ||
func RestoreDockerClusterStatus(restored *infrav1.DockerClusterStatus, dst *infrav1.DockerClusterStatus) { | ||
// Restore fields added in v1beta2. | ||
dst.Conditions = restored.Conditions | ||
} | ||
|
||
func (dst *DockerCluster) ConvertFrom(srcRaw conversion.Hub) error { | ||
|
@@ -70,12 +91,7 @@ func (dst *DockerCluster) ConvertFrom(srcRaw conversion.Hub) error { | |
return err | ||
} | ||
|
||
// Preserve Hub data on down-conversion except for metadata | ||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
return utilconversion.MarshalData(src, dst) | ||
} | ||
|
||
func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error { | ||
|
@@ -87,20 +103,40 @@ func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error { | |
|
||
// Manually restore data. | ||
restored := &infrav1.DockerMachine{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
ok, err := utilconversion.UnmarshalData(src, restored) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if restored.Spec.BootstrapTimeout != nil { | ||
dst.Spec.BootstrapTimeout = restored.Spec.BootstrapTimeout | ||
// Recover intent for bool values converted to *bool. | ||
initialization := infrav1.DockerMachineInitializationStatus{} | ||
restoredDockerMachineProvisioned := restored.Status.Initialization.Provisioned | ||
clusterv1.Convert_bool_To_Pointer_bool(src.Status.Ready, ok, restoredDockerMachineProvisioned, &initialization.Provisioned) | ||
if !reflect.DeepEqual(initialization, infrav1.DockerMachineInitializationStatus{}) { | ||
dst.Status.Initialization = initialization | ||
} | ||
|
||
if ok { | ||
RestoreDockerMachineSpec(&restored.Spec, &dst.Spec) | ||
} | ||
|
||
dst.Status.Conditions = restored.Status.Conditions | ||
dst.Status.Initialization = restored.Status.Initialization | ||
RestoreDockerMachineStatus(&restored.Status, &dst.Status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
return nil | ||
} | ||
|
||
func RestoreDockerMachineSpec(restored *infrav1.DockerMachineSpec, dst *infrav1.DockerMachineSpec) { | ||
// Restore fields added in v1beta2. | ||
if restored.BootstrapTimeout != nil { | ||
dst.BootstrapTimeout = restored.BootstrapTimeout | ||
} | ||
} | ||
|
||
func RestoreDockerMachineStatus(restored *infrav1.DockerMachineStatus, dst *infrav1.DockerMachineStatus) { | ||
// Restore fields added in v1beta2. | ||
dst.Conditions = restored.Conditions | ||
} | ||
|
||
func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*infrav1.DockerMachine) | ||
|
||
|
@@ -112,11 +148,7 @@ func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error { | |
dst.Spec.ProviderID = nil | ||
} | ||
|
||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
return utilconversion.MarshalData(src, dst) | ||
} | ||
|
||
func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { | ||
|
@@ -128,16 +160,24 @@ func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { | |
|
||
// Manually restore data. | ||
restored := &infrav1.DockerMachineTemplate{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
ok, err := utilconversion.UnmarshalData(src, restored) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta | ||
dst.Spec.Template.Spec.BootstrapTimeout = restored.Spec.Template.Spec.BootstrapTimeout | ||
if ok { | ||
RestoreDockerMachineTemplateSpec(&restored.Spec, &dst.Spec) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func RestoreDockerMachineTemplateSpec(restored *infrav1.DockerMachineTemplateSpec, dst *infrav1.DockerMachineTemplateSpec) { | ||
// Restore fields added in v1beta2. | ||
dst.Template.ObjectMeta = restored.Template.ObjectMeta | ||
dst.Template.Spec.BootstrapTimeout = restored.Template.Spec.BootstrapTimeout | ||
} | ||
|
||
func (dst *DockerMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*infrav1.DockerMachineTemplate) | ||
|
||
|
@@ -149,12 +189,7 @@ func (dst *DockerMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { | |
dst.Spec.Template.Spec.ProviderID = nil | ||
} | ||
|
||
// Preserve Hub data on down-conversion except for metadata | ||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
return utilconversion.MarshalData(src, dst) | ||
} | ||
|
||
// Convert_v1beta2_DockerClusterSpec_To_v1alpha3_DockerClusterSpec is an autogenerated conversion function. | ||
|
@@ -201,9 +236,7 @@ func Convert_v1beta2_DockerClusterStatus_To_v1alpha3_DockerClusterStatus(in *inf | |
clusterv1alpha3.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1alpha3_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions) | ||
} | ||
|
||
if in.Initialization.Provisioned != nil { | ||
out.Ready = *in.Initialization.Provisioned | ||
} | ||
out.Ready = ptr.Deref(in.Initialization.Provisioned, false) | ||
|
||
// Move FailureDomains | ||
if in.FailureDomains != nil { | ||
|
@@ -231,9 +264,7 @@ func Convert_v1beta2_DockerMachineStatus_To_v1alpha3_DockerMachineStatus(in *inf | |
clusterv1alpha3.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1alpha3_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions) | ||
} | ||
|
||
if in.Initialization.Provisioned != nil { | ||
out.Ready = *in.Initialization.Provisioned | ||
} | ||
out.Ready = ptr.Deref(in.Initialization.Provisioned, false) | ||
|
||
return nil | ||
} | ||
|
@@ -263,10 +294,6 @@ func Convert_v1alpha3_DockerMachineStatus_To_v1beta2_DockerMachineStatus(in *Doc | |
clusterv1alpha3.Convert_v1alpha3_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions) | ||
} | ||
|
||
if in.Ready { | ||
out.Initialization.Provisioned = ptr.To(in.Ready) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -285,10 +312,6 @@ func Convert_v1alpha3_DockerClusterStatus_To_v1beta2_DockerClusterStatus(in *Doc | |
clusterv1alpha3.Convert_v1alpha3_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions) | ||
} | ||
|
||
if in.Ready { | ||
out.Initialization.Provisioned = ptr.To(in.Ready) | ||
} | ||
|
||
// Move FailureDomains | ||
if in.FailureDomains != nil { | ||
out.FailureDomains = []clusterv1.FailureDomain{} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this also has to be inside the if ok