mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #22243 from nikhiljindal/updatePodWithRetries
deployment e2e flake: Fix updatePodWithRetries to get and then immediately try update
This commit is contained in:
commit
6deb2612dc
@ -624,7 +624,7 @@ func (r *Request) tryThrottle() {
|
|||||||
r.throttle.Accept()
|
r.throttle.Accept()
|
||||||
}
|
}
|
||||||
if latency := time.Since(now); latency > longThrottleLatency {
|
if latency := time.Since(now); latency > longThrottleLatency {
|
||||||
glog.Warningf("Throttling request took %v, request: %s", latency, r.URL().String())
|
glog.Warningf("Throttling request took %v, request: %s:%s", latency, r.verb, r.URL().String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,19 +267,17 @@ func updateRSWithRetries(rsClient unversionedextensions.ReplicaSetInterface, rs
|
|||||||
var err error
|
var err error
|
||||||
oldRs := rs
|
oldRs := rs
|
||||||
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
|
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
|
||||||
|
rs, err = rsClient.Get(oldRs.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
// Apply the update, then attempt to push it to the apiserver.
|
// Apply the update, then attempt to push it to the apiserver.
|
||||||
applyUpdate(rs)
|
applyUpdate(rs)
|
||||||
if rs, err = rsClient.Update(rs); err == nil {
|
if rs, err = rsClient.Update(rs); err == nil {
|
||||||
// rs contains the latest controller post update
|
// Update successful.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
// Update the controller with the latest resource version, if the update failed we
|
// Update could have failed due to conflict error. Try again.
|
||||||
// can't trust rs so use oldRs.Name.
|
|
||||||
if rs, err = rsClient.Get(oldRs.Name); err != nil {
|
|
||||||
// The Get failed: Value in rs cannot be trusted.
|
|
||||||
rs = oldRs
|
|
||||||
}
|
|
||||||
// The Get passed: rs contains the latest controller, expect a poll for the update.
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
// If the error is non-nil the returned controller cannot be trusted, if it is nil, the returned
|
// If the error is non-nil the returned controller cannot be trusted, if it is nil, the returned
|
||||||
@ -293,14 +291,17 @@ func updatePodWithRetries(podClient unversionedcore.PodInterface, pod *api.Pod,
|
|||||||
var err error
|
var err error
|
||||||
oldPod := pod
|
oldPod := pod
|
||||||
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
|
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
|
||||||
|
pod, err = podClient.Get(oldPod.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
// Apply the update, then attempt to push it to the apiserver.
|
// Apply the update, then attempt to push it to the apiserver.
|
||||||
applyUpdate(pod)
|
applyUpdate(pod)
|
||||||
if pod, err = podClient.Update(pod); err == nil {
|
if pod, err = podClient.Update(pod); err == nil {
|
||||||
|
// Update successful.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if pod, err = podClient.Get(oldPod.Name); err != nil {
|
// Update could have failed due to conflict error. Try again.
|
||||||
pod = oldPod
|
|
||||||
}
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
return pod, err
|
return pod, err
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package deployment
|
package deployment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -44,6 +45,23 @@ func addListPodsReactor(fakeClient *fake.Clientset, obj runtime.Object) *fake.Cl
|
|||||||
return fakeClient
|
return fakeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addGetRSReactor(fakeClient *fake.Clientset, obj runtime.Object) *fake.Clientset {
|
||||||
|
rsList, ok := obj.(*extensions.ReplicaSetList)
|
||||||
|
fakeClient.AddReactor("get", "replicasets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
name := action.(testclient.GetAction).GetName()
|
||||||
|
if ok {
|
||||||
|
for _, rs := range rsList.Items {
|
||||||
|
if rs.Name == name {
|
||||||
|
return true, &rs, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil, fmt.Errorf("could not find the requested replica set: %s", name)
|
||||||
|
|
||||||
|
})
|
||||||
|
return fakeClient
|
||||||
|
}
|
||||||
|
|
||||||
func addUpdateRSReactor(fakeClient *fake.Clientset) *fake.Clientset {
|
func addUpdateRSReactor(fakeClient *fake.Clientset) *fake.Clientset {
|
||||||
fakeClient.AddReactor("update", "replicasets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
fakeClient.AddReactor("update", "replicasets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
obj := action.(testclient.UpdateAction).GetObject().(*extensions.ReplicaSet)
|
obj := action.(testclient.UpdateAction).GetObject().(*extensions.ReplicaSet)
|
||||||
@ -346,6 +364,7 @@ func TestGetOldRCs(t *testing.T) {
|
|||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
fakeClient = addListPodsReactor(fakeClient, test.objs[0])
|
fakeClient = addListPodsReactor(fakeClient, test.objs[0])
|
||||||
fakeClient = addListRSReactor(fakeClient, test.objs[1])
|
fakeClient = addListRSReactor(fakeClient, test.objs[1])
|
||||||
|
fakeClient = addGetRSReactor(fakeClient, test.objs[1])
|
||||||
fakeClient = addUpdatePodsReactor(fakeClient)
|
fakeClient = addUpdatePodsReactor(fakeClient)
|
||||||
fakeClient = addUpdateRSReactor(fakeClient)
|
fakeClient = addUpdateRSReactor(fakeClient)
|
||||||
rss, _, err := GetOldReplicaSets(&newDeployment, fakeClient)
|
rss, _, err := GetOldReplicaSets(&newDeployment, fakeClient)
|
||||||
|
Loading…
Reference in New Issue
Block a user