Skip to content

Fix incorrect machineinformer callback #1002

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func NewController(
// MachineDeployment Controller Informers
_, _ = machineInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: controller.updateMachineToMachineDeployment,
DeleteFunc: controller.deleteMachineDeployment,
DeleteFunc: controller.deleteMachineToMachineDeployment,
})

_, _ = machineSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
19 changes: 10 additions & 9 deletions pkg/controller/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (dc *controller) deleteMachineDeployment(obj interface{}) {
}
d, ok = tombstone.Obj.(*v1alpha1.MachineDeployment)
if !ok {
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a Machine Deployment %#v", obj))
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a Machine Deployment %#v", obj))
return
}
}
Expand Down Expand Up @@ -199,12 +199,12 @@ func (dc *controller) deleteMachineSetToDeployment(obj interface{}) {
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", obj))
return
}
machineSet, ok = tombstone.Obj.(*v1alpha1.MachineSet)
if !ok {
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a MachineSet %#v", obj))
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a MachineSet %#v", obj))
return
}
}
Expand Down Expand Up @@ -249,7 +249,8 @@ func (dc *controller) updateMachineToMachineDeployment(old, cur any) {
}

// deleteMachine will enqueue a Recreate Deployment once all of its Machines have stopped running.
func (dc *controller) deleteMachineToMachineDeployment(ctx context.Context, obj interface{}) {
func (dc *controller) deleteMachineToMachineDeployment(obj interface{}) {
ctx := context.Background()
machine, ok := obj.(*v1alpha1.Machine)

// When a delete is dropped, the relist will notice a Machine in the store not
Expand All @@ -259,12 +260,12 @@ func (dc *controller) deleteMachineToMachineDeployment(ctx context.Context, obj
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", obj))
return
}
machine, ok = tombstone.Obj.(*v1alpha1.Machine)
if !ok {
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a machine %#v", obj))
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a machine %#v", obj))
return
}
}
Expand Down Expand Up @@ -292,7 +293,7 @@ func (dc *controller) deleteMachineToMachineDeployment(ctx context.Context, obj
func (dc *controller) enqueueMachineDeployment(deployment *v1alpha1.MachineDeployment) {
key, err := KeyFunc(deployment)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %#v: %v", deployment, err))
utilruntime.HandleError(fmt.Errorf("couldn't get key for object %#v: %v", deployment, err))
return
}

Expand All @@ -302,7 +303,7 @@ func (dc *controller) enqueueMachineDeployment(deployment *v1alpha1.MachineDeplo
func (dc *controller) enqueueRateLimited(deployment *v1alpha1.MachineDeployment) {
key, err := KeyFunc(deployment)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %#v: %v", deployment, err))
utilruntime.HandleError(fmt.Errorf("couldn't get key for object %#v: %v", deployment, err))
return
}

Expand All @@ -313,7 +314,7 @@ func (dc *controller) enqueueRateLimited(deployment *v1alpha1.MachineDeployment)
func (dc *controller) enqueueMachineDeploymentAfter(deployment *v1alpha1.MachineDeployment, after time.Duration) {
key, err := KeyFunc(deployment)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %#v: %v", deployment, err))
utilruntime.HandleError(fmt.Errorf("couldn't get key for object %#v: %v", deployment, err))
return
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ var _ = Describe("machineDeployment", func() {

defer trackers.Stop()
waitForCacheSync(stop, c)
c.deleteMachineToMachineDeployment(context.Background(), testMachine)
c.deleteMachineToMachineDeployment(testMachine)

waitForCacheSync(stop, c)
Expect(c.machineDeploymentQueue.Len()).To(Equal(queueLength))
Expand Down Expand Up @@ -1359,7 +1359,7 @@ var _ = Describe("machineDeployment", func() {

defer trackers.Stop()
waitForCacheSync(stop, c)
actualMachineSets, err := c.getMachineSetsForMachineDeployment(context.Background(), testMachineDeployment)
actualMachineSets, err := c.getMachineSetsForMachineDeployment(context.TODO(), testMachineDeployment)

waitForCacheSync(stop, c)
if expectedErr != nil {
Expand Down Expand Up @@ -2088,7 +2088,7 @@ var _ = Describe("machineDeployment", func() {

defer trackers.Stop()
waitForCacheSync(stop, c)
c.terminateMachineSets(context.Background(), testMachineSets, testMachineDeployment)
c.terminateMachineSets(context.TODO(), testMachineSets, testMachineDeployment)

waitForCacheSync(stop, c)
actualMachineSets, _ := c.controlMachineClient.MachineSets(testNamespace).List(context.Background(), metav1.ListOptions{})
Expand Down Expand Up @@ -2158,7 +2158,7 @@ var _ = Describe("machineDeployment", func() {

defer trackers.Stop()
waitForCacheSync(stop, c)
c.deleteMachineDeploymentFinalizers(context.Background(), testMachineDeployment)
c.deleteMachineDeploymentFinalizers(context.TODO(), testMachineDeployment)

waitForCacheSync(stop, c)
actualMachineDeployment, _ := c.controlMachineClient.MachineDeployments(testNamespace).Get(context.Background(), testMachineDeployment.Name, metav1.GetOptions{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func (c *controller) prepareMachineForDeletion(ctx context.Context, targetMachin

machineSetKey, err := KeyFunc(machineSet)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for %v %#v: %v", machineSet.Kind, machineSet, err))
utilruntime.HandleError(fmt.Errorf("couldn't get key for %v %#v: %v", machineSet.Kind, machineSet, err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/machineset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ var _ = Describe("machineset", func() {
activeMachines := []*machinev1.Machine{testActiveMachine1, testActiveMachine2}

testMachineSet.TypeMeta = metav1.TypeMeta{}
Err := c.manageReplicas(context.Background(), activeMachines, testMachineSet)
Err := c.manageReplicas(context.TODO(), activeMachines, testMachineSet)
waitForCacheSync(stop, c)

Expect(Err).Should(BeNil())
Expand All @@ -747,7 +747,7 @@ var _ = Describe("machineset", func() {
waitForCacheSync(stop, c)

activeMachines := []*machinev1.Machine{testActiveMachine1, testActiveMachine2}
Expect(c.manageReplicas(context.Background(), activeMachines, testMachineSet)).NotTo(HaveOccurred())
Expect(c.manageReplicas(context.TODO(), activeMachines, testMachineSet)).NotTo(HaveOccurred())
waitForCacheSync(stop, c)
// TODO: Could not use Listers here, need to check more.
machines, err := c.controlMachineClient.Machines(testNamespace).List(context.Background(), metav1.ListOptions{})
Expand Down Expand Up @@ -837,7 +837,7 @@ var _ = Describe("machineset", func() {
Expect(len(machines.Items)).To(Equal(int(testMachineSet.Spec.Replicas + 1)))

activeMachines := []*machinev1.Machine{testActiveMachine1, testActiveMachine2, testActiveMachine3, testActiveMachine4}
Err := c.manageReplicas(context.Background(), activeMachines, testMachineSet)
Err := c.manageReplicas(context.TODO(), activeMachines, testMachineSet)
waitForCacheSync(stop, c)
machines, _ = c.controlMachineClient.Machines(testNamespace).List(context.Background(), metav1.ListOptions{})
Expect(len(machines.Items)).To(Equal(int(testMachineSet.Spec.Replicas)))
Expand Down