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

Commit a0661e0

Browse files
authored
Always ensure node has Provider ID (#7)
1 parent f0c4598 commit a0661e0

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

controllers/dockermachine_controller.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func (r *DockerMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
135135
}
136136
if ok {
137137
log.Info("machine already exists")
138+
if err := r.ensureNodeProviderID(ctx, dm.Spec.ContainerName); err != nil {
139+
return ctrl.Result{}, err
140+
}
138141
return ctrl.Result{}, nil
139142
}
140143

@@ -159,3 +162,20 @@ func (r *DockerMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
159162
dm.Status.Ready = true
160163
return ctrl.Result{}, nil
161164
}
165+
166+
func (r *DockerMachineReconciler) ensureNodeProviderID(ctx context.Context, name string) error {
167+
n := &corev1.Node{}
168+
if err := r.Get(ctx, client.ObjectKey{Name: name}, n); err != nil {
169+
return err
170+
}
171+
if n.Spec.ProviderID != "" {
172+
return nil
173+
}
174+
client, err := kubernetes.NewForConfig(r.config)
175+
if err != nil {
176+
return err
177+
}
178+
return nodeutil.PatchNode(ctx, client, name, func(n *corev1.Node) {
179+
n.Spec.ProviderID = fmt.Sprintf("docker://%s", name)
180+
})
181+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/criticalstack/machine-api-provider-docker
33
go 1.14
44

55
require (
6-
github.com/criticalstack/crit v1.0.3
6+
github.com/criticalstack/crit v1.0.7
77
github.com/criticalstack/machine-api v1.0.5
88
github.com/go-logr/logr v0.1.0
99
github.com/go-openapi/spec v0.19.3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
8686
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
8787
github.com/criticalstack/crit v1.0.3 h1:1I/xyXzazV3d9u2Bg/NguqYiArNLwAQWSkWSnBM0Sgw=
8888
github.com/criticalstack/crit v1.0.3/go.mod h1:ULOKHjqXNtCGg4sH46kYxTBje0P9mgkpV8forMVxhGk=
89+
github.com/criticalstack/crit v1.0.7 h1:LmoKCNLu1Z0TJESojGR6dUR74A4wi3Pmml4kU9BadRQ=
90+
github.com/criticalstack/crit v1.0.7/go.mod h1:ULOKHjqXNtCGg4sH46kYxTBje0P9mgkpV8forMVxhGk=
8991
github.com/criticalstack/e2d v0.4.14/go.mod h1:Bxbt5zWKhtA81n/YibGi8dlOdTVjNuBzy2zkbjJBf98=
90-
github.com/criticalstack/machine-api v1.0.1 h1:6dXUYX+ZXNsDGI1xfWyvUXJ8rAMbliOVg0t5G3tbbkQ=
91-
github.com/criticalstack/machine-api v1.0.1/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
92-
github.com/criticalstack/machine-api v1.0.3 h1:VVLoQFKyoMjcIpnn+aixsE8GB9KrzhJV3elHeswEhEE=
93-
github.com/criticalstack/machine-api v1.0.3/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
92+
github.com/criticalstack/machine-api v1.0.5 h1:QGveBtAQlDnv++rDhi22CM9c9MmYAO+Vxk1mBLXBo2A=
93+
github.com/criticalstack/machine-api v1.0.5/go.mod h1:yrAmVXEoPnjNKtB+zz3/Hslqk5ewOm9HOM52xbfeMtg=
9494
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
9595
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9696
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)