mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-18 18:28:18 -05:00
fix flake on ipaddress allocator integration test
The test need to consider the time for the Delete operation to populate the ipallocator informer, otherwise, it can happen the allocator fails with a range full failing the test. Co-authored-by: hiirrxnn <hiren2004sharma@gmail.com>
This commit is contained in:
parent
59cddedb04
commit
2cfc90672a
2 changed files with 9 additions and 4 deletions
|
|
@ -419,7 +419,7 @@ func (al *Allocators) allocIPs(service *api.Service, toAlloc map[api.IPFamily]st
|
|||
el := field.ErrorList{field.Invalid(field.NewPath("spec", "clusterIPs"), service.Spec.ClusterIPs, fmt.Sprintf("failed to allocate IP: %v", err))}
|
||||
return allocated, apierrors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
}
|
||||
return allocated, apierrors.NewInternalError(fmt.Errorf("failed to allocate a serviceIP: %w", err))
|
||||
return allocated, apierrors.NewInternalError(fmt.Errorf("failed to allocate a serviceIP for Service %q: %w", service.Name, err))
|
||||
}
|
||||
allocated[family] = allocatedIP.String()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -139,9 +139,14 @@ func TestServiceAllocation(t *testing.T) {
|
|||
t.Fatalf("got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
// This time creating the second service should work.
|
||||
if _, err := client.CoreV1().Services(metav1.NamespaceDefault).Create(context.TODO(), svc(8), metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("got unexpected error: %v", err)
|
||||
// The ipallocator has an informer, and it needs to wait for the deletion to be propagated before it can allocate the IP again.
|
||||
// This time creating the second service should work, assume a maximum of 2 seconds for the informer to catch up.
|
||||
err = wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 2*time.Second, true, func(ctx context.Context) (bool, error) {
|
||||
_, err := client.CoreV1().Services(metav1.NamespaceDefault).Create(ctx, svc(8), metav1.CreateOptions{})
|
||||
return err == nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected creation failure: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue