Unverified Commit 3956bba3 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #67315 from mortent/FixFlakeDaemonsetTest

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix flakiness in daemonset TestLaunchWithHashCollisiion **What this PR does / why we need it**: Addresses flakiness in test/integration/daemonset TestLaunchWithHashCollision. It makes sure the test waits for the pod to be added to the daemonset before updating the daemonset. The should avoid the race where the daemonset gets updated in between the calls to get and update in the test. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #67273 **Special notes for your reviewer**: @janetkuo **Release note**: ```release-note NONE ```
parents cd786bda d6ffcae3
...@@ -41,6 +41,7 @@ go_test( ...@@ -41,6 +41,7 @@ go_test(
"//staging/src/k8s.io/client-go/rest:go_default_library", "//staging/src/k8s.io/client-go/rest:go_default_library",
"//staging/src/k8s.io/client-go/tools/cache:go_default_library", "//staging/src/k8s.io/client-go/tools/cache:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//staging/src/k8s.io/client-go/util/retry:go_default_library",
"//test/integration/framework:go_default_library", "//test/integration/framework:go_default_library",
], ],
) )
......
...@@ -51,6 +51,7 @@ import ( ...@@ -51,6 +51,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/factory" "k8s.io/kubernetes/pkg/scheduler/factory"
labelsutil "k8s.io/kubernetes/pkg/util/labels" labelsutil "k8s.io/kubernetes/pkg/util/labels"
"k8s.io/kubernetes/pkg/util/metrics" "k8s.io/kubernetes/pkg/util/metrics"
"k8s.io/kubernetes/staging/src/k8s.io/client-go/util/retry"
"k8s.io/kubernetes/test/integration/framework" "k8s.io/kubernetes/test/integration/framework"
) )
...@@ -461,6 +462,22 @@ func validateFailedPlacementEvent(eventClient corev1typed.EventInterface, t *tes ...@@ -461,6 +462,22 @@ func validateFailedPlacementEvent(eventClient corev1typed.EventInterface, t *tes
} }
} }
func updateDS(t *testing.T, dsClient appstyped.DaemonSetInterface, dsName string, updateFunc func(*apps.DaemonSet)) *apps.DaemonSet {
var ds *apps.DaemonSet
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
newDS, err := dsClient.Get(dsName, metav1.GetOptions{})
if err != nil {
return err
}
updateFunc(newDS)
ds, err = dsClient.Update(newDS)
return err
}); err != nil {
t.Fatalf("Failed to update DaemonSet: %v", err)
}
return ds
}
func forEachFeatureGate(t *testing.T, tf func(t *testing.T)) { func forEachFeatureGate(t *testing.T, tf func(t *testing.T)) {
for _, fg := range featureGates() { for _, fg := range featureGates() {
func() { func() {
...@@ -832,7 +849,7 @@ func TestLaunchWithHashCollision(t *testing.T) { ...@@ -832,7 +849,7 @@ func TestLaunchWithHashCollision(t *testing.T) {
// Wait for the DaemonSet to be created before proceeding // Wait for the DaemonSet to be created before proceeding
err = waitForDaemonSetAndControllerRevisionCreated(clientset, ds.Name, ds.Namespace) err = waitForDaemonSetAndControllerRevisionCreated(clientset, ds.Name, ds.Namespace)
if err != nil { if err != nil {
t.Fatalf("Failed to create DeamonSet: %v", err) t.Fatalf("Failed to create DaemonSet: %v", err)
} }
ds, err = dsClient.Get(ds.Name, metav1.GetOptions{}) ds, err = dsClient.Get(ds.Name, metav1.GetOptions{})
...@@ -875,10 +892,9 @@ func TestLaunchWithHashCollision(t *testing.T) { ...@@ -875,10 +892,9 @@ func TestLaunchWithHashCollision(t *testing.T) {
// Make an update of the DaemonSet which we know will create a hash collision when // Make an update of the DaemonSet which we know will create a hash collision when
// the next ControllerRevision is created. // the next ControllerRevision is created.
_, err = dsClient.Update(ds) ds = updateDS(t, dsClient, ds.Name, func(updateDS *apps.DaemonSet) {
if err != nil { updateDS.Spec.Template.Spec.TerminationGracePeriodSeconds = &one
t.Fatalf("Failed to update DaemonSet: %v", err) })
}
// Wait for any pod with the latest Spec to exist // Wait for any pod with the latest Spec to exist
err = wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) { err = wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment