From ad511cd249f862636369705452a1dbb514b40b49 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Thu, 12 Dec 2024 11:55:17 +0000 Subject: [PATCH] update registry --- pkg/registry/core/rest/storage_core.go | 22 +-- .../core/service/ipallocator/cidrallocator.go | 44 +++--- .../service/ipallocator/cidrallocator_test.go | 30 ++-- .../ipallocator/controller/repairip.go | 42 +++--- .../ipallocator/controller/repairip_test.go | 136 +++++++++--------- .../core/service/ipallocator/ipallocator.go | 36 ++--- .../service/ipallocator/ipallocator_test.go | 12 +- 7 files changed, 161 insertions(+), 161 deletions(-) diff --git a/pkg/registry/core/rest/storage_core.go b/pkg/registry/core/rest/storage_core.go index 69329088a0c..0da3e488e39 100644 --- a/pkg/registry/core/rest/storage_core.go +++ b/pkg/registry/core/rest/storage_core.go @@ -34,7 +34,7 @@ import ( serverstorage "k8s.io/apiserver/pkg/server/storage" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/kubernetes" - 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" "k8s.io/klog/v2" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -140,8 +140,8 @@ func New(c Config) (*legacyProvider, error) { c.Services.IPRepairInterval, client, c.Informers.Core().V1().Services(), - c.Informers.Networking().V1beta1().ServiceCIDRs(), - c.Informers.Networking().V1beta1().IPAddresses(), + c.Informers.Networking().V1().ServiceCIDRs(), + c.Informers.Networking().V1().IPAddresses(), ).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) } } else { - networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig) + networkingv1Client, err := networkingv1client.NewForConfig(c.LoopbackClientConfig) if err != nil { 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 // existing default ServiceCIDR primaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( - networkingv1beta1Client, - c.Informers.Networking().V1beta1().ServiceCIDRs(), - c.Informers.Networking().V1beta1().IPAddresses(), + networkingv1Client, + c.Informers.Networking().V1().ServiceCIDRs(), + c.Informers.Networking().V1().IPAddresses(), netutils.IsIPv6CIDR(&serviceClusterIPRange), 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) } } else { - networkingv1beta1Client, err := networkingv1beta1client.NewForConfig(c.LoopbackClientConfig) + networkingv1Client, err := networkingv1client.NewForConfig(c.LoopbackClientConfig) if err != nil { 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 // existing default ServiceCIDR secondaryClusterIPAllocator, err = ipallocator.NewMetaAllocator( - networkingv1beta1Client, - c.Informers.Networking().V1beta1().ServiceCIDRs(), - c.Informers.Networking().V1beta1().IPAddresses(), + networkingv1Client, + c.Informers.Networking().V1().ServiceCIDRs(), + c.Informers.Networking().V1().IPAddresses(), netutils.IsIPv6CIDR(&c.Services.SecondaryClusterIPRange), bitmapAllocator, ) diff --git a/pkg/registry/core/service/ipallocator/cidrallocator.go b/pkg/registry/core/service/ipallocator/cidrallocator.go index 1bc377dac86..53d9bb2de66 100644 --- a/pkg/registry/core/service/ipallocator/cidrallocator.go +++ b/pkg/registry/core/service/ipallocator/cidrallocator.go @@ -24,16 +24,16 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" - networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" - networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1" - networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1" + networkingv1informers "k8s.io/client-go/informers/networking/v1" + networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1" + networkingv1listers "k8s.io/client-go/listers/networking/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -52,12 +52,12 @@ import ( // MetaAllocator implements current allocator interface using // ServiceCIDR and IPAddress API objects. type MetaAllocator struct { - client networkingv1beta1client.NetworkingV1beta1Interface - serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister + client networkingv1client.NetworkingV1Interface + serviceCIDRLister networkingv1listers.ServiceCIDRLister serviceCIDRSynced cache.InformerSynced - ipAddressLister networkingv1beta1listers.IPAddressLister + ipAddressLister networkingv1listers.IPAddressLister ipAddressSynced cache.InformerSynced - ipAddressInformer networkingv1beta1informers.IPAddressInformer + ipAddressInformer networkingv1informers.IPAddressInformer queue workqueue.TypedRateLimitingInterface[string] internalStopCh chan struct{} @@ -87,9 +87,9 @@ var _ Interface = &MetaAllocator{} // and ServiceCIDR objects to track the assigned IP addresses, // using an informer cache as storage. func NewMetaAllocator( - client networkingv1beta1client.NetworkingV1beta1Interface, - serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer, - ipAddressInformer networkingv1beta1informers.IPAddressInformer, + client networkingv1client.NetworkingV1Interface, + serviceCIDRInformer networkingv1informers.ServiceCIDRInformer, + ipAddressInformer networkingv1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) (*MetaAllocator, error) { @@ -100,9 +100,9 @@ func NewMetaAllocator( } // newMetaAllocator is used to build the allocator for testing -func newMetaAllocator(client networkingv1beta1client.NetworkingV1beta1Interface, - serviceCIDRInformer networkingv1beta1informers.ServiceCIDRInformer, - ipAddressInformer networkingv1beta1informers.IPAddressInformer, +func newMetaAllocator(client networkingv1client.NetworkingV1Interface, + serviceCIDRInformer networkingv1informers.ServiceCIDRInformer, + ipAddressInformer networkingv1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) *MetaAllocator { @@ -152,13 +152,13 @@ func (c *MetaAllocator) enqueueServiceCIDR(obj interface{}) { } func (c *MetaAllocator) deleteServiceCIDR(obj interface{}) { - serviceCIDR, ok := obj.(*networkingv1beta1.ServiceCIDR) + serviceCIDR, ok := obj.(*networkingv1.ServiceCIDR) if !ok { tombstone, ok := obj.(cache.DeletedFinalStateUnknown) if !ok { return } - serviceCIDR, ok = tombstone.Obj.(*networkingv1beta1.ServiceCIDR) + serviceCIDR, ok = tombstone.Obj.(*networkingv1.ServiceCIDR) if !ok { return } @@ -414,8 +414,8 @@ func (c *MetaAllocator) Release(ip net.IP) error { } func (c *MetaAllocator) ForEach(f func(ip net.IP)) { ipLabelSelector := labels.Set(map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()), - networkingv1beta1.LabelManagedBy: ControllerName, + networkingv1.LabelIPAddressFamily: string(c.IPFamily()), + networkingv1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := c.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -454,8 +454,8 @@ func (c *MetaAllocator) Destroy() { // for testing func (c *MetaAllocator) Used() int { ipLabelSelector := labels.Set(map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(c.IPFamily()), - networkingv1beta1.LabelManagedBy: ControllerName, + networkingv1.LabelIPAddressFamily: string(c.IPFamily()), + networkingv1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := c.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -512,13 +512,13 @@ func (c *MetaAllocator) DryRun() Interface { return &Allocator{} } -func isReady(serviceCIDR *networkingv1beta1.ServiceCIDR) bool { +func isReady(serviceCIDR *networkingv1.ServiceCIDR) bool { if serviceCIDR == nil { return false } for _, condition := range serviceCIDR.Status.Conditions { - if condition.Type == networkingv1beta1.ServiceCIDRConditionReady { + if condition.Type == networkingv1.ServiceCIDRConditionReady { return condition.Status == metav1.ConditionStatus(metav1.ConditionTrue) } } diff --git a/pkg/registry/core/service/ipallocator/cidrallocator_test.go b/pkg/registry/core/service/ipallocator/cidrallocator_test.go index bfcfdd00424..7bc8b279e8b 100644 --- a/pkg/registry/core/service/ipallocator/cidrallocator_test.go +++ b/pkg/registry/core/service/ipallocator/cidrallocator_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -41,13 +41,13 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) - serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs() serviceCIDRStore := serviceCIDRInformer.Informer().GetIndexer() - ipInformer := informerFactory.Networking().V1beta1().IPAddresses() + ipInformer := informerFactory.Networking().V1().IPAddresses() ipStore := ipInformer.Informer().GetIndexer() 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) if exists && err != nil { return false, nil, fmt.Errorf("cidr already exist") @@ -59,16 +59,16 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client.PrependReactor("delete", "servicecidrs", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := serviceCIDRStore.GetByKey(name) - cidr := &networkingv1beta1.ServiceCIDR{} + cidr := &networkingv1.ServiceCIDR{} if exists && err == nil { - cidr = obj.(*networkingv1beta1.ServiceCIDR) + cidr = obj.(*networkingv1.ServiceCIDR) err = serviceCIDRStore.Delete(cidr) } return false, cidr, err })) client.PrependReactor("create", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1beta1.IPAddress) + ip := action.(k8stesting.CreateAction).GetObject().(*networkingv1.IPAddress) _, exists, err := ipStore.GetByKey(ip.Name) if exists && err != nil { return false, nil, fmt.Errorf("ip already exist") @@ -80,15 +80,15 @@ func newTestMetaAllocator() (*MetaAllocator, error) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := ipStore.GetByKey(name) - ip := &networkingv1beta1.IPAddress{} + ip := &networkingv1.IPAddress{} if exists && err == nil { - ip = obj.(*networkingv1beta1.IPAddress) + ip = obj.(*networkingv1.IPAddress) err = ipStore.Delete(ip) } 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.ipAddressSynced = func() bool { return true } @@ -602,18 +602,18 @@ func TestCIDRAllocateDualWriteCollision(t *testing.T) { } // TODO: add IPv6 and dual stack test cases -func newServiceCIDR(name, cidr string) *networkingv1beta1.ServiceCIDR { - return &networkingv1beta1.ServiceCIDR{ +func newServiceCIDR(name, cidr string) *networkingv1.ServiceCIDR { + return &networkingv1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingv1beta1.ServiceCIDRSpec{ + Spec: networkingv1.ServiceCIDRSpec{ CIDRs: []string{cidr}, }, - Status: networkingv1beta1.ServiceCIDRStatus{ + Status: networkingv1.ServiceCIDRStatus{ Conditions: []metav1.Condition{ { - Type: string(networkingv1beta1.ServiceCIDRConditionReady), + Type: string(networkingv1.ServiceCIDRConditionReady), Status: metav1.ConditionTrue, }, }, diff --git a/pkg/registry/core/service/ipallocator/controller/repairip.go b/pkg/registry/core/service/ipallocator/controller/repairip.go index 112f908dce9..c7669210384 100644 --- a/pkg/registry/core/service/ipallocator/controller/repairip.go +++ b/pkg/registry/core/service/ipallocator/controller/repairip.go @@ -23,17 +23,17 @@ import ( "time" v1 "k8s.io/api/core/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" coreinformers "k8s.io/client-go/informers/core/v1" - networkinginformers "k8s.io/client-go/informers/networking/v1beta1" + networkinginformers "k8s.io/client-go/informers/networking/v1" "k8s.io/client-go/kubernetes" 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/events" "k8s.io/client-go/util/retry" @@ -263,7 +263,7 @@ func (r *RepairIPAddress) doRunOnce() error { // Check that there is no IP created by the allocator without // a Service associated. ipLabelSelector := labels.Set(map[string]string{ - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelManagedBy: ipallocator.ControllerName, }).AsSelectorPreValidated() ipAddresses, err := r.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -360,7 +360,7 @@ func (r *RepairIPAddress) syncService(key string) error { // ClusterIP doesn't seem to be allocated, create it. r.recorder.Eventf(svc, nil, v1.EventTypeWarning, "ClusterIPNotAllocated", "ClusterIPAllocation", "Cluster IP [%v]: %s is not allocated; repairing", family, ip) runtime.HandleError(fmt.Errorf("the ClusterIP [%v]: %s for Service %s/%s is not allocated; repairing", family, ip, svc.Namespace, svc.Name)) - _, err := r.client.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 { return err } @@ -417,11 +417,11 @@ func (r *RepairIPAddress) syncService(key string) error { } func (r *RepairIPAddress) recreateIPAddress(name string, svc *v1.Service) error { - err := r.client.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) { 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 { return err } @@ -482,7 +482,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { if ipAddress.Spec.ParentRef.Group != "" || ipAddress.Spec.ParentRef.Resource != "services" { runtime.HandleError(fmt.Errorf("IPAddress %s appears to have been modified, not referencing a Service %v: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressNotAllocated", "IPAddressAllocation", "IPAddress %s appears to have been modified, not referencing a Service %v: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef) - err := r.client.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) { return err } @@ -499,7 +499,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { if ipLifetime > gracePeriod { runtime.HandleError(fmt.Errorf("IPAddress %s appears to have leaked: cleaning up", ipAddress.Name)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressNotAllocated", "IPAddressAllocation", "IPAddress: %s for Service %s/%s appears to have leaked: cleaning up", ipAddress.Name, ipAddress.Spec.ParentRef.Namespace, ipAddress.Spec.ParentRef.Name) - err := r.client.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) { return err } @@ -522,7 +522,7 @@ func (r *RepairIPAddress) syncIPAddress(key string) error { } runtime.HandleError(fmt.Errorf("the IPAddress: %s for Service %s/%s has a wrong reference %#v; cleaning up", ipAddress.Name, svc.Name, svc.Namespace, ipAddress.Spec.ParentRef)) r.recorder.Eventf(ipAddress, nil, v1.EventTypeWarning, "IPAddressWrongReference", "IPAddressAllocation", "IPAddress: %s for Service %s/%s has a wrong reference; cleaning up", ipAddress.Name, svc.Namespace, svc.Name) - err = r.client.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) { return err } @@ -535,31 +535,31 @@ func (r *RepairIPAddress) isIPOutOfRange(ip net.IP) bool { return len(servicecidr.ContainsIP(r.serviceCIDRLister, ip)) == 0 } -func newIPAddress(name string, svc *v1.Service) *networkingv1beta1.IPAddress { +func newIPAddress(name string, svc *v1.Service) *networkingv1.IPAddress { family := string(v1.IPv4Protocol) if netutils.IsIPv6String(name) { family = string(v1.IPv6Protocol) } - return &networkingv1beta1.IPAddress{ + return &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: family, - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelIPAddressFamily: family, + networkingv1.LabelManagedBy: ipallocator.ControllerName, }, }, - Spec: networkingv1beta1.IPAddressSpec{ + Spec: networkingv1.IPAddressSpec{ ParentRef: serviceToRef(svc), }, } } -func serviceToRef(svc *v1.Service) *networkingv1beta1.ParentReference { +func serviceToRef(svc *v1.Service) *networkingv1.ParentReference { if svc == nil { return nil } - return &networkingv1beta1.ParentReference{ + return &networkingv1.ParentReference{ Group: "", Resource: "services", Namespace: svc.Namespace, @@ -576,16 +576,16 @@ func getFamilyByIP(ip net.IP) v1.IPFamily { // managedByController returns true if the controller of the provided // EndpointSlices is the EndpointSlice controller. -func managedByController(ip *networkingv1beta1.IPAddress) bool { - managedBy, ok := ip.Labels[networkingv1beta1.LabelManagedBy] +func managedByController(ip *networkingv1.IPAddress) bool { + managedBy, ok := ip.Labels[networkingv1.LabelManagedBy] if !ok { return false } return managedBy == ipallocator.ControllerName } -func verifyIPAddressLabels(ip *networkingv1beta1.IPAddress) bool { - labelFamily, ok := ip.Labels[networkingv1beta1.LabelIPAddressFamily] +func verifyIPAddressLabels(ip *networkingv1.IPAddress) bool { + labelFamily, ok := ip.Labels[networkingv1.LabelIPAddressFamily] if !ok { return false } diff --git a/pkg/registry/core/service/ipallocator/controller/repairip_test.go b/pkg/registry/core/service/ipallocator/controller/repairip_test.go index f2c0e10ec39..ccee3666c5d 100644 --- a/pkg/registry/core/service/ipallocator/controller/repairip_test.go +++ b/pkg/registry/core/service/ipallocator/controller/repairip_test.go @@ -23,7 +23,7 @@ import ( "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -54,25 +54,25 @@ func newFakeRepair() (*fake.Clientset, *fakeRepair) { serviceInformer := informerFactory.Core().V1().Services() serviceIndexer := serviceInformer.Informer().GetIndexer() - serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs() + serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs() serviceCIDRIndexer := serviceCIDRInformer.Informer().GetIndexer() - ipInformer := informerFactory.Networking().V1beta1().IPAddresses() + ipInformer := informerFactory.Networking().V1().IPAddresses() ipIndexer := ipInformer.Informer().GetIndexer() 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) return false, ip, err })) 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") })) fakeClient.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { ip := action.(k8stesting.DeleteAction).GetName() err := ipIndexer.Delete(ip) - return false, &networkingv1beta1.IPAddress{}, err + return false, &networkingv1.IPAddress{}, err })) r := NewRepairIPAddress(0*time.Second, @@ -88,8 +88,8 @@ func TestRepairServiceIP(t *testing.T) { tests := []struct { name string svcs []*v1.Service - ipAddresses []*networkingv1beta1.IPAddress - cidrs []*networkingv1beta1.ServiceCIDR + ipAddresses []*networkingv1.IPAddress + cidrs []*networkingv1.ServiceCIDR expectedIPs []string actions [][]string // verb and resource events []string @@ -97,10 +97,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed single stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -110,11 +110,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -124,11 +124,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "no changes needed dual stack multiple cidrs", svcs: []*v1.Service{newService("test-svc", []string{"192.168.0.1", "2001:db8:a:b::10"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("192.168.0.1", newService("test-svc", []string{"192.168.0.1"})), newIPAddress("2001:db8:a:b::10", newService("test-svc", []string{"2001:db8:a:b::10"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("custom", "192.168.0.0/24", "2001:db8:a:b::/64"), }, @@ -140,7 +140,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddress single stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -150,7 +150,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddresses dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -163,7 +163,7 @@ func TestRepairServiceIP(t *testing.T) { { name: "create IPAddress single stack from secondary", svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1"})}, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), newServiceCIDR("custom", "192.168.1.0/24", ""), }, @@ -174,10 +174,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "reconcile IPAddress single stack wrong reference", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1"}, @@ -187,11 +187,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "reconcile IPAddresses dual stack", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), newIPAddress("2001:db8::10", newService("test-svc2", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.1.1", "2001:db8::10"}, @@ -204,11 +204,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range", svcs: []*v1.Service{newService("test-svc", []string{"192.168.1.1", "2001:db8::10"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("192.168.1.1", newService("test-svc", []string{"192.168.1.1"})), newIPAddress("2001:db8::10", newService("test-svc", []string{"2001:db8::10"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"2001:db8::10"}, @@ -217,10 +217,10 @@ func TestRepairServiceIP(t *testing.T) { }, { name: "one IP orphan", - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -229,10 +229,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range matching the network address", svcs: []*v1.Service{newService("test-svc", []string{"10.0.0.0"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.0.0", newService("test-svc", []string{"10.0.0.0"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.0.0"}, @@ -242,10 +242,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IP out of range matching the broadcast address", svcs: []*v1.Service{newService("test-svc", []string{"10.0.255.255"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.255.255", newService("test-svc", []string{"10.0.255.255"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"10.0.255.255"}, @@ -255,10 +255,10 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IPv6 out of range matching the subnet address", svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("2001:db8::", newService("test-svc", []string{"2001:db8::"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, expectedIPs: []string{"2001:db8::"}, @@ -268,20 +268,20 @@ func TestRepairServiceIP(t *testing.T) { { name: "one IPv6 matching the broadcast address", svcs: []*v1.Service{newService("test-svc", []string{"2001:db8::ffff:ffff:ffff:ffff"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ 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), }, expectedIPs: []string{"2001:db8::ffff:ffff:ffff:ffff"}, }, { 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"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -290,11 +290,11 @@ func TestRepairServiceIP(t *testing.T) { { name: "Two IPAddresses referencing the same service", svcs: []*v1.Service{newService("test-svc", []string{"10.0.1.1"})}, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc", []string{"10.0.1.1"})), newIPAddress("10.0.1.2", newService("test-svc", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, actions: [][]string{{"delete", "ipaddresses"}}, @@ -306,10 +306,10 @@ func TestRepairServiceIP(t *testing.T) { newService("test-svc", []string{"10.0.1.1"}), newService("test-svc2", []string{"10.0.1.1"}), }, - ipAddresses: []*networkingv1beta1.IPAddress{ + ipAddresses: []*networkingv1.IPAddress{ newIPAddress("10.0.1.1", newService("test-svc2", []string{"10.0.1.1"})), }, - cidrs: []*networkingv1beta1.ServiceCIDR{ + cidrs: []*networkingv1.ServiceCIDR{ newServiceCIDR("kubernetes", serviceCIDRv4, serviceCIDRv6), }, events: []string{"Warning ClusterIPAlreadyAllocated Cluster IP [IPv4]:10.0.1.1 was assigned to multiple services; please recreate service"}, @@ -370,23 +370,23 @@ func TestRepairServiceIP(t *testing.T) { func TestRepairIPAddress_syncIPAddress(t *testing.T) { tests := []struct { name string - ip *networkingv1beta1.IPAddress + ip *networkingv1.IPAddress actions [][]string // verb and resource wantErr bool }{ { name: "correct ipv4 address", - ip: &networkingv1beta1.IPAddress{ + ip: &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "10.0.1.1", Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(v1.IPv4Protocol), - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelIPAddressFamily: string(v1.IPv4Protocol), + networkingv1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1beta1.IPAddressSpec{ - ParentRef: &networkingv1beta1.ParentReference{ + Spec: networkingv1.IPAddressSpec{ + ParentRef: &networkingv1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -397,17 +397,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "correct ipv6 address", - ip: &networkingv1beta1.IPAddress{ + ip: &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "2001:db8::11", Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1beta1.IPAddressSpec{ - ParentRef: &networkingv1beta1.ParentReference{ + Spec: networkingv1.IPAddressSpec{ + ParentRef: &networkingv1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -418,17 +418,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "not managed by this controller", - ip: &networkingv1beta1.IPAddress{ + ip: &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "2001:db8::11", Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1beta1.LabelManagedBy: "controller-foo", + networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1.LabelManagedBy: "controller-foo", }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1beta1.IPAddressSpec{ - ParentRef: &networkingv1beta1.ParentReference{ + Spec: networkingv1.IPAddressSpec{ + ParentRef: &networkingv1.ParentReference{ Group: "networking.gateway.k8s.io", Resource: "gateway", Name: "foo", @@ -439,17 +439,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "out of range", - ip: &networkingv1beta1.IPAddress{ + ip: &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "fd00:db8::11", Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1beta1.IPAddressSpec{ - ParentRef: &networkingv1beta1.ParentReference{ + Spec: networkingv1.IPAddressSpec{ + ParentRef: &networkingv1.ParentReference{ Group: "", Resource: "services", Name: "foo", @@ -460,17 +460,17 @@ func TestRepairIPAddress_syncIPAddress(t *testing.T) { }, { name: "leaked ip", - ip: &networkingv1beta1.IPAddress{ + ip: &networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: "10.0.1.1", Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(v1.IPv6Protocol), - networkingv1beta1.LabelManagedBy: ipallocator.ControllerName, + networkingv1.LabelIPAddressFamily: string(v1.IPv6Protocol), + networkingv1.LabelManagedBy: ipallocator.ControllerName, }, CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), }, - Spec: networkingv1beta1.IPAddressSpec{ - ParentRef: &networkingv1beta1.ParentReference{ + Spec: networkingv1.IPAddressSpec{ + ParentRef: &networkingv1.ParentReference{ Group: "", Resource: "services", Name: "noexist", @@ -522,12 +522,12 @@ func newService(name string, ips []string) *v1.Service { return svc } -func newServiceCIDR(name, primary, secondary string) *networkingv1beta1.ServiceCIDR { - serviceCIDR := &networkingv1beta1.ServiceCIDR{ +func newServiceCIDR(name, primary, secondary string) *networkingv1.ServiceCIDR { + serviceCIDR := &networkingv1.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: networkingv1beta1.ServiceCIDRSpec{}, + Spec: networkingv1.ServiceCIDRSpec{}, } serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary) if secondary != "" { diff --git a/pkg/registry/core/service/ipallocator/ipallocator.go b/pkg/registry/core/service/ipallocator/ipallocator.go index 9d52af45ac2..6613523f4df 100644 --- a/pkg/registry/core/service/ipallocator/ipallocator.go +++ b/pkg/registry/core/service/ipallocator/ipallocator.go @@ -27,13 +27,13 @@ import ( "sync/atomic" "time" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1" - networkingv1beta1client "k8s.io/client-go/kubernetes/typed/networking/v1beta1" - networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1" + networkingv1informers "k8s.io/client-go/informers/networking/v1" + networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1" + networkingv1listers "k8s.io/client-go/listers/networking/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" api "k8s.io/kubernetes/pkg/apis/core" @@ -56,8 +56,8 @@ type Allocator struct { rangeOffset int // subdivides the assigned IP range to prefer dynamic allocation from the upper range size uint64 // cap the total number of IPs available to maxInt64 - client networkingv1beta1client.NetworkingV1beta1Interface - ipAddressLister networkingv1beta1listers.IPAddressLister + client networkingv1client.NetworkingV1Interface + ipAddressLister networkingv1listers.IPAddressLister ipAddressSynced cache.InformerSynced // ready indicates if the allocator is able to allocate new IP addresses. // This is required because it depends on the ServiceCIDR to be ready. @@ -77,8 +77,8 @@ var _ Interface = &Allocator{} // using an informer cache as storage. func NewIPAllocator( cidr *net.IPNet, - client networkingv1beta1client.NetworkingV1beta1Interface, - ipAddressInformer networkingv1beta1informers.IPAddressInformer, + client networkingv1client.NetworkingV1Interface, + ipAddressInformer networkingv1informers.IPAddressInformer, ) (*Allocator, error) { prefix, err := netip.ParsePrefix(cidr.String()) if err != nil { @@ -139,15 +139,15 @@ func NewIPAllocator( } func (a *Allocator) createIPAddress(name string, svc *api.Service, scope string) error { - ipAddress := networkingv1beta1.IPAddress{ + ipAddress := networkingv1.IPAddress{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1beta1.LabelManagedBy: ControllerName, + networkingv1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1.LabelManagedBy: ControllerName, }, }, - Spec: networkingv1beta1.IPAddressSpec{ + Spec: networkingv1.IPAddressSpec{ ParentRef: serviceToRef(svc), }, } @@ -379,8 +379,8 @@ func (a *Allocator) release(ip net.IP, dryRun bool) error { // This is required to satisfy the Allocator Interface only func (a *Allocator) ForEach(f func(net.IP)) { ipLabelSelector := labels.Set(map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1beta1.LabelManagedBy: ControllerName, + networkingv1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := a.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -413,8 +413,8 @@ func (a *Allocator) IPFamily() api.IPFamily { // for testing, it assumes this is the allocator is unique for the ipFamily func (a *Allocator) Used() int { ipLabelSelector := labels.Set(map[string]string{ - networkingv1beta1.LabelIPAddressFamily: string(a.IPFamily()), - networkingv1beta1.LabelManagedBy: ControllerName, + networkingv1.LabelIPAddressFamily: string(a.IPFamily()), + networkingv1.LabelManagedBy: ControllerName, }).AsSelectorPreValidated() ips, err := a.ipAddressLister.List(ipLabelSelector) if err != nil { @@ -568,12 +568,12 @@ func broadcastAddress(subnet netip.Prefix) (netip.Addr, error) { } // serviceToRef obtain the Service Parent Reference -func serviceToRef(svc *api.Service) *networkingv1beta1.ParentReference { +func serviceToRef(svc *api.Service) *networkingv1.ParentReference { if svc == nil { return nil } - return &networkingv1beta1.ParentReference{ + return &networkingv1.ParentReference{ Group: "", Resource: "services", Namespace: svc.Namespace, diff --git a/pkg/registry/core/service/ipallocator/ipallocator_test.go b/pkg/registry/core/service/ipallocator/ipallocator_test.go index e211f3aaebe..62e5409b54f 100644 --- a/pkg/registry/core/service/ipallocator/ipallocator_test.go +++ b/pkg/registry/core/service/ipallocator/ipallocator_test.go @@ -25,7 +25,7 @@ import ( "testing" "time" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + networkingv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/informers" @@ -40,11 +40,11 @@ func newTestAllocator(cidr *net.IPNet) (*Allocator, error) { client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0*time.Second) - ipInformer := informerFactory.Networking().V1beta1().IPAddresses() + ipInformer := informerFactory.Networking().V1().IPAddresses() ipStore := ipInformer.Informer().GetIndexer() 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) if exists && err != nil { return false, nil, fmt.Errorf("ip already exist") @@ -56,15 +56,15 @@ func newTestAllocator(cidr *net.IPNet) (*Allocator, error) { client.PrependReactor("delete", "ipaddresses", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { name := action.(k8stesting.DeleteAction).GetName() obj, exists, err := ipStore.GetByKey(name) - ip := &networkingv1beta1.IPAddress{} + ip := &networkingv1.IPAddress{} if exists && err == nil { - ip = obj.(*networkingv1beta1.IPAddress) + ip = obj.(*networkingv1.IPAddress) err = ipStore.Delete(ip) } return false, ip, err })) - c, err := NewIPAllocator(cidr, client.NetworkingV1beta1(), ipInformer) + c, err := NewIPAllocator(cidr, client.NetworkingV1(), ipInformer) if err != nil { return nil, err }