From 50de33e10238a68b77b2a42b5f1d9a95f9a4e4bf Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 23 Dec 2018 15:52:53 +0100 Subject: [PATCH] Register machine actuator to the manager directly Given there is only one actuator to register, the registration can be done directly without any mediator. --- cmd/manager/main.go | 22 ++++++++++++-------- pkg/actuators/machine/actuator.go | 3 --- pkg/controller/add_machine.go | 27 ------------------------ pkg/controller/controller.go | 34 ------------------------------- 4 files changed, 14 insertions(+), 72 deletions(-) delete mode 100644 pkg/controller/add_machine.go delete mode 100644 pkg/controller/controller.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index f19e0b720d..cbb2bdc091 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -15,6 +15,7 @@ package main import ( "flag" + "fmt" "github.com/golang/glog" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -22,8 +23,8 @@ import ( "sigs.k8s.io/cluster-api-provider-aws/pkg/apis" "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1" awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client" - "sigs.k8s.io/cluster-api-provider-aws/pkg/controller" clusterapis "sigs.k8s.io/cluster-api/pkg/apis" + "sigs.k8s.io/cluster-api/pkg/controller/machine" "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/runtime/signals" @@ -55,9 +56,12 @@ func main() { glog.Fatal(err) } - initActuator(mgr) - // Setup all Controllers - if err := controller.AddToManager(mgr); err != nil { + machineActuator, err := initActuator(mgr) + if err != nil { + glog.Fatal(err) + } + + if err := machine.AddWithActuator(mgr, machineActuator); err != nil { glog.Fatal(err) } @@ -67,10 +71,10 @@ func main() { glog.Fatal(mgr.Start(signals.SetupSignalHandler())) } -func initActuator(mgr manager.Manager) { +func initActuator(mgr manager.Manager) (*machineactuator.Actuator, error) { codec, err := v1alpha1.NewCodec() if err != nil { - glog.Fatal(err) + return nil, fmt.Errorf("unable to create codec: %v", err) } params := machineactuator.ActuatorParams{ @@ -80,8 +84,10 @@ func initActuator(mgr manager.Manager) { EventRecorder: mgr.GetRecorder("aws-controller"), } - machineactuator.MachineActuator, err = machineactuator.NewActuator(params) + actuator, err := machineactuator.NewActuator(params) if err != nil { - glog.Fatalf("Could not create AWS machine actuator: %v", err) + return nil, fmt.Errorf("could not create AWS machine actuator: %v", err) } + + return actuator, nil } diff --git a/pkg/actuators/machine/actuator.go b/pkg/actuators/machine/actuator.go index e098b27190..c7f94d284b 100644 --- a/pkg/actuators/machine/actuator.go +++ b/pkg/actuators/machine/actuator.go @@ -52,9 +52,6 @@ const ( MachineCreationFailed = "MachineCreationFailed" ) -// MachineActuator is a variable used to include the actuator into the machine controller -var MachineActuator *Actuator - // Actuator is the AWS-specific actuator for the Cluster API machine controller type Actuator struct { awsClientBuilder awsclient.AwsClientBuilderFuncType diff --git a/pkg/controller/add_machine.go b/pkg/controller/add_machine.go deleted file mode 100644 index a87d84beab..0000000000 --- a/pkg/controller/add_machine.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2018 The Kubernetes authors. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machine" - "sigs.k8s.io/cluster-api/pkg/controller/machine" - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, func(m manager.Manager) error { - return machine.AddWithActuator(m, machineactuator.MachineActuator) - }) -} diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go deleted file mode 100644 index 75c78148ac..0000000000 --- a/pkg/controller/controller.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -}