From 164276175fb2fa36d223e3fdeae799d8cf86b0cd Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Mon, 13 Mar 2023 23:04:06 +0000 Subject: [PATCH] plumb the new multicidr clusterip allocator --- pkg/registry/core/rest/storage_core.go | 23 ++++++++++++++++++++-- pkg/registry/core/service/storage/alloc.go | 6 ++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/registry/core/rest/storage_core.go b/pkg/registry/core/rest/storage_core.go index 95d0b29ede5..f808615ecd1 100644 --- a/pkg/registry/core/rest/storage_core.go +++ b/pkg/registry/core/rest/storage_core.go @@ -61,6 +61,7 @@ import ( serviceaccountstore "k8s.io/kubernetes/pkg/registry/core/serviceaccount/storage" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/util/async" + netutils "k8s.io/utils/net" ) // Config provides information needed to build RESTStorage for core. @@ -350,7 +351,16 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl if err != nil { return rangeRegistries{}, nil, nil, nil, err } - primaryClusterIPAllocator, err = ipallocator.NewIPAllocator(&serviceClusterIPRange, networkingv1alphaClient, c.Informers.Networking().V1alpha1().IPAddresses()) + // TODO(aojea) Revisit the initialization of the allocators + // since right now it depends on the service-cidr flags and + // sets the default IPFamily that may not be coherent with the + // existing default ServiceCIDR + primaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( + networkingv1alphaClient, + c.Informers.Networking().V1alpha1().ServiceCIDRs(), + c.Informers.Networking().V1alpha1().IPAddresses(), + netutils.IsIPv6CIDR(&serviceClusterIPRange), + ) if err != nil { return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster IP allocator: %v", err) } @@ -381,7 +391,16 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl if err != nil { return rangeRegistries{}, nil, nil, nil, err } - secondaryClusterIPAllocator, err = ipallocator.NewIPAllocator(&c.Services.SecondaryClusterIPRange, networkingv1alphaClient, c.Informers.Networking().V1alpha1().IPAddresses()) + // TODO(aojea) Revisit the initialization of the allocators + // since right now it depends on the service-cidr flags and + // sets the default IPFamily that may not be coherent with the + // existing default ServiceCIDR + secondaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( + networkingv1alphaClient, + c.Informers.Networking().V1alpha1().ServiceCIDRs(), + c.Informers.Networking().V1alpha1().IPAddresses(), + netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange), + ) if err != nil { return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster secondary IP allocator: %v", err) } diff --git a/pkg/registry/core/service/storage/alloc.go b/pkg/registry/core/service/storage/alloc.go index 19a64c2b887..a69261fb91f 100644 --- a/pkg/registry/core/service/storage/alloc.go +++ b/pkg/registry/core/service/storage/alloc.go @@ -405,7 +405,8 @@ func (al *Allocators) allocIPs(service *api.Service, toAlloc map[api.IPFamily]st var allocatedIP net.IP var err error if utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) { - svcAllocator, ok := allocator.(*ipallocator.Allocator) + // TODO: simplify this and avoid all this duplicate code + svcAllocator, ok := allocator.(*ipallocator.MetaAllocator) if ok { allocatedIP, err = svcAllocator.AllocateNextService(service) } else { @@ -425,7 +426,8 @@ func (al *Allocators) allocIPs(service *api.Service, toAlloc map[api.IPFamily]st } var err error if utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) { - svcAllocator, ok := allocator.(*ipallocator.Allocator) + // TODO: simplify this and avoid all this duplicate code + svcAllocator, ok := allocator.(*ipallocator.MetaAllocator) if ok { err = svcAllocator.AllocateService(service, parsedIP) } else {