Skip to content

Commit

Permalink
Add MachinePool Machine implementation to DockerMachines and DockerMa…
Browse files Browse the repository at this point in the history
…chinePools
  • Loading branch information
Jont828 committed Jun 12, 2023
1 parent ae90e1a commit 7b1951c
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 141 deletions.
26 changes: 24 additions & 2 deletions test/infrastructure/docker/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,30 @@ func (dst *DockerClusterList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.DockerMachine)

return Convert_v1alpha3_DockerMachine_To_v1beta1_DockerMachine(src, dst, nil)
if err := Convert_v1alpha3_DockerMachine_To_v1beta1_DockerMachine(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &infrav1.DockerMachine{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.InstanceName = restored.Spec.InstanceName

return nil
}

func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.DockerMachine)

return Convert_v1beta1_DockerMachine_To_v1alpha3_DockerMachine(src, dst, nil)
if err := Convert_v1beta1_DockerMachine_To_v1alpha3_DockerMachine(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
return utilconversion.MarshalData(src, dst)
}

func (src *DockerMachineList) ConvertTo(dstRaw conversion.Hub) error {
Expand Down Expand Up @@ -113,6 +130,7 @@ func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
dst.Spec.Template.Spec.InstanceName = restored.Spec.Template.Spec.InstanceName

return nil
}
Expand Down Expand Up @@ -154,3 +172,7 @@ func Convert_v1beta1_DockerMachineTemplateResource_To_v1alpha3_DockerMachineTemp
// NOTE: custom conversion func is required because spec.template.metadata has been added in v1beta1.
return autoConvert_v1beta1_DockerMachineTemplateResource_To_v1alpha3_DockerMachineTemplateResource(in, out, s)
}

func Convert_v1beta1_DockerMachineSpec_To_v1alpha3_DockerMachineSpec(in *infrav1.DockerMachineSpec, out *DockerMachineSpec, s apiconversion.Scope) error {
return autoConvert_v1beta1_DockerMachineSpec_To_v1alpha3_DockerMachineSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions test/infrastructure/docker/api/v1alpha3/zz_generated.conversion.go

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

26 changes: 24 additions & 2 deletions test/infrastructure/docker/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@ func (dst *DockerClusterTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.DockerMachine)

return Convert_v1alpha4_DockerMachine_To_v1beta1_DockerMachine(src, dst, nil)
if err := Convert_v1alpha4_DockerMachine_To_v1beta1_DockerMachine(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &infrav1.DockerMachine{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.InstanceName = restored.Spec.InstanceName

return nil
}

func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.DockerMachine)

return Convert_v1beta1_DockerMachine_To_v1alpha4_DockerMachine(src, dst, nil)
if err := Convert_v1beta1_DockerMachine_To_v1alpha4_DockerMachine(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
return utilconversion.MarshalData(src, dst)
}

func (src *DockerMachineList) ConvertTo(dstRaw conversion.Hub) error {
Expand Down Expand Up @@ -131,6 +148,7 @@ func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
dst.Spec.Template.Spec.InstanceName = restored.Spec.Template.Spec.InstanceName

return nil
}
Expand Down Expand Up @@ -171,3 +189,7 @@ func Convert_v1beta1_DockerMachineTemplateResource_To_v1alpha4_DockerMachineTemp
// NOTE: custom conversion func is required because spec.template.metadata has been added in v1beta1.
return autoConvert_v1beta1_DockerMachineTemplateResource_To_v1alpha4_DockerMachineTemplateResource(in, out, s)
}

func Convert_v1beta1_DockerMachineSpec_To_v1alpha4_DockerMachineSpec(in *infrav1.DockerMachineSpec, out *DockerMachineSpec, s apiconversion.Scope) error {
return autoConvert_v1beta1_DockerMachineSpec_To_v1alpha4_DockerMachineSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions test/infrastructure/docker/api/v1alpha4/zz_generated.conversion.go

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

7 changes: 7 additions & 0 deletions test/infrastructure/docker/api/v1beta1/dockermachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const (

// DockerMachineSpec defines the desired state of DockerMachine.
type DockerMachineSpec struct {
// InstanceName indicates the name of the Docker container associated with this DockerMachine.
// Since the provider ID is not set until after the container is online, this field is used to
// maintain the association. If it is not populated, the name of the container will be the same
// as the name of the owner Machine.
// +optional
InstanceName string `json:"instanceName,omitempty"`

// ProviderID will be the container name in ProviderID format (docker:////<containername>)
// +optional
ProviderID *string `json:"providerID,omitempty"`
Expand Down

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

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

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

29 changes: 27 additions & 2 deletions test/infrastructure/docker/exp/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,41 @@ limitations under the License.
package v1alpha3

import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

infraexpv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func (src *DockerMachinePool) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infraexpv1.DockerMachinePool)

return Convert_v1alpha3_DockerMachinePool_To_v1beta1_DockerMachinePool(src, dst, nil)
if err := Convert_v1alpha3_DockerMachinePool_To_v1beta1_DockerMachinePool(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &infraexpv1.DockerMachinePool{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Status.InfrastructureMachineKind = restored.Status.InfrastructureMachineKind
dst.Status.InfrastructureMachineSelector = restored.Status.InfrastructureMachineSelector

return nil
}

func (dst *DockerMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infraexpv1.DockerMachinePool)

return Convert_v1beta1_DockerMachinePool_To_v1alpha3_DockerMachinePool(src, dst, nil)
if err := Convert_v1beta1_DockerMachinePool_To_v1alpha3_DockerMachinePool(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
return utilconversion.MarshalData(src, dst)
}

func (src *DockerMachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -45,3 +65,8 @@ func (dst *DockerMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {

return Convert_v1beta1_DockerMachinePoolList_To_v1alpha3_DockerMachinePoolList(src, dst, nil)
}

func Convert_v1beta1_DockerMachinePoolStatus_To_v1alpha3_DockerMachinePoolStatus(in *infraexpv1.DockerMachinePoolStatus, out *DockerMachinePoolStatus, s apiconversion.Scope) error {
// NOTE: custom conversion func is required because spec.template.metadata has been added in v1beta1.
return autoConvert_v1beta1_DockerMachinePoolStatus_To_v1alpha3_DockerMachinePoolStatus(in, out, s)
}

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

Loading

0 comments on commit 7b1951c

Please sign in to comment.