modify components to use the networking v1beta1 API

This commit is contained in:
Antonio Ojea
2024-06-29 10:06:55 +00:00
parent ed597316d6
commit 0e1f9dadd6
19 changed files with 373 additions and 370 deletions

View File

@@ -40,6 +40,7 @@ var apiVersionPriorities = merge(controlplaneapiserver.DefaultGenericAPIServiceP
{Group: "batch", Version: "v1beta1"}: {Group: 17400, Version: 9}, {Group: "batch", Version: "v1beta1"}: {Group: 17400, Version: 9},
{Group: "batch", Version: "v2alpha1"}: {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: "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: "networking.k8s.io", Version: "v1alpha1"}: {Group: 17200, Version: 1},
{Group: "policy", Version: "v1"}: {Group: 17100, Version: 15}, {Group: "policy", Version: "v1"}: {Group: 17100, Version: 15},
{Group: "policy", Version: "v1beta1"}: {Group: 17100, Version: 9}, {Group: "policy", Version: "v1beta1"}: {Group: 17100, Version: 9},

View File

@@ -40,8 +40,8 @@ func newServiceCIDRsControllerDescriptor() *ControllerDescriptor {
func startServiceCIDRsController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) { func startServiceCIDRsController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
go servicecidrs.NewController( go servicecidrs.NewController(
ctx, ctx,
controllerContext.InformerFactory.Networking().V1alpha1().ServiceCIDRs(), controllerContext.InformerFactory.Networking().V1beta1().ServiceCIDRs(),
controllerContext.InformerFactory.Networking().V1alpha1().IPAddresses(), controllerContext.InformerFactory.Networking().V1beta1().IPAddresses(),
controllerContext.ClientBuilder.ClientOrDie("service-cidrs-controller"), controllerContext.ClientBuilder.ClientOrDie("service-cidrs-controller"),
).Run(ctx, 5) ).Run(ctx, 5)
// TODO use component config // TODO use component config

View File

@@ -982,7 +982,7 @@ func (s *ProxyServer) Run(ctx context.Context) error {
go endpointSliceConfig.Run(ctx.Done()) go endpointSliceConfig.Run(ctx.Done())
if utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) { 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) serviceCIDRConfig.RegisterEventHandler(s.Proxier)
go serviceCIDRConfig.Run(wait.NeverStop) go serviceCIDRConfig.Run(wait.NeverStop)
} }

View File

@@ -21,14 +21,14 @@ import (
"net" "net"
"net/netip" "net/netip"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/labels" "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 // OverlapsPrefix return the list of ServiceCIDR that overlaps with the prefix passed as argument
func OverlapsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1alpha1.ServiceCIDR { func OverlapsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1beta1.ServiceCIDR {
result := []*networkingv1alpha1.ServiceCIDR{} result := []*networkingv1beta1.ServiceCIDR{}
serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) serviceCIDRList, err := serviceCIDRLister.List(labels.Everything())
if err != nil { if err != nil {
return result 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 // ContainsPrefix return the list of ServiceCIDR that contains the prefix passed as argument
func ContainsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1alpha1.ServiceCIDR { func ContainsPrefix(serviceCIDRLister networkinglisters.ServiceCIDRLister, prefix netip.Prefix) []*networkingv1beta1.ServiceCIDR {
result := []*networkingv1alpha1.ServiceCIDR{} result := []*networkingv1beta1.ServiceCIDR{}
serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) serviceCIDRList, err := serviceCIDRLister.List(labels.Everything())
if err != nil { if err != nil {
return result 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 // 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) address := IPToAddr(ip)
return ContainsAddress(serviceCIDRLister, address) return ContainsAddress(serviceCIDRLister, address)
} }
// ContainsAddress return the list of ServiceCIDR that contains the address passed as argument // ContainsAddress return the list of ServiceCIDR that contains the address passed as argument
func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, address netip.Addr) []*networkingv1alpha1.ServiceCIDR { func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, address netip.Addr) []*networkingv1beta1.ServiceCIDR {
result := []*networkingv1alpha1.ServiceCIDR{} result := []*networkingv1beta1.ServiceCIDR{}
serviceCIDRList, err := serviceCIDRLister.List(labels.Everything()) serviceCIDRList, err := serviceCIDRLister.List(labels.Everything())
if err != nil { if err != nil {
return result return result

View File

@@ -22,19 +22,19 @@ import (
"sort" "sort"
"testing" "testing"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 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" "k8s.io/client-go/tools/cache"
netutils "k8s.io/utils/net" netutils "k8s.io/utils/net"
) )
func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.ServiceCIDR { func newServiceCIDR(name, primary, secondary string) *networkingv1beta1.ServiceCIDR {
serviceCIDR := &networkingv1alpha1.ServiceCIDR{ serviceCIDR := &networkingv1beta1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
}, },
Spec: networkingv1alpha1.ServiceCIDRSpec{}, Spec: networkingv1beta1.ServiceCIDRSpec{},
} }
serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
if secondary != "" { if secondary != "" {
@@ -46,13 +46,13 @@ func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.Service
func TestOverlapsPrefix(t *testing.T) { func TestOverlapsPrefix(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
serviceCIDRs []*networkingv1alpha1.ServiceCIDR serviceCIDRs []*networkingv1beta1.ServiceCIDR
prefix netip.Prefix prefix netip.Prefix
want []string want []string
}{ }{
{ {
name: "only one ServiceCIDR and IPv4 prefix contained", name: "only one ServiceCIDR and IPv4 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/26"), 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", name: "only one ServiceCIDR and same IPv4 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/24"), 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", name: "only one ServiceCIDR and larger IPv4 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/16"), 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", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("192.168.0.0/24"), 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", name: "only one ServiceCIDR and IPv6 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db8::/112"), prefix: netip.MustParsePrefix("2001:db8::/112"),
@@ -92,7 +92,7 @@ func TestOverlapsPrefix(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and same IPv6 prefix", name: "only one ServiceCIDR and same IPv6 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("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", name: "only one ServiceCIDR and IPv6 larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db8::/64"), 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", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db2::/112"), prefix: netip.MustParsePrefix("2001:db2::/112"),
@@ -116,7 +116,7 @@ func TestOverlapsPrefix(t *testing.T) {
}, },
{ {
name: "two ServiceCIDR and IPv4 prefix contained", name: "two ServiceCIDR and IPv4 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv4 larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv6 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and aprefix larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "multiple ServiceCIDR match with overlap contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("kubernetes2", "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"), 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", name: "multiple ServiceCIDR match with overlap contains",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("kubernetes2", "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"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"),
@@ -234,13 +234,13 @@ func TestOverlapsPrefix(t *testing.T) {
func TestContainsPrefix(t *testing.T) { func TestContainsPrefix(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
serviceCIDRs []*networkingv1alpha1.ServiceCIDR serviceCIDRs []*networkingv1beta1.ServiceCIDR
prefix netip.Prefix prefix netip.Prefix
want []string want []string
}{ }{
{ {
name: "only one ServiceCIDR and IPv4 prefix contained", name: "only one ServiceCIDR and IPv4 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/26"), 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", name: "only one ServiceCIDR and same IPv4 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/24"), 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", name: "only one ServiceCIDR and larger IPv4 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("10.0.0.0/16"), 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", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("192.168.0.0/24"), 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", name: "only one ServiceCIDR and IPv6 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db8::/112"), prefix: netip.MustParsePrefix("2001:db8::/112"),
@@ -280,7 +280,7 @@ func TestContainsPrefix(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and same IPv6 prefix", name: "only one ServiceCIDR and same IPv6 prefix",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("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", name: "only one ServiceCIDR and IPv6 larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db8::/64"), 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", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
prefix: netip.MustParsePrefix("2001:db2::/112"), prefix: netip.MustParsePrefix("2001:db2::/112"),
@@ -304,7 +304,7 @@ func TestContainsPrefix(t *testing.T) {
}, },
{ {
name: "two ServiceCIDR and IPv4 prefix contained", name: "two ServiceCIDR and IPv4 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv4 larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv6 prefix contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and aprefix larger",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "multiple ServiceCIDR match with overlap",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("kubernetes2", "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"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"),
@@ -412,13 +412,13 @@ func TestContainsPrefix(t *testing.T) {
func TestContainsAddress(t *testing.T) { func TestContainsAddress(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
serviceCIDRs []*networkingv1alpha1.ServiceCIDR serviceCIDRs []*networkingv1beta1.ServiceCIDR
address netip.Addr address netip.Addr
want []string want []string
}{ }{
{ {
name: "only one ServiceCIDR and IPv4 address contained", name: "only one ServiceCIDR and IPv4 address contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("10.0.0.1"), address: netip.MustParseAddr("10.0.0.1"),
@@ -426,7 +426,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv4 address broadcast", name: "only one ServiceCIDR and IPv4 address broadcast",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("10.0.0.255"), address: netip.MustParseAddr("10.0.0.255"),
@@ -434,7 +434,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv4 address base", name: "only one ServiceCIDR and IPv4 address base",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("10.0.0.0"), 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", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("192.0.0.1"), address: netip.MustParseAddr("192.0.0.1"),
@@ -450,7 +450,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv6 address contained", name: "only one ServiceCIDR and IPv6 address contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("2001:db8::2:3"), address: netip.MustParseAddr("2001:db8::2:3"),
@@ -458,7 +458,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv6 address broadcast", name: "only one ServiceCIDR and IPv6 address broadcast",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("2001:db8::ffff:ffff"), address: netip.MustParseAddr("2001:db8::ffff:ffff"),
@@ -466,7 +466,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv6 address base", name: "only one ServiceCIDR and IPv6 address base",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("2001:db8::"), address: netip.MustParseAddr("2001:db8::"),
@@ -474,7 +474,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "only one ServiceCIDR and IPv6 address out of range", 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"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
}, },
address: netip.MustParseAddr("2002:1:2:3::2"), address: netip.MustParseAddr("2002:1:2:3::2"),
@@ -482,7 +482,7 @@ func TestContainsAddress(t *testing.T) {
}, },
{ {
name: "two ServiceCIDR and IPv4 address contained", name: "two ServiceCIDR and IPv4 address contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv4 address broadcast",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv4 address base",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and IPv6 address contained",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and address broadcast",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "two ServiceCIDR and address base",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", 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("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"), 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", name: "multiple ServiceCIDR match with overlap",
serviceCIDRs: []*networkingv1alpha1.ServiceCIDR{ serviceCIDRs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"), newServiceCIDR("kubernetes", "10.0.0.0/24", "2001:db8::/96"),
newServiceCIDR("kubernetes2", "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"), newServiceCIDR("secondary", "10.0.0.0/16", "2001:db8::/64"),

View File

@@ -23,7 +23,7 @@ import (
"time" "time"
v1 "k8s.io/api/core/v1" 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" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
@@ -32,12 +32,12 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
metav1apply "k8s.io/client-go/applyconfigurations/meta/v1" metav1apply "k8s.io/client-go/applyconfigurations/meta/v1"
networkingapiv1alpha1apply "k8s.io/client-go/applyconfigurations/networking/v1alpha1" networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1"
networkinginformers "k8s.io/client-go/informers/networking/v1alpha1" networkinginformers "k8s.io/client-go/informers/networking/v1beta1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
v1core "k8s.io/client-go/kubernetes/typed/core/v1" 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/cache"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue" "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{}) { func (c *Controller) addServiceCIDR(obj interface{}) {
cidr, ok := obj.(*networkingapiv1alpha1.ServiceCIDR) cidr, ok := obj.(*networkingapiv1beta1.ServiceCIDR)
if !ok { if !ok {
return return
} }
@@ -174,7 +174,7 @@ func (c *Controller) deleteServiceCIDR(obj interface{}) {
// addIPAddress may block a ServiceCIDR deletion // addIPAddress may block a ServiceCIDR deletion
func (c *Controller) addIPAddress(obj interface{}) { func (c *Controller) addIPAddress(obj interface{}) {
ip, ok := obj.(*networkingapiv1alpha1.IPAddress) ip, ok := obj.(*networkingapiv1beta1.IPAddress)
if !ok { if !ok {
return return
} }
@@ -186,13 +186,13 @@ func (c *Controller) addIPAddress(obj interface{}) {
// deleteIPAddress may unblock a ServiceCIDR deletion // deleteIPAddress may unblock a ServiceCIDR deletion
func (c *Controller) deleteIPAddress(obj interface{}) { func (c *Controller) deleteIPAddress(obj interface{}) {
ip, ok := obj.(*networkingapiv1alpha1.IPAddress) ip, ok := obj.(*networkingapiv1beta1.IPAddress)
if !ok { if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok { if !ok {
return return
} }
ip, ok = tombstone.Obj.(*networkingapiv1alpha1.IPAddress) ip, ok = tombstone.Obj.(*networkingapiv1beta1.IPAddress)
if !ok { if !ok {
return return
} }
@@ -206,7 +206,7 @@ func (c *Controller) deleteIPAddress(obj interface{}) {
// overlappingServiceCIDRs, given a ServiceCIDR return the ServiceCIDRs that contain or are contained, // 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 // 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. // 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]() result := sets.New[string]()
for _, cidr := range serviceCIDR.Spec.CIDRs { for _, cidr := range serviceCIDR.Spec.CIDRs {
if prefix, err := netip.ParsePrefix(cidr); err == nil { // if is empty err will not be nil 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, // 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. // 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 // 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 { if !ok || managedBy != ipallocator.ControllerName {
return []string{} 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, // 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 // it will be reevaludated by an event on any ServiceCIDR or IPAddress related object
// that may remove this condition. // that may remove this condition.
svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
metav1apply.Condition(). metav1apply.Condition().
WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
WithStatus(metav1.ConditionFalse). 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"). WithMessage("There are still IPAddresses referencing the ServiceCIDR, please remove them or create a new ServiceCIDR").
WithLastTransitionTime(metav1.Now())) WithLastTransitionTime(metav1.Now()))
svcApply := networkingapiv1alpha1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
_, err = c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}) _, err = c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true})
return err return err
} }
// If there are no IPAddress depending on this ServiceCIDR is safe to remove it, // 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. // Set Ready condition to True.
svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
metav1apply.Condition(). metav1apply.Condition().
WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
WithStatus(metav1.ConditionTrue). WithStatus(metav1.ConditionTrue).
WithMessage("Kubernetes Service CIDR is ready"). WithMessage("Kubernetes Service CIDR is ready").
WithLastTransitionTime(metav1.Now())) WithLastTransitionTime(metav1.Now()))
svcApply := networkingapiv1alpha1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus) svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
if _, err := c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); err != nil { 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) 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") c.eventRecorder.Eventf(cidr, v1.EventTypeWarning, "KubernetesServiceCIDRError", "The ServiceCIDR Status can not be set to Ready=True")
return err 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 // 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) logger := klog.FromContext(ctx)
// Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted. // Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted.
hasParent := true hasParent := true
@@ -379,8 +379,8 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
for _, cidr := range serviceCIDR.Spec.CIDRs { for _, cidr := range serviceCIDR.Spec.CIDRs {
// get all the IPv4 addresses // get all the IPv4 addresses
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingapiv1alpha1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))), networkingapiv1beta1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))),
networkingapiv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ips, err := c.ipAddressLister.List(ipLabelSelector) ips, err := c.ipAddressLister.List(ipLabelSelector)
if err != nil { if err != nil {
@@ -411,7 +411,7 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
return true, nil 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() { for _, f := range cidr.GetFinalizers() {
if f == ServiceCIDRProtectionFinalizer { if f == ServiceCIDRProtectionFinalizer {
return nil return nil
@@ -427,7 +427,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
if err != nil { if err != nil {
return err 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) { if err != nil && !apierrors.IsNotFound(err) {
return 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 found := false
for _, f := range cidr.GetFinalizers() { for _, f := range cidr.GetFinalizers() {
if f == ServiceCIDRProtectionFinalizer { if f == ServiceCIDRProtectionFinalizer {
@@ -456,7 +456,7 @@ func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cid
if err != nil { if err != nil {
return err 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) { if err != nil && !apierrors.IsNotFound(err) {
return err return err
} }

View File

@@ -24,7 +24,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
v1 "k8s.io/api/core/v1" 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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
@@ -44,12 +44,12 @@ type testController struct {
ipaddressesStore cache.Store 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() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc()) informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc())
serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
cidrStore := serviceCIDRInformer.Informer().GetStore() cidrStore := serviceCIDRInformer.Informer().GetStore()
for _, obj := range cidrs { for _, obj := range cidrs {
err := cidrStore.Add(obj) err := cidrStore.Add(obj)
@@ -57,7 +57,7 @@ func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1al
t.Fatal(err) t.Fatal(err)
} }
} }
ipAddressInformer := informerFactory.Networking().V1alpha1().IPAddresses() ipAddressInformer := informerFactory.Networking().V1beta1().IPAddresses()
ipStore := ipAddressInformer.Informer().GetStore() ipStore := ipAddressInformer.Informer().GetStore()
for _, obj := range ips { for _, obj := range ips {
err := ipStore.Add(obj) err := ipStore.Add(obj)
@@ -97,8 +97,8 @@ func TestControllerSync(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
cidrs []*networkingapiv1alpha1.ServiceCIDR cidrs []*networkingapiv1beta1.ServiceCIDR
ips []*networkingapiv1alpha1.IPAddress ips []*networkingapiv1beta1.IPAddress
cidrSynced string cidrSynced string
actions [][]string // verb and resource and subresource actions [][]string // verb and resource and subresource
}{ }{
@@ -107,7 +107,7 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "default service CIDR must have finalizer", name: "default service CIDR must have finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
cidrSynced: defaultservicecidr.DefaultServiceCIDRName, cidrSynced: defaultservicecidr.DefaultServiceCIDRName,
@@ -115,7 +115,7 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "service CIDR must have finalizer", name: "service CIDR must have finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR("no-finalizer", "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR("no-finalizer", "192.168.0.0/24", "2001:db2::/64"),
}, },
cidrSynced: "no-finalizer", cidrSynced: "no-finalizer",
@@ -123,7 +123,7 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "service CIDR being deleted must remove the finalizer", name: "service CIDR being deleted must remove the finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
}, },
cidrSynced: deletedServiceCIDR.Name, 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 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, deletingServiceCIDR,
}, },
cidrSynced: deletingServiceCIDR.Name, cidrSynced: deletingServiceCIDR.Name,
@@ -139,10 +139,10 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "service CIDR being deleted with IPv4 addresses should update the status", name: "service CIDR being deleted with IPv4 addresses should update the status",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.1"), makeIPAddress("192.168.0.1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and overlapping same range and IPv4 addresses should remove the finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "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.1"), makeIPAddress("192.168.0.1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and overlapping and IPv4 addresses should remove the finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.1"), makeIPAddress("192.168.0.1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and not overlapping and IPv4 addresses should update the status",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.1"), makeIPAddress("192.168.0.1"),
}, },
cidrSynced: deletedServiceCIDR.Name, cidrSynced: deletedServiceCIDR.Name,
@@ -186,10 +186,10 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "service CIDR being deleted with IPv6 addresses should update the status", name: "service CIDR being deleted with IPv6 addresses should update the status",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("2001:db2::1"), makeIPAddress("2001:db2::1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and overlapping same range and IPv6 addresses should remove the finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "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("2001:db2::1"), makeIPAddress("2001:db2::1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and overlapping and IPv6 addresses should remove the finalizer",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/48"), makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/48"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("2001:db2::1"), makeIPAddress("2001:db2::1"),
}, },
cidrSynced: deletedServiceCIDR.Name, 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", name: "service CIDR being deleted and not overlapping and IPv6 addresses should update the status",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
deletedServiceCIDR, deletedServiceCIDR,
makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2:a:b::/64"), makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2:a:b::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("2001:db2::1"), makeIPAddress("2001:db2::1"),
}, },
cidrSynced: deletedServiceCIDR.Name, cidrSynced: deletedServiceCIDR.Name,
@@ -247,12 +247,12 @@ func TestControllerSync(t *testing.T) {
} }
} }
func makeServiceCIDR(name, primary, secondary string) *networkingapiv1alpha1.ServiceCIDR { func makeServiceCIDR(name, primary, secondary string) *networkingapiv1beta1.ServiceCIDR {
serviceCIDR := &networkingapiv1alpha1.ServiceCIDR{ serviceCIDR := &networkingapiv1beta1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{}, Spec: networkingapiv1beta1.ServiceCIDRSpec{},
} }
serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
if secondary != "" { if secondary != "" {
@@ -261,17 +261,17 @@ func makeServiceCIDR(name, primary, secondary string) *networkingapiv1alpha1.Ser
return serviceCIDR return serviceCIDR
} }
func makeIPAddress(name string) *networkingapiv1alpha1.IPAddress { func makeIPAddress(name string) *networkingapiv1beta1.IPAddress {
family := string(v1.IPv4Protocol) family := string(v1.IPv4Protocol)
if netutils.IsIPv6String(name) { if netutils.IsIPv6String(name) {
family = string(v1.IPv6Protocol) family = string(v1.IPv6Protocol)
} }
return &networkingapiv1alpha1.IPAddress{ return &networkingapiv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Labels: map[string]string{ Labels: map[string]string{
networkingapiv1alpha1.LabelIPAddressFamily: family, networkingapiv1beta1.LabelIPAddressFamily: family,
networkingapiv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
}, },
} }
@@ -302,9 +302,9 @@ func expectAction(t *testing.T, actions []k8stesting.Action, expected [][]string
func TestController_canDeleteCIDR(t *testing.T) { func TestController_canDeleteCIDR(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
cidrs []*networkingapiv1alpha1.ServiceCIDR cidrs []*networkingapiv1beta1.ServiceCIDR
ips []*networkingapiv1alpha1.IPAddress ips []*networkingapiv1beta1.IPAddress
cidrSynced *networkingapiv1alpha1.ServiceCIDR cidrSynced *networkingapiv1beta1.ServiceCIDR
want bool want bool
}{ }{
{ {
@@ -314,7 +314,7 @@ func TestController_canDeleteCIDR(t *testing.T) {
}, },
{ {
name: "CIDR and no IPs", name: "CIDR and no IPs",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
cidrSynced: 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", name: "CIDR with IPs",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.24"), makeIPAddress("192.168.0.24"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", name: "CIDR without IPs",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.1.24"), makeIPAddress("192.168.1.24"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.0"), makeIPAddress("192.168.0.0"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.255"), makeIPAddress("192.168.0.255"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("2001:0db2::ffff:ffff:ffff:ffff"), makeIPAddress("2001:0db2::ffff:ffff:ffff:ffff"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), makeIPAddress("192.168.0.23"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "192.168.0.0/26", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/26", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.23"), makeIPAddress("192.168.0.23"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "192.168.0.0/28", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/28", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.23"), makeIPAddress("192.168.0.23"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"), makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"),
}, },
ips: []*networkingapiv1alpha1.IPAddress{ ips: []*networkingapiv1beta1.IPAddress{
makeIPAddress("192.168.0.23"), makeIPAddress("192.168.0.23"),
}, },
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), 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) { func TestController_ipToCidrs(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
cidrs []*networkingapiv1alpha1.ServiceCIDR cidrs []*networkingapiv1beta1.ServiceCIDR
ip *networkingapiv1alpha1.IPAddress ip *networkingapiv1beta1.IPAddress
want []string want []string
}{ }{
{ {
@@ -452,7 +452,7 @@ func TestController_ipToCidrs(t *testing.T) {
want: []string{}, want: []string{},
}, { }, {
name: "one CIDR", name: "one CIDR",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
makeServiceCIDR("unrelated2", "10.0.0.0/16", ""), makeServiceCIDR("unrelated2", "10.0.0.0/16", ""),
@@ -461,7 +461,7 @@ func TestController_ipToCidrs(t *testing.T) {
want: []string{defaultservicecidr.DefaultServiceCIDRName}, want: []string{defaultservicecidr.DefaultServiceCIDRName},
}, { }, {
name: "two equal CIDR", name: "two equal CIDR",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"),
makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
@@ -471,7 +471,7 @@ func TestController_ipToCidrs(t *testing.T) {
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"}, want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
}, { }, {
name: "three CIDR - two same and one larger", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), 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"}, want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping", "overlapping2"},
}, { }, {
name: "three CIDR - two same and one larger - IPv4 subnet address", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
@@ -493,7 +493,7 @@ func TestController_ipToCidrs(t *testing.T) {
want: []string{}, want: []string{},
}, { }, {
name: "three CIDR - two same and one larger - IPv4 broadcast address", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), 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"}, want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
}, { }, {
name: "three CIDR - two same and one larger - IPv6 subnet address", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
@@ -515,7 +515,7 @@ func TestController_ipToCidrs(t *testing.T) {
want: []string{}, want: []string{},
}, { }, {
name: "three CIDR - two same and one larger - IPv6 broadcast address", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), 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) { func TestController_cidrToCidrs(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
cidrs []*networkingapiv1alpha1.ServiceCIDR cidrs []*networkingapiv1beta1.ServiceCIDR
cidr *networkingapiv1alpha1.ServiceCIDR cidr *networkingapiv1beta1.ServiceCIDR
want []string want []string
}{ }{
{ {
@@ -549,7 +549,7 @@ func TestController_cidrToCidrs(t *testing.T) {
want: []string{}, want: []string{},
}, { }, {
name: "one CIDR", name: "one CIDR",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
makeServiceCIDR("unrelated2", "10.0.0.0/16", ""), makeServiceCIDR("unrelated2", "10.0.0.0/16", ""),
@@ -558,7 +558,7 @@ func TestController_cidrToCidrs(t *testing.T) {
want: []string{defaultservicecidr.DefaultServiceCIDRName}, want: []string{defaultservicecidr.DefaultServiceCIDRName},
}, { }, {
name: "two equal CIDR", name: "two equal CIDR",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"), makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"), makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"),
makeServiceCIDR("unrelated", "10.0.0.0/24", ""), makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
@@ -568,7 +568,7 @@ func TestController_cidrToCidrs(t *testing.T) {
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"}, want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
}, { }, {
name: "three CIDR - two same and one larger", 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(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
makeServiceCIDR("overlapping", "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"), makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),

View File

@@ -23,19 +23,19 @@ import (
"time" "time"
v1 "k8s.io/api/core/v1" 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" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/fields"
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
metav1apply "k8s.io/client-go/applyconfigurations/meta/v1" metav1apply "k8s.io/client-go/applyconfigurations/meta/v1"
networkingapiv1alpha1apply "k8s.io/client-go/applyconfigurations/networking/v1alpha1" networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1"
networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
v1core "k8s.io/client-go/kubernetes/typed/core/v1" 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/cache"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/klog/v2" "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 // 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 // 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}, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
func(options *metav1.ListOptions) { func(options *metav1.ListOptions) {
options.FieldSelector = fields.OneTermEqualSelector("metadata.name", DefaultServiceCIDRName).String() 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 c.serviceCIDRsSynced = c.serviceCIDRInformer.HasSynced
return c return c
@@ -88,7 +88,7 @@ type Controller struct {
eventRecorder record.EventRecorder eventRecorder record.EventRecorder
serviceCIDRInformer cache.SharedIndexInformer serviceCIDRInformer cache.SharedIndexInformer
serviceCIDRLister networkingv1alpha1listers.ServiceCIDRLister serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister
serviceCIDRsSynced cache.InformerSynced serviceCIDRsSynced cache.InformerSynced
interval time.Duration interval time.Duration
@@ -149,15 +149,15 @@ func (c *Controller) sync() error {
// default ServiceCIDR does not exist // default ServiceCIDR does not exist
klog.Infof("Creating default ServiceCIDR with CIDRs: %v", c.cidrs) klog.Infof("Creating default ServiceCIDR with CIDRs: %v", c.cidrs)
serviceCIDR = &networkingapiv1alpha1.ServiceCIDR{ serviceCIDR = &networkingapiv1beta1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: DefaultServiceCIDRName, Name: DefaultServiceCIDRName,
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: c.cidrs, 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) { if err != nil && !apierrors.IsAlreadyExists(err) {
c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR can not be created") c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR can not be created")
return err return err
@@ -166,7 +166,7 @@ func (c *Controller) sync() error {
return nil 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, // don't sync the status of the ServiceCIDR if is being deleted,
// deletion must be handled by the controller-manager // deletion must be handled by the controller-manager
if !serviceCIDR.GetDeletionTimestamp().IsZero() { 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 // 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. // does not exist and the CIDR values match this controller CIDR values.
for _, condition := range serviceCIDR.Status.Conditions { for _, condition := range serviceCIDR.Status.Conditions {
if condition.Type == networkingapiv1alpha1.ServiceCIDRConditionReady { if condition.Type == networkingapiv1beta1.ServiceCIDRConditionReady {
if condition.Status == metav1.ConditionTrue { if condition.Status == metav1.ConditionTrue {
return return
} }
@@ -188,14 +188,14 @@ func (c *Controller) syncStatus(serviceCIDR *networkingapiv1alpha1.ServiceCIDR)
// set status to ready if the ServiceCIDR matches this configuration // set status to ready if the ServiceCIDR matches this configuration
if reflect.DeepEqual(c.cidrs, serviceCIDR.Spec.CIDRs) { if reflect.DeepEqual(c.cidrs, serviceCIDR.Spec.CIDRs) {
klog.Infof("Setting default ServiceCIDR condition Ready to True") klog.Infof("Setting default ServiceCIDR condition Ready to True")
svcApplyStatus := networkingapiv1alpha1apply.ServiceCIDRStatus().WithConditions( svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
metav1apply.Condition(). metav1apply.Condition().
WithType(networkingapiv1alpha1.ServiceCIDRConditionReady). WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
WithStatus(metav1.ConditionTrue). WithStatus(metav1.ConditionTrue).
WithMessage("Kubernetes default Service CIDR is ready"). WithMessage("Kubernetes default Service CIDR is ready").
WithLastTransitionTime(metav1.Now())) WithLastTransitionTime(metav1.Now()))
svcApply := networkingapiv1alpha1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus) svcApply := networkingapiv1beta1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus)
if _, errApply := c.client.NetworkingV1alpha1().ServiceCIDRs().ApplyStatus(context.Background(), svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); errApply != nil { 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) 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") c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR Status can not be set to Ready=True")
} }

View File

@@ -21,7 +21,7 @@ import (
"time" "time"
"github.com/google/go-cmp/cmp" "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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
@@ -35,11 +35,11 @@ const (
defaultIPv6CIDR = "2001:db8::/64" 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() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0) informerFactory := informers.NewSharedInformerFactory(client, 0)
serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
store := serviceCIDRInformer.Informer().GetStore() store := serviceCIDRInformer.Informer().GetStore()
for _, obj := range objects { for _, obj := range objects {
@@ -64,7 +64,7 @@ func newController(t *testing.T, objects []*networkingapiv1alpha1.ServiceCIDR) (
func TestControllerSync(t *testing.T) { func TestControllerSync(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
cidrs []*networkingapiv1alpha1.ServiceCIDR cidrs []*networkingapiv1beta1.ServiceCIDR
actions [][]string // verb and resource actions [][]string // verb and resource
}{ }{
{ {
@@ -73,12 +73,12 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "existing default service CIDR update Ready condition", name: "existing default service CIDR update Ready condition",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: DefaultServiceCIDRName, Name: DefaultServiceCIDRName,
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
}, },
}, },
@@ -87,12 +87,12 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "existing default service CIDR not matching cidrs", name: "existing default service CIDR not matching cidrs",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: DefaultServiceCIDRName, Name: DefaultServiceCIDRName,
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: []string{"fd00::/112"}, CIDRs: []string{"fd00::/112"},
}, },
}, },
@@ -100,18 +100,18 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "existing default service CIDR not ready", name: "existing default service CIDR not ready",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: DefaultServiceCIDRName, Name: DefaultServiceCIDRName,
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
}, },
Status: networkingapiv1alpha1.ServiceCIDRStatus{ Status: networkingapiv1beta1.ServiceCIDRStatus{
Conditions: []metav1.Condition{ Conditions: []metav1.Condition{
{ {
Type: string(networkingapiv1alpha1.ServiceCIDRConditionReady), Type: string(networkingapiv1beta1.ServiceCIDRConditionReady),
Status: metav1.ConditionFalse, Status: metav1.ConditionFalse,
}, },
}, },
@@ -121,13 +121,13 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "existing default service CIDR being deleted", name: "existing default service CIDR being deleted",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: DefaultServiceCIDRName, Name: DefaultServiceCIDRName,
DeletionTimestamp: ptr.To(metav1.Now()), DeletionTimestamp: ptr.To(metav1.Now()),
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
}, },
}, },
@@ -135,12 +135,12 @@ func TestControllerSync(t *testing.T) {
}, },
{ {
name: "existing service CIDRs but not default", name: "existing service CIDRs but not default",
cidrs: []*networkingapiv1alpha1.ServiceCIDR{ cidrs: []*networkingapiv1beta1.ServiceCIDR{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "non-default-cidr", Name: "non-default-cidr",
}, },
Spec: networkingapiv1alpha1.ServiceCIDRSpec{ Spec: networkingapiv1beta1.ServiceCIDRSpec{
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR}, CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
}, },
}, },

View File

@@ -43,6 +43,7 @@ import (
eventsv1 "k8s.io/api/events/v1" eventsv1 "k8s.io/api/events/v1"
networkingapiv1 "k8s.io/api/networking/v1" networkingapiv1 "k8s.io/api/networking/v1"
networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1" networkingapiv1alpha1 "k8s.io/api/networking/v1alpha1"
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
nodev1 "k8s.io/api/node/v1" nodev1 "k8s.io/api/node/v1"
policyapiv1 "k8s.io/api/policy/v1" policyapiv1 "k8s.io/api/policy/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
@@ -466,6 +467,7 @@ var (
flowcontrolv1beta1.SchemeGroupVersion, flowcontrolv1beta1.SchemeGroupVersion,
flowcontrolv1beta2.SchemeGroupVersion, flowcontrolv1beta2.SchemeGroupVersion,
flowcontrolv1beta3.SchemeGroupVersion, flowcontrolv1beta3.SchemeGroupVersion,
networkingapiv1beta1.SchemeGroupVersion,
} }
// alphaAPIGroupVersionsDisabledByDefault holds the alpha APIs we have. They are always disabled by default. // alphaAPIGroupVersionsDisabledByDefault holds the alpha APIs we have. They are always disabled by default.

View File

@@ -38,7 +38,7 @@ import (
discoveryv1beta1 "k8s.io/api/discovery/v1beta1" discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
flowcontrolv1 "k8s.io/api/flowcontrol/v1" flowcontrolv1 "k8s.io/api/flowcontrol/v1"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1" rbacv1beta1 "k8s.io/api/rbac/v1beta1"
resourcev1alpha2 "k8s.io/api/resource/v1alpha2" resourcev1alpha2 "k8s.io/api/resource/v1alpha2"
schedulingv1 "k8s.io/api/scheduling/v1" schedulingv1 "k8s.io/api/scheduling/v1"
@@ -685,7 +685,7 @@ func AddHandlers(h printers.PrintHandler) {
serviceCIDRColumnDefinitions := []metav1.TableColumnDefinition{ serviceCIDRColumnDefinitions := []metav1.TableColumnDefinition{
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, {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"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
} }
@@ -694,7 +694,7 @@ func AddHandlers(h printers.PrintHandler) {
ipAddressColumnDefinitions := []metav1.TableColumnDefinition{ ipAddressColumnDefinitions := []metav1.TableColumnDefinition{
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, {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) _ = h.TableHandler(ipAddressColumnDefinitions, printIPAddress)

View File

@@ -24,12 +24,12 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/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" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
v1informers "k8s.io/client-go/informers/core/v1" v1informers "k8s.io/client-go/informers/core/v1"
discoveryv1informers "k8s.io/client-go/informers/discovery/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/client-go/tools/cache"
"k8s.io/klog/v2" "k8s.io/klog/v2"
) )
@@ -401,7 +401,7 @@ type ServiceCIDRConfig struct {
} }
// NewServiceCIDRConfig creates a new ServiceCIDRConfig. // 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{ result := &ServiceCIDRConfig{
listerSynced: serviceCIDRInformer.Informer().HasSynced, listerSynced: serviceCIDRInformer.Informer().HasSynced,
cidrs: sets.New[string](), 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 // handleServiceCIDREvent is a helper function to handle Add, Update and Delete
// events on ServiceCIDR objects and call downstream event handlers. // events on ServiceCIDR objects and call downstream event handlers.
func (c *ServiceCIDRConfig) handleServiceCIDREvent(oldObj, newObj interface{}) { func (c *ServiceCIDRConfig) handleServiceCIDREvent(oldObj, newObj interface{}) {
var oldServiceCIDR, newServiceCIDR *networkingv1alpha1.ServiceCIDR var oldServiceCIDR, newServiceCIDR *networkingv1beta1.ServiceCIDR
var ok bool var ok bool
if oldObj != nil { if oldObj != nil {
oldServiceCIDR, ok = oldObj.(*networkingv1alpha1.ServiceCIDR) oldServiceCIDR, ok = oldObj.(*networkingv1beta1.ServiceCIDR)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj))
return return
@@ -455,7 +455,7 @@ func (c *ServiceCIDRConfig) handleServiceCIDREvent(oldObj, newObj interface{}) {
} }
if newObj != nil { if newObj != nil {
newServiceCIDR, ok = newObj.(*networkingv1alpha1.ServiceCIDR) newServiceCIDR, ok = newObj.(*networkingv1beta1.ServiceCIDR)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
return return

View File

@@ -34,7 +34,7 @@ import (
serverstorage "k8s.io/apiserver/pkg/server/storage" serverstorage "k8s.io/apiserver/pkg/server/storage"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/kubernetes" "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" policyclient "k8s.io/client-go/kubernetes/typed/policy/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
@@ -140,8 +140,8 @@ func New(c Config) (*legacyProvider, error) {
c.Services.IPRepairInterval, c.Services.IPRepairInterval,
client, client,
c.Informers.Core().V1().Services(), c.Informers.Core().V1().Services(),
c.Informers.Networking().V1alpha1().ServiceCIDRs(), c.Informers.Networking().V1beta1().ServiceCIDRs(),
c.Informers.Networking().V1alpha1().IPAddresses(), c.Informers.Networking().V1beta1().IPAddresses(),
).RunUntil ).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) return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster IP allocator: %v", err)
} }
} else { } else {
networkingv1alphaClient, err := networkingv1alpha1client.NewForConfig(c.LoopbackClientConfig) networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig)
if err != nil { if err != nil {
return rangeRegistries{}, nil, nil, nil, err 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 // sets the default IPFamily that may not be coherent with the
// existing default ServiceCIDR // existing default ServiceCIDR
primaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( primaryClusterIPAllocator, err = ipallocator.NewMetaAllocator(
networkingv1alphaClient, networkingv1beta1Client,
c.Informers.Networking().V1alpha1().ServiceCIDRs(), c.Informers.Networking().V1beta1().ServiceCIDRs(),
c.Informers.Networking().V1alpha1().IPAddresses(), c.Informers.Networking().V1beta1().IPAddresses(),
netutils.IsIPv6CIDR(&serviceClusterIPRange), netutils.IsIPv6CIDR(&serviceClusterIPRange),
bitmapAllocator, 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) return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster secondary IP allocator: %v", err)
} }
} else { } else {
networkingv1alphaClient, err := networkingv1alpha1client.NewForConfig(c.LoopbackClientConfig) networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig)
if err != nil { if err != nil {
return rangeRegistries{}, nil, nil, nil, err 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 // sets the default IPFamily that may not be coherent with the
// existing default ServiceCIDR // existing default ServiceCIDR
secondaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( secondaryClusterIPAllocator, err = ipallocator.NewMetaAllocator(
networkingv1alphaClient, networkingv1beta1Client,
c.Informers.Networking().V1alpha1().ServiceCIDRs(), c.Informers.Networking().V1beta1().ServiceCIDRs(),
c.Informers.Networking().V1alpha1().IPAddresses(), c.Informers.Networking().V1beta1().IPAddresses(),
netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange), netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange),
bitmapAllocator, bitmapAllocator,
) )

View File

@@ -24,16 +24,16 @@ import (
"time" "time"
v1 "k8s.io/api/core/v1" 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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
networkingv1alpha1client "k8s.io/client-go/kubernetes/typed/networking/v1alpha1" networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
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/cache"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2" "k8s.io/klog/v2"
@@ -52,12 +52,12 @@ import (
// MetaAllocator implements current allocator interface using // MetaAllocator implements current allocator interface using
// ServiceCIDR and IPAddress API objects. // ServiceCIDR and IPAddress API objects.
type MetaAllocator struct { type MetaAllocator struct {
client networkingv1alpha1client.NetworkingV1alpha1Interface client networkingv1beta1client.NetworkingV1beta1Interface
serviceCIDRLister networkingv1alpha1listers.ServiceCIDRLister serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister
serviceCIDRSynced cache.InformerSynced serviceCIDRSynced cache.InformerSynced
ipAddressLister networkingv1alpha1listers.IPAddressLister ipAddressLister networkingv1beta1listers.IPAddressLister
ipAddressSynced cache.InformerSynced ipAddressSynced cache.InformerSynced
ipAddressInformer networkingv1alpha1informers.IPAddressInformer ipAddressInformer networkingv1beta1informers.IPAddressInformer
queue workqueue.TypedRateLimitingInterface[string] queue workqueue.TypedRateLimitingInterface[string]
internalStopCh chan struct{} internalStopCh chan struct{}
@@ -87,9 +87,9 @@ var _ Interface = &MetaAllocator{}
// and ServiceCIDR objects to track the assigned IP addresses, // and ServiceCIDR objects to track the assigned IP addresses,
// using an informer cache as storage. // using an informer cache as storage.
func NewMetaAllocator( func NewMetaAllocator(
client networkingv1alpha1client.NetworkingV1alpha1Interface, client networkingv1beta1client.NetworkingV1beta1Interface,
serviceCIDRInformer networkingv1alpha1informers.ServiceCIDRInformer, serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer,
ipAddressInformer networkingv1alpha1informers.IPAddressInformer, ipAddressInformer networkingv1beta1informers.IPAddressInformer,
isIPv6 bool, isIPv6 bool,
bitmapAllocator Interface, bitmapAllocator Interface,
) (*MetaAllocator, error) { ) (*MetaAllocator, error) {
@@ -100,9 +100,9 @@ func NewMetaAllocator(
} }
// newMetaAllocator is used to build the allocator for testing // newMetaAllocator is used to build the allocator for testing
func newMetaAllocator(client networkingv1alpha1client.NetworkingV1alpha1Interface, func newMetaAllocator(client networkingv1beta1client.NetworkingV1beta1Interface,
serviceCIDRInformer networkingv1alpha1informers.ServiceCIDRInformer, serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer,
ipAddressInformer networkingv1alpha1informers.IPAddressInformer, ipAddressInformer networkingv1beta1informers.IPAddressInformer,
isIPv6 bool, isIPv6 bool,
bitmapAllocator Interface, bitmapAllocator Interface,
) *MetaAllocator { ) *MetaAllocator {
@@ -152,13 +152,13 @@ func (c *MetaAllocator) enqueueServiceCIDR(obj interface{}) {
} }
func (c *MetaAllocator) deleteServiceCIDR(obj interface{}) { func (c *MetaAllocator) deleteServiceCIDR(obj interface{}) {
serviceCIDR, ok := obj.(*networkingv1alpha1.ServiceCIDR) serviceCIDR, ok := obj.(*networkingv1beta1.ServiceCIDR)
if !ok { if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok { if !ok {
return return
} }
serviceCIDR, ok = tombstone.Obj.(*networkingv1alpha1.ServiceCIDR) serviceCIDR, ok = tombstone.Obj.(*networkingv1beta1.ServiceCIDR)
if !ok { if !ok {
return return
} }
@@ -414,8 +414,8 @@ func (c *MetaAllocator) Release(ip net.IP) error {
} }
func (c *MetaAllocator) ForEach(f func(ip net.IP)) { func (c *MetaAllocator) ForEach(f func(ip net.IP)) {
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(c.IPFamily()), networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()),
networkingv1alpha1.LabelManagedBy: ControllerName, networkingv1beta1.LabelManagedBy: ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ips, err := c.ipAddressLister.List(ipLabelSelector) ips, err := c.ipAddressLister.List(ipLabelSelector)
if err != nil { if err != nil {
@@ -454,8 +454,8 @@ func (c *MetaAllocator) Destroy() {
// for testing // for testing
func (c *MetaAllocator) Used() int { func (c *MetaAllocator) Used() int {
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(c.IPFamily()), networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()),
networkingv1alpha1.LabelManagedBy: ControllerName, networkingv1beta1.LabelManagedBy: ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ips, err := c.ipAddressLister.List(ipLabelSelector) ips, err := c.ipAddressLister.List(ipLabelSelector)
if err != nil { if err != nil {
@@ -512,13 +512,13 @@ func (c *MetaAllocator) DryRun() Interface {
return &Allocator{} return &Allocator{}
} }
func isReady(serviceCIDR *networkingv1alpha1.ServiceCIDR) bool { func isReady(serviceCIDR *networkingv1beta1.ServiceCIDR) bool {
if serviceCIDR == nil { if serviceCIDR == nil {
return false return false
} }
for _, condition := range serviceCIDR.Status.Conditions { for _, condition := range serviceCIDR.Status.Conditions {
if condition.Type == networkingv1alpha1.ServiceCIDRConditionReady { if condition.Type == networkingv1beta1.ServiceCIDRConditionReady {
return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue) return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue)
} }
} }

View File

@@ -23,7 +23,7 @@ import (
"testing" "testing"
"time" "time"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
@@ -41,13 +41,13 @@ func newTestMetaAllocator() (*MetaAllocator, error) {
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second)
serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer() serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer()
ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() ipInformer := informerFactory.Networking().V1beta1().IPAddresses()
ipStore := ipInformer.Informer().GetIndexer() ipStore := ipInformer.Informer().GetIndexer()
client.PrependReactor("create", "servicecidrs", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { 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) _, exists, err := serviceCIDRStore.GetByKey(cidr.Name)
if exists && err != nil { if exists && err != nil {
return false, nil, fmt.Errorf("cidr already exist") 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) { client.PrependReactor("delete", "servicecidrs", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) {
name := action.(k8stesting.DeleteAction).GetName() name := action.(k8stesting.DeleteAction).GetName()
obj, exists, err := serviceCIDRStore.GetByKey(name) obj, exists, err := serviceCIDRStore.GetByKey(name)
cidr := &networkingv1alpha1.ServiceCIDR{} cidr := &networkingv1beta1.ServiceCIDR{}
if exists && err == nil { if exists && err == nil {
cidr = obj.(*networkingv1alpha1.ServiceCIDR) cidr = obj.(*networkingv1beta1.ServiceCIDR)
err = serviceCIDRStore.Delete(cidr) err = serviceCIDRStore.Delete(cidr)
} }
return false, cidr, err return false, cidr, err
})) }))
client.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { 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) _, exists, err := ipStore.GetByKey(ip.Name)
if exists && err != nil { if exists && err != nil {
return false, nil, fmt.Errorf("ip already exist") 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) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) {
name := action.(k8stesting.DeleteAction).GetName() name := action.(k8stesting.DeleteAction).GetName()
obj, exists, err := ipStore.GetByKey(name) obj, exists, err := ipStore.GetByKey(name)
ip := &networkingv1alpha1.IPAddress{} ip := &networkingv1beta1.IPAddress{}
if exists && err == nil { if exists && err == nil {
ip = obj.(*networkingv1alpha1.IPAddress) ip = obj.(*networkingv1beta1.IPAddress)
err = ipStore.Delete(ip) err = ipStore.Delete(ip)
} }
return false, ip, err 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.serviceCIDRSynced = func() bool { return true }
c.ipAddressSynced = 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 // TODO: add IPv6 and dual stack test cases
func newServiceCIDR(name, cidr string) *networkingv1alpha1.ServiceCIDR { func newServiceCIDR(name, cidr string) *networkingv1beta1.ServiceCIDR {
return &networkingv1alpha1.ServiceCIDR{ return &networkingv1beta1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
}, },
Spec: networkingv1alpha1.ServiceCIDRSpec{ Spec: networkingv1beta1.ServiceCIDRSpec{
CIDRs: []string{cidr}, CIDRs: []string{cidr},
}, },
Status: networkingv1alpha1.ServiceCIDRStatus{ Status: networkingv1beta1.ServiceCIDRStatus{
Conditions: []metav1.Condition{ Conditions: []metav1.Condition{
{ {
Type: string(networkingv1alpha1.ServiceCIDRConditionReady), Type: string(networkingv1beta1.ServiceCIDRConditionReady),
Status: metav1.ConditionTrue, Status: metav1.ConditionTrue,
}, },
}, },

View File

@@ -23,17 +23,17 @@ import (
"time" "time"
v1 "k8s.io/api/core/v1" 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" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
coreinformers "k8s.io/client-go/informers/core/v1" 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" "k8s.io/client-go/kubernetes"
corelisters "k8s.io/client-go/listers/core/v1" 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/cache"
"k8s.io/client-go/tools/events" "k8s.io/client-go/tools/events"
"k8s.io/client-go/util/retry" "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 // Check that there is no IP created by the allocator without
// a Service associated. // a Service associated.
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ipAddresses, err := r.ipAddressLister.List(ipLabelSelector) ipAddresses, err := r.ipAddressLister.List(ipLabelSelector)
if err != nil { if err != nil {
@@ -360,7 +360,7 @@ func (r *RepairIPAddress) syncService(key string) error {
// ClusterIP doesn't seem to be allocated, create it. // 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) 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)) 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 { if err != nil {
return err return err
} }
@@ -417,11 +417,11 @@ func (r *RepairIPAddress) syncService(key string) error {
} }
func (r *RepairIPAddress) recreateIPAddress(name string, svc *v1.Service) 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) { if err != nil && !apierrors.IsNotFound(err) {
return 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 { if err != nil {
return err return err
} }
@@ -482,7 +482,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error {
if ipAddress.Spec.ParentRef.Group != "" || ipAddress.Spec.ParentRef.Resource != "services" { 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)) 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) 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) { if err != nil && !apierrors.IsNotFound(err) {
return err return err
} }
@@ -499,7 +499,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error {
if ipLifetime > gracePeriod { if ipLifetime > gracePeriod {
runtime.HandleError(fmt.Errorf("IPAddress %s appears to have leaked: cleaning up", ipAddress.Name)) 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) 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) { if err != nil && !apierrors.IsNotFound(err) {
return 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)) 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) 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) { if err != nil && !apierrors.IsNotFound(err) {
return err return err
} }
@@ -535,31 +535,31 @@ func (r *RepairIPAddress) isIPOutOfRange(ip net.IP) bool {
return len(servicecidr.ContainsIP(r.serviceCIDRLister, ip)) == 0 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) family := string(v1.IPv4Protocol)
if netutils.IsIPv6String(name) { if netutils.IsIPv6String(name) {
family = string(v1.IPv6Protocol) family = string(v1.IPv6Protocol)
} }
return &networkingv1alpha1.IPAddress{ return &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: family, networkingv1beta1.LabelIPAddressFamily: family,
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: serviceToRef(svc), ParentRef: serviceToRef(svc),
}, },
} }
} }
func serviceToRef(svc *v1.Service) *networkingv1alpha1.ParentReference { func serviceToRef(svc *v1.Service) *networkingv1beta1.ParentReference {
if svc == nil { if svc == nil {
return nil return nil
} }
return &networkingv1alpha1.ParentReference{ return &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Namespace: svc.Namespace, Namespace: svc.Namespace,
@@ -576,16 +576,16 @@ func getFamilyByIP(ip net.IP) v1.IPFamily {
// managedByController returns true if the controller of the provided // managedByController returns true if the controller of the provided
// EndpointSlices is the EndpointSlice controller. // EndpointSlices is the EndpointSlice controller.
func managedByController(ip *networkingv1alpha1.IPAddress) bool { func managedByController(ip *networkingv1beta1.IPAddress) bool {
managedBy, ok := ip.Labels[networkingv1alpha1.LabelManagedBy] managedBy, ok := ip.Labels[networkingv1beta1.LabelManagedBy]
if !ok { if !ok {
return false return false
} }
return managedBy == ipallocator.ControllerName return managedBy == ipallocator.ControllerName
} }
func verifyIPAddressLabels(ip *networkingv1alpha1.IPAddress) bool { func verifyIPAddressLabels(ip *networkingv1beta1.IPAddress) bool {
labelFamily, ok := ip.Labels[networkingv1alpha1.LabelIPAddressFamily] labelFamily, ok := ip.Labels[networkingv1beta1.LabelIPAddressFamily]
if !ok { if !ok {
return false return false
} }

View File

@@ -23,7 +23,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1" 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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -54,25 +54,25 @@ func newFakeRepair() (*fake.Clientset, *fakeRepair) {
serviceInformer := informerFactory.Core().V1().Services() serviceInformer := informerFactory.Core().V1().Services()
serviceIndexer := serviceInformer.Informer().GetIndexer() serviceIndexer := serviceInformer.Informer().GetIndexer()
serviceCIDRInformer := informerFactory.Networking().V1alpha1().ServiceCIDRs() serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer() serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer()
ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() ipInformer := informerFactory.Networking().V1beta1().IPAddresses()
ipIndexer := ipInformer.Informer().GetIndexer() ipIndexer := ipInformer.Informer().GetIndexer()
fakeClient.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { 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) err := ipIndexer.Add(ip)
return false, ip, err return false, ip, err
})) }))
fakeClient.PrependReactor("update", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { 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") return false, ip, fmt.Errorf("IPAddress is inmutable after creation")
})) }))
fakeClient.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { fakeClient.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) {
ip := action.(k8stesting.DeleteAction).GetName() ip := action.(k8stesting.DeleteAction).GetName()
err := ipIndexer.Delete(ip) err := ipIndexer.Delete(ip)
return false, &networkingv1alpha1.IPAddress{}, err return false, &networkingv1beta1.IPAddress{}, err
})) }))
r := NewRepairIPAddress(0*time.Second, r := NewRepairIPAddress(0*time.Second,
@@ -88,8 +88,8 @@ func TestRepairServiceIP(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
svcs []*v1.Service svcs []*v1.Service
ipAddresses []*networkingv1alpha1.IPAddress ipAddresses []*networkingv1beta1.IPAddress
cidrs []*networkingv1alpha1.ServiceCIDR cidrs []*networkingv1beta1.ServiceCIDR
expectedIPs []string expectedIPs []string
actions [][]string // verb and resource actions [][]string // verb and resource
events []string events []string
@@ -97,10 +97,10 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "no changes needed single stack", name: "no changes needed single stack",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, 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.1", newService("test-svc", []string{"10.0.1.1"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1"}, expectedIPs: []string{"10.0.1.1"},
@@ -110,11 +110,11 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "no changes needed dual stack", name: "no changes needed dual stack",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, 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("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})),
newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, 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", name: "no changes needed dual stack multiple cidrs",
svcs: []*v1.Service{newService("test-svc", []string{"192.168.0.1", "2001:db8:a:b::10"})}, 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("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"})), 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("kubernetes", serviceCIDRv4, serviceCIDRv6),
newServiceCIDR("custom", "192.168.0.0/24", "2001:db8:a:b::/64"), 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", name: "create IPAddress single stack",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})},
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1"}, expectedIPs: []string{"10.0.1.1"},
@@ -150,7 +150,7 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "create IPAddresses dual stack", name: "create IPAddresses dual stack",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})},
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, 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", name: "create IPAddress single stack from secondary",
svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1"})}, svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1"})},
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
newServiceCIDR("custom", "192.168.1.0/24", ""), newServiceCIDR("custom", "192.168.1.0/24", ""),
}, },
@@ -174,10 +174,10 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "reconcile IPAddress single stack wrong reference", name: "reconcile IPAddress single stack wrong reference",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, 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"})), newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1"}, expectedIPs: []string{"10.0.1.1"},
@@ -187,11 +187,11 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "reconcile IPAddresses dual stack", name: "reconcile IPAddresses dual stack",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, 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("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})),
newIPAddress("2001:db8::10", newService("test-svc2", []string{"2001:db8::10"})), newIPAddress("2001:db8::10", newService("test-svc2", []string{"2001:db8::10"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, expectedIPs: []string{"10.0.1.1", "2001:db8::10"},
@@ -204,11 +204,11 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "one IP out of range", name: "one IP out of range",
svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1", "2001:db8::10"})}, 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("192.168.1.1", newService("test-svc", []string{"192.168.1.1"})),
newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"2001:db8::10"}, expectedIPs: []string{"2001:db8::10"},
@@ -217,10 +217,10 @@ func TestRepairServiceIP(t *testing.T) {
}, },
{ {
name: "one IP orphan", name: "one IP orphan",
ipAddresses: []*networkingv1alpha1.IPAddress{ ipAddresses: []*networkingv1beta1.IPAddress{
newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
actions: [][]string{{"delete", "ipaddresses"}}, actions: [][]string{{"delete", "ipaddresses"}},
@@ -229,10 +229,10 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "one IP out of range matching the network address", name: "one IP out of range matching the network address",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.0.0"})}, 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"})), newIPAddress("10.0.0.0", newService("test-svc", []string{"10.0.0.0"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.0.0"}, 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", name: "one IP out of range matching the broadcast address",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.255.255"})}, 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"})), newIPAddress("10.0.255.255", newService("test-svc", []string{"10.0.255.255"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"10.0.255.255"}, 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", name: "one IPv6 out of range matching the subnet address",
svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::"})}, svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::"})},
ipAddresses: []*networkingv1alpha1.IPAddress{ ipAddresses: []*networkingv1beta1.IPAddress{
newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})), newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"2001:db8::"}, expectedIPs: []string{"2001:db8::"},
@@ -268,20 +268,20 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "one IPv6 matching the broadcast address", name: "one IPv6 matching the broadcast address",
svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::ffff:ffff:ffff:ffff"})}, 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"})), 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), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
expectedIPs: []string{"2001:db8::ffff:ffff:ffff:ffff"}, expectedIPs: []string{"2001:db8::ffff:ffff:ffff:ffff"},
}, },
{ {
name: "one IP orphan matching the broadcast address", 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"})), newIPAddress("10.0.255.255", newService("test-svc", []string{"10.0.255.255"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
actions: [][]string{{"delete", "ipaddresses"}}, actions: [][]string{{"delete", "ipaddresses"}},
@@ -290,11 +290,11 @@ func TestRepairServiceIP(t *testing.T) {
{ {
name: "Two IPAddresses referencing the same service", name: "Two IPAddresses referencing the same service",
svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, 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.1", newService("test-svc", []string{"10.0.1.1"})),
newIPAddress("10.0.1.2", 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), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
actions: [][]string{{"delete", "ipaddresses"}}, actions: [][]string{{"delete", "ipaddresses"}},
@@ -306,10 +306,10 @@ func TestRepairServiceIP(t *testing.T) {
newService("test-svc", []string{"10.0.1.1"}), newService("test-svc", []string{"10.0.1.1"}),
newService("test-svc2", []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"})), newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})),
}, },
cidrs: []*networkingv1alpha1.ServiceCIDR{ cidrs: []*networkingv1beta1.ServiceCIDR{
newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6),
}, },
events: []string{"Warning ClusterIPAlreadyAllocated Cluster IP [IPv4]:10.0.1.1 was assigned to multiple services; please recreate service"}, 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) { func TestRepairIPAddress_syncIPAddress(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
ip *networkingv1alpha1.IPAddress ip *networkingv1beta1.IPAddress
actions [][]string // verb and resource actions [][]string // verb and resource
wantErr bool wantErr bool
}{ }{
{ {
name: "correct ipv4 address", name: "correct ipv4 address",
ip: &networkingv1alpha1.IPAddress{ ip: &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "10.0.1.1", Name: "10.0.1.1",
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv4Protocol), networkingv1beta1.LabelIPAddressFamily: string(v1.IPv4Protocol),
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{ ParentRef: &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Name: "foo", Name: "foo",
@@ -397,17 +397,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) {
}, },
{ {
name: "correct ipv6 address", name: "correct ipv6 address",
ip: &networkingv1alpha1.IPAddress{ ip: &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "2001:db8::11", Name: "2001:db8::11",
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{ ParentRef: &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Name: "foo", Name: "foo",
@@ -418,17 +418,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) {
}, },
{ {
name: "not managed by this controller", name: "not managed by this controller",
ip: &networkingv1alpha1.IPAddress{ ip: &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "2001:db8::11", Name: "2001:db8::11",
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
networkingv1alpha1.LabelManagedBy: "controller-foo", networkingv1beta1.LabelManagedBy: "controller-foo",
}, },
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{ ParentRef: &networkingv1beta1.ParentReference{
Group: "networking.gateway.k8s.io", Group: "networking.gateway.k8s.io",
Resource: "gateway", Resource: "gateway",
Name: "foo", Name: "foo",
@@ -439,17 +439,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) {
}, },
{ {
name: "out of range", name: "out of range",
ip: &networkingv1alpha1.IPAddress{ ip: &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "fd00:db8::11", Name: "fd00:db8::11",
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{ ParentRef: &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Name: "foo", Name: "foo",
@@ -460,17 +460,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) {
}, },
{ {
name: "leaked ip", name: "leaked ip",
ip: &networkingv1alpha1.IPAddress{ ip: &networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "10.0.1.1", Name: "10.0.1.1",
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(v1.IPv6Protocol), networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
networkingv1alpha1.LabelManagedBy: ipallocator.ControllerName, networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
}, },
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{ ParentRef: &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Name: "noexist", Name: "noexist",
@@ -522,12 +522,12 @@ func newService(name string, ips []string) *v1.Service {
return svc return svc
} }
func newServiceCIDR(name, primary, secondary string) *networkingv1alpha1.ServiceCIDR { func newServiceCIDR(name, primary, secondary string) *networkingv1beta1.ServiceCIDR {
serviceCIDR := &networkingv1alpha1.ServiceCIDR{ serviceCIDR := &networkingv1beta1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
}, },
Spec: networkingv1alpha1.ServiceCIDRSpec{}, Spec: networkingv1beta1.ServiceCIDRSpec{},
} }
serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
if secondary != "" { if secondary != "" {

View File

@@ -27,13 +27,13 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
networkingv1alpha1informers "k8s.io/client-go/informers/networking/v1alpha1" networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
networkingv1alpha1client "k8s.io/client-go/kubernetes/typed/networking/v1alpha1" networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
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/cache"
"k8s.io/klog/v2" "k8s.io/klog/v2"
api "k8s.io/kubernetes/pkg/apis/core" 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 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 size uint64 // cap the total number of IPs available to maxInt64
client networkingv1alpha1client.NetworkingV1alpha1Interface client networkingv1beta1client.NetworkingV1beta1Interface
ipAddressLister networkingv1alpha1listers.IPAddressLister ipAddressLister networkingv1beta1listers.IPAddressLister
ipAddressSynced cache.InformerSynced ipAddressSynced cache.InformerSynced
// ready indicates if the allocator is able to allocate new IP addresses. // ready indicates if the allocator is able to allocate new IP addresses.
// This is required because it depends on the ServiceCIDR to be ready. // 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. // using an informer cache as storage.
func NewIPAllocator( func NewIPAllocator(
cidr *net.IPNet, cidr *net.IPNet,
client networkingv1alpha1client.NetworkingV1alpha1Interface, client networkingv1beta1client.NetworkingV1beta1Interface,
ipAddressInformer networkingv1alpha1informers.IPAddressInformer, ipAddressInformer networkingv1beta1informers.IPAddressInformer,
) (*Allocator, error) { ) (*Allocator, error) {
prefix, err := netip.ParsePrefix(cidr.String()) prefix, err := netip.ParsePrefix(cidr.String())
if err != nil { if err != nil {
@@ -139,15 +139,15 @@ func NewIPAllocator(
} }
func (a *Allocator) createIPAddress(name string, svc *api.Service, scope string) error { func (a *Allocator) createIPAddress(name string, svc *api.Service, scope string) error {
ipAddress := networkingv1alpha1.IPAddress{ ipAddress := networkingv1beta1.IPAddress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Labels: map[string]string{ Labels: map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
networkingv1alpha1.LabelManagedBy: ControllerName, networkingv1beta1.LabelManagedBy: ControllerName,
}, },
}, },
Spec: networkingv1alpha1.IPAddressSpec{ Spec: networkingv1beta1.IPAddressSpec{
ParentRef: serviceToRef(svc), 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 // This is required to satisfy the Allocator Interface only
func (a *Allocator) ForEach(f func(net.IP)) { func (a *Allocator) ForEach(f func(net.IP)) {
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
networkingv1alpha1.LabelManagedBy: ControllerName, networkingv1beta1.LabelManagedBy: ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ips, err := a.ipAddressLister.List(ipLabelSelector) ips, err := a.ipAddressLister.List(ipLabelSelector)
if err != nil { 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 // for testing, it assumes this is the allocator is unique for the ipFamily
func (a *Allocator) Used() int { func (a *Allocator) Used() int {
ipLabelSelector := labels.Set(map[string]string{ ipLabelSelector := labels.Set(map[string]string{
networkingv1alpha1.LabelIPAddressFamily: string(a.IPFamily()), networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
networkingv1alpha1.LabelManagedBy: ControllerName, networkingv1beta1.LabelManagedBy: ControllerName,
}).AsSelectorPreValidated() }).AsSelectorPreValidated()
ips, err := a.ipAddressLister.List(ipLabelSelector) ips, err := a.ipAddressLister.List(ipLabelSelector)
if err != nil { if err != nil {
@@ -568,12 +568,12 @@ func broadcastAddress(subnet netip.Prefix) (netip.Addr, error) {
} }
// serviceToRef obtain the Service Parent Reference // serviceToRef obtain the Service Parent Reference
func serviceToRef(svc *api.Service) *networkingv1alpha1.ParentReference { func serviceToRef(svc *api.Service) *networkingv1beta1.ParentReference {
if svc == nil { if svc == nil {
return nil return nil
} }
return &networkingv1alpha1.ParentReference{ return &networkingv1beta1.ParentReference{
Group: "", Group: "",
Resource: "services", Resource: "services",
Namespace: svc.Namespace, Namespace: svc.Namespace,

View File

@@ -25,7 +25,7 @@ import (
"testing" "testing"
"time" "time"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1" networkingv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
@@ -40,11 +40,11 @@ func newTestAllocator(cidr *net.IPNet) (*Allocator, error) {
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second)
ipInformer := informerFactory.Networking().V1alpha1().IPAddresses() ipInformer := informerFactory.Networking().V1beta1().IPAddresses()
ipStore := ipInformer.Informer().GetIndexer() ipStore := ipInformer.Informer().GetIndexer()
client.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { 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) _, exists, err := ipStore.GetByKey(ip.Name)
if exists && err != nil { if exists && err != nil {
return false, nil, fmt.Errorf("ip already exist") 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) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) {
name := action.(k8stesting.DeleteAction).GetName() name := action.(k8stesting.DeleteAction).GetName()
obj, exists, err := ipStore.GetByKey(name) obj, exists, err := ipStore.GetByKey(name)
ip := &networkingv1alpha1.IPAddress{} ip := &networkingv1beta1.IPAddress{}
if exists && err == nil { if exists && err == nil {
ip = obj.(*networkingv1alpha1.IPAddress) ip = obj.(*networkingv1beta1.IPAddress)
err = ipStore.Delete(ip) err = ipStore.Delete(ip)
} }
return false, ip, err return false, ip, err
})) }))
c, err := NewIPAllocator(cidr, client.NetworkingV1alpha1(), ipInformer) c, err := NewIPAllocator(cidr, client.NetworkingV1beta1(), ipInformer)
if err != nil { if err != nil {
return nil, err return nil, err
} }