Skip to content

Commit 7721590

Browse files
committed
update controller manager
1 parent 33ba585 commit 7721590

File tree

3 files changed

+98
-98
lines changed

3 files changed

+98
-98
lines changed

cmd/kube-controller-manager/app/networking.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func newServiceCIDRsControllerDescriptor() *ControllerDescriptor {
4040
func startServiceCIDRsController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
4141
go servicecidrs.NewController(
4242
ctx,
43-
controllerContext.InformerFactory.Networking().V1beta1().ServiceCIDRs(),
44-
controllerContext.InformerFactory.Networking().V1beta1().IPAddresses(),
43+
controllerContext.InformerFactory.Networking().V1().ServiceCIDRs(),
44+
controllerContext.InformerFactory.Networking().V1().IPAddresses(),
4545
controllerContext.ClientBuilder.ClientOrDie("service-cidrs-controller"),
4646
).Run(ctx, 5)
4747
// TODO use component config

pkg/controller/servicecidrs/servicecidrs_controller.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"time"
2424

2525
v1 "k8s.io/api/core/v1"
26-
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
26+
networkingapiv1 "k8s.io/api/networking/v1"
2727
apierrors "k8s.io/apimachinery/pkg/api/errors"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/labels"
@@ -32,12 +32,12 @@ import (
3232
"k8s.io/apimachinery/pkg/util/sets"
3333
"k8s.io/apimachinery/pkg/util/wait"
3434
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"
3737
clientset "k8s.io/client-go/kubernetes"
3838
"k8s.io/client-go/kubernetes/scheme"
3939
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"
4141
"k8s.io/client-go/tools/cache"
4242
"k8s.io/client-go/tools/record"
4343
"k8s.io/client-go/util/workqueue"
@@ -147,7 +147,7 @@ func (c *Controller) Run(ctx context.Context, workers int) {
147147
}
148148

149149
func (c *Controller) addServiceCIDR(obj interface{}) {
150-
cidr, ok := obj.(*networkingapiv1beta1.ServiceCIDR)
150+
cidr, ok := obj.(*networkingapiv1.ServiceCIDR)
151151
if !ok {
152152
return
153153
}
@@ -174,7 +174,7 @@ func (c *Controller) deleteServiceCIDR(obj interface{}) {
174174

175175
// addIPAddress may block a ServiceCIDR deletion
176176
func (c *Controller) addIPAddress(obj interface{}) {
177-
ip, ok := obj.(*networkingapiv1beta1.IPAddress)
177+
ip, ok := obj.(*networkingapiv1.IPAddress)
178178
if !ok {
179179
return
180180
}
@@ -186,13 +186,13 @@ func (c *Controller) addIPAddress(obj interface{}) {
186186

187187
// deleteIPAddress may unblock a ServiceCIDR deletion
188188
func (c *Controller) deleteIPAddress(obj interface{}) {
189-
ip, ok := obj.(*networkingapiv1beta1.IPAddress)
189+
ip, ok := obj.(*networkingapiv1.IPAddress)
190190
if !ok {
191191
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
192192
if !ok {
193193
return
194194
}
195-
ip, ok = tombstone.Obj.(*networkingapiv1beta1.IPAddress)
195+
ip, ok = tombstone.Obj.(*networkingapiv1.IPAddress)
196196
if !ok {
197197
return
198198
}
@@ -206,7 +206,7 @@ func (c *Controller) deleteIPAddress(obj interface{}) {
206206
// overlappingServiceCIDRs, given a ServiceCIDR return the ServiceCIDRs that contain or are contained,
207207
// this is required because adding or removing a CIDR will require to recompute the
208208
// 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 {
210210
result := sets.New[string]()
211211
for _, cidr := range serviceCIDR.Spec.CIDRs {
212212
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
222222

223223
// containingServiceCIDRs, given an IPAddress return the ServiceCIDRs that contains the IP,
224224
// 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 {
226226
// only process IPs managed by the kube-apiserver
227-
managedBy, ok := ip.Labels[networkingapiv1beta1.LabelManagedBy]
227+
managedBy, ok := ip.Labels[networkingapiv1.LabelManagedBy]
228228
if !ok || managedBy != ipallocator.ControllerName {
229229
return []string{}
230230
}
@@ -302,15 +302,15 @@ func (c *Controller) sync(ctx context.Context, key string) error {
302302
// update the status to indicate why the ServiceCIDR can not be deleted,
303303
// it will be reevaludated by an event on any ServiceCIDR or IPAddress related object
304304
// that may remove this condition.
305-
svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
305+
svcApplyStatus := networkingapiv1apply.ServiceCIDRStatus().WithConditions(
306306
metav1apply.Condition().
307-
WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
307+
WithType(networkingapiv1.ServiceCIDRConditionReady).
308308
WithStatus(metav1.ConditionFalse).
309-
WithReason(networkingapiv1beta1.ServiceCIDRReasonTerminating).
309+
WithReason(networkingapiv1.ServiceCIDRReasonTerminating).
310310
WithMessage("There are still IPAddresses referencing the ServiceCIDR, please remove them or create a new ServiceCIDR").
311311
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})
314314
return err
315315
}
316316
// 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 {
333333
}
334334

335335
// Set Ready condition to True.
336-
svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
336+
svcApplyStatus := networkingapiv1apply.ServiceCIDRStatus().WithConditions(
337337
metav1apply.Condition().
338-
WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
338+
WithType(networkingapiv1.ServiceCIDRConditionReady).
339339
WithStatus(metav1.ConditionTrue).
340340
WithMessage("Kubernetes Service CIDR is ready").
341341
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 {
344344
logger.Info("error updating default ServiceCIDR status", "error", err)
345345
c.eventRecorder.Eventf(cidr, v1.EventTypeWarning, "KubernetesServiceCIDRError", "The ServiceCIDR Status can not be set to Ready=True")
346346
return err
@@ -350,7 +350,7 @@ func (c *Controller) sync(ctx context.Context, key string) error {
350350
}
351351

352352
// 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) {
354354
logger := klog.FromContext(ctx)
355355
// Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted.
356356
hasParent := true
@@ -379,8 +379,8 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
379379
for _, cidr := range serviceCIDR.Spec.CIDRs {
380380
// get all the IPv4 addresses
381381
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,
384384
}).AsSelectorPreValidated()
385385
ips, err := c.ipAddressLister.List(ipLabelSelector)
386386
if err != nil {
@@ -411,7 +411,7 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
411411
return true, nil
412412
}
413413

414-
func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error {
414+
func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1.ServiceCIDR) error {
415415
for _, f := range cidr.GetFinalizers() {
416416
if f == ServiceCIDRProtectionFinalizer {
417417
return nil
@@ -427,7 +427,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
427427
if err != nil {
428428
return err
429429
}
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{})
431431
if err != nil && !apierrors.IsNotFound(err) {
432432
return err
433433
}
@@ -436,7 +436,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
436436

437437
}
438438

439-
func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error {
439+
func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1.ServiceCIDR) error {
440440
found := false
441441
for _, f := range cidr.GetFinalizers() {
442442
if f == ServiceCIDRProtectionFinalizer {
@@ -456,7 +456,7 @@ func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cid
456456
if err != nil {
457457
return err
458458
}
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{})
460460
if err != nil && !apierrors.IsNotFound(err) {
461461
return err
462462
}

0 commit comments

Comments
 (0)