@@ -28,7 +28,7 @@ func TestNodeController_Run(t *testing.T) {
2828 client := mocks .NewMockClient (ctrl )
2929 kubeClient := fake .NewSimpleClientset ()
3030 informer := informers .NewSharedInformerFactory (kubeClient , 0 ).Core ().V1 ().Nodes ()
31- mockQueue := workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [any ]{Name : "test" })
31+ mockQueue := workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [nodeRequest ]{Name : "test" })
3232
3333 nodeCtrl := newNodeController (kubeClient , client , informer , newInstances (client ))
3434 nodeCtrl .queue = mockQueue
@@ -68,7 +68,7 @@ func TestNodeController_processNext(t *testing.T) {
6868 defer ctrl .Finish ()
6969 client := mocks .NewMockClient (ctrl )
7070 kubeClient := fake .NewSimpleClientset ()
71- queue := workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [any ]{Name : "testQueue" })
71+ queue := workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [nodeRequest ]{Name : "testQueue" })
7272 node := & v1.Node {
7373 ObjectMeta : metav1.ObjectMeta {
7474 Name : "test" ,
@@ -87,10 +87,11 @@ func TestNodeController_processNext(t *testing.T) {
8787 queue : queue ,
8888 metadataLastUpdate : make (map [string ]time.Time ),
8989 ttl : defaultMetadataTTL ,
90+ nodeLastAdded : make (map [string ]time.Time ),
9091 }
9192
9293 t .Run ("should return no error on unknown errors" , func (t * testing.T ) {
93- queue . Add (node )
94+ controller . addNodeToQueue (node )
9495 client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {}, errors .New ("lookup failed" ))
9596 result := controller .processNext ()
9697 assert .True (t , result , "processNext should return true" )
@@ -99,22 +100,23 @@ func TestNodeController_processNext(t *testing.T) {
99100 }
100101 })
101102
102- t .Run ("should return no error if node exists" , func (t * testing.T ) {
103- queue .Add (node )
104- publicIP := net .ParseIP ("172.234.31.123" )
105- privateIP := net .ParseIP ("192.168.159.135" )
106- client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {
107- {ID : 111 , Label : "test" , IPv4 : []* net.IP {& publicIP , & privateIP }, HostUUID : "111" },
108- }, nil )
103+ t .Run ("should return no error if timestamp for node being processed is older than the most recent request" , func (t * testing.T ) {
104+ controller .addNodeToQueue (node )
105+ controller .nodeLastAdded ["test" ] = time .Now ().Add (controller .ttl )
109106 result := controller .processNext ()
110107 assert .True (t , result , "processNext should return true" )
111108 if queue .Len () != 0 {
112109 t .Errorf ("expected queue to be empty, got %d items" , queue .Len ())
113110 }
114111 })
115112
116- t .Run ("should return no error if queued object is not of type Node" , func (t * testing.T ) {
117- queue .Add ("abc" )
113+ t .Run ("should return no error if node exists" , func (t * testing.T ) {
114+ controller .addNodeToQueue (node )
115+ publicIP := net .ParseIP ("172.234.31.123" )
116+ privateIP := net .ParseIP ("192.168.159.135" )
117+ client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {
118+ {ID : 111 , Label : "test" , IPv4 : []* net.IP {& publicIP , & privateIP }, HostUUID : "111" },
119+ }, nil )
118120 result := controller .processNext ()
119121 assert .True (t , result , "processNext should return true" )
120122 if queue .Len () != 0 {
@@ -123,7 +125,7 @@ func TestNodeController_processNext(t *testing.T) {
123125 })
124126
125127 t .Run ("should return no error if node in k8s doesn't exist" , func (t * testing.T ) {
126- queue . Add (node )
128+ controller . addNodeToQueue (node )
127129 controller .kubeclient = fake .NewSimpleClientset ()
128130 defer func () { controller .kubeclient = kubeClient }()
129131 result := controller .processNext ()
@@ -134,9 +136,9 @@ func TestNodeController_processNext(t *testing.T) {
134136 })
135137
136138 t .Run ("should return error and requeue when it gets 429 from linode API" , func (t * testing.T ) {
137- queue = workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [any ]{Name : "testQueue1" })
138- queue .Add (node )
139+ queue = workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [nodeRequest ]{Name : "testQueue1" })
139140 controller .queue = queue
141+ controller .addNodeToQueue (node )
140142 client := mocks .NewMockClient (ctrl )
141143 controller .instances = newInstances (client )
142144 retryInterval = 1 * time .Nanosecond
@@ -150,9 +152,9 @@ func TestNodeController_processNext(t *testing.T) {
150152 })
151153
152154 t .Run ("should return error and requeue when it gets error >= 500 from linode API" , func (t * testing.T ) {
153- queue = workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [any ]{Name : "testQueue2" })
154- queue .Add (node )
155+ queue = workqueue .NewTypedDelayingQueueWithConfig (workqueue.TypedDelayingQueueConfig [nodeRequest ]{Name : "testQueue2" })
155156 controller .queue = queue
157+ controller .addNodeToQueue (node )
156158 client := mocks .NewMockClient (ctrl )
157159 controller .instances = newInstances (client )
158160 retryInterval = 1 * time .Nanosecond
0 commit comments