Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watching Channels doesn't work #116

Closed
AMecea opened this issue Aug 23, 2018 · 1 comment
Closed

Watching Channels doesn't work #116

AMecea opened this issue Aug 23, 2018 · 1 comment

Comments

@AMecea
Copy link

AMecea commented Aug 23, 2018

Adding a watch on channels, as mentioned in kubebuilder docs, on a fresh generated controller fails when running tests with the following error:

	testing_t_support.go:22: 
			/home/u/go/src/github.com/presslabs/mysql-operator/vendor/github.com/onsi/gomega/internal/assertion/assertion.go:69 +0x1ed
		github.com/presslabs/mysql-operator/vendor/github.com/onsi/gomega/internal/assertion.(*Assertion).NotTo(0xc42039ba40, 0x1332420, 0x1b92b68, 0x0, 0x0, 0x0, 0x1342260)
			/home/u/go/src/github.com/presslabs/mysql-operator/vendor/github.com/onsi/gomega/internal/assertion/assertion.go:43 +0xae
		github.com/presslabs/mysql-operator/pkg/controller/mysqlbackup.TestReconcile(0xc42010e1e0)
			/home/u/go/src/github.com/presslabs/mysql-operator/pkg/controller/mysqlbackup/mysqlbackup_controller_test.go:53 +0x2f5
		testing.tRunner(0xc42010e1e0, 0x12ae268)
			/usr/local/go/src/testing/testing.go:777 +0xd0
		created by testing.(*T).Run
			/usr/local/go/src/testing/testing.go:824 +0x2e0
		
		Expected error:
		    <*errors.errorString | 0xc4200bf5d0>: {
		        s: "must call InjectStop on Channel before calling Start",
		    }
		    must call InjectStop on Channel before calling Start
		not to have occurred

The changes that I made to a fresh generated controller are:

diff --git a/pkg/controller/mysqlbackup/mysqlbackup_controller.go b/pkg/controller/mysqlbackup/mysqlbackup_controller.go
index bebdfce8..7935c0fb 100644
--- a/pkg/controller/mysqlbackup/mysqlbackup_controller.go
+++ b/pkg/controller/mysqlbackup/mysqlbackup_controller.go
@@ -35,6 +35,8 @@ import (
        "sigs.k8s.io/controller-runtime/pkg/manager"
        "sigs.k8s.io/controller-runtime/pkg/reconcile"
        "sigs.k8s.io/controller-runtime/pkg/source"
+
+       "sigs.k8s.io/controller-runtime/pkg/event"
 )
 
 /**
@@ -78,6 +80,15 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
                return err
        }
 
+       events := make(chan event.GenericEvent)
+       err = c.Watch(
+               &source.Channel{Source: events},
+               &handler.EnqueueRequestForObject{},
+       )
+       if err != nil {
+               return err
+       }
+
        return nil
 }

What happens:

  • the stop channel is added after the watcher is registered, when the manager is started
  • then when the Channel source is registered in the Watch method the stop channel is inserted but its inserts a nil channel.
  • when the source starts checks for a stop channel to be different than nil and fails , here
@AMecea
Copy link
Author

AMecea commented Aug 23, 2018

I will close it, it's a duplicate of #103

@AMecea AMecea closed this as completed Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant