Skip to content

Commit

Permalink
feat: make docker machine bootstrap timeout configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Salas <[email protected]>
  • Loading branch information
salasberryfin committed Jan 4, 2024
1 parent 624f892 commit 0653b0c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
31 changes: 29 additions & 2 deletions test/infrastructure/docker/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,35 @@ 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
}

if restored.Spec.BootstrapTimeout != 0 {
dst.Spec.BootstrapTimeout = restored.Spec.BootstrapTimeout
}

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
}

if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

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

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
dst.Spec.Template.Spec.BootstrapTimeout = restored.Spec.Template.Spec.BootstrapTimeout

return nil
}
Expand Down Expand Up @@ -201,3 +224,7 @@ func Convert_v1beta1_DockerMachineTemplateResource_To_v1alpha4_DockerMachineTemp
func Convert_v1beta1_DockerLoadBalancer_To_v1alpha4_DockerLoadBalancer(in *infrav1.DockerLoadBalancer, out *DockerLoadBalancer, s apiconversion.Scope) error {
return autoConvert_v1beta1_DockerLoadBalancer_To_v1alpha4_DockerLoadBalancer(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.

5 changes: 5 additions & 0 deletions test/infrastructure/docker/api/v1beta1/dockermachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type DockerMachineSpec struct {
// When removing also remove from staticcheck exclude-rules for SA1019 in golangci.yml.
// +optional
Bootstrapped bool `json:"bootstrapped,omitempty"`

// BootstrapTimeout is the total time (in minutes) to wait for the machine to bootstrap before timing out.
// Defaults to 3 minutes if not set.
// +optional
BootstrapTimeout int `json:"bootstrapTimeout,omitempty"`
}

// Mount specifies a host volume to mount into a container.
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.

Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, cluster *

// if the machine isn't bootstrapped, only then run bootstrap scripts
if !dockerMachine.Spec.Bootstrapped {
timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Minute)
if dockerMachine.Spec.BootstrapTimeout == 0 {
dockerMachine.Spec.BootstrapTimeout = 3
}
timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(dockerMachine.Spec.BootstrapTimeout)*time.Minute)
defer cancel()

// Check for bootstrap success
Expand Down

0 comments on commit 0653b0c

Please sign in to comment.