mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
update controller manager
This commit is contained in:
parent
33ba585534
commit
7721590b9e
@ -40,8 +40,8 @@ func newServiceCIDRsControllerDescriptor() *ControllerDescriptor {
|
||||
func startServiceCIDRsController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
|
||||
go servicecidrs.NewController(
|
||||
ctx,
|
||||
controllerContext.InformerFactory.Networking().V1beta1().ServiceCIDRs(),
|
||||
controllerContext.InformerFactory.Networking().V1beta1().IPAddresses(),
|
||||
controllerContext.InformerFactory.Networking().V1().ServiceCIDRs(),
|
||||
controllerContext.InformerFactory.Networking().V1().IPAddresses(),
|
||||
controllerContext.ClientBuilder.ClientOrDie("service-cidrs-controller"),
|
||||
).Run(ctx, 5)
|
||||
// TODO use component config
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingapiv1 "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"
|
||||
@ -32,12 +32,12 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
metav1apply "k8s.io/client-go/applyconfigurations/meta/v1"
|
||||
networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1"
|
||||
networkinginformers "k8s.io/client-go/informers/networking/v1beta1"
|
||||
networkingapiv1apply "k8s.io/client-go/applyconfigurations/networking/v1"
|
||||
networkinginformers "k8s.io/client-go/informers/networking/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/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/record"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
@ -147,7 +147,7 @@ func (c *Controller) Run(ctx context.Context, workers int) {
|
||||
}
|
||||
|
||||
func (c *Controller) addServiceCIDR(obj interface{}) {
|
||||
cidr, ok := obj.(*networkingapiv1beta1.ServiceCIDR)
|
||||
cidr, ok := obj.(*networkingapiv1.ServiceCIDR)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
@ -174,7 +174,7 @@ func (c *Controller) deleteServiceCIDR(obj interface{}) {
|
||||
|
||||
// addIPAddress may block a ServiceCIDR deletion
|
||||
func (c *Controller) addIPAddress(obj interface{}) {
|
||||
ip, ok := obj.(*networkingapiv1beta1.IPAddress)
|
||||
ip, ok := obj.(*networkingapiv1.IPAddress)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
@ -186,13 +186,13 @@ func (c *Controller) addIPAddress(obj interface{}) {
|
||||
|
||||
// deleteIPAddress may unblock a ServiceCIDR deletion
|
||||
func (c *Controller) deleteIPAddress(obj interface{}) {
|
||||
ip, ok := obj.(*networkingapiv1beta1.IPAddress)
|
||||
ip, ok := obj.(*networkingapiv1.IPAddress)
|
||||
if !ok {
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
ip, ok = tombstone.Obj.(*networkingapiv1beta1.IPAddress)
|
||||
ip, ok = tombstone.Obj.(*networkingapiv1.IPAddress)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
@ -206,7 +206,7 @@ func (c *Controller) deleteIPAddress(obj interface{}) {
|
||||
// overlappingServiceCIDRs, given a ServiceCIDR return the ServiceCIDRs that contain or are contained,
|
||||
// this is required because adding or removing a CIDR will require to recompute the
|
||||
// state of each ServiceCIDR to check if can be unblocked on deletion.
|
||||
func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1beta1.ServiceCIDR) []string {
|
||||
func (c *Controller) overlappingServiceCIDRs(serviceCIDR *networkingapiv1.ServiceCIDR) []string {
|
||||
result := sets.New[string]()
|
||||
for _, cidr := range serviceCIDR.Spec.CIDRs {
|
||||
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
|
||||
|
||||
// containingServiceCIDRs, given an IPAddress return the ServiceCIDRs that contains the IP,
|
||||
// as it may block or be blocking the deletion of the ServiceCIDRs that contain it.
|
||||
func (c *Controller) containingServiceCIDRs(ip *networkingapiv1beta1.IPAddress) []string {
|
||||
func (c *Controller) containingServiceCIDRs(ip *networkingapiv1.IPAddress) []string {
|
||||
// only process IPs managed by the kube-apiserver
|
||||
managedBy, ok := ip.Labels[networkingapiv1beta1.LabelManagedBy]
|
||||
managedBy, ok := ip.Labels[networkingapiv1.LabelManagedBy]
|
||||
if !ok || managedBy != ipallocator.ControllerName {
|
||||
return []string{}
|
||||
}
|
||||
@ -302,15 +302,15 @@ func (c *Controller) sync(ctx context.Context, key string) error {
|
||||
// update the status to indicate why the ServiceCIDR can not be deleted,
|
||||
// it will be reevaludated by an event on any ServiceCIDR or IPAddress related object
|
||||
// that may remove this condition.
|
||||
svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
|
||||
svcApplyStatus := networkingapiv1apply.ServiceCIDRStatus().WithConditions(
|
||||
metav1apply.Condition().
|
||||
WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
|
||||
WithType(networkingapiv1.ServiceCIDRConditionReady).
|
||||
WithStatus(metav1.ConditionFalse).
|
||||
WithReason(networkingapiv1beta1.ServiceCIDRReasonTerminating).
|
||||
WithReason(networkingapiv1.ServiceCIDRReasonTerminating).
|
||||
WithMessage("There are still IPAddresses referencing the ServiceCIDR, please remove them or create a new ServiceCIDR").
|
||||
WithLastTransitionTime(metav1.Now()))
|
||||
svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
|
||||
_, err = c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true})
|
||||
svcApply := networkingapiv1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
|
||||
_, err = c.client.NetworkingV1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true})
|
||||
return err
|
||||
}
|
||||
// If there are no IPAddress depending on this ServiceCIDR is safe to remove it,
|
||||
@ -333,14 +333,14 @@ func (c *Controller) sync(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
// Set Ready condition to True.
|
||||
svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
|
||||
svcApplyStatus := networkingapiv1apply.ServiceCIDRStatus().WithConditions(
|
||||
metav1apply.Condition().
|
||||
WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
|
||||
WithType(networkingapiv1.ServiceCIDRConditionReady).
|
||||
WithStatus(metav1.ConditionTrue).
|
||||
WithMessage("Kubernetes Service CIDR is ready").
|
||||
WithLastTransitionTime(metav1.Now()))
|
||||
svcApply := networkingapiv1beta1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
|
||||
if _, err := c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); err != nil {
|
||||
svcApply := networkingapiv1apply.ServiceCIDR(cidr.Name).WithStatus(svcApplyStatus)
|
||||
if _, err := c.client.NetworkingV1().ServiceCIDRs().ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); err != nil {
|
||||
logger.Info("error updating default ServiceCIDR status", "error", err)
|
||||
c.eventRecorder.Eventf(cidr, v1.EventTypeWarning, "KubernetesServiceCIDRError", "The ServiceCIDR Status can not be set to Ready=True")
|
||||
return err
|
||||
@ -350,7 +350,7 @@ func (c *Controller) sync(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
// canDeleteCIDR checks that the ServiceCIDR can be safely deleted and not leave orphan IPAddresses
|
||||
func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkingapiv1beta1.ServiceCIDR) (bool, error) {
|
||||
func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkingapiv1.ServiceCIDR) (bool, error) {
|
||||
logger := klog.FromContext(ctx)
|
||||
// Check if there is a subnet that already contains the ServiceCIDR that is going to be deleted.
|
||||
hasParent := true
|
||||
@ -379,8 +379,8 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
|
||||
for _, cidr := range serviceCIDR.Spec.CIDRs {
|
||||
// get all the IPv4 addresses
|
||||
ipLabelSelector := labels.Set(map[string]string{
|
||||
networkingapiv1beta1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))),
|
||||
networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName,
|
||||
networkingapiv1.LabelIPAddressFamily: string(convertToV1IPFamily(netutils.IPFamilyOfCIDRString(cidr))),
|
||||
networkingapiv1.LabelManagedBy: ipallocator.ControllerName,
|
||||
}).AsSelectorPreValidated()
|
||||
ips, err := c.ipAddressLister.List(ipLabelSelector)
|
||||
if err != nil {
|
||||
@ -411,7 +411,7 @@ func (c *Controller) canDeleteCIDR(ctx context.Context, serviceCIDR *networkinga
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error {
|
||||
func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1.ServiceCIDR) error {
|
||||
for _, f := range cidr.GetFinalizers() {
|
||||
if f == ServiceCIDRProtectionFinalizer {
|
||||
return nil
|
||||
@ -427,7 +427,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.client.NetworkingV1beta1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{})
|
||||
_, err = c.client.NetworkingV1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
@ -436,7 +436,7 @@ func (c *Controller) addServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *
|
||||
|
||||
}
|
||||
|
||||
func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1beta1.ServiceCIDR) error {
|
||||
func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cidr *networkingapiv1.ServiceCIDR) error {
|
||||
found := false
|
||||
for _, f := range cidr.GetFinalizers() {
|
||||
if f == ServiceCIDRProtectionFinalizer {
|
||||
@ -456,7 +456,7 @@ func (c *Controller) removeServiceCIDRFinalizerIfNeeded(ctx context.Context, cid
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.client.NetworkingV1beta1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{})
|
||||
_, err = c.client.NetworkingV1().ServiceCIDRs().Patch(ctx, cidr.Name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingapiv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
@ -44,12 +44,12 @@ type testController struct {
|
||||
ipaddressesStore cache.Store
|
||||
}
|
||||
|
||||
func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1beta1.ServiceCIDR, ips []*networkingapiv1beta1.IPAddress) (*fake.Clientset, *testController) {
|
||||
func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1.ServiceCIDR, ips []*networkingapiv1.IPAddress) (*fake.Clientset, *testController) {
|
||||
client := fake.NewSimpleClientset()
|
||||
|
||||
informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc())
|
||||
|
||||
serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
|
||||
serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs()
|
||||
cidrStore := serviceCIDRInformer.Informer().GetStore()
|
||||
for _, obj := range cidrs {
|
||||
err := cidrStore.Add(obj)
|
||||
@ -57,7 +57,7 @@ func newController(ctx context.Context, t *testing.T, cidrs []*networkingapiv1be
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
ipAddressInformer := informerFactory.Networking().V1beta1().IPAddresses()
|
||||
ipAddressInformer := informerFactory.Networking().V1().IPAddresses()
|
||||
ipStore := ipAddressInformer.Informer().GetStore()
|
||||
for _, obj := range ips {
|
||||
err := ipStore.Add(obj)
|
||||
@ -97,8 +97,8 @@ func TestControllerSync(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
cidrs []*networkingapiv1beta1.ServiceCIDR
|
||||
ips []*networkingapiv1beta1.IPAddress
|
||||
cidrs []*networkingapiv1.ServiceCIDR
|
||||
ips []*networkingapiv1.IPAddress
|
||||
cidrSynced string
|
||||
actions [][]string // verb and resource and subresource
|
||||
}{
|
||||
@ -107,7 +107,7 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "default service CIDR must have finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
cidrSynced: defaultservicecidr.DefaultServiceCIDRName,
|
||||
@ -115,7 +115,7 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR must have finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR("no-finalizer", "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
cidrSynced: "no-finalizer",
|
||||
@ -123,7 +123,7 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted must remove the finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -131,7 +131,7 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted but within the grace period must be requeued not remove the finalizer", // TODO: assert is actually requeued
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletingServiceCIDR,
|
||||
},
|
||||
cidrSynced: deletingServiceCIDR.Name,
|
||||
@ -139,10 +139,10 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted with IPv4 addresses should update the status",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -150,11 +150,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and overlapping same range and IPv4 addresses should remove the finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -162,11 +162,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and overlapping and IPv4 addresses should remove the finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -174,11 +174,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and not overlapping and IPv4 addresses should update the status",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -186,10 +186,10 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted with IPv6 addresses should update the status",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("2001:db2::1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -197,11 +197,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and overlapping same range and IPv6 addresses should remove the finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("2001:db2::1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -209,11 +209,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and overlapping and IPv6 addresses should remove the finalizer",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/48"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("2001:db2::1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -221,11 +221,11 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "service CIDR being deleted and not overlapping and IPv6 addresses should update the status",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
deletedServiceCIDR,
|
||||
makeServiceCIDR("overlapping", "192.168.255.0/26", "2001:db2:a:b::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("2001:db2::1"),
|
||||
},
|
||||
cidrSynced: deletedServiceCIDR.Name,
|
||||
@ -247,12 +247,12 @@ func TestControllerSync(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeServiceCIDR(name, primary, secondary string) *networkingapiv1beta1.ServiceCIDR {
|
||||
serviceCIDR := &networkingapiv1beta1.ServiceCIDR{
|
||||
func makeServiceCIDR(name, primary, secondary string) *networkingapiv1.ServiceCIDR {
|
||||
serviceCIDR := &networkingapiv1.ServiceCIDR{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{},
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{},
|
||||
}
|
||||
serviceCIDR.Spec.CIDRs = append(serviceCIDR.Spec.CIDRs, primary)
|
||||
if secondary != "" {
|
||||
@ -261,17 +261,17 @@ func makeServiceCIDR(name, primary, secondary string) *networkingapiv1beta1.Serv
|
||||
return serviceCIDR
|
||||
}
|
||||
|
||||
func makeIPAddress(name string) *networkingapiv1beta1.IPAddress {
|
||||
func makeIPAddress(name string) *networkingapiv1.IPAddress {
|
||||
family := string(v1.IPv4Protocol)
|
||||
if netutils.IsIPv6String(name) {
|
||||
family = string(v1.IPv6Protocol)
|
||||
}
|
||||
return &networkingapiv1beta1.IPAddress{
|
||||
return &networkingapiv1.IPAddress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: map[string]string{
|
||||
networkingapiv1beta1.LabelIPAddressFamily: family,
|
||||
networkingapiv1beta1.LabelManagedBy: ipallocator.ControllerName,
|
||||
networkingapiv1.LabelIPAddressFamily: family,
|
||||
networkingapiv1.LabelManagedBy: ipallocator.ControllerName,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -302,9 +302,9 @@ func expectAction(t *testing.T, actions []k8stesting.Action, expected [][]string
|
||||
func TestController_canDeleteCIDR(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cidrs []*networkingapiv1beta1.ServiceCIDR
|
||||
ips []*networkingapiv1beta1.IPAddress
|
||||
cidrSynced *networkingapiv1beta1.ServiceCIDR
|
||||
cidrs []*networkingapiv1.ServiceCIDR
|
||||
ips []*networkingapiv1.IPAddress
|
||||
cidrSynced *networkingapiv1.ServiceCIDR
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
@ -314,7 +314,7 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR and no IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -322,10 +322,10 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.24"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -333,10 +333,10 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR without IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.1.24"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -344,10 +344,10 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with IPv4 address referencing the subnet address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.0"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -355,10 +355,10 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with IPv4 address referencing the broadcast address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.255"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -366,10 +366,10 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with IPv6 address referencing the broadcast address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("2001:0db2::ffff:ffff:ffff:ffff"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -377,11 +377,11 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with same range overlapping and IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.23"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -389,11 +389,11 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with smaller range overlapping and IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/26", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.23"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -401,11 +401,11 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with smaller range overlapping but IPs orphan",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/28", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.23"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -413,11 +413,11 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "CIDR with larger range overlapping and IPs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/16", "2001:db2::/64"),
|
||||
},
|
||||
ips: []*networkingapiv1beta1.IPAddress{
|
||||
ips: []*networkingapiv1.IPAddress{
|
||||
makeIPAddress("192.168.0.23"),
|
||||
},
|
||||
cidrSynced: makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
@ -442,8 +442,8 @@ func TestController_canDeleteCIDR(t *testing.T) {
|
||||
func TestController_ipToCidrs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cidrs []*networkingapiv1beta1.ServiceCIDR
|
||||
ip *networkingapiv1beta1.IPAddress
|
||||
cidrs []*networkingapiv1.ServiceCIDR
|
||||
ip *networkingapiv1.IPAddress
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
@ -452,7 +452,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{},
|
||||
}, {
|
||||
name: "one CIDR",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
|
||||
makeServiceCIDR("unrelated2", "10.0.0.0/16", ""),
|
||||
@ -461,7 +461,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName},
|
||||
}, {
|
||||
name: "two equal CIDR",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"),
|
||||
makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
|
||||
@ -471,7 +471,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
@ -482,7 +482,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping", "overlapping2"},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger - IPv4 subnet address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
@ -493,7 +493,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger - IPv4 broadcast address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
@ -504,7 +504,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger - IPv6 subnet address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
@ -515,7 +515,7 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
want: []string{},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger - IPv6 broadcast address",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
@ -539,8 +539,8 @@ func TestController_ipToCidrs(t *testing.T) {
|
||||
func TestController_cidrToCidrs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cidrs []*networkingapiv1beta1.ServiceCIDR
|
||||
cidr *networkingapiv1beta1.ServiceCIDR
|
||||
cidrs []*networkingapiv1.ServiceCIDR
|
||||
cidr *networkingapiv1.ServiceCIDR
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
@ -549,7 +549,7 @@ func TestController_cidrToCidrs(t *testing.T) {
|
||||
want: []string{},
|
||||
}, {
|
||||
name: "one CIDR",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
|
||||
makeServiceCIDR("unrelated2", "10.0.0.0/16", ""),
|
||||
@ -558,7 +558,7 @@ func TestController_cidrToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName},
|
||||
}, {
|
||||
name: "two equal CIDR",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/96"),
|
||||
makeServiceCIDR("unrelated", "10.0.0.0/24", ""),
|
||||
@ -568,7 +568,7 @@ func TestController_cidrToCidrs(t *testing.T) {
|
||||
want: []string{defaultservicecidr.DefaultServiceCIDRName, "overlapping"},
|
||||
}, {
|
||||
name: "three CIDR - two same and one larger",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
makeServiceCIDR(defaultservicecidr.DefaultServiceCIDRName, "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping", "192.168.0.0/24", "2001:db2::/64"),
|
||||
makeServiceCIDR("overlapping2", "192.168.0.0/26", "2001:db2::/96"),
|
||||
|
Loading…
Reference in New Issue
Block a user