Skip to content
This repository has been archived by the owner on Nov 20, 2021. It is now read-only.

Commit

Permalink
Always ensure node has Provider ID (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRx authored Nov 5, 2020
1 parent f0c4598 commit a0661e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 20 additions & 0 deletions controllers/dockermachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (r *DockerMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
}
if ok {
log.Info("machine already exists")
if err := r.ensureNodeProviderID(ctx, dm.Spec.ContainerName); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}

Expand All @@ -159,3 +162,20 @@ func (r *DockerMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
dm.Status.Ready = true
return ctrl.Result{}, nil
}

func (r *DockerMachineReconciler) ensureNodeProviderID(ctx context.Context, name string) error {
n := &corev1.Node{}
if err := r.Get(ctx, client.ObjectKey{Name: name}, n); err != nil {
return err
}
if n.Spec.ProviderID != "" {
return nil
}
client, err := kubernetes.NewForConfig(r.config)
if err != nil {
return err
}
return nodeutil.PatchNode(ctx, client, name, func(n *corev1.Node) {
n.Spec.ProviderID = fmt.Sprintf("docker://%s", name)
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/criticalstack/machine-api-provider-docker
go 1.14

require (
github.com/criticalstack/crit v1.0.3
github.com/criticalstack/crit v1.0.7
github.com/criticalstack/machine-api v1.0.5
github.com/go-logr/logr v0.1.0
github.com/go-openapi/spec v0.19.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/criticalstack/crit v1.0.3 h1:1I/xyXzazV3d9u2Bg/NguqYiArNLwAQWSkWSnBM0Sgw=
github.com/criticalstack/crit v1.0.3/go.mod h1:ULOKHjqXNtCGg4sH46kYxTBje0P9mgkpV8forMVxhGk=
github.com/criticalstack/crit v1.0.7 h1:LmoKCNLu1Z0TJESojGR6dUR74A4wi3Pmml4kU9BadRQ=
github.com/criticalstack/crit v1.0.7/go.mod h1:ULOKHjqXNtCGg4sH46kYxTBje0P9mgkpV8forMVxhGk=
github.com/criticalstack/e2d v0.4.14/go.mod h1:Bxbt5zWKhtA81n/YibGi8dlOdTVjNuBzy2zkbjJBf98=
github.com/criticalstack/machine-api v1.0.1 h1:6dXUYX+ZXNsDGI1xfWyvUXJ8rAMbliOVg0t5G3tbbkQ=
github.com/criticalstack/machine-api v1.0.1/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
github.com/criticalstack/machine-api v1.0.3 h1:VVLoQFKyoMjcIpnn+aixsE8GB9KrzhJV3elHeswEhEE=
github.com/criticalstack/machine-api v1.0.3/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
github.com/criticalstack/machine-api v1.0.5 h1:QGveBtAQlDnv++rDhi22CM9c9MmYAO+Vxk1mBLXBo2A=
github.com/criticalstack/machine-api v1.0.5/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit a0661e0

Please sign in to comment.