diff --git a/cmd/kube-apiserver/app/aggregator.go b/cmd/kube-apiserver/app/aggregator.go index 6da672bb29f..e561980d64d 100644 --- a/cmd/kube-apiserver/app/aggregator.go +++ b/cmd/kube-apiserver/app/aggregator.go @@ -40,6 +40,7 @@ var apiVersionPriorities = merge(controlplaneapiserver.DefaultGenericAPIServiceP {Group: "batch", Version: "v1beta1"}: {Group: 17400, Version: 9}, {Group: "batch", Version: "v2alpha1"}: {Group: 17400, Version: 9}, {Group: "networking.k8s.io", Version: "v1"}: {Group: 17200, Version: 15}, + {Group: "networking.k8s.io", Version: "v1beta1"}: {Group: 17200, Version: 9}, {Group: "networking.k8s.io", Version: "v1alpha1"}: {Group: 17200, Version: 1}, {Group: "policy", Version: "v1"}: {Group: 17100, Version: 15}, {Group: "policy", Version: "v1beta1"}: {Group: 17100, Version: 9}, diff --git a/cmd/kube-controller-manager/app/networking.go b/cmd/kube-controller-manager/app/networking.go index 65314ef06c3..0c05fafeb12 100644 --- a/cmd/kube-controller-manager/app/networking.go +++ b/cmd/kube-controller-manager/app/networking.go @@ -40,8 +40,8 @@ func newServiceCIDRsControllerDescriptor() *ControllerDescriptor { func startServiceCIDRsController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) { go servicecidrs.NewController( ctx, - controllerContext.InformerFactory.Networking().V1alpha1().ServiceCIDRs(), - controllerContext.InformerFactory.Networking().V1alpha1().IPAddresses(), + controllerContext.InformerFactory.Networking().V1beta1().ServiceCIDRs(), + controllerContext.InformerFactory.Networking().V1beta1().IPAddresses(), controllerContext.ClientBuilder.ClientOrDie("service-cidrs-controller"), ).Run(ctx, 5) // TODO use component config diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index 3e132baf95f..84b65bb8d0e 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -982,7 +982,7 @@ func (s *ProxyServer) Run(ctx context.Context) error { go endpointSliceConfig.Run(ctx.Done()) if utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) { - serviceCIDRConfig := config.NewServiceCIDRConfig(ctx, informerFactory.Networking().V1alpha1().ServiceCIDRs(), s.Config.ConfigSyncPeriod.Duration) + serviceCIDRConfig := config.NewServiceCIDRConfig(ctx, informerFactory.Networking().V1beta1().ServiceCIDRs(), s.Config.ConfigSyncPeriod.Duration) serviceCIDRConfig.RegisterEventHandler(s.Proxier) go serviceCIDRConfig.Run(wait.NeverStop) } diff --git a/pkg/api/servicecidr/servicecidr.go b/pkg/api/servicecidr/servicecidr.go index 7c1e7c2c170..13ceae49251 100644 --- a/pkg/api/servicecidr/servicecidr.go +++ b/pkg/api/servicecidr/servicecidr.go @@ -21,14 +21,14 @@ import ( "net" "net/netip" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/labels" - networkinglisters "k8s.io/client-go/listers/networking/v1alpha1" + networkinglisters "k8s.io/client-go/listers/networking/v1beta1" ) // OverlapsPrefix return the list of ServiceCIDR that overlaps with the prefix passed as argument -func OverlapsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1alpha1.ServiceCIDR { - result := []*networkingv1alpha1.ServiceCIDR{} +func OverlapsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1beta1.ServiceCIDR { + result := []*networkingv1beta1.ServiceCIDR{} serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) if err != nil { return result @@ -47,8 +47,8 @@ func OverlapsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefi } // ContainsPrefix return the list of ServiceCIDR that contains the prefix passed as argument -func ContainsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1alpha1.ServiceCIDR { - result := []*networkingv1alpha1.ServiceCIDR{} +func ContainsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1beta1.ServiceCIDR { + result := []*networkingv1beta1.ServiceCIDR{} serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) if err != nil { return result @@ -67,14 +67,14 @@ func ContainsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefi } // ContainsIP return the list of ServiceCIDR that contains the IP address passed as argument -func ContainsIP(serviceCIDRLister networkinglisters.ServiceCIDRLister, ip net.IP) []*networkingv1alpha1.ServiceCIDR { +func ContainsIP(serviceCIDRLister networkinglisters.ServiceCIDRLister, ip net.IP) []*networkingv1beta1.ServiceCIDR { address := IPToAddr(ip) return ContainsAddress(serviceCIDRLister, address) } // ContainsAddress return the list of ServiceCIDR that contains the address passed as argument -func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, address netip.Addr) []*networkingv1alpha1.ServiceCIDR { - result := []*networkingv1alpha1.ServiceCIDR{} +func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, address netip.Addr) []*networkingv1beta1.ServiceCIDR { + result := []*networkingv1beta1.ServiceCIDR{} serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) if err != nil { return result diff --git a/pkg/api/servicecidr/servicecidr_test.go b/pkg/api/servicecidr/servicecidr_test.go index 7d887ed92a9..6a75166ffed 100644 --- a/pkg/api/servicecidr/servicecidr_test.go +++ b/pkg/api/servicecidr/servicecidr_test.go @@ -22,19 +22,19 @@ import ( "sort" "testing" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - networkinglisters "k8s.io/client-go/listers/networking/v1alpha1" + networkinglisters "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" netutils "k8s.io/utils/net" ) -func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.ServiceCIDR { - serviceCIDR := &networkingv1alpha1.ServiceCIDR{ +func newServiceCIDR(name, primary, secondary string) *networkingv1beta1.ServiceCIDR { + serviceCIDR := &networkingv1beta1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingv1alpha1.ServiceCIDRSpec{}, + Spec: networkingv1beta1.ServiceCIDRSpec{}, } serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) if secondary != "" { @@ -46,13 +46,13 @@ func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.Service func TestOverlapsPrefix(t *testing.T) { tests := []struct { name string - serviceCIDRs []*networkingv1alpha1.ServiceCIDR + serviceCIDRs []*networkingv1beta1.ServiceCIDR prefix netip.Prefix want []string }{ { name: "only one ServiceCIDR and IPv4 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/26"), @@ -60,7 +60,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and same IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/24"), @@ -68,7 +68,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and larger IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/16"), @@ -76,7 +76,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and non contained IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("192.168.0.0/24"), @@ -84,7 +84,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/112"), @@ -92,7 +92,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and same IPv6 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/96"), @@ -100,7 +100,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/64"), @@ -108,7 +108,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 prefix out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db2::/112"), @@ -116,7 +116,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -125,7 +125,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two overlapping ServiceCIDR and IPv4 prefix only contained in one", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -134,7 +134,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -143,7 +143,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 prefix not contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -152,7 +152,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv6 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -161,7 +161,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv6 prefix contained in one", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -170,7 +170,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and aprefix larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -179,7 +179,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and prefix out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -188,7 +188,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "multiple ServiceCIDR match with overlap contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes2", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), @@ -198,7 +198,7 @@ func TestOverlapsPrefix(t *testing.T) { }, { name: "multiple ServiceCIDR match with overlap contains", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes2", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), @@ -234,13 +234,13 @@ func TestOverlapsPrefix(t *testing.T) { func TestContainsPrefix(t *testing.T) { tests := []struct { name string - serviceCIDRs []*networkingv1alpha1.ServiceCIDR + serviceCIDRs []*networkingv1beta1.ServiceCIDR prefix netip.Prefix want []string }{ { name: "only one ServiceCIDR and IPv4 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/26"), @@ -248,7 +248,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and same IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/24"), @@ -256,7 +256,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and larger IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("10.0.0.0/16"), @@ -264,7 +264,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and non containerd IPv4 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("192.168.0.0/24"), @@ -272,7 +272,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/112"), @@ -280,7 +280,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and same IPv6 prefix", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/96"), @@ -288,7 +288,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db8::/64"), @@ -296,7 +296,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 prefix out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, prefix: netip.MustParsePrefix("2001:db2::/112"), @@ -304,7 +304,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -313,7 +313,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 prefix only contained in one", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -322,7 +322,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -331,7 +331,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 prefix not contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -340,7 +340,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv6 prefix contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -349,7 +349,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and IPv6 prefix contained in one", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -358,7 +358,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and aprefix larger", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -367,7 +367,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "two ServiceCIDR and prefix out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -376,7 +376,7 @@ func TestContainsPrefix(t *testing.T) { }, { name: "multiple ServiceCIDR match with overlap", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes2", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), @@ -412,13 +412,13 @@ func TestContainsPrefix(t *testing.T) { func TestContainsAddress(t *testing.T) { tests := []struct { name string - serviceCIDRs []*networkingv1alpha1.ServiceCIDR + serviceCIDRs []*networkingv1beta1.ServiceCIDR address netip.Addr want []string }{ { name: "only one ServiceCIDR and IPv4 address contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("10.0.0.1"), @@ -426,7 +426,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv4 address broadcast", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("10.0.0.255"), @@ -434,7 +434,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv4 address base", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("10.0.0.0"), @@ -442,7 +442,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv4 address out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("192.0.0.1"), @@ -450,7 +450,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 address contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("2001:db8::2:3"), @@ -458,7 +458,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 address broadcast", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("2001:db8::ffff:ffff"), @@ -466,7 +466,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 address base", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("2001:db8::"), @@ -474,7 +474,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "only one ServiceCIDR and IPv6 address out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), }, address: netip.MustParseAddr("2002:1:2:3::2"), @@ -482,7 +482,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 address contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -491,7 +491,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 address broadcast", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -500,7 +500,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 address base", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -509,7 +509,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and IPv4 address out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -518,7 +518,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and IPv6 address contained", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -527,7 +527,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and address broadcast", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -536,7 +536,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and address base", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -545,7 +545,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "two ServiceCIDR and address out of range", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), }, @@ -554,7 +554,7 @@ func TestContainsAddress(t *testing.T) { }, { name: "multiple ServiceCIDR match with overlap", - serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ + serviceCIDRs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes2", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), diff --git a/pkg/controller/servicecidrs/servicecidrs_controller.go b/pkg/controller/servicecidrs/servicecidrs_controller.go index b31a0b03396..64305dd62d9 100644 --- a/pkg/controller/servicecidrs/servicecidrs_controller.go +++ b/pkg/controller/servicecidrs/servicecidrs_controller.go @@ -23,7 +23,7 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingapiv1beta1 "k8s.io/api/networking/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -32,12 +32,12 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" metav1apply "k8s.io/client-go/applyconfigurations/meta/v1" - networkingapiv1alpha1apply "k8s.io/client-go/applyconfigurations/networking/v1alpha1" - networkinginformers "k8s.io/client-go/informers/networking/v1alpha1" + networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1" + networkinginformers "k8s.io/client-go/informers/networking/v1beta1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" v1core "k8s.io/client-go/kubernetes/typed/core/v1" - networkinglisters "k8s.io/client-go/listers/networking/v1alpha1" + networkinglisters "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" @@ -147,7 +147,7 @@ func (c *Controller) Run(ctx context.Context, workers int) { } func (c *Controller) addServiceCIDR(obj interface{}) { - cidr, ok := obj.(*networkingapiv1alpha1.ServiceCIDR) + cidr, ok := obj.(*networkingapiv1beta1.ServiceCIDR) if !ok { return } @@ -174,7 +174,7 @@ func (c *Controller) deleteServiceCIDR(obj interface{}) { // addIPAddress may block a ServiceCIDR deletion func (c *Controller) addIPAddress(obj interface{}) { - ip, ok := obj.(*networkingapiv1alpha1.IPAddress) + ip, ok := obj.(*networkingapiv1beta1.IPAddress) if !ok { return } @@ -186,13 +186,13 @@ func (c *Controller) addIPAddress(obj interface{}) { // deleteIPAddress may unblock a ServiceCIDR deletion func (c *Controller) deleteIPAddress(obj interface{}) { - ip, ok := obj.(*networkingapiv1alpha1.IPAddress) + ip, ok := obj.(*networkingapiv1beta1.IPAddress) if !ok { tombstone, ok := obj.(cache.DeletedFinalStateUnknown) if !ok { return } - ip, ok = tombstone.Obj.(*networkingapiv1alpha1.IPAddress) + ip, ok = tombstone.Obj.(*networkingapiv1beta1.IPAddress) if !ok { return } @@ -206,7 +206,7 @@ func (c *Controller) deleteIPAddress(obj interface{}) { // overlappingServiceCIDRs, given a ServiceCIDR return the ServiceCIDRs that contain or are contained, // this is required because adding or removing a CIDR will require to recompute the // state of each ServiceCIDR to check if can be unblocked on deletion. -func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1alpha1.ServiceCIDR) []string { +func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1beta1.ServiceCIDR) []string { result := sets.New[string]() for _, cidr := range serviceCIDR.Spec.CIDRs { if prefix, err := netip.ParsePrefix(cidr); err == nil { // if is empty err will not be nil @@ -222,9 +222,9 @@ func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1alpha1. // containingServiceCIDRs, given an IPAddress return the ServiceCIDRs that contains the IP, // as it may block or be blocking the deletion of the ServiceCIDRs that contain it. -func (c *Controller) containingServiceCIDRs(ip *networkingapiv1alpha1.IPAddress) []string { +func (c *Controller) containingServiceCIDRs(ip *networkingapiv1beta1.IPAddress) []string { // only process IPs managed by the kube-apiserver - managedBy, ok := ip.Labels[networkingapiv1alpha1.LabelManagedBy] + managedBy, ok := ip.Labels[networkingapiv1beta1.LabelManagedBy] if !ok || managedBy != ipallocator.ControllerName { return []string{} } @@ -302,15 +302,15 @@ func (c *Controller) sync(ctx context.Context, key string) error { // update the status to indicate why the ServiceCIDR can not be deleted, // it will be reevaludated by an event on any ServiceCIDR or IPAddress related object // that may remove this condition. - svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( + svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions( metav1apply.Condition(). - WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). + WithType(networkingapiv1beta1.ServiceCIDRConditionReady). WithStatus(metav1.ConditionFalse). - WithReason(networkingapiv1alpha1.ServiceCIDRReasonTerminating). + WithReason(networkingapiv1beta1.ServiceCIDRReasonTerminating). WithMessage("There are still IPAddresses referencing the ServiceCIDR, please remove them or create a new ServiceCIDR"). WithLastTransitionTime(metav1.Now())) - svcApply := networkingapiv1alpha1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) - _, err = c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}) + svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) + _, err = c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}) return err } // If there are no IPAddress depending on this ServiceCIDR is safe to remove it, @@ -333,14 +333,14 @@ func (c *Controller) sync(ctx context.Context, key string) error { } // Set Ready condition to True. - svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( + svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions( metav1apply.Condition(). - WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). + WithType(networkingapiv1beta1.ServiceCIDRConditionReady). WithStatus(metav1.ConditionTrue). WithMessage("Kubernetes Service CIDR is ready"). WithLastTransitionTime(metav1.Now())) - svcApply := networkingapiv1alpha1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) - if _, err := c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); err != nil { + svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) + if _, err := c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); err != nil { logger.Info("error updating default ServiceCIDR status", "error", err) c.eventRecorder.Eventf(cidr, v1.EventTypeWarning, "KubernetesServiceCIDRError", "The ServiceCIDR Status can not be set to Ready=True") return err @@ -350,7 +350,7 @@ func (c *Controller) sync(ctx context.Context, key string) error { } // canDeleteCIDR checks that the ServiceCIDR can be safely deleted and not leave orphan IPAddresses -func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkingapiv1alpha1.ServiceCIDR) (bool, error) { +func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkingapiv1beta1.ServiceCIDR) (bool, error) { logger := klog.FromContext(ctx) // Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted. hasParent := true @@ -379,8 +379,8 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga for _, cidr := range serviceCIDR.Spec.CIDRs { // get all the IPv4 addresses ipLabelSelector := labels.Set(map[string]string{ - networkingapiv1alpha1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))), - networkingapiv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingapiv1beta1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))), + networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName, }).AsSelectorPreValidated() ips, err := c.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -411,7 +411,7 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga return true, nil } -func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1alpha1.ServiceCIDR) error { +func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error { for _, f := range cidr.GetFinalizers() { if f == ServiceCIDRProtectionFinalizer { return nil @@ -427,7 +427,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr * if err != nil { return err } - _, err = c.client.NetworkingV1alpha1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{}) + _, err = c.client.NetworkingV1beta1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } @@ -436,7 +436,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr * } -func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1alpha1.ServiceCIDR) error { +func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error { found := false for _, f := range cidr.GetFinalizers() { if f == ServiceCIDRProtectionFinalizer { @@ -456,7 +456,7 @@ func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cid if err != nil { return err } - _, err = c.client.NetworkingV1alpha1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{}) + _, err = c.client.NetworkingV1beta1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } diff --git a/pkg/controller/servicecidrs/servicecidrs_controller_test.go b/pkg/controller/servicecidrs/servicecidrs_controller_test.go index 251fb2f019c..abb17e8090d 100644 --- a/pkg/controller/servicecidrs/servicecidrs_controller_test.go +++ b/pkg/controller/servicecidrs/servicecidrs_controller_test.go @@ -24,7 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" v1 "k8s.io/api/core/v1" - networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingapiv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" @@ -44,12 +44,12 @@ type testController struct { ipaddressesStore cache.Store } -func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1alpha1.ServiceCIDR, ips []*networkingapiv1alpha1.IPAddress) (*fake.Clientset, *testController) { +func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1beta1.ServiceCIDR, ips []*networkingapiv1beta1.IPAddress) (*fake.Clientset, *testController) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc()) - serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() cidrStore := serviceCIDRInformer.Informer().GetStore() for _, obj := range cidrs { err := cidrStore.Add(obj) @@ -57,7 +57,7 @@ func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1al t.Fatal(err) } } - ipAddressInformer := informerFactory.Networking().V1alpha1().IPAddresses() + ipAddressInformer := informerFactory.Networking().V1beta1().IPAddresses() ipStore := ipAddressInformer.Informer().GetStore() for _, obj := range ips { err := ipStore.Add(obj) @@ -97,8 +97,8 @@ func TestControllerSync(t *testing.T) { testCases := []struct { name string - cidrs []*networkingapiv1alpha1.ServiceCIDR - ips []*networkingapiv1alpha1.IPAddress + cidrs []*networkingapiv1beta1.ServiceCIDR + ips []*networkingapiv1beta1.IPAddress cidrSynced string actions [][]string // verb and resource and subresource }{ @@ -107,7 +107,7 @@ func TestControllerSync(t *testing.T) { }, { name: "default service CIDR must have finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, cidrSynced: defaultservicecidr.DefaultServiceCIDRName, @@ -115,7 +115,7 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR must have finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR("no-finalizer", "192.168.0.0/24", "2001:db2::/64"), }, cidrSynced: "no-finalizer", @@ -123,7 +123,7 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted must remove the finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, }, cidrSynced: deletedServiceCIDR.Name, @@ -131,7 +131,7 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted but within the grace period must be requeued not remove the finalizer", // TODO: assert is actually requeued - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletingServiceCIDR, }, cidrSynced: deletingServiceCIDR.Name, @@ -139,10 +139,10 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted with IPv4 addresses should update the status", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -150,11 +150,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and overlapping same range and IPv4 addresses should remove the finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -162,11 +162,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and overlapping and IPv4 addresses should remove the finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -174,11 +174,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and not overlapping and IPv4 addresses should update the status", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -186,10 +186,10 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted with IPv6 addresses should update the status", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("2001:db2::1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -197,11 +197,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and overlapping same range and IPv6 addresses should remove the finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("2001:db2::1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -209,11 +209,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and overlapping and IPv6 addresses should remove the finalizer", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/48"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("2001:db2::1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -221,11 +221,11 @@ func TestControllerSync(t *testing.T) { }, { name: "service CIDR being deleted and not overlapping and IPv6 addresses should update the status", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ deletedServiceCIDR, makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2:a:b::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("2001:db2::1"), }, cidrSynced: deletedServiceCIDR.Name, @@ -247,12 +247,12 @@ func TestControllerSync(t *testing.T) { } } -func makeServiceCIDR(name, primary, secondary string) *networkingapiv1alpha1.ServiceCIDR { - serviceCIDR := &networkingapiv1alpha1.ServiceCIDR{ +func makeServiceCIDR(name, primary, secondary string) *networkingapiv1beta1.ServiceCIDR { + serviceCIDR := &networkingapiv1beta1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{}, + Spec: networkingapiv1beta1.ServiceCIDRSpec{}, } serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) if secondary != "" { @@ -261,17 +261,17 @@ func makeServiceCIDR(name, primary, secondary string) *networkingapiv1alpha1.Ser return serviceCIDR } -func makeIPAddress(name string) *networkingapiv1alpha1.IPAddress { +func makeIPAddress(name string) *networkingapiv1beta1.IPAddress { family := string(v1.IPv4Protocol) if netutils.IsIPv6String(name) { family = string(v1.IPv6Protocol) } - return &networkingapiv1alpha1.IPAddress{ + return &networkingapiv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{ - networkingapiv1alpha1.LabelIPAddressFamily: family, - networkingapiv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingapiv1beta1.LabelIPAddressFamily: family, + networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName, }, }, } @@ -302,9 +302,9 @@ func expectAction(t *testing.T, actions []k8stesting.Action, expected [][]string func TestController_canDeleteCIDR(t *testing.T) { tests := []struct { name string - cidrs []*networkingapiv1alpha1.ServiceCIDR - ips []*networkingapiv1alpha1.IPAddress - cidrSynced *networkingapiv1alpha1.ServiceCIDR + cidrs []*networkingapiv1beta1.ServiceCIDR + ips []*networkingapiv1beta1.IPAddress + cidrSynced *networkingapiv1beta1.ServiceCIDR want bool }{ { @@ -314,7 +314,7 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR and no IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -322,10 +322,10 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.24"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -333,10 +333,10 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR without IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.1.24"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -344,10 +344,10 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with IPv4 address referencing the subnet address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.0"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -355,10 +355,10 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with IPv4 address referencing the broadcast address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.255"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -366,10 +366,10 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with IPv6 address referencing the broadcast address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("2001:0db2::ffff:ffff:ffff:ffff"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -377,11 +377,11 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with same range overlapping and IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.23"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -389,11 +389,11 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with smaller range overlapping and IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/26", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.23"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -401,11 +401,11 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with smaller range overlapping but IPs orphan", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/28", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.23"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -413,11 +413,11 @@ func TestController_canDeleteCIDR(t *testing.T) { }, { name: "CIDR with larger range overlapping and IPs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"), }, - ips: []*networkingapiv1alpha1.IPAddress{ + ips: []*networkingapiv1beta1.IPAddress{ makeIPAddress("192.168.0.23"), }, cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), @@ -442,8 +442,8 @@ func TestController_canDeleteCIDR(t *testing.T) { func TestController_ipToCidrs(t *testing.T) { tests := []struct { name string - cidrs []*networkingapiv1alpha1.ServiceCIDR - ip *networkingapiv1alpha1.IPAddress + cidrs []*networkingapiv1beta1.ServiceCIDR + ip *networkingapiv1beta1.IPAddress want []string }{ { @@ -452,7 +452,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{}, }, { name: "one CIDR", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated2", "10.0.0.0/16", ""), @@ -461,7 +461,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName}, }, { name: "two equal CIDR", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"), makeServiceCIDR("unrelated", "10.0.0.0/24", ""), @@ -471,7 +471,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"}, }, { name: "three CIDR - two same and one larger", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), @@ -482,7 +482,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping", "overlapping2"}, }, { name: "three CIDR - two same and one larger - IPv4 subnet address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), @@ -493,7 +493,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{}, }, { name: "three CIDR - two same and one larger - IPv4 broadcast address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), @@ -504,7 +504,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"}, }, { name: "three CIDR - two same and one larger - IPv6 subnet address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), @@ -515,7 +515,7 @@ func TestController_ipToCidrs(t *testing.T) { want: []string{}, }, { name: "three CIDR - two same and one larger - IPv6 broadcast address", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), @@ -539,8 +539,8 @@ func TestController_ipToCidrs(t *testing.T) { func TestController_cidrToCidrs(t *testing.T) { tests := []struct { name string - cidrs []*networkingapiv1alpha1.ServiceCIDR - cidr *networkingapiv1alpha1.ServiceCIDR + cidrs []*networkingapiv1beta1.ServiceCIDR + cidr *networkingapiv1beta1.ServiceCIDR want []string }{ { @@ -549,7 +549,7 @@ func TestController_cidrToCidrs(t *testing.T) { want: []string{}, }, { name: "one CIDR", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated2", "10.0.0.0/16", ""), @@ -558,7 +558,7 @@ func TestController_cidrToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName}, }, { name: "two equal CIDR", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"), makeServiceCIDR("unrelated", "10.0.0.0/24", ""), @@ -568,7 +568,7 @@ func TestController_cidrToCidrs(t *testing.T) { want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"}, }, { name: "three CIDR - two same and one larger", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"), diff --git a/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller.go b/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller.go index 194746dc11c..3ed98161c11 100644 --- a/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller.go +++ b/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller.go @@ -23,19 +23,19 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingapiv1beta1 "k8s.io/api/networking/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" metav1apply "k8s.io/client-go/applyconfigurations/meta/v1" - networkingapiv1alpha1apply "k8s.io/client-go/applyconfigurations/networking/v1alpha1" - networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" + networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1" + networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" v1core "k8s.io/client-go/kubernetes/typed/core/v1" - networkingv1alpha1listers "k8s.io/client-go/listers/networking/v1alpha1" + networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/klog/v2" @@ -67,13 +67,13 @@ func NewController( } // instead of using the shared informers from the controlplane instance, we construct our own informer // because we need such a small subset of the information available, only the kubernetes.default ServiceCIDR - c.serviceCIDRInformer = networkingv1alpha1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour, + c.serviceCIDRInformer = networkingv1beta1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, func(options *metav1.ListOptions) { options.FieldSelector = fields.OneTermEqualSelector("metadata.name", DefaultServiceCIDRName).String() }) - c.serviceCIDRLister = networkingv1alpha1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer()) + c.serviceCIDRLister = networkingv1beta1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer()) c.serviceCIDRsSynced = c.serviceCIDRInformer.HasSynced return c @@ -88,7 +88,7 @@ type Controller struct { eventRecorder record.EventRecorder serviceCIDRInformer cache.SharedIndexInformer - serviceCIDRLister networkingv1alpha1listers.ServiceCIDRLister + serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister serviceCIDRsSynced cache.InformerSynced interval time.Duration @@ -149,15 +149,15 @@ func (c *Controller) sync() error { // default ServiceCIDR does not exist klog.Infof("Creating default ServiceCIDR with CIDRs: %v", c.cidrs) - serviceCIDR = &networkingapiv1alpha1.ServiceCIDR{ + serviceCIDR = &networkingapiv1beta1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: DefaultServiceCIDRName, }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: c.cidrs, }, } - serviceCIDR, err = c.client.NetworkingV1alpha1().ServiceCIDRs().Create(context.Background(), serviceCIDR, metav1.CreateOptions{}) + serviceCIDR, err = c.client.NetworkingV1beta1().ServiceCIDRs().Create(context.Background(), serviceCIDR, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR can not be created") return err @@ -166,7 +166,7 @@ func (c *Controller) sync() error { return nil } -func (c *Controller) syncStatus(serviceCIDR *networkingapiv1alpha1.ServiceCIDR) { +func (c *Controller) syncStatus(serviceCIDR *networkingapiv1beta1.ServiceCIDR) { // don't sync the status of the ServiceCIDR if is being deleted, // deletion must be handled by the controller-manager if !serviceCIDR.GetDeletionTimestamp().IsZero() { @@ -176,7 +176,7 @@ func (c *Controller) syncStatus(serviceCIDR *networkingapiv1alpha1.ServiceCIDR) // This controller will set the Ready condition to true if the Ready condition // does not exist and the CIDR values match this controller CIDR values. for _, condition := range serviceCIDR.Status.Conditions { - if condition.Type == networkingapiv1alpha1.ServiceCIDRConditionReady { + if condition.Type == networkingapiv1beta1.ServiceCIDRConditionReady { if condition.Status == metav1.ConditionTrue { return } @@ -188,14 +188,14 @@ func (c *Controller) syncStatus(serviceCIDR *networkingapiv1alpha1.ServiceCIDR) // set status to ready if the ServiceCIDR matches this configuration if reflect.DeepEqual(c.cidrs, serviceCIDR.Spec.CIDRs) { klog.Infof("Setting default ServiceCIDR condition Ready to True") - svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( + svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions( metav1apply.Condition(). - WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). + WithType(networkingapiv1beta1.ServiceCIDRConditionReady). WithStatus(metav1.ConditionTrue). WithMessage("Kubernetes default Service CIDR is ready"). WithLastTransitionTime(metav1.Now())) - svcApply := networkingapiv1alpha1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus) - if _, errApply := c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(context.Background(), svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); errApply != nil { + svcApply := networkingapiv1beta1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus) + if _, errApply := c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(context.Background(), svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); errApply != nil { klog.Infof("error updating default ServiceCIDR status: %v", errApply) c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR Status can not be set to Ready=True") } diff --git a/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller_test.go b/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller_test.go index cf94a594703..050a6b609c1 100644 --- a/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller_test.go +++ b/pkg/controlplane/controller/defaultservicecidr/default_servicecidr_controller_test.go @@ -21,7 +21,7 @@ import ( "time" "github.com/google/go-cmp/cmp" - networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingapiv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" @@ -35,11 +35,11 @@ const ( defaultIPv6CIDR = "2001:db8::/64" ) -func newController(t *testing.T, objects []*networkingapiv1alpha1.ServiceCIDR) (*fake.Clientset, *Controller) { +func newController(t *testing.T, objects []*networkingapiv1beta1.ServiceCIDR) (*fake.Clientset, *Controller) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0) - serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() store := serviceCIDRInformer.Informer().GetStore() for _, obj := range objects { @@ -64,7 +64,7 @@ func newController(t *testing.T, objects []*networkingapiv1alpha1.ServiceCIDR) ( func TestControllerSync(t *testing.T) { testCases := []struct { name string - cidrs []*networkingapiv1alpha1.ServiceCIDR + cidrs []*networkingapiv1beta1.ServiceCIDR actions [][]string // verb and resource }{ { @@ -73,12 +73,12 @@ func TestControllerSync(t *testing.T) { }, { name: "existing default service CIDR update Ready condition", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ { ObjectMeta: metav1.ObjectMeta{ Name: DefaultServiceCIDRName, }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, }, }, @@ -87,12 +87,12 @@ func TestControllerSync(t *testing.T) { }, { name: "existing default service CIDR not matching cidrs", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ { ObjectMeta: metav1.ObjectMeta{ Name: DefaultServiceCIDRName, }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: []string{"fd00::/112"}, }, }, @@ -100,18 +100,18 @@ func TestControllerSync(t *testing.T) { }, { name: "existing default service CIDR not ready", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ { ObjectMeta: metav1.ObjectMeta{ Name: DefaultServiceCIDRName, }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, }, - Status: networkingapiv1alpha1.ServiceCIDRStatus{ + Status: networkingapiv1beta1.ServiceCIDRStatus{ Conditions: []metav1.Condition{ { - Type: string(networkingapiv1alpha1.ServiceCIDRConditionReady), + Type: string(networkingapiv1beta1.ServiceCIDRConditionReady), Status: metav1.ConditionFalse, }, }, @@ -121,13 +121,13 @@ func TestControllerSync(t *testing.T) { }, { name: "existing default service CIDR being deleted", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ { ObjectMeta: metav1.ObjectMeta{ Name: DefaultServiceCIDRName, DeletionTimestamp: ptr.To(metav1.Now()), }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, }, }, @@ -135,12 +135,12 @@ func TestControllerSync(t *testing.T) { }, { name: "existing service CIDRs but not default", - cidrs: []*networkingapiv1alpha1.ServiceCIDR{ + cidrs: []*networkingapiv1beta1.ServiceCIDR{ { ObjectMeta: metav1.ObjectMeta{ Name: "non-default-cidr", }, - Spec: networkingapiv1alpha1.ServiceCIDRSpec{ + Spec: networkingapiv1beta1.ServiceCIDRSpec{ CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, }, }, diff --git a/pkg/controlplane/instance.go b/pkg/controlplane/instance.go index 5f1b732de5b..205162b2f35 100644 --- a/pkg/controlplane/instance.go +++ b/pkg/controlplane/instance.go @@ -43,6 +43,7 @@ import ( eventsv1 "k8s.io/api/events/v1" networkingapiv1 "k8s.io/api/networking/v1" networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingapiv1beta1 "k8s.io/api/networking/v1beta1" nodev1 "k8s.io/api/node/v1" policyapiv1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -466,6 +467,7 @@ var ( flowcontrolv1beta1.SchemeGroupVersion, flowcontrolv1beta2.SchemeGroupVersion, flowcontrolv1beta3.SchemeGroupVersion, + networkingapiv1beta1.SchemeGroupVersion, } // alphaAPIGroupVersionsDisabledByDefault holds the alpha APIs we have. They are always disabled by default. diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index a7c09864675..0a4ddc4572a 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -38,7 +38,7 @@ import ( discoveryv1beta1 "k8s.io/api/discovery/v1beta1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" flowcontrolv1 "k8s.io/api/flowcontrol/v1" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" rbacv1beta1 "k8s.io/api/rbac/v1beta1" resourcev1alpha2 "k8s.io/api/resource/v1alpha2" schedulingv1 "k8s.io/api/scheduling/v1" @@ -685,7 +685,7 @@ func AddHandlers(h printers.PrintHandler) { serviceCIDRColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, - {Name: "CIDRs", Type: "string", Description: networkingv1alpha1.ServiceCIDRSpec{}.SwaggerDoc()["cidrs"]}, + {Name: "CIDRs", Type: "string", Description: networkingv1beta1.ServiceCIDRSpec{}.SwaggerDoc()["cidrs"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, } @@ -694,7 +694,7 @@ func AddHandlers(h printers.PrintHandler) { ipAddressColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, - {Name: "ParentRef", Type: "string", Description: networkingv1alpha1.IPAddressSpec{}.SwaggerDoc()["parentRef"]}, + {Name: "ParentRef", Type: "string", Description: networkingv1beta1.IPAddressSpec{}.SwaggerDoc()["parentRef"]}, } _ = h.TableHandler(ipAddressColumnDefinitions, printIPAddress) diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index eddb0b866ec..373cd0a1c64 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -24,12 +24,12 @@ import ( v1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" v1informers "k8s.io/client-go/informers/core/v1" discoveryv1informers "k8s.io/client-go/informers/discovery/v1" - networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" + networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" ) @@ -401,7 +401,7 @@ type ServiceCIDRConfig struct { } // NewServiceCIDRConfig creates a new ServiceCIDRConfig. -func NewServiceCIDRConfig(ctx context.Context, serviceCIDRInformer networkingv1alpha1informers.ServiceCIDRInformer, resyncPeriod time.Duration) *ServiceCIDRConfig { +func NewServiceCIDRConfig(ctx context.Context, serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer, resyncPeriod time.Duration) *ServiceCIDRConfig { result := &ServiceCIDRConfig{ listerSynced: serviceCIDRInformer.Informer().HasSynced, cidrs: sets.New[string](), @@ -443,11 +443,11 @@ func (c *ServiceCIDRConfig) Run(stopCh <-chan struct{}) { // handleServiceCIDREvent is a helper function to handle Add, Update and Delete // events on ServiceCIDR objects and call downstream event handlers. func (c *ServiceCIDRConfig) handleServiceCIDREvent(oldObj, newObj interface{}) { - var oldServiceCIDR, newServiceCIDR *networkingv1alpha1.ServiceCIDR + var oldServiceCIDR, newServiceCIDR *networkingv1beta1.ServiceCIDR var ok bool if oldObj != nil { - oldServiceCIDR, ok = oldObj.(*networkingv1alpha1.ServiceCIDR) + oldServiceCIDR, ok = oldObj.(*networkingv1beta1.ServiceCIDR) if !ok { utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj)) return @@ -455,7 +455,7 @@ func (c *ServiceCIDRConfig) handleServiceCIDREvent(oldObj, newObj interface{}) { } if newObj != nil { - newServiceCIDR, ok = newObj.(*networkingv1alpha1.ServiceCIDR) + newServiceCIDR, ok = newObj.(*networkingv1beta1.ServiceCIDR) if !ok { utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj)) return diff --git a/pkg/registry/core/rest/storage_core.go b/pkg/registry/core/rest/storage_core.go index e164ff63c49..d7ff0bdeed4 100644 --- a/pkg/registry/core/rest/storage_core.go +++ b/pkg/registry/core/rest/storage_core.go @@ -34,7 +34,7 @@ import ( serverstorage "k8s.io/apiserver/pkg/server/storage" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/kubernetes" - networkingv1alpha1client "k8s.io/client-go/kubernetes/typed/networking/v1alpha1" + networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1" policyclient "k8s.io/client-go/kubernetes/typed/policy/v1" "k8s.io/klog/v2" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -140,8 +140,8 @@ func New(c Config) (*legacyProvider, error) { c.Services.IPRepairInterval, client, c.Informers.Core().V1().Services(), - c.Informers.Networking().V1alpha1().ServiceCIDRs(), - c.Informers.Networking().V1alpha1().IPAddresses(), + c.Informers.Networking().V1beta1().ServiceCIDRs(), + c.Informers.Networking().V1beta1().IPAddresses(), ).RunUntil } @@ -348,7 +348,7 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster IP allocator: %v", err) } } else { - networkingv1alphaClient, err := networkingv1alpha1client.NewForConfig(c.LoopbackClientConfig) + networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig) if err != nil { return rangeRegistries{}, nil, nil, nil, err } @@ -388,9 +388,9 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl // 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(), + networkingv1beta1Client, + c.Informers.Networking().V1beta1().ServiceCIDRs(), + c.Informers.Networking().V1beta1().IPAddresses(), netutils.IsIPv6CIDR(&serviceClusterIPRange), bitmapAllocator, ) @@ -420,7 +420,7 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster secondary IP allocator: %v", err) } } else { - networkingv1alphaClient, err := networkingv1alpha1client.NewForConfig(c.LoopbackClientConfig) + networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig) if err != nil { return rangeRegistries{}, nil, nil, nil, err } @@ -460,9 +460,9 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl // 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(), + networkingv1beta1Client, + c.Informers.Networking().V1beta1().ServiceCIDRs(), + c.Informers.Networking().V1beta1().IPAddresses(), netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange), bitmapAllocator, ) diff --git a/pkg/registry/core/service/ipallocator/cidrallocator.go b/pkg/registry/core/service/ipallocator/cidrallocator.go index 41be1b9a969..1bc377dac86 100644 --- a/pkg/registry/core/service/ipallocator/cidrallocator.go +++ b/pkg/registry/core/service/ipallocator/cidrallocator.go @@ -24,16 +24,16 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" - networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" - networkingv1alpha1client "k8s.io/client-go/kubernetes/typed/networking/v1alpha1" - networkingv1alpha1listers "k8s.io/client-go/listers/networking/v1alpha1" + networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" + networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1" + networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -52,12 +52,12 @@ import ( // MetaAllocator implements current allocator interface using // ServiceCIDR and IPAddress API objects. type MetaAllocator struct { - client networkingv1alpha1client.NetworkingV1alpha1Interface - serviceCIDRLister networkingv1alpha1listers.ServiceCIDRLister + client networkingv1beta1client.NetworkingV1beta1Interface + serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister serviceCIDRSynced cache.InformerSynced - ipAddressLister networkingv1alpha1listers.IPAddressLister + ipAddressLister networkingv1beta1listers.IPAddressLister ipAddressSynced cache.InformerSynced - ipAddressInformer networkingv1alpha1informers.IPAddressInformer + ipAddressInformer networkingv1beta1informers.IPAddressInformer queue workqueue.TypedRateLimitingInterface[string] internalStopCh chan struct{} @@ -87,9 +87,9 @@ var _ Interface = &MetaAllocator{} // and ServiceCIDR objects to track the assigned IP addresses, // using an informer cache as storage. func NewMetaAllocator( - client networkingv1alpha1client.NetworkingV1alpha1Interface, - serviceCIDRInformer networkingv1alpha1informers.ServiceCIDRInformer, - ipAddressInformer networkingv1alpha1informers.IPAddressInformer, + client networkingv1beta1client.NetworkingV1beta1Interface, + serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer, + ipAddressInformer networkingv1beta1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) (*MetaAllocator, error) { @@ -100,9 +100,9 @@ func NewMetaAllocator( } // newMetaAllocator is used to build the allocator for testing -func newMetaAllocator(client networkingv1alpha1client.NetworkingV1alpha1Interface, - serviceCIDRInformer networkingv1alpha1informers.ServiceCIDRInformer, - ipAddressInformer networkingv1alpha1informers.IPAddressInformer, +func newMetaAllocator(client networkingv1beta1client.NetworkingV1beta1Interface, + serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer, + ipAddressInformer networkingv1beta1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) *MetaAllocator { @@ -152,13 +152,13 @@ func (c *MetaAllocator) enqueueServiceCIDR(obj interface{}) { } func (c *MetaAllocator) deleteServiceCIDR(obj interface{}) { - serviceCIDR, ok := obj.(*networkingv1alpha1.ServiceCIDR) + serviceCIDR, ok := obj.(*networkingv1beta1.ServiceCIDR) if !ok { tombstone, ok := obj.(cache.DeletedFinalStateUnknown) if !ok { return } - serviceCIDR, ok = tombstone.Obj.(*networkingv1alpha1.ServiceCIDR) + serviceCIDR, ok = tombstone.Obj.(*networkingv1beta1.ServiceCIDR) if !ok { return } @@ -414,8 +414,8 @@ func (c *MetaAllocator) Release(ip net.IP) error { } func (c *MetaAllocator) ForEach(f func(ip net.IP)) { ipLabelSelector := labels.Set(map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(c.IPFamily()), - networkingv1alpha1.LabelManagedBy: ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()), + networkingv1beta1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := c.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -454,8 +454,8 @@ func (c *MetaAllocator) Destroy() { // for testing func (c *MetaAllocator) Used() int { ipLabelSelector := labels.Set(map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(c.IPFamily()), - networkingv1alpha1.LabelManagedBy: ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()), + networkingv1beta1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := c.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -512,13 +512,13 @@ func (c *MetaAllocator) DryRun() Interface { return &Allocator{} } -func isReady(serviceCIDR *networkingv1alpha1.ServiceCIDR) bool { +func isReady(serviceCIDR *networkingv1beta1.ServiceCIDR) bool { if serviceCIDR == nil { return false } for _, condition := range serviceCIDR.Status.Conditions { - if condition.Type == networkingv1alpha1.ServiceCIDRConditionReady { + if condition.Type == networkingv1beta1.ServiceCIDRConditionReady { return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue) } } diff --git a/pkg/registry/core/service/ipallocator/cidrallocator_test.go b/pkg/registry/core/service/ipallocator/cidrallocator_test.go index c37c6cb5c98..bfcfdd00424 100644 --- a/pkg/registry/core/service/ipallocator/cidrallocator_test.go +++ b/pkg/registry/core/service/ipallocator/cidrallocator_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -41,13 +41,13 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) - serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer() - ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() + ipInformer := informerFactory.Networking().V1beta1().IPAddresses() ipStore := ipInformer.Informer().GetIndexer() client.PrependReactor("create", "servicecidrs", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - cidr := action.(k8stesting.CreateAction).GetObject().(*networkingv1alpha1.ServiceCIDR) + cidr := action.(k8stesting.CreateAction).GetObject().(*networkingv1beta1.ServiceCIDR) _, exists, err := serviceCIDRStore.GetByKey(cidr.Name) if exists && err != nil { return false, nil, fmt.Errorf("cidr already exist") @@ -59,16 +59,16 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client.PrependReactor("delete", "servicecidrs", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := serviceCIDRStore.GetByKey(name) - cidr := &networkingv1alpha1.ServiceCIDR{} + cidr := &networkingv1beta1.ServiceCIDR{} if exists && err == nil { - cidr = obj.(*networkingv1alpha1.ServiceCIDR) + cidr = obj.(*networkingv1beta1.ServiceCIDR) err = serviceCIDRStore.Delete(cidr) } return false, cidr, err })) client.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1alpha1.IPAddress) + ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1beta1.IPAddress) _, exists, err := ipStore.GetByKey(ip.Name) if exists && err != nil { return false, nil, fmt.Errorf("ip already exist") @@ -80,15 +80,15 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := ipStore.GetByKey(name) - ip := &networkingv1alpha1.IPAddress{} + ip := &networkingv1beta1.IPAddress{} if exists && err == nil { - ip = obj.(*networkingv1alpha1.IPAddress) + ip = obj.(*networkingv1beta1.IPAddress) err = ipStore.Delete(ip) } return false, ip, err })) - c := newMetaAllocator(client.NetworkingV1alpha1(), serviceCIDRInformer, ipInformer, false, nil) + c := newMetaAllocator(client.NetworkingV1beta1(), serviceCIDRInformer, ipInformer, false, nil) c.serviceCIDRSynced = func() bool { return true } c.ipAddressSynced = func() bool { return true } @@ -602,18 +602,18 @@ func TestCIDRAllocateDualWriteCollision(t *testing.T) { } // TODO: add IPv6 and dual stack test cases -func newServiceCIDR(name, cidr string) *networkingv1alpha1.ServiceCIDR { - return &networkingv1alpha1.ServiceCIDR{ +func newServiceCIDR(name, cidr string) *networkingv1beta1.ServiceCIDR { + return &networkingv1beta1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingv1alpha1.ServiceCIDRSpec{ + Spec: networkingv1beta1.ServiceCIDRSpec{ CIDRs: []string{cidr}, }, - Status: networkingv1alpha1.ServiceCIDRStatus{ + Status: networkingv1beta1.ServiceCIDRStatus{ Conditions: []metav1.Condition{ { - Type: string(networkingv1alpha1.ServiceCIDRConditionReady), + Type: string(networkingv1beta1.ServiceCIDRConditionReady), Status: metav1.ConditionTrue, }, }, diff --git a/pkg/registry/core/service/ipallocator/controller/repairip.go b/pkg/registry/core/service/ipallocator/controller/repairip.go index 1e420ea8a8d..112f908dce9 100644 --- a/pkg/registry/core/service/ipallocator/controller/repairip.go +++ b/pkg/registry/core/service/ipallocator/controller/repairip.go @@ -23,17 +23,17 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" coreinformers "k8s.io/client-go/informers/core/v1" - networkinginformers "k8s.io/client-go/informers/networking/v1alpha1" + networkinginformers "k8s.io/client-go/informers/networking/v1beta1" "k8s.io/client-go/kubernetes" corelisters "k8s.io/client-go/listers/core/v1" - networkinglisters "k8s.io/client-go/listers/networking/v1alpha1" + networkinglisters "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/events" "k8s.io/client-go/util/retry" @@ -263,7 +263,7 @@ func (r *RepairIPAddress) doRunOnce() error { // Check that there is no IP created by the allocator without // a Service associated. ipLabelSelector := labels.Set(map[string]string{ - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }).AsSelectorPreValidated() ipAddresses, err := r.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -360,7 +360,7 @@ func (r *RepairIPAddress) syncService(key string) error { // ClusterIP doesn't seem to be allocated, create it. r.recorder.Eventf(svc, nil, v1.EventTypeWarning, "ClusterIPNotAllocated", "ClusterIPAllocation", "Cluster IP [%v]: %s is not allocated; repairing", family, ip) runtime.HandleError(fmt.Errorf("the ClusterIP [%v]: %s for Service %s/%s is not allocated; repairing", family, ip, svc.Namespace, svc.Name)) - _, err := r.client.NetworkingV1alpha1().IPAddresses().Create(context.Background(), newIPAddress(ip.String(), svc), metav1.CreateOptions{}) + _, err := r.client.NetworkingV1beta1().IPAddresses().Create(context.Background(), newIPAddress(ip.String(), svc), metav1.CreateOptions{}) if err != nil { return err } @@ -417,11 +417,11 @@ func (r *RepairIPAddress) syncService(key string) error { } func (r *RepairIPAddress) recreateIPAddress(name string, svc *v1.Service) error { - err := r.client.NetworkingV1alpha1().IPAddresses().Delete(context.Background(), name, metav1.DeleteOptions{}) + err := r.client.NetworkingV1beta1().IPAddresses().Delete(context.Background(), name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } - _, err = r.client.NetworkingV1alpha1().IPAddresses().Create(context.Background(), newIPAddress(name, svc), metav1.CreateOptions{}) + _, err = r.client.NetworkingV1beta1().IPAddresses().Create(context.Background(), newIPAddress(name, svc), metav1.CreateOptions{}) if err != nil { return err } @@ -482,7 +482,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { if ipAddress.Spec.ParentRef.Group != "" || ipAddress.Spec.ParentRef.Resource != "services" { runtime.HandleError(fmt.Errorf("IPAddress %s appears to have been modified, not referencing a Service %v: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressNotAllocated", "IPAddressAllocation", "IPAddress %s appears to have been modified, not referencing a Service %v: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef) - err := r.client.NetworkingV1alpha1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) + err := r.client.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } @@ -499,7 +499,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { if ipLifetime > gracePeriod { runtime.HandleError(fmt.Errorf("IPAddress %s appears to have leaked: cleaning up", ipAddress.Name)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressNotAllocated", "IPAddressAllocation", "IPAddress: %s for Service %s/%s appears to have leaked: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef.Namespace, ipAddress.Spec.ParentRef.Name) - err := r.client.NetworkingV1alpha1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) + err := r.client.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } @@ -522,7 +522,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { } runtime.HandleError(fmt.Errorf("the IPAddress: %s for Service %s/%s has a wrong reference %#v; cleaning up", ipAddress.Name, svc.Name, svc.Namespace, ipAddress.Spec.ParentRef)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressWrongReference", "IPAddressAllocation", "IPAddress: %s for Service %s/%s has a wrong reference; cleaning up", ipAddress.Name, svc.Namespace, svc.Name) - err = r.client.NetworkingV1alpha1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) + err = r.client.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } @@ -535,31 +535,31 @@ func (r *RepairIPAddress) isIPOutOfRange(ip net.IP) bool { return len(servicecidr.ContainsIP(r.serviceCIDRLister, ip)) == 0 } -func newIPAddress(name string, svc *v1.Service) *networkingv1alpha1.IPAddress { +func newIPAddress(name string, svc *v1.Service) *networkingv1beta1.IPAddress { family := string(v1.IPv4Protocol) if netutils.IsIPv6String(name) { family = string(v1.IPv6Protocol) } - return &networkingv1alpha1.IPAddress{ + return &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: family, - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelIPAddressFamily: family, + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }, }, - Spec: networkingv1alpha1.IPAddressSpec{ + Spec: networkingv1beta1.IPAddressSpec{ ParentRef: serviceToRef(svc), }, } } -func serviceToRef(svc *v1.Service) *networkingv1alpha1.ParentReference { +func serviceToRef(svc *v1.Service) *networkingv1beta1.ParentReference { if svc == nil { return nil } - return &networkingv1alpha1.ParentReference{ + return &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Namespace: svc.Namespace, @@ -576,16 +576,16 @@ func getFamilyByIP(ip net.IP) v1.IPFamily { // managedByController returns true if the controller of the provided // EndpointSlices is the EndpointSlice controller. -func managedByController(ip *networkingv1alpha1.IPAddress) bool { - managedBy, ok := ip.Labels[networkingv1alpha1.LabelManagedBy] +func managedByController(ip *networkingv1beta1.IPAddress) bool { + managedBy, ok := ip.Labels[networkingv1beta1.LabelManagedBy] if !ok { return false } return managedBy == ipallocator.ControllerName } -func verifyIPAddressLabels(ip *networkingv1alpha1.IPAddress) bool { - labelFamily, ok := ip.Labels[networkingv1alpha1.LabelIPAddressFamily] +func verifyIPAddressLabels(ip *networkingv1beta1.IPAddress) bool { + labelFamily, ok := ip.Labels[networkingv1beta1.LabelIPAddressFamily] if !ok { return false } diff --git a/pkg/registry/core/service/ipallocator/controller/repairip_test.go b/pkg/registry/core/service/ipallocator/controller/repairip_test.go index 37dc56b1703..f2c0e10ec39 100644 --- a/pkg/registry/core/service/ipallocator/controller/repairip_test.go +++ b/pkg/registry/core/service/ipallocator/controller/repairip_test.go @@ -23,7 +23,7 @@ import ( "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -54,25 +54,25 @@ func newFakeRepair() (*fake.Clientset, *fakeRepair) { serviceInformer := informerFactory.Core().V1().Services() serviceIndexer := serviceInformer.Informer().GetIndexer() - serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer() - ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() + ipInformer := informerFactory.Networking().V1beta1().IPAddresses() ipIndexer := ipInformer.Informer().GetIndexer() fakeClient.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1alpha1.IPAddress) + ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1beta1.IPAddress) err := ipIndexer.Add(ip) return false, ip, err })) fakeClient.PrependReactor("update", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - ip := action.(k8stesting.UpdateAction).GetObject().(*networkingv1alpha1.IPAddress) + ip := action.(k8stesting.UpdateAction).GetObject().(*networkingv1beta1.IPAddress) return false, ip, fmt.Errorf("IPAddress is inmutable after creation") })) fakeClient.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { ip := action.(k8stesting.DeleteAction).GetName() err := ipIndexer.Delete(ip) - return false, &networkingv1alpha1.IPAddress{}, err + return false, &networkingv1beta1.IPAddress{}, err })) r := NewRepairIPAddress(0*time.Second, @@ -88,8 +88,8 @@ func TestRepairServiceIP(t *testing.T) { tests := []struct { name string svcs []*v1.Service - ipAddresses []*networkingv1alpha1.IPAddress - cidrs []*networkingv1alpha1.ServiceCIDR + ipAddresses []*networkingv1beta1.IPAddress + cidrs []*networkingv1beta1.ServiceCIDR expectedIPs []string actions [][]string // verb and resource events []string @@ -97,10 +97,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed single stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -110,11 +110,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -124,11 +124,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed dual stack multiple cidrs", svcs: []*v1.Service{newService("test-svc", []string{"192.168.0.1", "2001:db8:a:b::10"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("192.168.0.1", newService("test-svc", []string{"192.168.0.1"})), newIPAddress("2001:db8:a:b::10", newService("test-svc", []string{"2001:db8:a:b::10"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("custom", "192.168.0.0/24", "2001:db8:a:b::/64"), }, @@ -140,7 +140,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddress single stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -150,7 +150,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddresses dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -163,7 +163,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddress single stack from secondary", svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1"})}, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("custom", "192.168.1.0/24", ""), }, @@ -174,10 +174,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "reconcile IPAddress single stack wrong reference", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -187,11 +187,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "reconcile IPAddresses dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), newIPAddress("2001:db8::10", newService("test-svc2", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -204,11 +204,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range", svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("192.168.1.1", newService("test-svc", []string{"192.168.1.1"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"2001:db8::10"}, @@ -217,10 +217,10 @@ func TestRepairServiceIP(t *testing.T) { }, { name: "one IP orphan", - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -229,10 +229,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range matching the network address", svcs: []*v1.Service{newService("test-svc", []string{"10.0.0.0"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.0.0", newService("test-svc", []string{"10.0.0.0"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.0.0"}, @@ -242,10 +242,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range matching the broadcast address", svcs: []*v1.Service{newService("test-svc", []string{"10.0.255.255"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.255.255", newService("test-svc", []string{"10.0.255.255"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.255.255"}, @@ -255,10 +255,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IPv6 out of range matching the subnet address", svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"2001:db8::"}, @@ -268,20 +268,20 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IPv6 matching the broadcast address", svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::ffff:ffff:ffff:ffff"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("2001:db8::ffff:ffff:ffff:ffff", newService("test-svc", []string{"2001:db8::ffff:ffff:ffff:ffff"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"2001:db8::ffff:ffff:ffff:ffff"}, }, { name: "one IP orphan matching the broadcast address", - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.255.255", newService("test-svc", []string{"10.0.255.255"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -290,11 +290,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "Two IPAddresses referencing the same service", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), newIPAddress("10.0.1.2", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -306,10 +306,10 @@ func TestRepairServiceIP(t *testing.T) { newService("test-svc", []string{"10.0.1.1"}), newService("test-svc2", []string{"10.0.1.1"}), }, - ipAddresses: []*networkingv1alpha1.IPAddress{ + ipAddresses: []*networkingv1beta1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1alpha1.ServiceCIDR{ + cidrs: []*networkingv1beta1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, events: []string{"Warning ClusterIPAlreadyAllocated Cluster IP [IPv4]:10.0.1.1 was assigned to multiple services; please recreate service"}, @@ -370,23 +370,23 @@ func TestRepairServiceIP(t *testing.T) { func TestRepairIPAddress_syncIPAddress(t *testing.T) { tests := []struct { name string - ip *networkingv1alpha1.IPAddress + ip *networkingv1beta1.IPAddress actions [][]string // verb and resource wantErr bool }{ { name: "correct ipv4 address", - ip: &networkingv1alpha1.IPAddress{ + ip: &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "10.0.1.1", Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv4Protocol), - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(v1.IPv4Protocol), + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1alpha1.IPAddressSpec{ - ParentRef: &networkingv1alpha1.ParentReference{ + Spec: networkingv1beta1.IPAddressSpec{ + ParentRef: &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -397,17 +397,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "correct ipv6 address", - ip: &networkingv1alpha1.IPAddress{ + ip: &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "2001:db8::11", Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1alpha1.IPAddressSpec{ - ParentRef: &networkingv1alpha1.ParentReference{ + Spec: networkingv1beta1.IPAddressSpec{ + ParentRef: &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -418,17 +418,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "not managed by this controller", - ip: &networkingv1alpha1.IPAddress{ + ip: &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "2001:db8::11", Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1alpha1.LabelManagedBy: "controller-foo", + networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1beta1.LabelManagedBy: "controller-foo", }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1alpha1.IPAddressSpec{ - ParentRef: &networkingv1alpha1.ParentReference{ + Spec: networkingv1beta1.IPAddressSpec{ + ParentRef: &networkingv1beta1.ParentReference{ Group: "networking.gateway.k8s.io", Resource: "gateway", Name: "foo", @@ -439,17 +439,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "out of range", - ip: &networkingv1alpha1.IPAddress{ + ip: &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "fd00:db8::11", Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1alpha1.IPAddressSpec{ - ParentRef: &networkingv1alpha1.ParentReference{ + Spec: networkingv1beta1.IPAddressSpec{ + ParentRef: &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -460,17 +460,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "leaked ip", - ip: &networkingv1alpha1.IPAddress{ + ip: &networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "10.0.1.1", Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1alpha1.IPAddressSpec{ - ParentRef: &networkingv1alpha1.ParentReference{ + Spec: networkingv1beta1.IPAddressSpec{ + ParentRef: &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Name: "noexist", @@ -522,12 +522,12 @@ func newService(name string, ips []string) *v1.Service { return svc } -func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.ServiceCIDR { - serviceCIDR := &networkingv1alpha1.ServiceCIDR{ +func newServiceCIDR(name, primary, secondary string) *networkingv1beta1.ServiceCIDR { + serviceCIDR := &networkingv1beta1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingv1alpha1.ServiceCIDRSpec{}, + Spec: networkingv1beta1.ServiceCIDRSpec{}, } serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) if secondary != "" { diff --git a/pkg/registry/core/service/ipallocator/ipallocator.go b/pkg/registry/core/service/ipallocator/ipallocator.go index 53b0109e5f7..9d52af45ac2 100644 --- a/pkg/registry/core/service/ipallocator/ipallocator.go +++ b/pkg/registry/core/service/ipallocator/ipallocator.go @@ -27,13 +27,13 @@ import ( "sync/atomic" "time" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" - networkingv1alpha1client "k8s.io/client-go/kubernetes/typed/networking/v1alpha1" - networkingv1alpha1listers "k8s.io/client-go/listers/networking/v1alpha1" + networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" + networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1" + networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" api "k8s.io/kubernetes/pkg/apis/core" @@ -56,8 +56,8 @@ type Allocator struct { rangeOffset int // subdivides the assigned IP range to prefer dynamic allocation from the upper range size uint64 // cap the total number of IPs available to maxInt64 - client networkingv1alpha1client.NetworkingV1alpha1Interface - ipAddressLister networkingv1alpha1listers.IPAddressLister + client networkingv1beta1client.NetworkingV1beta1Interface + ipAddressLister networkingv1beta1listers.IPAddressLister ipAddressSynced cache.InformerSynced // ready indicates if the allocator is able to allocate new IP addresses. // This is required because it depends on the ServiceCIDR to be ready. @@ -77,8 +77,8 @@ var _ Interface = &Allocator{} // using an informer cache as storage. func NewIPAllocator( cidr *net.IPNet, - client networkingv1alpha1client.NetworkingV1alpha1Interface, - ipAddressInformer networkingv1alpha1informers.IPAddressInformer, + client networkingv1beta1client.NetworkingV1beta1Interface, + ipAddressInformer networkingv1beta1informers.IPAddressInformer, ) (*Allocator, error) { prefix, err := netip.ParsePrefix(cidr.String()) if err != nil { @@ -139,15 +139,15 @@ func NewIPAllocator( } func (a *Allocator) createIPAddress(name string, svc *api.Service, scope string) error { - ipAddress := networkingv1alpha1.IPAddress{ + ipAddress := networkingv1beta1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1alpha1.LabelManagedBy: ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1beta1.LabelManagedBy: ControllerName, }, }, - Spec: networkingv1alpha1.IPAddressSpec{ + Spec: networkingv1beta1.IPAddressSpec{ ParentRef: serviceToRef(svc), }, } @@ -379,8 +379,8 @@ func (a *Allocator) release(ip net.IP, dryRun bool) error { // This is required to satisfy the Allocator Interface only func (a *Allocator) ForEach(f func(net.IP)) { ipLabelSelector := labels.Set(map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1alpha1.LabelManagedBy: ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1beta1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := a.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -413,8 +413,8 @@ func (a *Allocator) IPFamily() api.IPFamily { // for testing, it assumes this is the allocator is unique for the ipFamily func (a *Allocator) Used() int { ipLabelSelector := labels.Set(map[string]string{ - networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1alpha1.LabelManagedBy: ControllerName, + networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1beta1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := a.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -568,12 +568,12 @@ func broadcastAddress(subnet netip.Prefix) (netip.Addr, error) { } // serviceToRef obtain the Service Parent Reference -func serviceToRef(svc *api.Service) *networkingv1alpha1.ParentReference { +func serviceToRef(svc *api.Service) *networkingv1beta1.ParentReference { if svc == nil { return nil } - return &networkingv1alpha1.ParentReference{ + return &networkingv1beta1.ParentReference{ Group: "", Resource: "services", Namespace: svc.Namespace, diff --git a/pkg/registry/core/service/ipallocator/ipallocator_test.go b/pkg/registry/core/service/ipallocator/ipallocator_test.go index 6c5c73cde76..e211f3aaebe 100644 --- a/pkg/registry/core/service/ipallocator/ipallocator_test.go +++ b/pkg/registry/core/service/ipallocator/ipallocator_test.go @@ -25,7 +25,7 @@ import ( "testing" "time" - networkingv1alpha1 "k8s.io/api/networking/v1alpha1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/informers" @@ -40,11 +40,11 @@ func newTestAllocator(cidr *net.IPNet) (*Allocator, error) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) - ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() + ipInformer := informerFactory.Networking().V1beta1().IPAddresses() ipStore := ipInformer.Informer().GetIndexer() client.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1alpha1.IPAddress) + ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1beta1.IPAddress) _, exists, err := ipStore.GetByKey(ip.Name) if exists && err != nil { return false, nil, fmt.Errorf("ip already exist") @@ -56,15 +56,15 @@ func newTestAllocator(cidr *net.IPNet) (*Allocator, error) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := ipStore.GetByKey(name) - ip := &networkingv1alpha1.IPAddress{} + ip := &networkingv1beta1.IPAddress{} if exists && err == nil { - ip = obj.(*networkingv1alpha1.IPAddress) + ip = obj.(*networkingv1beta1.IPAddress) err = ipStore.Delete(ip) } return false, ip, err })) - c, err := NewIPAllocator(cidr, client.NetworkingV1alpha1(), ipInformer) + c, err := NewIPAllocator(cidr, client.NetworkingV1beta1(), ipInformer) if err != nil { return nil, err }