Skip to content

Commit 02a2945

Browse files
committed
fed: Fix flakey ingress unit test
The unit test for the ingress controller was previously adding a cluster twice, which resulted in a cluster being deleted and added back. The deletion was racing the controller shutdown to close informer channels. This change ensures that the informer clears its map of informers when Stop() is called to prevent a double close, and that the test no longer adds the cluster twice.
1 parent ab9b299 commit 02a2945

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

federation/pkg/federation-controller/ingress/ingress_controller_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,10 @@ func TestIngressController(t *testing.T) {
252252
assert.True(t, reflect.DeepEqual(updatedIngress2.Spec, fedIngress.Spec), "Spec of updated ingress is not equal")
253253
assert.Equal(t, updatedIngress2.ObjectMeta.Annotations["A"], fedIngress.ObjectMeta.Annotations["A"], "Updated annotation not transferred from federated to cluster ingress.")
254254

255-
// Test add cluster
256-
t.Log("Adding a second cluster")
257-
258255
fedIngress.Annotations[staticIPNameKeyWritable] = "foo" // Make sure that the base object has a static IP name first.
259256
fedIngressWatch.Modify(&fedIngress)
260-
clusterWatch.Add(cluster2)
261257

262-
t.Log("Checking that the ingress got created in cluster 2")
258+
t.Log("Checking that the ingress got created in cluster 2 after a global ip was assigned")
263259
createdIngress2 := GetIngressFromChan(t, cluster2IngressCreateChan)
264260
assert.NotNil(t, createdIngress2)
265261
assert.True(t, reflect.DeepEqual(fedIngress.Spec, createdIngress2.Spec), "Spec of created ingress is not equal")

federation/pkg/federation-controller/util/federated_informer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ func (f *federatedInformerImpl) Stop() {
281281
for key, informer := range f.targetInformers {
282282
glog.V(4).Infof("... Closing informer channel for %q.", key)
283283
close(informer.stopChan)
284+
// Remove each informer after it has been stopped to prevent
285+
// subsequent cluster deletion from attempting to double close
286+
// an informer's stop channel.
287+
delete(f.targetInformers, key)
284288
}
285289
}
286290

0 commit comments

Comments
 (0)