forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredicate_test.go
More file actions
82 lines (73 loc) · 2.84 KB
/
predicate_test.go
File metadata and controls
82 lines (73 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package worker_test
import (
machinev1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/event"
"github.com/gardener/gardener/extensions/pkg/controller/worker"
)
var _ = Describe("Worker Predicates", func() {
Describe("#MachineNodeInfoHasChanged", func() {
var (
oldMachine *machinev1alpha1.Machine
newMachine *machinev1alpha1.Machine
createEvent event.CreateEvent
updateEvent event.UpdateEvent
deleteEvent event.DeleteEvent
genericEvent event.GenericEvent
)
BeforeEach(func() {
oldMachine = &machinev1alpha1.Machine{}
newMachine = &machinev1alpha1.Machine{}
createEvent = event.CreateEvent{
Object: newMachine,
}
updateEvent = event.UpdateEvent{
ObjectOld: oldMachine,
ObjectNew: newMachine,
}
deleteEvent = event.DeleteEvent{
Object: newMachine,
}
genericEvent = event.GenericEvent{
Object: newMachine,
}
})
It("should notice the change of the provider id", func() {
predicate := worker.MachineNodeInfoHasChanged()
newMachine.Spec.ProviderID = "foo"
Expect(predicate.Create(createEvent)).To(BeTrue())
Expect(predicate.Update(updateEvent)).To(BeTrue())
Expect(predicate.Delete(deleteEvent)).To(BeTrue())
Expect(predicate.Generic(genericEvent)).To(BeFalse())
})
It("should notice the change of the node label", func() {
predicate := worker.MachineNodeInfoHasChanged()
metav1.SetMetaDataLabel(&newMachine.ObjectMeta, "node", "ip.10-256-18-291.cluster.node")
Expect(predicate.Create(createEvent)).To(BeTrue())
Expect(predicate.Update(updateEvent)).To(BeTrue())
Expect(predicate.Delete(deleteEvent)).To(BeTrue())
Expect(predicate.Generic(genericEvent)).To(BeFalse())
})
It("should not react when there are no changes of the node label", func() {
predicate := worker.MachineNodeInfoHasChanged()
metav1.SetMetaDataLabel(&oldMachine.ObjectMeta, "node", "ip.10-256-18-291.cluster.node")
metav1.SetMetaDataLabel(&newMachine.ObjectMeta, "node", "ip.10-256-18-291.cluster.node")
Expect(predicate.Create(createEvent)).To(BeTrue())
Expect(predicate.Update(updateEvent)).To(BeFalse())
Expect(predicate.Delete(deleteEvent)).To(BeTrue())
Expect(predicate.Generic(genericEvent)).To(BeFalse())
})
It("should not react when there is not specified node label", func() {
predicate := worker.MachineNodeInfoHasChanged()
Expect(predicate.Create(createEvent)).To(BeTrue())
Expect(predicate.Update(updateEvent)).To(BeFalse())
Expect(predicate.Delete(deleteEvent)).To(BeTrue())
Expect(predicate.Generic(genericEvent)).To(BeFalse())
})
})
})