mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 14:23:37 +00:00
fix pods tracking and internal error checking in statefulset tests
This commit is contained in:
parent
7cf91cf387
commit
a58d4f54cf
@ -450,8 +450,8 @@ func CreatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF
|
||||
om, _, ssc := setupController(client)
|
||||
om.SetCreateStatefulPodError(apierrors.NewInternalError(errors.New("API server failed")), 2)
|
||||
|
||||
if err := scaleUpStatefulSetControl(set, ssc, om, invariants); err != nil && isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError found %s", err)
|
||||
if err := scaleUpStatefulSetControl(set, ssc, om, invariants); !isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError, found %s", err)
|
||||
}
|
||||
// Update so set.Status is set for the next scaleUpStatefulSetControl call.
|
||||
var err error
|
||||
@ -514,8 +514,8 @@ func UpdatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF
|
||||
om.podsIndexer.Update(pods[0])
|
||||
|
||||
// now it should fail
|
||||
if _, err := ssc.UpdateStatefulSet(context.TODO(), set, pods); err != nil && isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError found %s", err)
|
||||
if _, err := ssc.UpdateStatefulSet(context.TODO(), set, pods); !isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError, found %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,8 +524,8 @@ func UpdateSetStatusFailure(t *testing.T, set *apps.StatefulSet, invariants inva
|
||||
om, ssu, ssc := setupController(client)
|
||||
ssu.SetUpdateStatefulSetStatusError(apierrors.NewInternalError(errors.New("API server failed")), 2)
|
||||
|
||||
if err := scaleUpStatefulSetControl(set, ssc, om, invariants); err != nil && isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError found %s", err)
|
||||
if err := scaleUpStatefulSetControl(set, ssc, om, invariants); !isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError, found %s", err)
|
||||
}
|
||||
// Update so set.Status is set for the next scaleUpStatefulSetControl call.
|
||||
var err error
|
||||
@ -576,8 +576,8 @@ func PodRecreateDeleteFailure(t *testing.T, set *apps.StatefulSet, invariants in
|
||||
pods[0].Status.Phase = v1.PodFailed
|
||||
om.podsIndexer.Update(pods[0])
|
||||
om.SetDeleteStatefulPodError(apierrors.NewInternalError(errors.New("API server failed")), 0)
|
||||
if _, err := ssc.UpdateStatefulSet(context.TODO(), set, pods); err != nil && isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSet failed to %s", err)
|
||||
if _, err := ssc.UpdateStatefulSet(context.TODO(), set, pods); !isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl did not return InternalError, found %s", err)
|
||||
}
|
||||
if err := invariants(set, om); err != nil {
|
||||
t.Error(err)
|
||||
@ -792,7 +792,7 @@ func TestStatefulSetControlScaleDownDeleteError(t *testing.T) {
|
||||
}
|
||||
*set.Spec.Replicas = 0
|
||||
om.SetDeleteStatefulPodError(apierrors.NewInternalError(errors.New("API server failed")), 2)
|
||||
if err := scaleDownStatefulSetControl(set, ssc, om, invariants); err != nil && isOrHasInternalError(err) {
|
||||
if err := scaleDownStatefulSetControl(set, ssc, om, invariants); !isOrHasInternalError(err) {
|
||||
t.Errorf("StatefulSetControl failed to throw error on delete %s", err)
|
||||
}
|
||||
set, err = om.setsLister.StatefulSets(set.Namespace).Get(set.Name)
|
||||
@ -2501,6 +2501,11 @@ func (om *fakeObjectManager) GetPod(namespace, podName string) (*v1.Pod, error)
|
||||
}
|
||||
|
||||
func (om *fakeObjectManager) UpdatePod(pod *v1.Pod) error {
|
||||
defer om.updatePodTracker.inc()
|
||||
if om.updatePodTracker.errorReady() {
|
||||
defer om.updatePodTracker.reset()
|
||||
return om.updatePodTracker.getErr()
|
||||
}
|
||||
return om.podsIndexer.Update(pod)
|
||||
}
|
||||
|
||||
@ -3356,6 +3361,16 @@ func newRevisionOrDie(set *apps.StatefulSet, revision int64) *apps.ControllerRev
|
||||
}
|
||||
|
||||
func isOrHasInternalError(err error) bool {
|
||||
agg, ok := err.(utilerrors.Aggregate)
|
||||
return !ok && !apierrors.IsInternalError(err) || ok && len(agg.Errors()) > 0 && !apierrors.IsInternalError(agg.Errors()[0])
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var agg utilerrors.Aggregate
|
||||
if errors.As(err, &agg) {
|
||||
for _, e := range agg.Errors() {
|
||||
if apierrors.IsInternalError(e) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return apierrors.IsInternalError(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user