Skip to content

Commit

Permalink
Fix controllers for updated controller-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Jan 4, 2021
1 parent d90a8c1 commit 71be1ff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/termination-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
}

// Start the termination handler
if err := handler.Run(ctrl.SetupSignalHandler()); err != nil {
if err := handler.Run(ctrl.SetupSignalHandler().Done()); err != nil {
logger.Error(err, "Error starting termination handler")
return
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/actuators/machine/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package machine

import (
"context"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -47,13 +48,13 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}

doneMgr := make(chan struct{})
mgrCtx, cancel := context.WithCancel(context.Background())
go func() {
if err := mgr.Start(doneMgr); err != nil {
if err := mgr.Start(mgrCtx); err != nil {
log.Fatal(err)
}
}()
defer close(doneMgr)
defer cancel()

k8sClient = mgr.GetClient()
eventRecorder = mgr.GetEventRecorderFor("awscontroller")
Expand Down
3 changes: 1 addition & 2 deletions pkg/actuators/machineset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, options controller.Optio
}

// Reconcile implements controller runtime Reconciler interface.
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("machineset", req.Name, "namespace", req.Namespace)
logger.V(3).Info("Reconciling")

ctx := context.Background()
machineSet := &machinev1.MachineSet{}
if err := r.Client.Get(ctx, req.NamespacedName, machineSet); err != nil {
if apierrors.IsNotFound(err) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/actuators/machineset/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ var _ = AfterSuite(func() {
})

// StartTestManager adds recFn
func StartTestManager(mgr manager.Manager) chan struct{} {
stop := make(chan struct{})
func StartTestManager(mgr manager.Manager) context.CancelFunc {
mgrCtx, cancel := context.WithCancel(ctx)
go func() {
defer GinkgoRecover()

Expect(mgr.Start(stop)).To(Succeed())
Expect(mgr.Start(mgrCtx)).To(Succeed())
}()
return stop
return cancel
}
5 changes: 3 additions & 2 deletions pkg/actuators/machineset/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package machineset

import (
"context"
"encoding/json"
"fmt"
"testing"
Expand All @@ -36,7 +37,7 @@ import (

var _ = Describe("MachineSetReconciler", func() {
var c client.Client
var stopMgr chan struct{}
var stopMgr context.CancelFunc
var fakeRecorder *record.FakeRecorder
var namespace *corev1.Namespace

Expand All @@ -62,7 +63,7 @@ var _ = Describe("MachineSetReconciler", func() {

AfterEach(func() {
Expect(deleteMachineSets(c, namespace.Name)).To(Succeed())
close(stopMgr)
stopMgr()
})

type reconcileTestCase = struct {
Expand Down

0 comments on commit 71be1ff

Please sign in to comment.