Skip to content

Commit

Permalink
Merge pull request #37291 from mwielgus/enable_unittest_daemonset
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Enable updates in unit test for federated daemonset controller

Fixes flakiness in federated daemonset controller unit tests. Adds an option to rerun the tests multiple times. 

cc: @nikhiljindal @madhusudancs
  • Loading branch information
Kubernetes Submit Queue committed Dec 1, 2016
2 parents 2cdb97d + a50b8c9 commit ee5aaaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 36 deletions.
1 change: 1 addition & 0 deletions federation/pkg/federation-controller/daemonset/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ go_test(
"//federation/apis/federation/v1beta1:go_default_library",
"//federation/client/clientset_generated/federation_release_1_5/fake:go_default_library",
"//federation/pkg/federation-controller/util:go_default_library",
"//federation/pkg/federation-controller/util/deletionhelper:go_default_library",
"//federation/pkg/federation-controller/util/test:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/api/v1:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
federationapi "k8s.io/kubernetes/federation/apis/federation/v1beta1"
fakefedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_5/fake"
"k8s.io/kubernetes/federation/pkg/federation-controller/util"
//"k8s.io/kubernetes/federation/pkg/federation-controller/util/deletionhelper"
"k8s.io/kubernetes/federation/pkg/federation-controller/util/deletionhelper"
. "k8s.io/kubernetes/federation/pkg/federation-controller/util/test"
"k8s.io/kubernetes/pkg/api/unversioned"
apiv1 "k8s.io/kubernetes/pkg/api/v1"
Expand All @@ -46,14 +46,14 @@ func TestDaemonSetController(t *testing.T) {
RegisterFakeList("clusters", &fakeClient.Fake, &federationapi.ClusterList{Items: []federationapi.Cluster{*cluster1}})
RegisterFakeList("daemonsets", &fakeClient.Fake, &extensionsv1.DaemonSetList{Items: []extensionsv1.DaemonSet{}})
daemonsetWatch := RegisterFakeWatch("daemonsets", &fakeClient.Fake)
// daemonsetUpdateChan := RegisterFakeCopyOnUpdate("daemonsets", &fakeClient.Fake, daemonsetWatch)
daemonsetUpdateChan := RegisterFakeCopyOnUpdate("daemonsets", &fakeClient.Fake, daemonsetWatch)
clusterWatch := RegisterFakeWatch("clusters", &fakeClient.Fake)

cluster1Client := &fakekubeclientset.Clientset{}
cluster1Watch := RegisterFakeWatch("daemonsets", &cluster1Client.Fake)
RegisterFakeList("daemonsets", &cluster1Client.Fake, &extensionsv1.DaemonSetList{Items: []extensionsv1.DaemonSet{}})
cluster1CreateChan := RegisterFakeCopyOnCreate("daemonsets", &cluster1Client.Fake, cluster1Watch)
// cluster1UpdateChan := RegisterFakeCopyOnUpdate("daemonsets", &cluster1Client.Fake, cluster1Watch)
cluster1UpdateChan := RegisterFakeCopyOnUpdate("daemonsets", &cluster1Client.Fake, cluster1Watch)

cluster2Client := &fakekubeclientset.Clientset{}
cluster2Watch := RegisterFakeWatch("daemonsets", &cluster2Client.Fake)
Expand Down Expand Up @@ -96,15 +96,14 @@ func TestDaemonSetController(t *testing.T) {

// Test add federated daemonset.
daemonsetWatch.Add(&daemonset1)
/*
// TODO: Re-enable this when we have fixed these flaky tests: https://github.com/kubernetes/kubernetes/issues/36540.
// There should be 2 updates to add both the finalizers.
updatedDaemonSet := GetDaemonSetFromChan(daemonsetUpdateChan)
assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
updatedDaemonSet = GetDaemonSetFromChan(daemonsetUpdateChan)
assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, apiv1.FinalizerOrphan))
daemonset1 = *updatedDaemonSet
*/

// There should be 2 updates to add both the finalizers.
updatedDaemonSet := GetDaemonSetFromChan(daemonsetUpdateChan)
assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
updatedDaemonSet = GetDaemonSetFromChan(daemonsetUpdateChan)
assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, apiv1.FinalizerOrphan))
daemonset1 = *updatedDaemonSet

createdDaemonSet := GetDaemonSetFromChan(cluster1CreateChan)
assert.NotNil(t, createdDaemonSet)
assert.Equal(t, daemonset1.Namespace, createdDaemonSet.Namespace)
Expand All @@ -118,30 +117,24 @@ func TestDaemonSetController(t *testing.T) {
cluster1.Name, getDaemonSetKey(daemonset1.Namespace, daemonset1.Name), wait.ForeverTestTimeout)
assert.Nil(t, err, "daemonset should have appeared in the informer store")

/*
// TODO: Re-enable this when we have fixed these flaky tests: https://github.com/kubernetes/kubernetes/issues/36540.
// Test update federated daemonset.
daemonset1.Annotations = map[string]string{
"A": "B",
}
daemonsetWatch.Modify(&daemonset1)
updatedDaemonSet = GetDaemonSetFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedDaemonSet)
assert.Equal(t, daemonset1.Name, updatedDaemonSet.Name)
assert.Equal(t, daemonset1.Namespace, updatedDaemonSet.Namespace)
assert.True(t, daemonsetsEqual(daemonset1, *updatedDaemonSet),
fmt.Sprintf("expected: %v, actual: %v", daemonset1, *updatedDaemonSet))
// Test update federated daemonset.
daemonset1.Spec.Template.Name = "TEST"
daemonsetWatch.Modify(&daemonset1)
updatedDaemonSet = GetDaemonSetFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedDaemonSet)
assert.Equal(t, daemonset1.Name, updatedDaemonSet.Name)
assert.Equal(t, daemonset1.Namespace, updatedDaemonSet.Namespace)
assert.True(t, daemonsetsEqual(daemonset1, *updatedDaemonSet),
fmt.Sprintf("expected: %v, actual: %v", daemonset1, *updatedDaemonSet))
*/
// TODO: Re-enable this when we have fixed these flaky tests: https://github.com/kubernetes/kubernetes/issues/36540.
// Test update federated daemonset.
daemonset1.Annotations = map[string]string{
"A": "B",
}
daemonsetWatch.Modify(&daemonset1)
updatedDaemonSet = GetDaemonSetFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedDaemonSet)
assert.Equal(t, daemonset1.Name, updatedDaemonSet.Name)
assert.Equal(t, daemonset1.Namespace, updatedDaemonSet.Namespace)
assert.True(t, daemonsetsEqual(daemonset1, *updatedDaemonSet),
fmt.Sprintf("expected: %v, actual: %v", daemonset1, *updatedDaemonSet))

// Test update federated daemonset.
daemonset1.Spec.Template.Name = "TEST"
daemonsetWatch.Modify(&daemonset1)
err = CheckObjectFromChan(cluster1UpdateChan, MetaAndSpecCheckingFunction(&daemonset1))
assert.NoError(t, err)

// Test add cluster
clusterWatch.Add(cluster2)
Expand Down

0 comments on commit ee5aaaa

Please sign in to comment.