Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down
33 changes: 15 additions & 18 deletions pkg/controller/kubelet-config/kubelet_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import (
)

var (
alwaysReady = func() bool { return true }
noResyncPeriodFunc = func() time.Duration { return 0 }
alwaysReady = func() bool { return true }
)

const (
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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")

Expand Down
37 changes: 15 additions & 22 deletions pkg/controller/node/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions pkg/controller/render/render_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions pkg/controller/template/template_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down