From a0661e080148d80b7fd94086c7b3c9e47e28a939 Mon Sep 17 00:00:00 2001 From: Chris Marshall Date: Thu, 5 Nov 2020 15:16:45 -0500 Subject: [PATCH] Always ensure node has Provider ID (#7) --- controllers/dockermachine_controller.go | 20 ++++++++++++++++++++ go.mod | 2 +- go.sum | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/controllers/dockermachine_controller.go b/controllers/dockermachine_controller.go index c2a2fab..6f05784 100644 --- a/controllers/dockermachine_controller.go +++ b/controllers/dockermachine_controller.go @@ -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 } @@ -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) + }) +} diff --git a/go.mod b/go.mod index 9420d40..fd590b1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c814c48..4f5e48b 100644 --- a/go.sum +++ b/go.sum @@ -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=