@@ -23,7 +23,7 @@ import (
23
23
"time"
24
24
25
25
v1 "k8s.io/api/core/v1"
26
- networkingapiv1beta1 "k8s.io/api/networking/v1beta1 "
26
+ networkingapiv1 "k8s.io/api/networking/v1 "
27
27
apierrors "k8s.io/apimachinery/pkg/api/errors"
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
29
"k8s.io/apimachinery/pkg/labels"
@@ -32,12 +32,12 @@ import (
32
32
"k8s.io/apimachinery/pkg/util/sets"
33
33
"k8s.io/apimachinery/pkg/util/wait"
34
34
metav1apply "k8s.io/client-go/applyconfigurations/meta/v1"
35
- networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1 "
36
- networkinginformers "k8s.io/client-go/informers/networking/v1beta1 "
35
+ networkingapiv1apply "k8s.io/client-go/applyconfigurations/networking/v1 "
36
+ networkinginformers "k8s.io/client-go/informers/networking/v1 "
37
37
clientset "k8s.io/client-go/kubernetes"
38
38
"k8s.io/client-go/kubernetes/scheme"
39
39
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
40
- networkinglisters "k8s.io/client-go/listers/networking/v1beta1 "
40
+ networkinglisters "k8s.io/client-go/listers/networking/v1 "
41
41
"k8s.io/client-go/tools/cache"
42
42
"k8s.io/client-go/tools/record"
43
43
"k8s.io/client-go/util/workqueue"
@@ -147,7 +147,7 @@ func (c *Controller) Run(ctx context.Context, workers int) {
147
147
}
148
148
149
149
func (c * Controller ) addServiceCIDR (obj interface {}) {
150
- cidr , ok := obj .(* networkingapiv1beta1 .ServiceCIDR )
150
+ cidr , ok := obj .(* networkingapiv1 .ServiceCIDR )
151
151
if ! ok {
152
152
return
153
153
}
@@ -174,7 +174,7 @@ func (c *Controller) deleteServiceCIDR(obj interface{}) {
174
174
175
175
// addIPAddress may block a ServiceCIDR deletion
176
176
func (c * Controller ) addIPAddress (obj interface {}) {
177
- ip , ok := obj .(* networkingapiv1beta1 .IPAddress )
177
+ ip , ok := obj .(* networkingapiv1 .IPAddress )
178
178
if ! ok {
179
179
return
180
180
}
@@ -186,13 +186,13 @@ func (c *Controller) addIPAddress(obj interface{}) {
186
186
187
187
// deleteIPAddress may unblock a ServiceCIDR deletion
188
188
func (c * Controller ) deleteIPAddress (obj interface {}) {
189
- ip , ok := obj .(* networkingapiv1beta1 .IPAddress )
189
+ ip , ok := obj .(* networkingapiv1 .IPAddress )
190
190
if ! ok {
191
191
tombstone , ok := obj .(cache.DeletedFinalStateUnknown )
192
192
if ! ok {
193
193
return
194
194
}
195
- ip , ok = tombstone .Obj .(* networkingapiv1beta1 .IPAddress )
195
+ ip , ok = tombstone .Obj .(* networkingapiv1 .IPAddress )
196
196
if ! ok {
197
197
return
198
198
}
@@ -206,7 +206,7 @@ func (c *Controller) deleteIPAddress(obj interface{}) {
206
206
// overlappingServiceCIDRs, given a ServiceCIDR return the ServiceCIDRs that contain or are contained,
207
207
// this is required because adding or removing a CIDR will require to recompute the
208
208
// state of each ServiceCIDR to check if can be unblocked on deletion.
209
- func (c * Controller ) overlappingServiceCIDRs (serviceCIDR * networkingapiv1beta1 .ServiceCIDR ) []string {
209
+ func (c * Controller ) overlappingServiceCIDRs (serviceCIDR * networkingapiv1 .ServiceCIDR ) []string {
210
210
result := sets .New [string ]()
211
211
for _ , cidr := range serviceCIDR .Spec .CIDRs {
212
212
if prefix , err := netip .ParsePrefix (cidr ); err == nil { // if is empty err will not be nil
@@ -222,9 +222,9 @@ func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1beta1.S
222
222
223
223
// containingServiceCIDRs, given an IPAddress return the ServiceCIDRs that contains the IP,
224
224
// as it may block or be blocking the deletion of the ServiceCIDRs that contain it.
225
- func (c * Controller ) containingServiceCIDRs (ip * networkingapiv1beta1 .IPAddress ) []string {
225
+ func (c * Controller ) containingServiceCIDRs (ip * networkingapiv1 .IPAddress ) []string {
226
226
// only process IPs managed by the kube-apiserver
227
- managedBy , ok := ip .Labels [networkingapiv1beta1 .LabelManagedBy ]
227
+ managedBy , ok := ip .Labels [networkingapiv1 .LabelManagedBy ]
228
228
if ! ok || managedBy != ipallocator .ControllerName {
229
229
return []string {}
230
230
}
@@ -302,15 +302,15 @@ func (c *Controller) sync(ctx context.Context, key string) error {
302
302
// update the status to indicate why the ServiceCIDR can not be deleted,
303
303
// it will be reevaludated by an event on any ServiceCIDR or IPAddress related object
304
304
// that may remove this condition.
305
- svcApplyStatus := networkingapiv1beta1apply .ServiceCIDRStatus ().WithConditions (
305
+ svcApplyStatus := networkingapiv1apply .ServiceCIDRStatus ().WithConditions (
306
306
metav1apply .Condition ().
307
- WithType (networkingapiv1beta1 .ServiceCIDRConditionReady ).
307
+ WithType (networkingapiv1 .ServiceCIDRConditionReady ).
308
308
WithStatus (metav1 .ConditionFalse ).
309
- WithReason (networkingapiv1beta1 .ServiceCIDRReasonTerminating ).
309
+ WithReason (networkingapiv1 .ServiceCIDRReasonTerminating ).
310
310
WithMessage ("There are still IPAddresses referencing the ServiceCIDR, please remove them or create a new ServiceCIDR" ).
311
311
WithLastTransitionTime (metav1 .Now ()))
312
- svcApply := networkingapiv1beta1apply .ServiceCIDR (cidr .Name ).WithStatus (svcApplyStatus )
313
- _ , err = c .client .NetworkingV1beta1 ().ServiceCIDRs ().ApplyStatus (ctx , svcApply , metav1.ApplyOptions {FieldManager : controllerName , Force : true })
312
+ svcApply := networkingapiv1apply .ServiceCIDR (cidr .Name ).WithStatus (svcApplyStatus )
313
+ _ , err = c .client .NetworkingV1 ().ServiceCIDRs ().ApplyStatus (ctx , svcApply , metav1.ApplyOptions {FieldManager : controllerName , Force : true })
314
314
return err
315
315
}
316
316
// If there are no IPAddress depending on this ServiceCIDR is safe to remove it,
@@ -333,14 +333,14 @@ func (c *Controller) sync(ctx context.Context, key string) error {
333
333
}
334
334
335
335
// Set Ready condition to True.
336
- svcApplyStatus := networkingapiv1beta1apply .ServiceCIDRStatus ().WithConditions (
336
+ svcApplyStatus := networkingapiv1apply .ServiceCIDRStatus ().WithConditions (
337
337
metav1apply .Condition ().
338
- WithType (networkingapiv1beta1 .ServiceCIDRConditionReady ).
338
+ WithType (networkingapiv1 .ServiceCIDRConditionReady ).
339
339
WithStatus (metav1 .ConditionTrue ).
340
340
WithMessage ("Kubernetes Service CIDR is ready" ).
341
341
WithLastTransitionTime (metav1 .Now ()))
342
- svcApply := networkingapiv1beta1apply .ServiceCIDR (cidr .Name ).WithStatus (svcApplyStatus )
343
- if _ , err := c .client .NetworkingV1beta1 ().ServiceCIDRs ().ApplyStatus (ctx , svcApply , metav1.ApplyOptions {FieldManager : controllerName , Force : true }); err != nil {
342
+ svcApply := networkingapiv1apply .ServiceCIDR (cidr .Name ).WithStatus (svcApplyStatus )
343
+ if _ , err := c .client .NetworkingV1 ().ServiceCIDRs ().ApplyStatus (ctx , svcApply , metav1.ApplyOptions {FieldManager : controllerName , Force : true }); err != nil {
344
344
logger .Info ("error updating default ServiceCIDR status" , "error" , err )
345
345
c .eventRecorder .Eventf (cidr , v1 .EventTypeWarning , "KubernetesServiceCIDRError" , "The ServiceCIDR Status can not be set to Ready=True" )
346
346
return err
@@ -350,7 +350,7 @@ func (c *Controller) sync(ctx context.Context, key string) error {
350
350
}
351
351
352
352
// canDeleteCIDR checks that the ServiceCIDR can be safely deleted and not leave orphan IPAddresses
353
- func (c * Controller ) canDeleteCIDR (ctx context.Context , serviceCIDR * networkingapiv1beta1 .ServiceCIDR ) (bool , error ) {
353
+ func (c * Controller ) canDeleteCIDR (ctx context.Context , serviceCIDR * networkingapiv1 .ServiceCIDR ) (bool , error ) {
354
354
logger := klog .FromContext (ctx )
355
355
// Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted.
356
356
hasParent := true
@@ -379,8 +379,8 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
379
379
for _ , cidr := range serviceCIDR .Spec .CIDRs {
380
380
// get all the IPv4 addresses
381
381
ipLabelSelector := labels .Set (map [string ]string {
382
- networkingapiv1beta1 .LabelIPAddressFamily : string (convertToV1IPFamily (netutils .IPFamilyOfCIDRString (cidr ))),
383
- networkingapiv1beta1 .LabelManagedBy : ipallocator .ControllerName ,
382
+ networkingapiv1 .LabelIPAddressFamily : string (convertToV1IPFamily (netutils .IPFamilyOfCIDRString (cidr ))),
383
+ networkingapiv1 .LabelManagedBy : ipallocator .ControllerName ,
384
384
}).AsSelectorPreValidated ()
385
385
ips , err := c .ipAddressLister .List (ipLabelSelector )
386
386
if err != nil {
@@ -411,7 +411,7 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
411
411
return true , nil
412
412
}
413
413
414
- func (c * Controller ) addServiceCIDRFinalizerIfNeeded (ctx context.Context , cidr * networkingapiv1beta1 .ServiceCIDR ) error {
414
+ func (c * Controller ) addServiceCIDRFinalizerIfNeeded (ctx context.Context , cidr * networkingapiv1 .ServiceCIDR ) error {
415
415
for _ , f := range cidr .GetFinalizers () {
416
416
if f == ServiceCIDRProtectionFinalizer {
417
417
return nil
@@ -427,7 +427,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
427
427
if err != nil {
428
428
return err
429
429
}
430
- _ , err = c .client .NetworkingV1beta1 ().ServiceCIDRs ().Patch (ctx , cidr .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
430
+ _ , err = c .client .NetworkingV1 ().ServiceCIDRs ().Patch (ctx , cidr .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
431
431
if err != nil && ! apierrors .IsNotFound (err ) {
432
432
return err
433
433
}
@@ -436,7 +436,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
436
436
437
437
}
438
438
439
- func (c * Controller ) removeServiceCIDRFinalizerIfNeeded (ctx context.Context , cidr * networkingapiv1beta1 .ServiceCIDR ) error {
439
+ func (c * Controller ) removeServiceCIDRFinalizerIfNeeded (ctx context.Context , cidr * networkingapiv1 .ServiceCIDR ) error {
440
440
found := false
441
441
for _ , f := range cidr .GetFinalizers () {
442
442
if f == ServiceCIDRProtectionFinalizer {
@@ -456,7 +456,7 @@ func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cid
456
456
if err != nil {
457
457
return err
458
458
}
459
- _ , err = c .client .NetworkingV1beta1 ().ServiceCIDRs ().Patch (ctx , cidr .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
459
+ _ , err = c .client .NetworkingV1 ().ServiceCIDRs ().Patch (ctx , cidr .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
460
460
if err != nil && ! apierrors .IsNotFound (err ) {
461
461
return err
462
462
}
0 commit comments