mirror of https://github.com/k3s-io/k3s
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 ```pull/8/head
commit
3956bba384
|
@ -41,6 +41,7 @@ go_test(
|
|||
"//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/record:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/util/retry:go_default_library",
|
||||
"//test/integration/framework:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -51,6 +51,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
||||
"k8s.io/kubernetes/pkg/util/metrics"
|
||||
"k8s.io/kubernetes/staging/src/k8s.io/client-go/util/retry"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
)
|
||||
|
||||
|
@ -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)) {
|
||||
for _, fg := range featureGates() {
|
||||
func() {
|
||||
|
@ -832,7 +849,7 @@ func TestLaunchWithHashCollision(t *testing.T) {
|
|||
// Wait for the DaemonSet to be created before proceeding
|
||||
err = waitForDaemonSetAndControllerRevisionCreated(clientset, ds.Name, ds.Namespace)
|
||||
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{})
|
||||
|
@ -875,10 +892,9 @@ func TestLaunchWithHashCollision(t *testing.T) {
|
|||
|
||||
// Make an update of the DaemonSet which we know will create a hash collision when
|
||||
// the next ControllerRevision is created.
|
||||
_, err = dsClient.Update(ds)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update DaemonSet: %v", err)
|
||||
}
|
||||
ds = updateDS(t, dsClient, ds.Name, func(updateDS *apps.DaemonSet) {
|
||||
updateDS.Spec.Template.Spec.TerminationGracePeriodSeconds = &one
|
||||
})
|
||||
|
||||
// Wait for any pod with the latest Spec to exist
|
||||
err = wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) {
|
||||
|
|
Loading…
Reference in New Issue