diff --git a/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go b/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go index d44be5074c..bd13a2f93b 100644 --- a/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go +++ b/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go @@ -129,7 +129,7 @@ func newImageConfig(name string, regconf *apicfgv1.RegistrySources) *apicfgv1.Im // return fakeconfigv1client.NewSimpleClientset(objects...) // } -func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, configv1informer.SharedInformerFactory) { +func (f *fixture) newController() *Controller { f.client = fake.NewSimpleClientset(f.objects...) f.imgClient = fakeconfigv1client.NewSimpleClientset(f.imgObjects...) @@ -148,6 +148,13 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, c.imgListerSynced = alwaysReady c.eventRecorder = &record.FakeRecorder{} + stopCh := make(chan struct{}) + defer close(stopCh) + i.Start(stopCh) + i.WaitForCacheSync(stopCh) + ci.Start(stopCh) + i.WaitForCacheSync(stopCh) + for _, c := range f.ccLister { i.Machineconfiguration().V1().ControllerConfigs().Informer().GetIndexer().Add(c) } @@ -161,25 +168,19 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, ci.Config().V1().Images().Informer().GetIndexer().Add(c) } - return c, i, ci + return c } func (f *fixture) run(mcpname string) { - f.runController(mcpname, true, false) + f.runController(mcpname, false) } func (f *fixture) runExpectError(mcpname string) { - f.runController(mcpname, true, true) + f.runController(mcpname, true) } -func (f *fixture) runController(mcpname string, startInformers bool, expectError bool) { - c, i, ci := f.newController() - if startInformers { - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - ci.Start(stopCh) - } +func (f *fixture) runController(mcpname string, expectError bool) { + c := f.newController() err := c.syncImgHandler(mcpname) if !expectError && err != nil { diff --git a/pkg/controller/kubelet-config/kubelet_config_controller_test.go b/pkg/controller/kubelet-config/kubelet_config_controller_test.go index 2a5f17a3ed..2b29e194d9 100644 --- a/pkg/controller/kubelet-config/kubelet_config_controller_test.go +++ b/pkg/controller/kubelet-config/kubelet_config_controller_test.go @@ -29,8 +29,7 @@ import ( ) var ( - alwaysReady = func() bool { return true } - noResyncPeriodFunc = func() time.Duration { return 0 } + alwaysReady = func() bool { return true } ) const ( @@ -129,10 +128,10 @@ func newKubeletConfig(name string, kubeconf *kubeletconfigv1beta1.KubeletConfigu } } -func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) { +func (f *fixture) newController() *Controller { f.client = fake.NewSimpleClientset(f.objects...) - i := informers.NewSharedInformerFactory(f.client, noResyncPeriodFunc()) + i := informers.NewSharedInformerFactory(f.client, 0) c := New(templateDir, i.Machineconfiguration().V1().MachineConfigPools(), i.Machineconfiguration().V1().ControllerConfigs(), @@ -144,6 +143,11 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) c.ccListerSynced = alwaysReady c.eventRecorder = &record.FakeRecorder{} + stopCh := make(chan struct{}) + defer close(stopCh) + i.Start(stopCh) + i.WaitForCacheSync(stopCh) + for _, c := range f.ccLister { i.Machineconfiguration().V1().ControllerConfigs().Informer().GetIndexer().Add(c) } @@ -154,24 +158,19 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) i.Machineconfiguration().V1().KubeletConfigs().Informer().GetIndexer().Add(c) } - return c, i + return c } func (f *fixture) run(mcpname string) { - f.runController(mcpname, true, false) + f.runController(mcpname, false) } func (f *fixture) runExpectError(mcpname string) { - f.runController(mcpname, true, true) + f.runController(mcpname, true) } -func (f *fixture) runController(mcpname string, startInformers bool, expectError bool) { - c, i := f.newController() - if startInformers { - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - } +func (f *fixture) runController(mcpname string, expectError bool) { + c := f.newController() err := c.syncHandler(mcpname) if !expectError && err != nil { @@ -320,9 +319,8 @@ func TestKubeletConfigUpdates(t *testing.T) { f.expectPatchKubeletConfig(kc1, []uint8{0x7b, 0x22, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3a, 0x7b, 0x22, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x39, 0x39, 0x2d, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2d, 0x68, 0x35, 0x35, 0x32, 0x6d, 0x2d, 0x73, 0x6d, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x2d, 0x6d, 0x61, 0x78, 0x2d, 0x70, 0x6f, 0x64, 0x73, 0x2d, 0x6b, 0x75, 0x62, 0x65, 0x6c, 0x65, 0x74, 0x22, 0x5d, 0x7d, 0x7d}) f.expectUpdateKubeletConfig(kc1) - c, i := f.newController() + c := f.newController() stopCh := make(chan struct{}) - i.Start(stopCh) err := c.syncHandler(getKey(kc1, t)) if err != nil { @@ -345,9 +343,8 @@ func TestKubeletConfigUpdates(t *testing.T) { f.mckLister = append(f.mckLister, kc1) f.objects = append(f.objects, mcs, kcUpdate) // MachineConfig exists - c, i = f.newController() + c = f.newController() stopCh = make(chan struct{}) - i.Start(stopCh) glog.Info("Applying update") diff --git a/pkg/controller/node/node_controller_test.go b/pkg/controller/node/node_controller_test.go index 0bc456851c..09b3f845cc 100644 --- a/pkg/controller/node/node_controller_test.go +++ b/pkg/controller/node/node_controller_test.go @@ -69,7 +69,7 @@ func newMachineConfigPool(name string, selector *metav1.LabelSelector, maxUnavai } } -func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, kubeinformers.SharedInformerFactory) { +func (f *fixture) newController() *Controller { f.client = fake.NewSimpleClientset(f.objects...) f.kubeclient = k8sfake.NewSimpleClientset(f.kubeobjects...) @@ -82,6 +82,13 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, c.nodeListerSynced = alwaysReady c.eventRecorder = &record.FakeRecorder{} + stopCh := make(chan struct{}) + defer close(stopCh) + i.Start(stopCh) + i.WaitForCacheSync(stopCh) + k8sI.Start(stopCh) + k8sI.WaitForCacheSync(stopCh) + for _, c := range f.mcpLister { i.Machineconfiguration().V1().MachineConfigPools().Informer().GetIndexer().Add(c) } @@ -90,25 +97,19 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, k8sI.Core().V1().Nodes().Informer().GetIndexer().Add(m) } - return c, i, k8sI + return c } func (f *fixture) run(pool string) { - f.runController(pool, true, false) + f.runController(pool, false) } func (f *fixture) runExpectError(pool string) { - f.runController(pool, true, true) + f.runController(pool, true) } -func (f *fixture) runController(pool string, startInformers bool, expectError bool) { - c, i, k8sI := f.newController() - if startInformers { - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - k8sI.Start(stopCh) - } +func (f *fixture) runController(pool string, expectError bool) { + c := f.newController() err := c.syncHandler(pool) if !expectError && err != nil { @@ -272,11 +273,7 @@ func TestGetPoolForNode(t *testing.T) { f.objects = append(f.objects, test.pools[idx]) } - c, i, k8sI := f.newController() - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - k8sI.Start(stopCh) + c := f.newController() got, err := c.getPoolForNode(node) if err != nil && !test.err { @@ -720,11 +717,7 @@ func TestSetDesiredMachineConfigAnnotation(t *testing.T) { f.nodeLister = append(f.nodeLister, test.node) f.kubeobjects = append(f.kubeobjects, test.node) - c, i, k8sI := f.newController() - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - k8sI.Start(stopCh) + c := f.newController() err := c.setDesiredMachineConfigAnnotation(test.node.Name, "v1") if err != nil { diff --git a/pkg/controller/render/render_controller_test.go b/pkg/controller/render/render_controller_test.go index 6c10d1cfeb..9adb16bc97 100644 --- a/pkg/controller/render/render_controller_test.go +++ b/pkg/controller/render/render_controller_test.go @@ -75,7 +75,7 @@ func newMachineConfig(name string, labels map[string]string, osurl string, files } } -func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) { +func (f *fixture) newController() *Controller { f.client = fake.NewSimpleClientset(f.objects...) i := informers.NewSharedInformerFactory(f.client, noResyncPeriodFunc()) @@ -86,6 +86,11 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) c.mcListerSynced = alwaysReady c.eventRecorder = &record.FakeRecorder{} + stopCh := make(chan struct{}) + defer close(stopCh) + i.Start(stopCh) + i.WaitForCacheSync(stopCh) + for _, c := range f.mcpLister { i.Machineconfiguration().V1().MachineConfigPools().Informer().GetIndexer().Add(c) } @@ -94,24 +99,19 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) i.Machineconfiguration().V1().MachineConfigs().Informer().GetIndexer().Add(m) } - return c, i + return c } func (f *fixture) run(mcpname string) { - f.runController(mcpname, true, false) + f.runController(mcpname, false) } func (f *fixture) runExpectError(mcpname string) { - f.runController(mcpname, true, true) + f.runController(mcpname, true) } -func (f *fixture) runController(mcpname string, startInformers bool, expectError bool) { - c, i := f.newController() - if startInformers { - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - } +func (f *fixture) runController(mcpname string, expectError bool) { + c := f.newController() err := c.syncHandler(mcpname) if !expectError && err != nil { diff --git a/pkg/controller/template/template_controller_test.go b/pkg/controller/template/template_controller_test.go index f06ec77a72..d13acdc52c 100644 --- a/pkg/controller/template/template_controller_test.go +++ b/pkg/controller/template/template_controller_test.go @@ -77,7 +77,7 @@ func newPullSecret(name string, contents []byte) *corev1.Secret { } } -func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) { +func (f *fixture) newController() *Controller { f.client = fake.NewSimpleClientset(f.objects...) f.kubeclient = k8sfake.NewSimpleClientset(f.kubeobjects...) @@ -90,6 +90,11 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) c.mcListerSynced = alwaysReady c.eventRecorder = &record.FakeRecorder{} + stopCh := make(chan struct{}) + defer close(stopCh) + i.Start(stopCh) + i.WaitForCacheSync(stopCh) + for _, c := range f.ccLister { i.Machineconfiguration().V1().ControllerConfigs().Informer().GetIndexer().Add(c) } @@ -98,24 +103,19 @@ func (f *fixture) newController() (*Controller, informers.SharedInformerFactory) i.Machineconfiguration().V1().MachineConfigs().Informer().GetIndexer().Add(m) } - return c, i + return c } func (f *fixture) run(ccname string) { - f.runController(ccname, true, false) + f.runController(ccname, false) } func (f *fixture) runExpectError(ccname string) { - f.runController(ccname, true, true) + f.runController(ccname, true) } -func (f *fixture) runController(ccname string, startInformers bool, expectError bool) { - c, i := f.newController() - if startInformers { - stopCh := make(chan struct{}) - defer close(stopCh) - i.Start(stopCh) - } +func (f *fixture) runController(ccname string, expectError bool) { + c := f.newController() err := c.syncHandler(ccname) if !expectError && err != nil {