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

fix: Do not use webhook in UT #657

Merged
merged 1 commit into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pkg/controller/v1alpha2/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,23 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

if err = addWatch(mgr, c); err != nil {
log.Error(err, "Trial watch failed")
return err
}
if err = addWebhook(mgr); err != nil {
log.Error(err, "Failed to create webhook")
return err
}

log.Info("Experiment controller created")
return nil
}

// addWatch adds a new Controller to mgr with r as the reconcile.Reconciler
func addWatch(mgr manager.Manager, c controller.Controller) error {
// Watch for changes to Experiment
err = c.Watch(&source.Kind{Type: &experimentsv1alpha2.Experiment{}}, &handler.EnqueueRequestForObject{})
err := c.Watch(&source.Kind{Type: &experimentsv1alpha2.Experiment{}}, &handler.EnqueueRequestForObject{})
if err != nil {
log.Error(err, "Experiment watch failed")
return err
Expand All @@ -123,12 +138,6 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
log.Error(err, "Trial watch failed")
return err
}
if err = addWebhook(mgr); err != nil {
log.Error(err, "Failed to create webhook")
return err
}

log.Info("Experiment controller created")
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -81,3 +82,21 @@ func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}
}()
return stop, wg
}

// addForTestPurpose adds a new Controller to mgr with r as the reconcile.Reconciler.
func addForTestPurpose(mgr manager.Manager, r reconcile.Reconciler) error {
// Create a new controller
c, err := controller.New("test-experiment-controller", mgr, controller.Options{Reconciler: r})
if err != nil {
log.Error(err, "Failed to create experiment controller for test purpose.")
return err
}

if err = addWatch(mgr, c); err != nil {
log.Error(err, "Trial watch failed")
return err
}

log.Info("Experiment controller created")
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestCreateExperiment(t *testing.T) {
return nil
},
})
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())
g.Expect(addForTestPurpose(mgr, recFn)).NotTo(gomega.HaveOccurred())

stopMgr, mgrStopped := StartTestManager(mgr, g)

Expand Down Expand Up @@ -211,7 +211,7 @@ spec:
}

recFn := SetupTestReconcile(r)
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())
g.Expect(addForTestPurpose(mgr, recFn)).NotTo(gomega.HaveOccurred())

stopMgr, mgrStopped := StartTestManager(mgr, g)

Expand Down