From 82ae17e967463a7532e2b76b0818eff69854c026 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Thu, 7 Jun 2018 19:58:09 -0700 Subject: [PATCH 1/4] Add golint to travis --- .travis.yml | 9 +++++++-- test.sh => install_test.sh | 9 +-------- 2 files changed, 8 insertions(+), 10 deletions(-) rename test.sh => install_test.sh (93%) diff --git a/.travis.yml b/.travis.yml index 94361307f1..b5bb4c7b4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,15 @@ before_install: # The dependencies have already been vendored by `dep` so # we don't need to fetch them. install: - - + - go get -u golang.org/x/lint/golint script: -- TRACE=1 ./test.sh +- go vet ./pkg/... +- golint -set_exit_status ./pkg/... +- TRACE=1 ./install_test.sh +- go test github.com/kubernetes-sigs/controller-runtime/pkg/... +- go install github.com/kubernetes-sigs/controller-runtime/example + # TBD. Suppressing for now. notifications: diff --git a/test.sh b/install_test.sh similarity index 93% rename from test.sh rename to install_test.sh index 564bbeb106..c4795ea3d3 100755 --- a/test.sh +++ b/install_test.sh @@ -99,11 +99,4 @@ function setup_envs { fetch_kb_tools # setup testing env -setup_envs - -go test github.com/kubernetes-sigs/controller-runtime/pkg/... -go install github.com/kubernetes-sigs/controller-runtime/example - -go vet ./pkg/... - -# golint -set_exit_status ./pkg/... \ No newline at end of file +setup_envs \ No newline at end of file From b06a1c0a3689c0da91126d1ee8c09ed73a2675c9 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Thu, 7 Jun 2018 20:25:54 -0700 Subject: [PATCH 2/4] fix golint errors --- example/main.go | 18 +-- pkg/controller/controller.go | 16 +-- pkg/controller/controller_integration_test.go | 18 +-- pkg/controller/controller_manager.go | 32 ++--- pkg/controller/controller_suite_test.go | 4 +- pkg/controller/doc.go | 6 +- pkg/controller/eventhandler/enqueue.go | 12 +- pkg/controller/eventhandler/enqueue_mapped.go | 8 +- pkg/controller/eventhandler/enqueue_owner.go | 12 +- pkg/controller/eventhandler/eventhandler.go | 14 +-- .../eventhandler/eventhandler_test.go | 112 +++++++++--------- pkg/controller/eventhandler/example_test.go | 18 +-- pkg/controller/example_test.go | 12 +- pkg/controller/predicate/example_test.go | 2 +- pkg/controller/predicate/predicate.go | 14 +-- pkg/controller/predicate/predicate_test.go | 4 +- pkg/controller/reconcile/example_test.go | 8 +- pkg/controller/reconcile/reconcile.go | 30 ++--- pkg/controller/reconcile/reconcile_test.go | 14 +-- .../source/internal/internal_test.go | 4 +- pkg/controller/source/source.go | 4 +- .../source/source_integration_test.go | 8 +- pkg/controller/source/source_suite_test.go | 4 +- pkg/controller/source/source_test.go | 12 +- pkg/runtime/inject/inject.go | 16 +-- pkg/test/server.go | 8 +- 26 files changed, 205 insertions(+), 205 deletions(-) diff --git a/example/main.go b/example/main.go index 07066641a1..4a7a624076 100644 --- a/example/main.go +++ b/example/main.go @@ -37,15 +37,15 @@ func main() { flag.Parse() logf.SetLogger(logf.ZapLogger(false)) - // Setup a ControllerManager - manager, err := controller.NewControllerManager(controller.ControllerManagerArgs{}) + // Setup a Manager + manager, err := controller.NewManager(controller.ManagerArgs{}) if err != nil { log.Fatal(err) } // Setup a new controller to Reconcile ReplicaSets c, err := manager.NewController( - controller.ControllerArgs{Name: "foo-controller", MaxConcurrentReconciles: 1}, + controller.Args{Name: "foo-controller", MaxConcurrentReconciles: 1}, &reconcileReplicaSet{client: manager.GetClient()}, ) if err != nil { @@ -81,18 +81,18 @@ type reconcileReplicaSet struct { // Implement reconcile.reconcile so the controller can reconcile objects var _ reconcile.Reconcile = &reconcileReplicaSet{} -func (r *reconcileReplicaSet) Reconcile(request reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { +func (r *reconcileReplicaSet) Reconcile(request reconcile.Request) (reconcile.Result, error) { // Fetch the ReplicaSet from the cache rs := &appsv1.ReplicaSet{} err := r.client.Get(context.TODO(), request.NamespacedName, rs) if errors.IsNotFound(err) { log.Printf("Could not find ReplicaSet %v.\n", request) - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil } if err != nil { log.Printf("Could not fetch ReplicaSet %v for %+v\n", err, request) - return reconcile.ReconcileResult{}, err + return reconcile.Result{}, err } // Print the ReplicaSet @@ -104,7 +104,7 @@ func (r *reconcileReplicaSet) Reconcile(request reconcile.ReconcileRequest) (rec rs.Labels = map[string]string{} } if rs.Labels["hello"] == "world" { - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil } // Update the ReplicaSet @@ -112,8 +112,8 @@ func (r *reconcileReplicaSet) Reconcile(request reconcile.ReconcileRequest) (rec err = r.client.Update(context.TODO(), rs) if err != nil { log.Printf("Could not write ReplicaSet %v\n", err) - return reconcile.ReconcileResult{}, err + return reconcile.Result{}, err } - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 5b763bf0dd..97701ec500 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -39,8 +39,8 @@ import ( var log = logf.KBLog.WithName("controller").WithName("controller") -// ControllerArgs are the arguments for creating a new Controller -type ControllerArgs struct { +// Args are the arguments for creating a new Controller +type Args struct { // Name is used to uniquely identify a controller in tracing, logging and monitoring. Name is required. Name string @@ -174,7 +174,7 @@ func (c *controller) processNextWorkItem() bool { obj, shutdown := c.queue.Get() if obj == nil { - log.Error(nil, "Encountered nil ReconcileRequest", "Object", obj) + log.Error(nil, "Encountered nil Request", "Object", obj) c.queue.Forget(obj) } @@ -190,14 +190,14 @@ func (c *controller) processNextWorkItem() bool { // put back on the workqueue and attempted again after a back-off // period. defer c.queue.Done(obj) - var req reconcile.ReconcileRequest + var req reconcile.Request var ok bool - if req, ok = obj.(reconcile.ReconcileRequest); !ok { + if req, ok = obj.(reconcile.Request); !ok { // As the item in the workqueue is actually invalid, we call // Forget here else we'd go into a loop of attempting to // process a work item that is invalid. c.queue.Forget(obj) - log.Error(nil, "Queue item was not a ReconcileRequest", + log.Error(nil, "Queue item was not a Request", "controller", c.name, "Type", fmt.Sprintf("%T", obj), "Value", obj) // Return true, don't take a break return true @@ -207,7 +207,7 @@ func (c *controller) processNextWorkItem() bool { // resource to be synced. if result, err := c.reconcile.Reconcile(req); err != nil { c.queue.AddRateLimited(req) - log.Error(nil, "reconcile error", "controller", c.name, "ReconcileRequest", req) + log.Error(nil, "reconcile error", "controller", c.name, "Request", req) // TODO(pwittrock): FTO Returning an error here seems to back things off for a second before restarting // the loop through wait.Util. @@ -224,7 +224,7 @@ func (c *controller) processNextWorkItem() bool { c.queue.Forget(obj) // TODO(directxman12): What does 1 mean? Do we want level constants? Do we want levels at all? - log.V(1).Info("Successfully Reconciled", "controller", c.name, "ReconcileRequest", req) + log.V(1).Info("Successfully Reconciled", "controller", c.name, "Request", req) // Return true, don't take a break return true diff --git a/pkg/controller/controller_integration_test.go b/pkg/controller/controller_integration_test.go index ffdc40453b..c9fd29cfc7 100644 --- a/pkg/controller/controller_integration_test.go +++ b/pkg/controller/controller_integration_test.go @@ -32,12 +32,12 @@ import ( ) var _ = Describe("controller", func() { - var reconciled chan reconcile.ReconcileRequest + var reconciled chan reconcile.Request var stop chan struct{} BeforeEach(func() { stop = make(chan struct{}) - reconciled = make(chan reconcile.ReconcileRequest) + reconciled = make(chan reconcile.Request) Expect(cfg).NotTo(BeNil()) }) @@ -49,15 +49,15 @@ var _ = Describe("controller", func() { // TODO(directxman12): write a whole suite of controller-client interaction tests It("should reconcile", func(done Done) { - By("Creating the ControllerManager") - cm, err := controller.NewControllerManager(controller.ControllerManagerArgs{Config: cfg}) + By("Creating the Manager") + cm, err := controller.NewManager(controller.ManagerArgs{Config: cfg}) Expect(err).NotTo(HaveOccurred()) By("Creating the Controller") - instance, err := cm.NewController(controller.ControllerArgs{Name: "foo-controller"}, reconcile.ReconcileFunc( - func(request reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { + instance, err := cm.NewController(controller.Args{Name: "foo-controller"}, reconcile.Func( + func(request reconcile.Request) (reconcile.Result, error) { reconciled <- request - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil })) Expect(err).NotTo(HaveOccurred()) @@ -70,7 +70,7 @@ var _ = Describe("controller", func() { err = instance.Watch(&source.KindSource{Type: &appsv1.Deployment{}}, &eventhandler.EnqueueHandler{}) Expect(err).NotTo(HaveOccurred()) - By("Starting the ControllerManager") + By("Starting the Manager") go func() { defer GinkgoRecover() Expect(cm.Start(stop)).NotTo(HaveOccurred()) @@ -95,7 +95,7 @@ var _ = Describe("controller", func() { }, }, } - expectedReconcileRequest := reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + expectedReconcileRequest := reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: "default", Name: "deployment-name", }} diff --git a/pkg/controller/controller_manager.go b/pkg/controller/controller_manager.go index 4c027c62ef..652eafbcd0 100644 --- a/pkg/controller/controller_manager.go +++ b/pkg/controller/controller_manager.go @@ -33,13 +33,13 @@ import ( "k8s.io/client-go/util/workqueue" ) -// ControllerManager initializes shared dependencies such as Caches and Clients, and starts Controllers. +// Manager initializes shared dependencies such as Caches and Clients, and starts Controllers. // -// Dependencies may be retrieved from the ControllerManager using the Get* functions -type ControllerManager interface { +// Dependencies may be retrieved from the Manager using the Get* functions +type Manager interface { // NewController creates a new initialized Controller with the Reconcile function - // and registers it with the ControllerManager. - NewController(ControllerArgs, reconcile.Reconcile) (Controller, error) + // and registers it with the Manager. + NewController(Args, reconcile.Reconcile) (Controller, error) // Start starts all registered Controllers and blocks until the Stop channel is closed. // Returns an error if there is an error starting any controller. @@ -58,7 +58,7 @@ type ControllerManager interface { GetFieldIndexer() client.FieldIndexer } -var _ ControllerManager = &controllerManager{} +var _ Manager = &controllerManager{} type controllerManager struct { // config is the rest.config used to talk to the apiserver. Required. @@ -88,12 +88,12 @@ type controllerManager struct { stop <-chan struct{} } -func (cm *controllerManager) NewController(ca ControllerArgs, r reconcile.Reconcile) (Controller, error) { +func (cm *controllerManager) NewController(ca Args, r reconcile.Reconcile) (Controller, error) { cm.mu.Lock() defer cm.mu.Unlock() if len(ca.Name) == 0 { - return nil, fmt.Errorf("Must specify name for Controller.") + return nil, fmt.Errorf("must specify name for Controller") } if ca.MaxConcurrentReconciles <= 0 { @@ -127,16 +127,16 @@ func (cm *controllerManager) NewController(ca ControllerArgs, r reconcile.Reconc } func (cm *controllerManager) injectInto(i interface{}) error { - if _, err := inject.InjectConfig(cm.config, i); err != nil { + if _, err := inject.DoConfig(cm.config, i); err != nil { return err } - if _, err := inject.InjectClient(cm.client, i); err != nil { + if _, err := inject.DoClient(cm.client, i); err != nil { return err } - if _, err := inject.InjectScheme(cm.scheme, i); err != nil { + if _, err := inject.DoScheme(cm.scheme, i); err != nil { return err } - if _, err := inject.InjectInformers(cm.informers, i); err != nil { + if _, err := inject.DoInformers(cm.informers, i); err != nil { return err } return nil @@ -187,8 +187,8 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error { } } -// ControllerManagerArgs are the arguments for creating a new ControllerManager -type ControllerManagerArgs struct { +// ManagerArgs are the arguments for creating a new Manager +type ManagerArgs struct { // Config is the config used to talk to an apiserver. Defaults to: // 1. Config specified with the --config flag // 2. Config specified with the KUBECONFIG environment variable @@ -201,8 +201,8 @@ type ControllerManagerArgs struct { Scheme *runtime.Scheme } -// NewControllerManager returns a new fully initialized ControllerManager. -func NewControllerManager(args ControllerManagerArgs) (ControllerManager, error) { +// NewManager returns a new fully initialized Manager. +func NewManager(args ManagerArgs) (Manager, error) { cm := &controllerManager{config: args.Config, scheme: args.Scheme, errChan: make(chan error)} // Initialize a rest.config if none was specified diff --git a/pkg/controller/controller_suite_test.go b/pkg/controller/controller_suite_test.go index dd21319cd0..2a41782310 100644 --- a/pkg/controller/controller_suite_test.go +++ b/pkg/controller/controller_suite_test.go @@ -34,7 +34,7 @@ func TestSource(t *testing.T) { RunSpecsWithDefaultAndCustomReporters(t, "controller Suite", []Reporter{test.NewlineReporter{}}) } -var testenv *test.TestEnvironment +var testenv *test.Environment var cfg *rest.Config var clientset *kubernetes.Clientset var icache informer.Informers @@ -42,7 +42,7 @@ var icache informer.Informers var _ = BeforeSuite(func() { logf.SetLogger(logf.ZapLogger(true)) - testenv = &test.TestEnvironment{} + testenv = &test.Environment{} var err error cfg, err = testenv.Start() diff --git a/pkg/controller/doc.go b/pkg/controller/doc.go index 278e6bcf36..f5896a5225 100644 --- a/pkg/controller/doc.go +++ b/pkg/controller/doc.go @@ -124,15 +124,15 @@ to Pod or ReplicaSet events. The Reconcile function simply adds a label to the flag.Parse() logf.SetLogger(logf.ZapLogger(false)) - // Setup a ControllerManager - manager, err := controller.NewControllerManager(controller.ControllerManagerArgs{}) + // Setup a Manager + manager, err := controller.NewManager(controller.ManagerArgs{}) if err != nil { log.Fatal(err) } // Setup a new controller to Reconcile ReplicaSets c := manager.NewController( - controller.ControllerArgs{Name: "my-replicaset-controller", MaxConcurrentReconciles: 1}, + controller.Args{Name: "my-replicaset-controller", MaxConcurrentReconciles: 1}, &ReconcileReplicaSet{client: manager.GetClient()}, ) diff --git a/pkg/controller/eventhandler/enqueue.go b/pkg/controller/eventhandler/enqueue.go index 50c78be831..b20f32443f 100644 --- a/pkg/controller/eventhandler/enqueue.go +++ b/pkg/controller/eventhandler/enqueue.go @@ -28,7 +28,7 @@ var enqueueLog = logf.KBLog.WithName("eventhandler").WithName("EnqueueHandler") var _ EventHandler = &EnqueueHandler{} -// EnqueueHandler enqueues a ReconcileRequest containing the Name and Namespace of the object for each event. +// EnqueueHandler enqueues a Request containing the Name and Namespace of the object for each event. type EnqueueHandler struct{} // Create implements EventHandler @@ -37,7 +37,7 @@ func (e *EnqueueHandler) Create(q workqueue.RateLimitingInterface, evt event.Cre enqueueLog.Error(nil, "CreateEvent received with no metadata", "CreateEvent", evt) return } - q.AddRateLimited(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.AddRateLimited(reconcile.Request{NamespacedName: types.NamespacedName{ Name: evt.Meta.GetName(), Namespace: evt.Meta.GetNamespace(), }}) @@ -46,7 +46,7 @@ func (e *EnqueueHandler) Create(q workqueue.RateLimitingInterface, evt event.Cre // Update implements EventHandler func (e *EnqueueHandler) Update(q workqueue.RateLimitingInterface, evt event.UpdateEvent) { if evt.MetaOld != nil { - q.AddRateLimited(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.AddRateLimited(reconcile.Request{NamespacedName: types.NamespacedName{ Name: evt.MetaOld.GetName(), Namespace: evt.MetaOld.GetNamespace(), }}) @@ -55,7 +55,7 @@ func (e *EnqueueHandler) Update(q workqueue.RateLimitingInterface, evt event.Upd } if evt.MetaNew != nil { - q.AddRateLimited(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.AddRateLimited(reconcile.Request{NamespacedName: types.NamespacedName{ Name: evt.MetaNew.GetName(), Namespace: evt.MetaNew.GetNamespace(), }}) @@ -70,7 +70,7 @@ func (e *EnqueueHandler) Delete(q workqueue.RateLimitingInterface, evt event.Del enqueueLog.Error(nil, "DeleteEvent received with no metadata", "DeleteEvent", evt) return } - q.AddRateLimited(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.AddRateLimited(reconcile.Request{NamespacedName: types.NamespacedName{ Name: evt.Meta.GetName(), Namespace: evt.Meta.GetNamespace(), }}) @@ -82,7 +82,7 @@ func (e *EnqueueHandler) Generic(q workqueue.RateLimitingInterface, evt event.Ge enqueueLog.Error(nil, "GenericEvent received with no metadata", "GenericEvent", evt) return } - q.AddRateLimited(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.AddRateLimited(reconcile.Request{NamespacedName: types.NamespacedName{ Name: evt.Meta.GetName(), Namespace: evt.Meta.GetNamespace(), }}) diff --git a/pkg/controller/eventhandler/enqueue_mapped.go b/pkg/controller/eventhandler/enqueue_mapped.go index b06648457f..4420de1f20 100644 --- a/pkg/controller/eventhandler/enqueue_mapped.go +++ b/pkg/controller/eventhandler/enqueue_mapped.go @@ -65,10 +65,10 @@ func (e *EnqueueMappedHandler) mapAndEnqueue(q workqueue.RateLimitingInterface, // Mapper maps an object to a collection of keys to be enqueued type Mapper interface { // Map maps an object - Map(MapObject) []reconcile.ReconcileRequest + Map(MapObject) []reconcile.Request } -// MapObject contains information from an event to be transformed into a ReconcileRequest. +// MapObject contains information from an event to be transformed into a Request. type MapObject struct { // Meta is the meta data for an object from an event. Meta metav1.Object @@ -80,9 +80,9 @@ type MapObject struct { var _ Mapper = ToRequestsFunc(nil) // ToRequestsFunc implements Mapper using a function. -type ToRequestsFunc func(MapObject) []reconcile.ReconcileRequest +type ToRequestsFunc func(MapObject) []reconcile.Request // Map implements Mapper -func (m ToRequestsFunc) Map(i MapObject) []reconcile.ReconcileRequest { +func (m ToRequestsFunc) Map(i MapObject) []reconcile.Request { return m(i) } diff --git a/pkg/controller/eventhandler/enqueue_owner.go b/pkg/controller/eventhandler/enqueue_owner.go index 891915ad10..efc8240e79 100644 --- a/pkg/controller/eventhandler/enqueue_owner.go +++ b/pkg/controller/eventhandler/enqueue_owner.go @@ -115,12 +115,12 @@ func (e *EnqueueOwnerHandler) parseOwnerTypeGroupKind(scheme *runtime.Scheme) er return nil } -// getOwnerReconcileRequest looks at object and returns a slice of reconcile.ReconcileRequest to reconcile +// getOwnerReconcileRequest looks at object and returns a slice of reconcile.Request to reconcile // owners of object that match e.OwnerType. -func (e *EnqueueOwnerHandler) getOwnerReconcileRequest(object metav1.Object) []reconcile.ReconcileRequest { +func (e *EnqueueOwnerHandler) getOwnerReconcileRequest(object metav1.Object) []reconcile.Request { // Iterate through the OwnerReferences looking for a match on Group and Kind against what was requested // by the user - var result []reconcile.ReconcileRequest + var result []reconcile.Request for _, ref := range e.getOwnersReferences(object) { // Parse the Group out of the OwnerReference to compare it to what was parsed out of the requested OwnerType refGV, err := schema.ParseGroupVersion(ref.APIVersion) @@ -131,12 +131,12 @@ func (e *EnqueueOwnerHandler) getOwnerReconcileRequest(object metav1.Object) []r } // Compare the OwnerReference Group and Kind against the OwnerType Group and Kind specified by the user. - // If the two match, create a ReconcileRequest for the objected referred to by + // If the two match, create a Request for the objected referred to by // the OwnerReference. Use the Name from the OwnerReference and the Namespace from the // object in the event. if ref.Kind == e.groupKind.Kind && refGV.Group == e.groupKind.Group { - // Match found - add a ReconcileRequest for the object referred to in the OwnerReference - result = append(result, reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + // Match found - add a Request for the object referred to in the OwnerReference + result = append(result, reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: object.GetNamespace(), Name: ref.Name, }}) diff --git a/pkg/controller/eventhandler/eventhandler.go b/pkg/controller/eventhandler/eventhandler.go index a002f30069..7f7d8ccc8d 100644 --- a/pkg/controller/eventhandler/eventhandler.go +++ b/pkg/controller/eventhandler/eventhandler.go @@ -54,10 +54,10 @@ type EventHandler interface { Generic(workqueue.RateLimitingInterface, event.GenericEvent) } -var _ EventHandler = EventHandlerFuncs{} +var _ EventHandler = Funcs{} -// EventHandlerFuncs allows specifying a subset of EventHandler functions are fields. -type EventHandlerFuncs struct { +// Funcs allows specifying a subset of EventHandler functions are fields. +type Funcs struct { // Create is called in response to an add event. Defaults to no-op. // RateLimitingInterface is used to enqueue reconcile.ReconcileRequests. CreateFunc func(workqueue.RateLimitingInterface, event.CreateEvent) @@ -76,28 +76,28 @@ type EventHandlerFuncs struct { } // Create implements EventHandler -func (h EventHandlerFuncs) Create(q workqueue.RateLimitingInterface, e event.CreateEvent) { +func (h Funcs) Create(q workqueue.RateLimitingInterface, e event.CreateEvent) { if h.CreateFunc != nil { h.CreateFunc(q, e) } } // Delete implements EventHandler -func (h EventHandlerFuncs) Delete(q workqueue.RateLimitingInterface, e event.DeleteEvent) { +func (h Funcs) Delete(q workqueue.RateLimitingInterface, e event.DeleteEvent) { if h.DeleteFunc != nil { h.DeleteFunc(q, e) } } // Update implements EventHandler -func (h EventHandlerFuncs) Update(q workqueue.RateLimitingInterface, e event.UpdateEvent) { +func (h Funcs) Update(q workqueue.RateLimitingInterface, e event.UpdateEvent) { if h.UpdateFunc != nil { h.UpdateFunc(q, e) } } // Generic implements EventHandler -func (h EventHandlerFuncs) Generic(q workqueue.RateLimitingInterface, e event.GenericEvent) { +func (h Funcs) Generic(q workqueue.RateLimitingInterface, e event.GenericEvent) { if h.GenericFunc != nil { h.GenericFunc(q, e) } diff --git a/pkg/controller/eventhandler/eventhandler_test.go b/pkg/controller/eventhandler/eventhandler_test.go index 503d8d4623..2967faa4db 100644 --- a/pkg/controller/eventhandler/eventhandler_test.go +++ b/pkg/controller/eventhandler/eventhandler_test.go @@ -45,7 +45,7 @@ var _ = Describe("Eventhandler", func() { }) Describe("EnqueueHandler", func() { - It("should enqueue a ReconcileRequest with the Name / Namespace of the object in the CreateEvent.", func(done Done) { + It("should enqueue a Request with the Name / Namespace of the object in the CreateEvent.", func(done Done) { evt := event.CreateEvent{ Object: pod, Meta: pod.GetObjectMeta(), @@ -55,14 +55,14 @@ var _ = Describe("Eventhandler", func() { i, _ := q.Get() Expect(i).NotTo(BeNil()) - req, ok := i.(reconcile.ReconcileRequest) + req, ok := i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz", Name: "baz"})) close(done) }) - It("should enqueue a ReconcileRequest with the Name / Namespace of the object in the DeleteEvent.", func(done Done) { + It("should enqueue a Request with the Name / Namespace of the object in the DeleteEvent.", func(done Done) { evt := event.DeleteEvent{ Object: pod, Meta: pod.GetObjectMeta(), @@ -72,14 +72,14 @@ var _ = Describe("Eventhandler", func() { i, _ := q.Get() Expect(i).NotTo(BeNil()) - req, ok := i.(reconcile.ReconcileRequest) + req, ok := i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz", Name: "baz"})) close(done) }) - It("should enqueue a ReconcileRequest with the Name / Namespace of both objects in the UpdateEvent.", + It("should enqueue a Request with the Name / Namespace of both objects in the UpdateEvent.", func(done Done) { newPod := pod.DeepCopy() newPod.Name = "baz2" @@ -96,20 +96,20 @@ var _ = Describe("Eventhandler", func() { i, _ := q.Get() Expect(i).NotTo(BeNil()) - req, ok := i.(reconcile.ReconcileRequest) + req, ok := i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz", Name: "baz"})) i, _ = q.Get() Expect(i).NotTo(BeNil()) - req, ok = i.(reconcile.ReconcileRequest) + req, ok = i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz2", Name: "baz2"})) close(done) }) - It("should enqueue a ReconcileRequest with the Name / Namespace of the object in the GenericEvent.", func(done Done) { + It("should enqueue a Request with the Name / Namespace of the object in the GenericEvent.", func(done Done) { evt := event.GenericEvent{ Object: pod, Meta: pod.GetObjectMeta(), @@ -118,7 +118,7 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() Expect(i).NotTo(BeNil()) - req, ok := i.(reconcile.ReconcileRequest) + req, ok := i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz", Name: "baz"})) @@ -149,7 +149,7 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() Expect(i).NotTo(BeNil()) - req, ok := i.(reconcile.ReconcileRequest) + req, ok := i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz2", Name: "baz2"})) @@ -159,7 +159,7 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ = q.Get() Expect(i).NotTo(BeNil()) - req, ok = i.(reconcile.ReconcileRequest) + req, ok = i.(reconcile.Request) Expect(ok).To(BeTrue()) Expect(req.NamespacedName).To(Equal(types.NamespacedName{Namespace: "biz", Name: "baz"})) @@ -187,14 +187,14 @@ var _ = Describe("Eventhandler", func() { }) Describe("EnqueueMappedHandler", func() { - It("should enqueue a ReconcileRequest with the function applied to the CreateEvent.", func() { - req := []reconcile.ReconcileRequest{} + It("should enqueue a Request with the function applied to the CreateEvent.", func() { + req := []reconcile.Request{} instance := eventhandler.EnqueueMappedHandler{ - ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.ReconcileRequest { + ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.Request { defer GinkgoRecover() Expect(a.Meta).To(Equal(pod.GetObjectMeta())) Expect(a.Object).To(Equal(pod)) - req = []reconcile.ReconcileRequest{ + req = []reconcile.Request{ { NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}, }, @@ -214,22 +214,22 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(2)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "biz", Name: "baz"}})) }) - It("should enqueue a ReconcileRequest with the function applied to the DeleteEvent.", func() { - req := []reconcile.ReconcileRequest{} + It("should enqueue a Request with the function applied to the DeleteEvent.", func() { + req := []reconcile.Request{} instance := eventhandler.EnqueueMappedHandler{ - ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.ReconcileRequest { + ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.Request { defer GinkgoRecover() Expect(a.Meta).To(Equal(pod.GetObjectMeta())) Expect(a.Object).To(Equal(pod)) - req = []reconcile.ReconcileRequest{ + req = []reconcile.Request{ { NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}, }, @@ -249,25 +249,25 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(2)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "biz", Name: "baz"}})) }) - It("should enqueue a ReconcileRequest with the function applied to both objects in the UpdateEvent.", + It("should enqueue a Request with the function applied to both objects in the UpdateEvent.", func() { newPod := pod.DeepCopy() newPod.Name = pod.Name + "2" newPod.Namespace = pod.Namespace + "2" - req := []reconcile.ReconcileRequest{} + req := []reconcile.Request{} instance := eventhandler.EnqueueMappedHandler{ - ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.ReconcileRequest { + ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.Request { defer GinkgoRecover() - req = []reconcile.ReconcileRequest{ + req = []reconcile.Request{ { NamespacedName: types.NamespacedName{Namespace: "foo", Name: a.Meta.GetName() + "-bar"}, }, @@ -289,30 +289,30 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(4)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "foo", Name: "baz-bar"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "biz", Name: "baz-baz"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "foo", Name: "baz2-bar"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "biz", Name: "baz2-baz"}})) }) - It("should enqueue a ReconcileRequest with the function applied to the GenericEvent.", func() { - req := []reconcile.ReconcileRequest{} + It("should enqueue a Request with the function applied to the GenericEvent.", func() { + req := []reconcile.Request{} instance := eventhandler.EnqueueMappedHandler{ - ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.ReconcileRequest { + ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.Request { defer GinkgoRecover() Expect(a.Meta).To(Equal(pod.GetObjectMeta())) Expect(a.Object).To(Equal(pod)) - req = []reconcile.ReconcileRequest{ + req = []reconcile.Request{ { NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}, }, @@ -332,17 +332,17 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(2)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "foo", Name: "bar"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: "biz", Name: "baz"}})) }) }) Describe("EnqueueOwnerHandler", func() { - It("should enqueue a ReconcileRequest with the Owner of the object in the CreateEvent.", func() { + It("should enqueue a Request with the Owner of the object in the CreateEvent.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, } @@ -363,11 +363,11 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo-parent"}})) }) - It("should enqueue a ReconcileRequest with the Owner of the object in the DeleteEvent.", func() { + It("should enqueue a Request with the Owner of the object in the DeleteEvent.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, } @@ -388,11 +388,11 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo-parent"}})) }) - It("should enqueue a ReconcileRequest with the Owners of both objects in the UpdateEvent.", func() { + It("should enqueue a Request with the Owners of both objects in the UpdateEvent.", func() { newPod := pod.DeepCopy() newPod.Name = pod.Name + "2" newPod.Namespace = pod.Namespace + "2" @@ -426,15 +426,15 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(2)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo1-parent"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: newPod.GetNamespace(), Name: "foo2-parent"}})) }) - It("should enqueue a ReconcileRequest with the Owner of the object in the GenericEvent.", func() { + It("should enqueue a Request with the Owner of the object in the GenericEvent.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, } @@ -455,11 +455,11 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo-parent"}})) }) - It("should not enqueue a ReconcileRequest if there are no owners matching Group and Kind.", func() { + It("should not enqueue a Request if there are no owners matching Group and Kind.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, IsController: t, @@ -485,7 +485,7 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(0)) }) - It("should enqueue a ReconcileRequest if there are owners matching Group "+ + It("should enqueue a Request if there are owners matching Group "+ "and Kind with a different version.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, @@ -506,11 +506,11 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(1)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo-parent"}})) }) - It("should not enqueue a ReconcileRequest if there are no owners.", func() { + It("should not enqueue a Request if there are no owners.", func() { instance := eventhandler.EnqueueOwnerHandler{ OwnerType: &appsv1.ReplicaSet{}, } @@ -567,7 +567,7 @@ var _ = Describe("Eventhandler", func() { instance.Create(q, evt) Expect(q.Len()).To(Equal(1)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo2-parent"}})) }) @@ -648,13 +648,13 @@ var _ = Describe("Eventhandler", func() { Expect(q.Len()).To(Equal(3)) i, _ := q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo1-parent"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo2-parent"}})) i, _ = q.Get() - Expect(i).To(Equal(reconcile.ReconcileRequest{ + Expect(i).To(Equal(reconcile.Request{ NamespacedName: types.NamespacedName{Namespace: pod.GetNamespace(), Name: "foo3-parent"}})) }) }) @@ -766,8 +766,8 @@ var _ = Describe("Eventhandler", func() { }) }) - Describe("EventHandlerFuncs", func() { - failingFuncs := eventhandler.EventHandlerFuncs{ + Describe("Funcs", func() { + failingFuncs := eventhandler.Funcs{ CreateFunc: func(workqueue.RateLimitingInterface, event.CreateEvent) { defer GinkgoRecover() Fail("Did not expect CreateEvent to be called.") diff --git a/pkg/controller/eventhandler/example_test.go b/pkg/controller/eventhandler/example_test.go index edd50cbbdd..8058047571 100644 --- a/pkg/controller/eventhandler/example_test.go +++ b/pkg/controller/eventhandler/example_test.go @@ -40,7 +40,7 @@ func ExampleEnqueueHandler() { ) } -// This example watches ReplicaSets and enqueues a ReconcileRequest containing the Name and Namespace of the +// This example watches ReplicaSets and enqueues a Request containing the Name and Namespace of the // owning (direct) Deployment responsible for the creation of the ReplicaSet. func ExampleEnqueueOwnerHandler() { // controller is a controller.controller @@ -53,15 +53,15 @@ func ExampleEnqueueOwnerHandler() { ) } -// This example watches Deployments and enqueues a ReconcileRequest contain the Name and Namespace of different +// This example watches Deployments and enqueues a Request contain the Name and Namespace of different // objects (of Type: MyKind) using a mapping function defined by the user. func ExampleEnqueueMappedHandler() { // controller is a controller.controller c.Watch( &source.KindSource{Type: &appsv1.Deployment{}}, &eventhandler.EnqueueMappedHandler{ - ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.ReconcileRequest { - return []reconcile.ReconcileRequest{ + ToRequests: eventhandler.ToRequestsFunc(func(a eventhandler.MapObject) []reconcile.Request { + return []reconcile.Request{ {NamespacedName: types.NamespacedName{ Name: a.Meta.GetName() + "-1", Namespace: a.Meta.GetNamespace(), @@ -80,27 +80,27 @@ func ExampleEventHandlerFuncs() { // controller is a controller.controller c.Watch( &source.KindSource{Type: &corev1.Pod{}}, - eventhandler.EventHandlerFuncs{ + eventhandler.Funcs{ CreateFunc: func(q workqueue.RateLimitingInterface, e event.CreateEvent) { - q.Add(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Name: e.Meta.GetName(), Namespace: e.Meta.GetNamespace(), }}) }, UpdateFunc: func(q workqueue.RateLimitingInterface, e event.UpdateEvent) { - q.Add(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Name: e.MetaNew.GetName(), Namespace: e.MetaNew.GetNamespace(), }}) }, DeleteFunc: func(q workqueue.RateLimitingInterface, e event.DeleteEvent) { - q.Add(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Name: e.Meta.GetName(), Namespace: e.Meta.GetNamespace(), }}) }, GenericFunc: func(q workqueue.RateLimitingInterface, e event.GenericEvent) { - q.Add(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{ + q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Name: e.Meta.GetName(), Namespace: e.Meta.GetNamespace(), }}) diff --git a/pkg/controller/example_test.go b/pkg/controller/example_test.go index b768542c65..db88be8cc1 100644 --- a/pkg/controller/example_test.go +++ b/pkg/controller/example_test.go @@ -30,15 +30,15 @@ import ( // This example creates a new controller named "pod-controller" with a no-op reconcile function and registers // it with the DefaultControllerManager. func ExampleController() { - cm, err := controller.NewControllerManager(controller.ControllerManagerArgs{Config: config.GetConfigOrDie()}) + cm, err := controller.NewManager(controller.ManagerArgs{Config: config.GetConfigOrDie()}) if err != nil { log.Fatal(err) } _, err = cm.NewController( - controller.ControllerArgs{Name: "pod-controller", MaxConcurrentReconciles: 1}, - reconcile.ReconcileFunc(func(o reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { + controller.Args{Name: "pod-controller", MaxConcurrentReconciles: 1}, + reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) { // Your business logic to implement the API by creating, updating, deleting objects goes here. - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil }), ) if err != nil { @@ -48,11 +48,11 @@ func ExampleController() { // This example watches Pods and enqueues ReconcileRequests with the changed Pod Name and Namespace. func ExampleController_Watch() { - cm, err := controller.NewControllerManager(controller.ControllerManagerArgs{Config: config.GetConfigOrDie()}) + cm, err := controller.NewManager(controller.ManagerArgs{Config: config.GetConfigOrDie()}) if err != nil { log.Fatal(err) } - c, err := cm.NewController(controller.ControllerArgs{Name: "foo-controller"}, nil) + c, err := cm.NewController(controller.Args{Name: "foo-controller"}, nil) if err != nil { log.Fatal(err) } diff --git a/pkg/controller/predicate/example_test.go b/pkg/controller/predicate/example_test.go index 585fac3dad..f3abd68b5a 100644 --- a/pkg/controller/predicate/example_test.go +++ b/pkg/controller/predicate/example_test.go @@ -25,7 +25,7 @@ var p predicate.Predicate // This example creates a new Predicate to drop Update Events where the Generation has not changed. func ExamplePredicateFuncs() { - p = predicate.PredicateFuncs{ + p = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { return e.MetaOld.GetGeneration() != e.MetaNew.GetGeneration() }, diff --git a/pkg/controller/predicate/predicate.go b/pkg/controller/predicate/predicate.go index a1493e71ac..cc19ff6eb1 100644 --- a/pkg/controller/predicate/predicate.go +++ b/pkg/controller/predicate/predicate.go @@ -33,10 +33,10 @@ type Predicate interface { Generic(event.GenericEvent) bool } -var _ Predicate = PredicateFuncs{} +var _ Predicate = Funcs{} -// PredicateFuncs is a function that implements Predicate. -type PredicateFuncs struct { +// Funcs is a function that implements Predicate. +type Funcs struct { // Create returns true if the Create event should be processed CreateFunc func(event.CreateEvent) bool @@ -51,7 +51,7 @@ type PredicateFuncs struct { } // Create implements Predicate -func (p PredicateFuncs) Create(e event.CreateEvent) bool { +func (p Funcs) Create(e event.CreateEvent) bool { if p.CreateFunc != nil { return p.CreateFunc(e) } @@ -59,7 +59,7 @@ func (p PredicateFuncs) Create(e event.CreateEvent) bool { } // Delete implements Predicate -func (p PredicateFuncs) Delete(e event.DeleteEvent) bool { +func (p Funcs) Delete(e event.DeleteEvent) bool { if p.DeleteFunc != nil { return p.DeleteFunc(e) } @@ -67,7 +67,7 @@ func (p PredicateFuncs) Delete(e event.DeleteEvent) bool { } // Update implements Predicate -func (p PredicateFuncs) Update(e event.UpdateEvent) bool { +func (p Funcs) Update(e event.UpdateEvent) bool { if p.UpdateFunc != nil { return p.UpdateFunc(e) } @@ -75,7 +75,7 @@ func (p PredicateFuncs) Update(e event.UpdateEvent) bool { } // Generic implements Predicate -func (p PredicateFuncs) Generic(e event.GenericEvent) bool { +func (p Funcs) Generic(e event.GenericEvent) bool { if p.GenericFunc != nil { return p.GenericFunc(e) } diff --git a/pkg/controller/predicate/predicate_test.go b/pkg/controller/predicate/predicate_test.go index 2b9a9dff3f..82b8551dc2 100644 --- a/pkg/controller/predicate/predicate_test.go +++ b/pkg/controller/predicate/predicate_test.go @@ -33,8 +33,8 @@ var _ = Describe("Predicate", func() { } }) - Describe("PredicateFuncs", func() { - failingFuncs := predicate.PredicateFuncs{ + Describe("Funcs", func() { + failingFuncs := predicate.Funcs{ CreateFunc: func(event.CreateEvent) bool { defer GinkgoRecover() Fail("Did not expect CreateFunc to be called.") diff --git a/pkg/controller/reconcile/example_test.go b/pkg/controller/reconcile/example_test.go index 4559b9c86a..4dec470415 100644 --- a/pkg/controller/reconcile/example_test.go +++ b/pkg/controller/reconcile/example_test.go @@ -25,13 +25,13 @@ import ( // This example implements a simple no-op reconcile function that prints the object to be Reconciled. func ExampleReconcileFunc() { - r := reconcile.ReconcileFunc(func(o reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { + r := reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) { // Create your business logic to create, update, delete objects here. fmt.Printf("Name: %s, Namespace: %s", o.Name, o.Namespace) - return reconcile.ReconcileResult{}, nil + return reconcile.Result{}, nil }) - r.Reconcile(reconcile.ReconcileRequest{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}}) + r.Reconcile(reconcile.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}}) // Output: Name: test, Namespace: default } @@ -39,6 +39,6 @@ func ExampleReconcileFunc() { // This example declares a simple type that implements reconcile. func ExampleReconcile() { type MyReconcileImplementation struct { - reconcile.ReconcileFunc + reconcile.Func } } diff --git a/pkg/controller/reconcile/reconcile.go b/pkg/controller/reconcile/reconcile.go index 488b702348..bbfd2dbe17 100644 --- a/pkg/controller/reconcile/reconcile.go +++ b/pkg/controller/reconcile/reconcile.go @@ -20,16 +20,16 @@ import ( "k8s.io/apimachinery/pkg/types" ) -// ReconcileResult contains the result of a reconcile. -type ReconcileResult struct { +// Result contains the result of a reconcile. +type Result struct { // Requeue tells the Controller to requeue the reconcile key. Defaults to false. Requeue bool } -// ReconcileRequest contains the information necessary to reconcile a Kubernetes object. This includes the +// Request contains the information necessary to reconcile a Kubernetes object. This includes the // information to uniquely identify the object - its Name and Namespace. It does NOT contain information about // any specific Event or the object contents itself. -type ReconcileRequest struct { +type Request struct { // NamespacedName is the name and namespace of the object to reconcile. types.NamespacedName } @@ -54,32 +54,32 @@ reconcile may be implemented as either a type: type reconcile struct {} - func (reconcile) reconcile(controller.ReconcileRequest) (controller.ReconcileResult, error) { + func (reconcile) reconcile(controller.Request) (controller.Result, error) { // Implement business logic of reading and writing objects here - return controller.ReconcileResult{}, nil + return controller.Result{}, nil } Or as a function: - controller.ReconcileFunc(func(o controller.ReconcileRequest) (controller.ReconcileResult, error) { + controller.Func(func(o controller.Request) (controller.Result, error) { // Implement business logic of reading and writing objects here - return controller.ReconcileResult{}, nil + return controller.Result{}, nil }) Reconciliation is level-based, meaning action isn't driven off changes in individual Events, but instead is driven by actual cluster state read from the apiserver or a local cache. -For example if responding to a Pod Delete Event, the ReconcileRequest won't contain that a Pod was deleted, +For example if responding to a Pod Delete Event, the Request won't contain that a Pod was deleted, instead the reconcile function observes this when reading the cluster state and seeing the Pod as missing. */ type Reconcile interface { - // reconcile performs a full reconciliation for the object referred to by the ReconcileRequest. - Reconcile(ReconcileRequest) (ReconcileResult, error) + // reconcile performs a full reconciliation for the object referred to by the Request. + Reconcile(Request) (Result, error) } -// ReconcileFunc is a function that implements the reconcile interface. -type ReconcileFunc func(ReconcileRequest) (ReconcileResult, error) +// Func is a function that implements the reconcile interface. +type Func func(Request) (Result, error) -var _ Reconcile = ReconcileFunc(nil) +var _ Reconcile = Func(nil) // Reconcile implements Reconcile. -func (r ReconcileFunc) Reconcile(o ReconcileRequest) (ReconcileResult, error) { return r(o) } +func (r Func) Reconcile(o Request) (Result, error) { return r(o) } diff --git a/pkg/controller/reconcile/reconcile_test.go b/pkg/controller/reconcile/reconcile_test.go index fb75125f4c..a4adde429b 100644 --- a/pkg/controller/reconcile/reconcile_test.go +++ b/pkg/controller/reconcile/reconcile_test.go @@ -26,16 +26,16 @@ import ( ) var _ = Describe("reconcile", func() { - Describe("ReconcileFunc", func() { + Describe("Func", func() { It("should call the function with the request and return a nil error.", func() { - request := reconcile.ReconcileRequest{ + request := reconcile.Request{ NamespacedName: types.NamespacedName{Name: "foo", Namespace: "bar"}, } - result := reconcile.ReconcileResult{ + result := reconcile.Result{ Requeue: true, } - instance := reconcile.ReconcileFunc(func(r reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { + instance := reconcile.Func(func(r reconcile.Request) (reconcile.Result, error) { defer GinkgoRecover() Expect(r).To(Equal(request)) @@ -47,15 +47,15 @@ var _ = Describe("reconcile", func() { }) It("should call the function with the request and return an error.", func() { - request := reconcile.ReconcileRequest{ + request := reconcile.Request{ NamespacedName: types.NamespacedName{Name: "foo", Namespace: "bar"}, } - result := reconcile.ReconcileResult{ + result := reconcile.Result{ Requeue: false, } err := fmt.Errorf("hello world") - instance := reconcile.ReconcileFunc(func(r reconcile.ReconcileRequest) (reconcile.ReconcileResult, error) { + instance := reconcile.Func(func(r reconcile.Request) (reconcile.Result, error) { defer GinkgoRecover() Expect(r).To(Equal(request)) diff --git a/pkg/controller/source/internal/internal_test.go b/pkg/controller/source/internal/internal_test.go index 0fd4edb0f5..7682bb87ab 100644 --- a/pkg/controller/source/internal/internal_test.go +++ b/pkg/controller/source/internal/internal_test.go @@ -34,9 +34,9 @@ import ( var _ = Describe("Internal", func() { var instance internal.EventHandler - var funcs *eventhandler.EventHandlerFuncs + var funcs *eventhandler.Funcs BeforeEach(func() { - funcs = &eventhandler.EventHandlerFuncs{ + funcs = &eventhandler.Funcs{ CreateFunc: func(workqueue.RateLimitingInterface, event.CreateEvent) { defer GinkgoRecover() Fail("Did not expect CreateEvent to be called.") diff --git a/pkg/controller/source/source.go b/pkg/controller/source/source.go index 2c5e66a387..66d61e0b50 100644 --- a/pkg/controller/source/source.go +++ b/pkg/controller/source/source.go @@ -77,7 +77,7 @@ func (ks *KindSource) Start(handler eventhandler.EventHandler, queue workqueue.R // informers should have been injected before Start was called if ks.informers == nil { - return fmt.Errorf("must call InjectInformers on KindSource before calling Start") + return fmt.Errorf("must call DoInformers on KindSource before calling Start") } // Lookup the Informer from the Informers and add an EventHandler which populates the Queue @@ -91,7 +91,7 @@ func (ks *KindSource) Start(handler eventhandler.EventHandler, queue workqueue.R var _ inject.Informers = &KindSource{} -// InjectInformers is internal should be called only by the Controller. InjectInformers should be called before Start. +// InjectInformers is internal should be called only by the Controller. DoInformers should be called before Start. func (ks *KindSource) InjectInformers(i informer.Informers) error { if ks.informers == nil { ks.informers = i diff --git a/pkg/controller/source/source_integration_test.go b/pkg/controller/source/source_integration_test.go index e849aba87c..5a99a165d2 100644 --- a/pkg/controller/source/source_integration_test.go +++ b/pkg/controller/source/source_integration_test.go @@ -57,10 +57,10 @@ var _ = Describe("Source", func() { JustBeforeEach(func() { instance1 = &source.KindSource{Type: obj} - inject.InjectInformers(icache, instance1) + inject.DoInformers(icache, instance1) instance2 = &source.KindSource{Type: obj} - inject.InjectInformers(icache, instance2) + inject.DoInformers(icache, instance2) }) AfterEach(func() { @@ -101,8 +101,8 @@ var _ = Describe("Source", func() { } // Create an event handler to verify the events - newHandler := func(c chan interface{}) eventhandler.EventHandlerFuncs { - return eventhandler.EventHandlerFuncs{ + newHandler := func(c chan interface{}) eventhandler.Funcs { + return eventhandler.Funcs{ CreateFunc: func(rli workqueue.RateLimitingInterface, evt event.CreateEvent) { defer GinkgoRecover() Expect(rli).To(Equal(q)) diff --git a/pkg/controller/source/source_suite_test.go b/pkg/controller/source/source_suite_test.go index 1aa04872f5..c8de596c9f 100644 --- a/pkg/controller/source/source_suite_test.go +++ b/pkg/controller/source/source_suite_test.go @@ -34,7 +34,7 @@ func TestSource(t *testing.T) { RunSpecsWithDefaultAndCustomReporters(t, "Source Suite", []Reporter{test.NewlineReporter{}}) } -var testenv *test.TestEnvironment +var testenv *test.Environment var config *rest.Config var clientset *kubernetes.Clientset var icache informer.Informers @@ -43,7 +43,7 @@ var stop = make(chan struct{}) var _ = BeforeSuite(func() { logf.SetLogger(logf.ZapLogger(true)) - testenv = &test.TestEnvironment{} + testenv = &test.Environment{} var err error config, err = testenv.Start() diff --git a/pkg/controller/source/source_test.go b/pkg/controller/source/source_test.go index 2c8f7b7016..4e418874e0 100644 --- a/pkg/controller/source/source_test.go +++ b/pkg/controller/source/source_test.go @@ -64,8 +64,8 @@ var _ = Describe("Source", func() { instance := &source.KindSource{ Type: &corev1.Pod{}, } - inject.InjectInformers(ic, instance) - err := instance.Start(eventhandler.EventHandlerFuncs{ + inject.DoInformers(ic, instance) + err := instance.Start(eventhandler.Funcs{ CreateFunc: func(q2 workqueue.RateLimitingInterface, evt event.CreateEvent) { defer GinkgoRecover() Expect(q2).To(Equal(q)) @@ -106,7 +106,7 @@ var _ = Describe("Source", func() { Type: &corev1.Pod{}, } instance.InjectInformers(ic) - err := instance.Start(eventhandler.EventHandlerFuncs{ + err := instance.Start(eventhandler.Funcs{ CreateFunc: func(q2 workqueue.RateLimitingInterface, evt event.CreateEvent) { defer GinkgoRecover() Fail("Unexpected CreateEvent") @@ -155,8 +155,8 @@ var _ = Describe("Source", func() { instance := &source.KindSource{ Type: &corev1.Pod{}, } - inject.InjectInformers(ic, instance) - err := instance.Start(eventhandler.EventHandlerFuncs{ + inject.DoInformers(ic, instance) + err := instance.Start(eventhandler.Funcs{ CreateFunc: func(workqueue.RateLimitingInterface, event.CreateEvent) { defer GinkgoRecover() Fail("Unexpected DeleteEvent") @@ -196,7 +196,7 @@ var _ = Describe("Source", func() { Type: &corev1.Pod{}, } instance.InjectInformers(ic) - err := instance.Start(eventhandler.EventHandlerFuncs{}, q) + err := instance.Start(eventhandler.Funcs{}, q) Expect(err).To(HaveOccurred()) close(done) diff --git a/pkg/runtime/inject/inject.go b/pkg/runtime/inject/inject.go index 32b4d21857..8c7614fb15 100644 --- a/pkg/runtime/inject/inject.go +++ b/pkg/runtime/inject/inject.go @@ -29,9 +29,9 @@ type Informers interface { InjectInformers(informer.Informers) error } -// InjectInformers will set informers on i and return the result if it implements Informers. Returns +// DoInformers will set informers on i and return the result if it implements Informers. Returns //// false if i does not implement Informers. -func InjectInformers(informers informer.Informers, i interface{}) (bool, error) { +func DoInformers(informers informer.Informers, i interface{}) (bool, error) { if s, ok := i.(Informers); ok { return true, s.InjectInformers(informers) } @@ -44,9 +44,9 @@ type Config interface { InjectConfig(*rest.Config) error } -// InjectConfig will set config on i and return the result if it implements Config. Returns +// DoConfig will set config on i and return the result if it implements Config. Returns //// false if i does not implement Config. -func InjectConfig(config *rest.Config, i interface{}) (bool, error) { +func DoConfig(config *rest.Config, i interface{}) (bool, error) { if s, ok := i.(Config); ok { return true, s.InjectConfig(config) } @@ -59,9 +59,9 @@ type Client interface { InjectClient(client.Interface) error } -// InjectClient will set client on i and return the result if it implements Client. Returns +// DoClient will set client on i and return the result if it implements Client. Returns //// false if i does not implement Client. -func InjectClient(client client.Interface, i interface{}) (bool, error) { +func DoClient(client client.Interface, i interface{}) (bool, error) { if s, ok := i.(Client); ok { return true, s.InjectClient(client) } @@ -74,9 +74,9 @@ type Scheme interface { InjectScheme(scheme *runtime.Scheme) error } -// InjectScheme will set client and return the result on i if it implements Scheme. Returns +// DoScheme will set client and return the result on i if it implements Scheme. Returns // false if i does not implement Scheme. -func InjectScheme(scheme *runtime.Scheme, i interface{}) (bool, error) { +func DoScheme(scheme *runtime.Scheme, i interface{}) (bool, error) { if is, ok := i.(Scheme); ok { return true, is.InjectScheme(scheme) } diff --git a/pkg/test/server.go b/pkg/test/server.go index fef8ec84fb..17d623c0ff 100644 --- a/pkg/test/server.go +++ b/pkg/test/server.go @@ -33,21 +33,21 @@ const ( defaultEtcdBin = "/usr/local/kubebuilder/bin/etcd" ) -// TestEnvironment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and +// Environment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and // install extension APIs -type TestEnvironment struct { +type Environment struct { ControlPlane integration.ControlPlane Config *rest.Config CRDs []*extensionsv1beta1.CustomResourceDefinition } // Stop stops a running server -func (te *TestEnvironment) Stop() { +func (te *Environment) Stop() { te.ControlPlane.Stop() } // Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on -func (te *TestEnvironment) Start() (*rest.Config, error) { +func (te *Environment) Start() (*rest.Config, error) { te.ControlPlane = integration.ControlPlane{} if os.Getenv(envKubeAPIServerBin) == "" { te.ControlPlane.APIServer = &integration.APIServer{Path: defaultKubeAPIServerBin} From 7f88891cea1ea68bb67fd446e42b2777b5fd90a7 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Thu, 7 Jun 2018 20:29:38 -0700 Subject: [PATCH 3/4] fix issue with test refactor --- .travis.yml | 4 +--- install_test.sh => test.sh | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) rename install_test.sh => test.sh (95%) diff --git a/.travis.yml b/.travis.yml index b5bb4c7b4d..7836fdf5b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,7 @@ install: script: - go vet ./pkg/... - golint -set_exit_status ./pkg/... -- TRACE=1 ./install_test.sh -- go test github.com/kubernetes-sigs/controller-runtime/pkg/... -- go install github.com/kubernetes-sigs/controller-runtime/example +- TRACE=1 ./test.sh # TBD. Suppressing for now. diff --git a/install_test.sh b/test.sh similarity index 95% rename from install_test.sh rename to test.sh index c4795ea3d3..01f6faeb1d 100755 --- a/install_test.sh +++ b/test.sh @@ -99,4 +99,7 @@ function setup_envs { fetch_kb_tools # setup testing env -setup_envs \ No newline at end of file +setup_envs + +go test github.com/kubernetes-sigs/controller-runtime/pkg/... +go install github.com/kubernetes-sigs/controller-runtime/example From a81c5353f3eea2a8252b88af1ddd5c678b00eb44 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Thu, 7 Jun 2018 20:45:46 -0700 Subject: [PATCH 4/4] address vet errors introduced by lint errors --- pkg/controller/eventhandler/example_test.go | 2 +- pkg/controller/predicate/example_test.go | 2 +- pkg/controller/reconcile/example_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/eventhandler/example_test.go b/pkg/controller/eventhandler/example_test.go index 8058047571..699d5e4b75 100644 --- a/pkg/controller/eventhandler/example_test.go +++ b/pkg/controller/eventhandler/example_test.go @@ -76,7 +76,7 @@ func ExampleEnqueueMappedHandler() { } // This example implements eventhandler.EnqueueHandler. -func ExampleEventHandlerFuncs() { +func ExampleFuncs() { // controller is a controller.controller c.Watch( &source.KindSource{Type: &corev1.Pod{}}, diff --git a/pkg/controller/predicate/example_test.go b/pkg/controller/predicate/example_test.go index f3abd68b5a..ce115cc342 100644 --- a/pkg/controller/predicate/example_test.go +++ b/pkg/controller/predicate/example_test.go @@ -24,7 +24,7 @@ import ( var p predicate.Predicate // This example creates a new Predicate to drop Update Events where the Generation has not changed. -func ExamplePredicateFuncs() { +func ExampleFuncs() { p = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { return e.MetaOld.GetGeneration() != e.MetaNew.GetGeneration() diff --git a/pkg/controller/reconcile/example_test.go b/pkg/controller/reconcile/example_test.go index 4dec470415..563772a982 100644 --- a/pkg/controller/reconcile/example_test.go +++ b/pkg/controller/reconcile/example_test.go @@ -24,7 +24,7 @@ import ( ) // This example implements a simple no-op reconcile function that prints the object to be Reconciled. -func ExampleReconcileFunc() { +func ExampleFunc() { r := reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) { // Create your business logic to create, update, delete objects here. fmt.Printf("Name: %s, Namespace: %s", o.Name, o.Namespace)