mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	update registry
This commit is contained in:
		@@ -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"
 | 
				
			||||||
	networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
 | 
						networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1"
 | 
				
			||||||
	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().V1beta1().ServiceCIDRs(),
 | 
								c.Informers.Networking().V1().ServiceCIDRs(),
 | 
				
			||||||
			c.Informers.Networking().V1beta1().IPAddresses(),
 | 
								c.Informers.Networking().V1().IPAddresses(),
 | 
				
			||||||
		).RunUntil
 | 
							).RunUntil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -351,7 +351,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 {
 | 
				
			||||||
		networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig)
 | 
							networkingv1Client, err := networkingv1client.NewForConfig(c.LoopbackClientConfig)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return rangeRegistries{}, nil, nil, nil, err
 | 
								return rangeRegistries{}, nil, nil, nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -391,9 +391,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(
 | 
				
			||||||
			networkingv1beta1Client,
 | 
								networkingv1Client,
 | 
				
			||||||
			c.Informers.Networking().V1beta1().ServiceCIDRs(),
 | 
								c.Informers.Networking().V1().ServiceCIDRs(),
 | 
				
			||||||
			c.Informers.Networking().V1beta1().IPAddresses(),
 | 
								c.Informers.Networking().V1().IPAddresses(),
 | 
				
			||||||
			netutils.IsIPv6CIDR(&serviceClusterIPRange),
 | 
								netutils.IsIPv6CIDR(&serviceClusterIPRange),
 | 
				
			||||||
			bitmapAllocator,
 | 
								bitmapAllocator,
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
@@ -423,7 +423,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 {
 | 
				
			||||||
			networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig)
 | 
								networkingv1Client, err := networkingv1client.NewForConfig(c.LoopbackClientConfig)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return rangeRegistries{}, nil, nil, nil, err
 | 
									return rangeRegistries{}, nil, nil, nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -463,9 +463,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(
 | 
				
			||||||
				networkingv1beta1Client,
 | 
									networkingv1Client,
 | 
				
			||||||
				c.Informers.Networking().V1beta1().ServiceCIDRs(),
 | 
									c.Informers.Networking().V1().ServiceCIDRs(),
 | 
				
			||||||
				c.Informers.Networking().V1beta1().IPAddresses(),
 | 
									c.Informers.Networking().V1().IPAddresses(),
 | 
				
			||||||
				netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange),
 | 
									netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange),
 | 
				
			||||||
				bitmapAllocator,
 | 
									bitmapAllocator,
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,16 +24,16 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	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"
 | 
				
			||||||
	networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
 | 
						networkingv1informers "k8s.io/client-go/informers/networking/v1"
 | 
				
			||||||
	networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
 | 
						networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1"
 | 
				
			||||||
	networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1"
 | 
						networkingv1listers "k8s.io/client-go/listers/networking/v1"
 | 
				
			||||||
	"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            networkingv1beta1client.NetworkingV1beta1Interface
 | 
						client            networkingv1client.NetworkingV1Interface
 | 
				
			||||||
	serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister
 | 
						serviceCIDRLister networkingv1listers.ServiceCIDRLister
 | 
				
			||||||
	serviceCIDRSynced cache.InformerSynced
 | 
						serviceCIDRSynced cache.InformerSynced
 | 
				
			||||||
	ipAddressLister   networkingv1beta1listers.IPAddressLister
 | 
						ipAddressLister   networkingv1listers.IPAddressLister
 | 
				
			||||||
	ipAddressSynced   cache.InformerSynced
 | 
						ipAddressSynced   cache.InformerSynced
 | 
				
			||||||
	ipAddressInformer networkingv1beta1informers.IPAddressInformer
 | 
						ipAddressInformer networkingv1informers.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 networkingv1beta1client.NetworkingV1beta1Interface,
 | 
						client networkingv1client.NetworkingV1Interface,
 | 
				
			||||||
	serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer,
 | 
						serviceCIDRInformer networkingv1informers.ServiceCIDRInformer,
 | 
				
			||||||
	ipAddressInformer networkingv1beta1informers.IPAddressInformer,
 | 
						ipAddressInformer networkingv1informers.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 networkingv1beta1client.NetworkingV1beta1Interface,
 | 
					func newMetaAllocator(client networkingv1client.NetworkingV1Interface,
 | 
				
			||||||
	serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer,
 | 
						serviceCIDRInformer networkingv1informers.ServiceCIDRInformer,
 | 
				
			||||||
	ipAddressInformer networkingv1beta1informers.IPAddressInformer,
 | 
						ipAddressInformer networkingv1informers.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.(*networkingv1beta1.ServiceCIDR)
 | 
						serviceCIDR, ok := obj.(*networkingv1.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.(*networkingv1beta1.ServiceCIDR)
 | 
							serviceCIDR, ok = tombstone.Obj.(*networkingv1.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{
 | 
				
			||||||
		networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()),
 | 
							networkingv1.LabelIPAddressFamily: string(c.IPFamily()),
 | 
				
			||||||
		networkingv1beta1.LabelManagedBy:       ControllerName,
 | 
							networkingv1.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{
 | 
				
			||||||
		networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()),
 | 
							networkingv1.LabelIPAddressFamily: string(c.IPFamily()),
 | 
				
			||||||
		networkingv1beta1.LabelManagedBy:       ControllerName,
 | 
							networkingv1.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 *networkingv1beta1.ServiceCIDR) bool {
 | 
					func isReady(serviceCIDR *networkingv1.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 == networkingv1beta1.ServiceCIDRConditionReady {
 | 
							if condition.Type == networkingv1.ServiceCIDRConditionReady {
 | 
				
			||||||
			return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue)
 | 
								return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	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().V1beta1().ServiceCIDRs()
 | 
						serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs()
 | 
				
			||||||
	serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer()
 | 
						serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer()
 | 
				
			||||||
	ipInformer := informerFactory.Networking().V1beta1().IPAddresses()
 | 
						ipInformer := informerFactory.Networking().V1().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().(*networkingv1beta1.ServiceCIDR)
 | 
							cidr := action.(k8stesting.CreateAction).GetObject().(*networkingv1.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 := &networkingv1beta1.ServiceCIDR{}
 | 
							cidr := &networkingv1.ServiceCIDR{}
 | 
				
			||||||
		if exists && err == nil {
 | 
							if exists && err == nil {
 | 
				
			||||||
			cidr = obj.(*networkingv1beta1.ServiceCIDR)
 | 
								cidr = obj.(*networkingv1.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().(*networkingv1beta1.IPAddress)
 | 
							ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1.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 := &networkingv1beta1.IPAddress{}
 | 
							ip := &networkingv1.IPAddress{}
 | 
				
			||||||
		if exists && err == nil {
 | 
							if exists && err == nil {
 | 
				
			||||||
			ip = obj.(*networkingv1beta1.IPAddress)
 | 
								ip = obj.(*networkingv1.IPAddress)
 | 
				
			||||||
			err = ipStore.Delete(ip)
 | 
								err = ipStore.Delete(ip)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return false, ip, err
 | 
							return false, ip, err
 | 
				
			||||||
	}))
 | 
						}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c := newMetaAllocator(client.NetworkingV1beta1(), serviceCIDRInformer, ipInformer, false, nil)
 | 
						c := newMetaAllocator(client.NetworkingV1(), 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) *networkingv1beta1.ServiceCIDR {
 | 
					func newServiceCIDR(name, cidr string) *networkingv1.ServiceCIDR {
 | 
				
			||||||
	return &networkingv1beta1.ServiceCIDR{
 | 
						return &networkingv1.ServiceCIDR{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name: name,
 | 
								Name: name,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: networkingv1beta1.ServiceCIDRSpec{
 | 
							Spec: networkingv1.ServiceCIDRSpec{
 | 
				
			||||||
			CIDRs: []string{cidr},
 | 
								CIDRs: []string{cidr},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Status: networkingv1beta1.ServiceCIDRStatus{
 | 
							Status: networkingv1.ServiceCIDRStatus{
 | 
				
			||||||
			Conditions: []metav1.Condition{
 | 
								Conditions: []metav1.Condition{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Type:   string(networkingv1beta1.ServiceCIDRConditionReady),
 | 
										Type:   string(networkingv1.ServiceCIDRConditionReady),
 | 
				
			||||||
					Status: metav1.ConditionTrue,
 | 
										Status: metav1.ConditionTrue,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,17 +23,17 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	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/v1beta1"
 | 
						networkinginformers "k8s.io/client-go/informers/networking/v1"
 | 
				
			||||||
	"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/v1beta1"
 | 
						networkinglisters "k8s.io/client-go/listers/networking/v1"
 | 
				
			||||||
	"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{
 | 
				
			||||||
		networkingv1beta1.LabelManagedBy: ipallocator.ControllerName,
 | 
							networkingv1.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.NetworkingV1beta1().IPAddresses().Create(context.Background(), newIPAddress(ip.String(), svc), metav1.CreateOptions{})
 | 
								_, err := r.client.NetworkingV1().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.NetworkingV1beta1().IPAddresses().Delete(context.Background(), name, metav1.DeleteOptions{})
 | 
						err := r.client.NetworkingV1().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.NetworkingV1beta1().IPAddresses().Create(context.Background(), newIPAddress(name, svc), metav1.CreateOptions{})
 | 
						_, err = r.client.NetworkingV1().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.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{})
 | 
							err := r.client.NetworkingV1().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.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{})
 | 
								err := r.client.NetworkingV1().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.NetworkingV1beta1().IPAddresses().Delete(context.Background(), ipAddress.Name, metav1.DeleteOptions{})
 | 
						err = r.client.NetworkingV1().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) *networkingv1beta1.IPAddress {
 | 
					func newIPAddress(name string, svc *v1.Service) *networkingv1.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 &networkingv1beta1.IPAddress{
 | 
						return &networkingv1.IPAddress{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name: name,
 | 
								Name: name,
 | 
				
			||||||
			Labels: map[string]string{
 | 
								Labels: map[string]string{
 | 
				
			||||||
				networkingv1beta1.LabelIPAddressFamily: family,
 | 
									networkingv1.LabelIPAddressFamily: family,
 | 
				
			||||||
				networkingv1beta1.LabelManagedBy:       ipallocator.ControllerName,
 | 
									networkingv1.LabelManagedBy:       ipallocator.ControllerName,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: networkingv1beta1.IPAddressSpec{
 | 
							Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
			ParentRef: serviceToRef(svc),
 | 
								ParentRef: serviceToRef(svc),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func serviceToRef(svc *v1.Service) *networkingv1beta1.ParentReference {
 | 
					func serviceToRef(svc *v1.Service) *networkingv1.ParentReference {
 | 
				
			||||||
	if svc == nil {
 | 
						if svc == nil {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &networkingv1beta1.ParentReference{
 | 
						return &networkingv1.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 *networkingv1beta1.IPAddress) bool {
 | 
					func managedByController(ip *networkingv1.IPAddress) bool {
 | 
				
			||||||
	managedBy, ok := ip.Labels[networkingv1beta1.LabelManagedBy]
 | 
						managedBy, ok := ip.Labels[networkingv1.LabelManagedBy]
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return managedBy == ipallocator.ControllerName
 | 
						return managedBy == ipallocator.ControllerName
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func verifyIPAddressLabels(ip *networkingv1beta1.IPAddress) bool {
 | 
					func verifyIPAddressLabels(ip *networkingv1.IPAddress) bool {
 | 
				
			||||||
	labelFamily, ok := ip.Labels[networkingv1beta1.LabelIPAddressFamily]
 | 
						labelFamily, ok := ip.Labels[networkingv1.LabelIPAddressFamily]
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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"
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	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().V1beta1().ServiceCIDRs()
 | 
						serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs()
 | 
				
			||||||
	serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer()
 | 
						serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ipInformer := informerFactory.Networking().V1beta1().IPAddresses()
 | 
						ipInformer := informerFactory.Networking().V1().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().(*networkingv1beta1.IPAddress)
 | 
							ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1.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().(*networkingv1beta1.IPAddress)
 | 
							ip := action.(k8stesting.UpdateAction).GetObject().(*networkingv1.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, &networkingv1beta1.IPAddress{}, err
 | 
							return false, &networkingv1.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 []*networkingv1beta1.IPAddress
 | 
							ipAddresses []*networkingv1.IPAddress
 | 
				
			||||||
		cidrs       []*networkingv1beta1.ServiceCIDR
 | 
							cidrs       []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.IPAddress{
 | 
				
			||||||
				newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})),
 | 
									newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			cidrs: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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: []*networkingv1beta1.IPAddress{
 | 
								ipAddresses: []*networkingv1.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: []*networkingv1beta1.ServiceCIDR{
 | 
								cidrs: []*networkingv1.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      *networkingv1beta1.IPAddress
 | 
							ip      *networkingv1.IPAddress
 | 
				
			||||||
		actions [][]string // verb and resource
 | 
							actions [][]string // verb and resource
 | 
				
			||||||
		wantErr bool
 | 
							wantErr bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "correct ipv4 address",
 | 
								name: "correct ipv4 address",
 | 
				
			||||||
			ip: &networkingv1beta1.IPAddress{
 | 
								ip: &networkingv1.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{
 | 
				
			||||||
						networkingv1beta1.LabelIPAddressFamily: string(v1.IPv4Protocol),
 | 
											networkingv1.LabelIPAddressFamily: string(v1.IPv4Protocol),
 | 
				
			||||||
						networkingv1beta1.LabelManagedBy:       ipallocator.ControllerName,
 | 
											networkingv1.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: networkingv1beta1.IPAddressSpec{
 | 
									Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
					ParentRef: &networkingv1beta1.ParentReference{
 | 
										ParentRef: &networkingv1.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: &networkingv1beta1.IPAddress{
 | 
								ip: &networkingv1.IPAddress{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "2001:db8::11",
 | 
										Name: "2001:db8::11",
 | 
				
			||||||
					Labels: map[string]string{
 | 
										Labels: map[string]string{
 | 
				
			||||||
						networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
											networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
				
			||||||
						networkingv1beta1.LabelManagedBy:       ipallocator.ControllerName,
 | 
											networkingv1.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: networkingv1beta1.IPAddressSpec{
 | 
									Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
					ParentRef: &networkingv1beta1.ParentReference{
 | 
										ParentRef: &networkingv1.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: &networkingv1beta1.IPAddress{
 | 
								ip: &networkingv1.IPAddress{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "2001:db8::11",
 | 
										Name: "2001:db8::11",
 | 
				
			||||||
					Labels: map[string]string{
 | 
										Labels: map[string]string{
 | 
				
			||||||
						networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
											networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
				
			||||||
						networkingv1beta1.LabelManagedBy:       "controller-foo",
 | 
											networkingv1.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: networkingv1beta1.IPAddressSpec{
 | 
									Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
					ParentRef: &networkingv1beta1.ParentReference{
 | 
										ParentRef: &networkingv1.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: &networkingv1beta1.IPAddress{
 | 
								ip: &networkingv1.IPAddress{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "fd00:db8::11",
 | 
										Name: "fd00:db8::11",
 | 
				
			||||||
					Labels: map[string]string{
 | 
										Labels: map[string]string{
 | 
				
			||||||
						networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
											networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
				
			||||||
						networkingv1beta1.LabelManagedBy:       ipallocator.ControllerName,
 | 
											networkingv1.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: networkingv1beta1.IPAddressSpec{
 | 
									Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
					ParentRef: &networkingv1beta1.ParentReference{
 | 
										ParentRef: &networkingv1.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: &networkingv1beta1.IPAddress{
 | 
								ip: &networkingv1.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{
 | 
				
			||||||
						networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
											networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol),
 | 
				
			||||||
						networkingv1beta1.LabelManagedBy:       ipallocator.ControllerName,
 | 
											networkingv1.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: networkingv1beta1.IPAddressSpec{
 | 
									Spec: networkingv1.IPAddressSpec{
 | 
				
			||||||
					ParentRef: &networkingv1beta1.ParentReference{
 | 
										ParentRef: &networkingv1.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) *networkingv1beta1.ServiceCIDR {
 | 
					func newServiceCIDR(name, primary, secondary string) *networkingv1.ServiceCIDR {
 | 
				
			||||||
	serviceCIDR := &networkingv1beta1.ServiceCIDR{
 | 
						serviceCIDR := &networkingv1.ServiceCIDR{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name: name,
 | 
								Name: name,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: networkingv1beta1.ServiceCIDRSpec{},
 | 
							Spec: networkingv1.ServiceCIDRSpec{},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
 | 
						serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
 | 
				
			||||||
	if secondary != "" {
 | 
						if secondary != "" {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,13 +27,13 @@ import (
 | 
				
			|||||||
	"sync/atomic"
 | 
						"sync/atomic"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	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"
 | 
				
			||||||
	networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
 | 
						networkingv1informers "k8s.io/client-go/informers/networking/v1"
 | 
				
			||||||
	networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
 | 
						networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1"
 | 
				
			||||||
	networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1"
 | 
						networkingv1listers "k8s.io/client-go/listers/networking/v1"
 | 
				
			||||||
	"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          networkingv1beta1client.NetworkingV1beta1Interface
 | 
						client          networkingv1client.NetworkingV1Interface
 | 
				
			||||||
	ipAddressLister networkingv1beta1listers.IPAddressLister
 | 
						ipAddressLister networkingv1listers.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 networkingv1beta1client.NetworkingV1beta1Interface,
 | 
						client networkingv1client.NetworkingV1Interface,
 | 
				
			||||||
	ipAddressInformer networkingv1beta1informers.IPAddressInformer,
 | 
						ipAddressInformer networkingv1informers.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 := networkingv1beta1.IPAddress{
 | 
						ipAddress := networkingv1.IPAddress{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name: name,
 | 
								Name: name,
 | 
				
			||||||
			Labels: map[string]string{
 | 
								Labels: map[string]string{
 | 
				
			||||||
				networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
									networkingv1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
				
			||||||
				networkingv1beta1.LabelManagedBy:       ControllerName,
 | 
									networkingv1.LabelManagedBy:       ControllerName,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: networkingv1beta1.IPAddressSpec{
 | 
							Spec: networkingv1.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{
 | 
				
			||||||
		networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
							networkingv1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
				
			||||||
		networkingv1beta1.LabelManagedBy:       ControllerName,
 | 
							networkingv1.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{
 | 
				
			||||||
		networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
							networkingv1.LabelIPAddressFamily: string(a.IPFamily()),
 | 
				
			||||||
		networkingv1beta1.LabelManagedBy:       ControllerName,
 | 
							networkingv1.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) *networkingv1beta1.ParentReference {
 | 
					func serviceToRef(svc *api.Service) *networkingv1.ParentReference {
 | 
				
			||||||
	if svc == nil {
 | 
						if svc == nil {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &networkingv1beta1.ParentReference{
 | 
						return &networkingv1.ParentReference{
 | 
				
			||||||
		Group:     "",
 | 
							Group:     "",
 | 
				
			||||||
		Resource:  "services",
 | 
							Resource:  "services",
 | 
				
			||||||
		Namespace: svc.Namespace,
 | 
							Namespace: svc.Namespace,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
 | 
						networkingv1 "k8s.io/api/networking/v1"
 | 
				
			||||||
	"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().V1beta1().IPAddresses()
 | 
						ipInformer := informerFactory.Networking().V1().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().(*networkingv1beta1.IPAddress)
 | 
							ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1.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 := &networkingv1beta1.IPAddress{}
 | 
							ip := &networkingv1.IPAddress{}
 | 
				
			||||||
		if exists && err == nil {
 | 
							if exists && err == nil {
 | 
				
			||||||
			ip = obj.(*networkingv1beta1.IPAddress)
 | 
								ip = obj.(*networkingv1.IPAddress)
 | 
				
			||||||
			err = ipStore.Delete(ip)
 | 
								err = ipStore.Delete(ip)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return false, ip, err
 | 
							return false, ip, err
 | 
				
			||||||
	}))
 | 
						}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c, err := NewIPAllocator(cidr, client.NetworkingV1beta1(), ipInformer)
 | 
						c, err := NewIPAllocator(cidr, client.NetworkingV1(), ipInformer)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user