diff --git a/pkg/registry/core/service/ipallocator/controller/repairip.go b/pkg/registry/core/service/ipallocator/controller/repairip.go index 2b207599de8..d263581adbe 100644 --- a/pkg/registry/core/service/ipallocator/controller/repairip.go +++ b/pkg/registry/core/service/ipallocator/controller/repairip.go @@ -42,6 +42,7 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/servicecidr" "k8s.io/kubernetes/pkg/apis/core/v1/helper" + "k8s.io/kubernetes/pkg/controlplane/controller/defaultservicecidr" "k8s.io/kubernetes/pkg/registry/core/service/ipallocator" "k8s.io/utils/clock" netutils "k8s.io/utils/net" @@ -203,6 +204,20 @@ func (r *RepairIPAddress) RunUntil(onFirstSuccess func(), stopCh chan struct{}) return } + // wait for the default ServiceCIDR + ctx := wait.ContextForChannel(stopCh) + err := wait.PollUntilContextCancel(ctx, 100*time.Millisecond, true, func(context.Context) (bool, error) { + _, err := r.serviceCIDRLister.Get(defaultservicecidr.DefaultServiceCIDRName) + if err != nil { + return false, nil + } + return true, nil + }) + if err != nil { + runtime.HandleError(err) + return + } + // First sync goes through all the Services and IPAddresses in the cache, // once synced, it signals the main loop and works using the handlers, since // it's less expensive and more optimal.