diff --git a/pkg/registry/core/service/storage/alloc.go b/pkg/registry/core/service/storage/alloc.go index 2fc48737538..4fcbe442bc5 100644 --- a/pkg/registry/core/service/storage/alloc.go +++ b/pkg/registry/core/service/storage/alloc.go @@ -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 { diff --git a/test/integration/servicecidr/allocator_test.go b/test/integration/servicecidr/allocator_test.go index 0e83e719a61..7ce380beed2 100644 --- a/test/integration/servicecidr/allocator_test.go +++ b/test/integration/servicecidr/allocator_test.go @@ -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) } }) }