diff --git a/apis/networking/v1beta1/configuration_types.go b/apis/networking/v1beta1/configuration_types.go index 153e553270..4f196251fa 100644 --- a/apis/networking/v1beta1/configuration_types.go +++ b/apis/networking/v1beta1/configuration_types.go @@ -37,9 +37,9 @@ var ConfigurationGroupVersionResource = GroupVersion.WithResource(ConfigurationR // ClusterConfigCIDR defines the CIDR of the cluster. type ClusterConfigCIDR struct { // Pod CIDR of the cluster. - Pod CIDR `json:"pod,omitempty"` + Pod []CIDR `json:"pod,omitempty"` // External CIDR of the cluster. - External CIDR `json:"external,omitempty"` + External []CIDR `json:"external,omitempty"` } // ClusterConfig defines the configuration of a cluster. diff --git a/apis/networking/v1beta1/zz_generated.deepcopy.go b/apis/networking/v1beta1/zz_generated.deepcopy.go index aac8e8fdcb..0d54c61d1b 100644 --- a/apis/networking/v1beta1/zz_generated.deepcopy.go +++ b/apis/networking/v1beta1/zz_generated.deepcopy.go @@ -26,7 +26,7 @@ import ( // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterConfig) DeepCopyInto(out *ClusterConfig) { *out = *in - out.CIDR = in.CIDR + in.CIDR.DeepCopyInto(&out.CIDR) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfig. @@ -42,6 +42,16 @@ func (in *ClusterConfig) DeepCopy() *ClusterConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterConfigCIDR) DeepCopyInto(out *ClusterConfigCIDR) { *out = *in + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = make([]CIDR, len(*in)) + copy(*out, *in) + } + if in.External != nil { + in, out := &in.External, &out.External + *out = make([]CIDR, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfigCIDR. @@ -119,9 +129,9 @@ func (in *ConfigurationSpec) DeepCopyInto(out *ConfigurationSpec) { if in.Local != nil { in, out := &in.Local, &out.Local *out = new(ClusterConfig) - **out = **in + (*in).DeepCopyInto(*out) } - out.Remote = in.Remote + in.Remote.DeepCopyInto(&out.Remote) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigurationSpec. @@ -140,7 +150,7 @@ func (in *ConfigurationStatus) DeepCopyInto(out *ConfigurationStatus) { if in.Remote != nil { in, out := &in.Remote, &out.Remote *out = new(ClusterConfig) - **out = **in + (*in).DeepCopyInto(*out) } } diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml index d55882bcb6..b44a62ad38 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml @@ -76,12 +76,18 @@ spec: properties: external: description: External CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array pod: description: Pod CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array type: object type: object remote: @@ -92,12 +98,18 @@ spec: properties: external: description: External CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array pod: description: Pod CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array type: object type: object type: object @@ -113,12 +125,18 @@ spec: properties: external: description: External CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array pod: description: Pod CIDR of the cluster. - format: cidr - type: string + items: + description: CIDR defines a syntax validated CIDR. + format: cidr + type: string + type: array type: object type: object type: object diff --git a/pkg/liqo-controller-manager/ipmapping/configuration_controller.go b/pkg/liqo-controller-manager/ipmapping/configuration_controller.go index f63f26fa3f..d0fc70863b 100644 --- a/pkg/liqo-controller-manager/ipmapping/configuration_controller.go +++ b/pkg/liqo-controller-manager/ipmapping/configuration_controller.go @@ -33,6 +33,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" + "github.com/liqotech/liqo/pkg/utils/cidr" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -74,8 +75,8 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques } klog.V(4).Infof("Reconciling configuration %q", req.NamespacedName) - extCIDR := cfg.Status.Remote.CIDR.External - remoteUnknownSourceIP, err := ipamutils.GetUnknownSourceIP(string(extCIDR)) + extCIDR := cidr.GetPrimary(cfg.Status.Remote.CIDR.External) + remoteUnknownSourceIP, err := ipamutils.GetUnknownSourceIP(extCIDR.String()) if err != nil { return ctrl.Result{}, fmt.Errorf("unable to get the unknown source IP: %w", err) } diff --git a/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go b/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go index fa9536bfc3..9d6ad03cbc 100644 --- a/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go @@ -28,6 +28,7 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" + "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/events" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" ) @@ -110,8 +111,8 @@ func (r *ConfigurationReconciler) defaultLocalNetwork(ctx context.Context, cfg * } r.localCIDR = &networkingv1beta1.ClusterConfigCIDR{ - Pod: networkingv1beta1.CIDR(podCIDR), - External: networkingv1beta1.CIDR(externalCIDR), + Pod: cidr.SetPrimary(networkingv1beta1.CIDR(podCIDR)), + External: cidr.SetPrimary(networkingv1beta1.CIDR(externalCIDR)), } } @@ -155,11 +156,11 @@ func ForgeConfigurationStatus(cfg *networkingv1beta1.Configuration, net *ipamv1a cidrNew = net.Status.CIDR switch cidrType { case LabelCIDRTypePod: - cidrOld = cfg.Spec.Remote.CIDR.Pod - cfg.Status.Remote.CIDR.Pod = cidrNew + cidrOld = *cidr.GetPrimary(cfg.Spec.Remote.CIDR.Pod) + cfg.Status.Remote.CIDR.Pod = cidr.SetPrimary(cidrNew) case LabelCIDRTypeExternal: - cidrOld = cfg.Spec.Remote.CIDR.External - cfg.Status.Remote.CIDR.External = cidrNew + cidrOld = *cidr.GetPrimary(cfg.Spec.Remote.CIDR.External) + cfg.Status.Remote.CIDR.External = cidr.SetPrimary(cidrNew) } klog.Infof("Configuration %s %s CIDR: %s -> %s", client.ObjectKeyFromObject(cfg).String(), cidrType, cidrOld, cidrNew) } @@ -168,7 +169,7 @@ func isConfigurationConfigured(cfg *networkingv1beta1.Configuration) bool { if cfg.Status.Remote == nil { return false } - return cfg.Status.Remote.CIDR.Pod != "" && cfg.Status.Remote.CIDR.External != "" + return !cidr.IsVoid(cidr.GetPrimary(cfg.Status.Remote.CIDR.Pod)) && !cidr.IsVoid(cidr.GetPrimary(cfg.Status.Remote.CIDR.External)) } // SetupWithManager register the ConfigurationReconciler to the manager. diff --git a/pkg/liqo-controller-manager/networking/external-network/configuration/network.go b/pkg/liqo-controller-manager/networking/external-network/configuration/network.go index 9125c3871d..257c1718b2 100644 --- a/pkg/liqo-controller-manager/networking/external-network/configuration/network.go +++ b/pkg/liqo-controller-manager/networking/external-network/configuration/network.go @@ -25,6 +25,7 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/events" "github.com/liqotech/liqo/pkg/utils/getters" "github.com/liqotech/liqo/pkg/utils/resource" @@ -51,9 +52,9 @@ func ForgeNetwork(net *ipamv1alpha1.Network, cfg *networkingv1beta1.Configuratio var cidr networkingv1beta1.CIDR switch cidrType { case LabelCIDRTypePod: - cidr = cfg.Spec.Remote.CIDR.Pod + cidr = *cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod) case LabelCIDRTypeExternal: - cidr = cfg.Spec.Remote.CIDR.External + cidr = *cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External) } net.Spec = ipamv1alpha1.NetworkSpec{ CIDR: cidr, diff --git a/pkg/liqo-controller-manager/networking/external-network/remapping/cidr.go b/pkg/liqo-controller-manager/networking/external-network/remapping/cidr.go index 8e95a30443..726da5f7be 100644 --- a/pkg/liqo-controller-manager/networking/external-network/remapping/cidr.go +++ b/pkg/liqo-controller-manager/networking/external-network/remapping/cidr.go @@ -29,6 +29,7 @@ import ( "github.com/liqotech/liqo/apis/networking/v1beta1/firewall" "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/gateway/tunnel" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -139,11 +140,11 @@ func forgeCIDRFirewallConfigurationDNATRules(cfg *networkingv1beta1.Configuratio var remoteCIDR, remoteRemapCIDR string switch cidrtype { case PodCIDR: - remoteCIDR = cfg.Spec.Remote.CIDR.Pod.String() - remoteRemapCIDR = cfg.Status.Remote.CIDR.Pod.String() + remoteCIDR = cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod).String() + remoteRemapCIDR = cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String() case ExternalCIDR: - remoteCIDR = cfg.Spec.Remote.CIDR.External.String() - remoteRemapCIDR = cfg.Status.Remote.CIDR.External.String() + remoteCIDR = cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External).String() + remoteRemapCIDR = cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String() } return []firewall.NatRule{ { @@ -181,11 +182,11 @@ func forgeCIDRFirewallConfigurationSNATRules(cfg *networkingv1beta1.Configuratio var localCIDR, remoteRemapCIDR string switch cidrtype { case PodCIDR: - localCIDR = cfg.Spec.Local.CIDR.Pod.String() - remoteRemapCIDR = cfg.Status.Remote.CIDR.Pod.String() + localCIDR = cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String() + remoteRemapCIDR = cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String() case ExternalCIDR: - localCIDR = cfg.Spec.Local.CIDR.External.String() - remoteRemapCIDR = cfg.Status.Remote.CIDR.External.String() + localCIDR = cidrutils.GetPrimary(cfg.Spec.Local.CIDR.External).String() + remoteRemapCIDR = cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String() } return []firewall.NatRule{ diff --git a/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go b/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go index 8c21bd30d9..18031c550a 100644 --- a/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go @@ -31,6 +31,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ) // cluster-role @@ -75,14 +76,14 @@ func (r *RemappingReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } klog.V(4).Infof("Reconciling configuration %q", req.NamespacedName) - if conf.Spec.Remote.CIDR.Pod != conf.Status.Remote.CIDR.Pod { + if cidrutils.GetPrimary(conf.Spec.Remote.CIDR.Pod) != cidrutils.GetPrimary(conf.Status.Remote.CIDR.Pod) { if err := CreateOrUpdateNatMappingCIDR(ctx, r.Client, r.Options, conf, r.Scheme, PodCIDR); err != nil { return ctrl.Result{}, err } } - if conf.Spec.Remote.CIDR.External != conf.Status.Remote.CIDR.External { + if cidrutils.GetPrimary(conf.Spec.Remote.CIDR.External) != cidrutils.GetPrimary(conf.Status.Remote.CIDR.External) { if err := CreateOrUpdateNatMappingCIDR(ctx, r.Client, r.Options, conf, r.Scheme, ExternalCIDR); err != nil { return ctrl.Result{}, err diff --git a/pkg/liqo-controller-manager/networking/external-network/route/k8s.go b/pkg/liqo-controller-manager/networking/external-network/route/k8s.go index 1bae7fe6f3..573e24a677 100644 --- a/pkg/liqo-controller-manager/networking/external-network/route/k8s.go +++ b/pkg/liqo-controller-manager/networking/external-network/route/k8s.go @@ -30,6 +30,7 @@ import ( "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/gateway" "github.com/liqotech/liqo/pkg/gateway/tunnel" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/getters" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -115,20 +116,20 @@ func forgeMutateRouteConfiguration(cfg *networkingv1beta1.Configuration, []networkingv1beta1.Rule{ { Iif: &internalNodes.Items[i].Spec.Interface.Gateway.Name, - Dst: &cfg.Spec.Remote.CIDR.Pod, + Dst: cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod), Routes: []networkingv1beta1.Route{ { - Dst: &cfg.Spec.Remote.CIDR.Pod, + Dst: cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod), Gw: ptr.To(networkingv1beta1.IP(remoteInterfaceIP)), }, }, }, { Iif: &internalNodes.Items[i].Spec.Interface.Gateway.Name, - Dst: &cfg.Spec.Remote.CIDR.External, + Dst: cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External), Routes: []networkingv1beta1.Route{ { - Dst: &cfg.Spec.Remote.CIDR.External, + Dst: cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External), Gw: ptr.To(networkingv1beta1.IP(remoteInterfaceIP)), }, }, diff --git a/pkg/liqo-controller-manager/networking/forge/configuration.go b/pkg/liqo-controller-manager/networking/forge/configuration.go index d352de5006..1c992a546d 100644 --- a/pkg/liqo-controller-manager/networking/forge/configuration.go +++ b/pkg/liqo-controller-manager/networking/forge/configuration.go @@ -26,6 +26,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" liqoutils "github.com/liqotech/liqo/pkg/utils" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" ) @@ -62,8 +63,8 @@ func MutateConfiguration(conf *networkingv1beta1.Configuration, remoteClusterID conf.Labels = make(map[string]string) } conf.Labels[consts.RemoteClusterID] = string(remoteClusterID) - conf.Spec.Remote.CIDR.Pod = networkingv1beta1.CIDR(podCIDR) - conf.Spec.Remote.CIDR.External = networkingv1beta1.CIDR(externalCIDR) + conf.Spec.Remote.CIDR.Pod = cidrutils.SetPrimary(networkingv1beta1.CIDR(podCIDR)) + conf.Spec.Remote.CIDR.External = cidrutils.SetPrimary(networkingv1beta1.CIDR(externalCIDR)) } // ConfigurationForRemoteCluster forges a Configuration of the local cluster to be applied to a remote cluster. @@ -99,8 +100,8 @@ func ConfigurationForRemoteCluster(ctx context.Context, cl client.Client, Spec: networkingv1beta1.ConfigurationSpec{ Remote: networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: networkingv1beta1.CIDR(podCIDR), - External: networkingv1beta1.CIDR(externalCIDR), + Pod: cidrutils.SetPrimary(networkingv1beta1.CIDR(podCIDR)), + External: cidrutils.SetPrimary(networkingv1beta1.CIDR(externalCIDR)), }, }, }, diff --git a/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go b/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go index c296991330..79744a02c3 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go @@ -32,6 +32,7 @@ import ( internalnetwork "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network" "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/fabricipam" "github.com/liqotech/liqo/pkg/utils" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/getters" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -131,8 +132,8 @@ func (r *ClientReconciler) ensureInternalFabric(ctx context.Context, gwClient *n internalFabric.Spec.Interface.Gateway.IP = networkingv1beta1.IP(ip.String()) internalFabric.Spec.RemoteCIDRs = []networkingv1beta1.CIDR{ - configuration.Status.Remote.CIDR.Pod, - configuration.Status.Remote.CIDR.External, + *cidrutils.GetPrimary(configuration.Status.Remote.CIDR.Pod), + *cidrutils.GetPrimary(configuration.Status.Remote.CIDR.External), } return controllerutil.SetControllerReference(gwClient, internalFabric, r.Scheme) diff --git a/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/firewall.go b/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/firewall.go index ed05b83b1a..4557e5598a 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/firewall.go +++ b/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/firewall.go @@ -27,6 +27,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" firewallapi "github.com/liqotech/liqo/apis/networking/v1beta1/firewall" "github.com/liqotech/liqo/pkg/fabric" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -94,7 +95,7 @@ func forgeFirewallChain() *firewallapi.Chain { } func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) (natrules []firewallapi.NatRule, err error) { - unknownSourceIP, err := ipamutils.GetUnknownSourceIP(cfg.Spec.Local.CIDR.External.String()) + unknownSourceIP, err := ipamutils.GetUnknownSourceIP(cidrutils.GetPrimary(cfg.Spec.Local.CIDR.External).String()) if err != nil { return nil, fmt.Errorf("unable to get first IP from CIDR: %w", err) } @@ -108,19 +109,19 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionDst, - Value: cfg.Status.Remote.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String(), }, }, { Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionSrc, - Value: cfg.Spec.Local.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String(), }, }, }, NatType: firewallapi.NatTypeSource, - To: ptr.To(cfg.Spec.Local.CIDR.Pod.String()), + To: ptr.To(cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String()), }) } @@ -131,7 +132,7 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionDst, - Value: cfg.Status.Remote.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String(), }, }, }, @@ -143,7 +144,7 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationNeq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionSrc, - Value: cfg.Spec.Local.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String(), }, }) } @@ -157,19 +158,19 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionDst, - Value: cfg.Status.Remote.CIDR.External.String(), + Value: cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String(), }, }, { Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionSrc, - Value: cfg.Spec.Local.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String(), }, }, }, NatType: firewallapi.NatTypeSource, - To: ptr.To(cfg.Spec.Local.CIDR.Pod.String()), + To: ptr.To(cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String()), }) } @@ -180,7 +181,7 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationEq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionDst, - Value: cfg.Status.Remote.CIDR.External.String(), + Value: cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String(), }, }, }, @@ -192,7 +193,7 @@ func forgeFirewallNatRule(cfg *networkingv1beta1.Configuration, opts *Options) ( Op: firewallapi.MatchOperationNeq, IP: &firewallapi.MatchIP{ Position: firewallapi.MatchPositionSrc, - Value: cfg.Spec.Local.CIDR.Pod.String(), + Value: cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String(), }, }) } diff --git a/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_k8s.go b/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_k8s.go index b0f7260a48..e37d96720e 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_k8s.go +++ b/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_k8s.go @@ -32,6 +32,7 @@ import ( "github.com/liqotech/liqo/apis/networking/v1beta1/firewall" "github.com/liqotech/liqo/pkg/gateway" "github.com/liqotech/liqo/pkg/gateway/tunnel" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -297,9 +298,9 @@ func forgeRouteConfigurationExtCIDRRules(internalnode *networkingv1beta1.Interna rules := []networkingv1beta1.Rule{} for i := range configurations { rules = append(rules, networkingv1beta1.Rule{ - Dst: &configurations[i].Status.Remote.CIDR.Pod, + Dst: cidrutils.GetPrimary(configurations[i].Status.Remote.CIDR.Pod), Iif: ptr.To(tunnel.TunnelInterfaceName), - Routes: forgeRouteConfigurationExtCIDRRoutes(internalnode, &configurations[i].Status.Remote.CIDR.Pod), + Routes: forgeRouteConfigurationExtCIDRRoutes(internalnode, cidrutils.GetPrimary(configurations[i].Status.Remote.CIDR.Pod)), }) } rules = append(rules, networkingv1beta1.Rule{ diff --git a/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go b/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go index 78901a1b04..03f9d26751 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go @@ -32,6 +32,7 @@ import ( internalnetwork "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network" "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/fabricipam" "github.com/liqotech/liqo/pkg/utils" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/getters" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -132,8 +133,8 @@ func (r *ServerReconciler) ensureInternalFabric(ctx context.Context, gwServer *n internalFabric.Spec.Interface.Gateway.IP = networkingv1beta1.IP(ip.String()) internalFabric.Spec.RemoteCIDRs = []networkingv1beta1.CIDR{ - configuration.Status.Remote.CIDR.Pod, - configuration.Status.Remote.CIDR.External, + *cidrutils.GetPrimary(configuration.Status.Remote.CIDR.Pod), + *cidrutils.GetPrimary(configuration.Status.Remote.CIDR.External), } return controllerutil.SetControllerReference(gwServer, internalFabric, r.Scheme) diff --git a/pkg/liqo-controller-manager/networking/utils/configuration.go b/pkg/liqo-controller-manager/networking/utils/configuration.go index 17a7524b2d..53082f4cc5 100644 --- a/pkg/liqo-controller-manager/networking/utils/configuration.go +++ b/pkg/liqo-controller-manager/networking/utils/configuration.go @@ -16,11 +16,12 @@ package utils import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ) // IsConfigurationStatusSet check if a Configuration is ready by checking if its status is correctly set. func IsConfigurationStatusSet(confStatus networkingv1beta1.ConfigurationStatus) bool { return confStatus.Remote != nil && - confStatus.Remote.CIDR.Pod.String() != "" && - confStatus.Remote.CIDR.External.String() != "" + !cidrutils.IsVoid(cidrutils.GetPrimary(confStatus.Remote.CIDR.Pod)) && + !cidrutils.IsVoid(cidrutils.GetPrimary(confStatus.Remote.CIDR.External)) } diff --git a/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller_test.go b/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller_test.go index 245e2e7380..04a1e3791b 100644 --- a/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller_test.go +++ b/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller_test.go @@ -36,6 +36,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" "github.com/liqotech/liqo/pkg/consts" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/errors" "github.com/liqotech/liqo/pkg/virtualKubelet/forge" ) @@ -189,16 +190,16 @@ var _ = Describe("ShadowEndpointSlice Controller", func() { Spec: networkingv1beta1.ConfigurationSpec{ Remote: networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: "10.10.0.0/16", - External: "10.20.0.0/16", + Pod: cidrutils.SetPrimary("10.10.0.0/16"), + External: cidrutils.SetPrimary("10.20.0.0/16"), }, }, }, Status: networkingv1beta1.ConfigurationStatus{ Remote: &networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: remappedPodCIDR, - External: remappedExternalCIDR, + Pod: cidrutils.SetPrimary(remappedPodCIDR), + External: cidrutils.SetPrimary(remappedExternalCIDR), }, }, }, diff --git a/pkg/liqoctl/info/peer/network.go b/pkg/liqoctl/info/peer/network.go index fa6a06e73a..dcdb5e5406 100644 --- a/pkg/liqoctl/info/peer/network.go +++ b/pkg/liqoctl/info/peer/network.go @@ -18,6 +18,7 @@ package peer import ( "context" "fmt" + "strings" "sigs.k8s.io/controller-runtime/pkg/client" @@ -117,12 +118,12 @@ func (nc *NetworkChecker) FormatForClusterID(clusterID liqov1beta1.ClusterID, op remoteCIDRSection := cidrSection.AddSection("Remote") if data.CIDRs.Remapped != nil { remoteCIDRSection.AddEntry("Pod CIDR", - fmt.Sprintf("%s → Remapped to %s", data.CIDRs.Remote.Pod, data.CIDRs.Remapped.Pod)) + fmt.Sprintf("%s → Remapped to %s", joinCidrs(data.CIDRs.Remote.Pod), joinCidrs(data.CIDRs.Remapped.Pod))) remoteCIDRSection.AddEntry("External CIDR", - fmt.Sprintf("%s → Remapped to %s", data.CIDRs.Remote.External, data.CIDRs.Remapped.External)) + fmt.Sprintf("%s → Remapped to %s", joinCidrs(data.CIDRs.Remote.External), joinCidrs(data.CIDRs.Remapped.External))) } else { - remoteCIDRSection.AddEntry("Pod CIDR", string(data.CIDRs.Remote.Pod)) - remoteCIDRSection.AddEntry("External CIDR", string(data.CIDRs.Remote.External)) + remoteCIDRSection.AddEntry("Pod CIDR", joinCidrs(data.CIDRs.Remote.Pod)) + remoteCIDRSection.AddEntry("External CIDR", joinCidrs(data.CIDRs.Remote.External)) } // Print info about Gateway @@ -190,3 +191,11 @@ func (nc *NetworkChecker) collectGatewayInfo(ctx context.Context, cl client.Clie return nil } + +func joinCidrs(cidrs []networkingv1beta1.CIDR) string { + cidrsString := make([]string, len(cidrs)) + for i := range cidrs { + cidrsString[i] = cidrs[i].String() + } + return strings.Join(cidrsString, ",") +} diff --git a/pkg/liqoctl/info/peer/network_test.go b/pkg/liqoctl/info/peer/network_test.go index 726fd1b2b9..3bc722d3df 100644 --- a/pkg/liqoctl/info/peer/network_test.go +++ b/pkg/liqoctl/info/peer/network_test.go @@ -33,6 +33,7 @@ import ( "github.com/liqotech/liqo/pkg/liqoctl/info" "github.com/liqotech/liqo/pkg/liqoctl/info/common" "github.com/liqotech/liqo/pkg/liqoctl/output" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/testutil" ) @@ -105,11 +106,19 @@ var _ = Describe("NetworkChecker tests", func() { Expect(data.Status).To(Equal(common.ModuleHealthy), "Unexpected status") - Expect(data.CIDRs.Remote.Pod).To(Equal(networkingv1beta1.CIDR(expectedPodCIDR)), "Unexpected remote Pod CIDR") - Expect(data.CIDRs.Remote.External).To(Equal(networkingv1beta1.CIDR(expectedExternalCIDR)), "Unexpected remote external CIDR") + Expect(data.CIDRs.Remote.Pod).To(HaveLen(1), "Unexpected alerts") + Expect(data.CIDRs.Remote.Pod).To(ContainElement(networkingv1beta1.CIDR(expectedPodCIDR)), "Unexpected remote Pod CIDR") + + Expect(data.CIDRs.Remote.External).To(HaveLen(1), "Unexpected alerts") + Expect(data.CIDRs.Remote.External).To(ContainElement(networkingv1beta1.CIDR(expectedExternalCIDR)), "Unexpected remote external CIDR") + Expect(data.CIDRs.Remapped).NotTo(BeNil(), "Expected remapped CIDRs but empty received") - Expect(data.CIDRs.Remapped.Pod).To(Equal(networkingv1beta1.CIDR(expectedRemappedPod)), "Unexpected remapped Pod CIDR") - Expect(data.CIDRs.Remapped.External).To(Equal(networkingv1beta1.CIDR(expectedRemappedExternal)), "Unexpected remapped external CIDR") + + Expect(data.CIDRs.Remapped.Pod).To(HaveLen(1), "Unexpected alerts") + Expect(data.CIDRs.Remapped.Pod).To(ContainElement(networkingv1beta1.CIDR(expectedRemappedPod)), "Unexpected remapped Pod CIDR") + + Expect(data.CIDRs.Remapped.External).To(HaveLen(1), "Unexpected alerts") + Expect(data.CIDRs.Remapped.External).To(ContainElement(networkingv1beta1.CIDR(expectedRemappedExternal)), "Unexpected remapped external CIDR") // Check gateway parameters Expect(data.Gateway.Role).To(Equal(GatewayServerType), "Unexpected Gateway type") @@ -185,19 +194,23 @@ var _ = Describe("NetworkChecker tests", func() { // Check CIDRs if testCase.CIDRs.Remapped != nil { Expect(text).To(ContainSubstring( - pterm.Sprintf("Pod CIDR: %s → Remapped to %s", testCase.CIDRs.Remote.Pod, testCase.CIDRs.Remapped.Pod)), + pterm.Sprintf("Pod CIDR: %s → Remapped to %s", + joinCidrs(testCase.CIDRs.Remote.Pod), joinCidrs(testCase.CIDRs.Remapped.Pod))), "Unexpected POD CIDR shown", ) Expect(text).To(ContainSubstring( - pterm.Sprintf("External CIDR: %s → Remapped to %s", testCase.CIDRs.Remote.External, testCase.CIDRs.Remapped.External)), + pterm.Sprintf("External CIDR: %s → Remapped to %s", + joinCidrs(testCase.CIDRs.Remote.External), joinCidrs(testCase.CIDRs.Remapped.External))), "Unexpected External CIDR shown", ) } else { Expect(text).To(ContainSubstring( - pterm.Sprintf("Pod CIDR: %s", testCase.CIDRs.Remote.Pod)), "Unexpected POD CIDR shown", + pterm.Sprintf("Pod CIDR: %s", + joinCidrs(testCase.CIDRs.Remote.Pod))), "Unexpected POD CIDR shown", ) Expect(text).To(ContainSubstring( - pterm.Sprintf("External CIDR: %s", testCase.CIDRs.Remote.External)), + pterm.Sprintf("External CIDR: %s", + joinCidrs(testCase.CIDRs.Remote.External))), "Unexpected External CIDR shown", ) } @@ -215,12 +228,12 @@ var _ = Describe("NetworkChecker tests", func() { Status: common.ModuleHealthy, CIDRs: CIDRInfo{ Remote: networkingv1beta1.ClusterConfigCIDR{ - Pod: "fakepod", - External: "fakeexternal", + Pod: cidrutils.SetPrimary("fakepod"), + External: cidrutils.SetPrimary("fakeexternal"), }, Remapped: &networkingv1beta1.ClusterConfigCIDR{ - Pod: "fakeremappedpod", - External: "fakeremappedexternal", + Pod: cidrutils.SetPrimary("fakeremappedpod"), + External: cidrutils.SetPrimary("fakeremappedexternal"), }, }, Gateway: GatewayInfo{ @@ -233,8 +246,8 @@ var _ = Describe("NetworkChecker tests", func() { Status: common.ModuleHealthy, CIDRs: CIDRInfo{ Remote: networkingv1beta1.ClusterConfigCIDR{ - Pod: "fakepod", - External: "fakeexternal", + Pod: cidrutils.SetPrimary("fakepod"), + External: cidrutils.SetPrimary("fakeexternal"), }, }, Gateway: GatewayInfo{ diff --git a/pkg/liqoctl/test/network/check/ip.go b/pkg/liqoctl/test/network/check/ip.go index a78ceb975e..166f6bca20 100644 --- a/pkg/liqoctl/test/network/check/ip.go +++ b/pkg/liqoctl/test/network/check/ip.go @@ -28,6 +28,7 @@ import ( "github.com/liqotech/liqo/pkg/liqoctl/test/network/client" "github.com/liqotech/liqo/pkg/liqoctl/test/network/flags" "github.com/liqotech/liqo/pkg/liqoctl/test/network/setup" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" "github.com/liqotech/liqo/pkg/utils/ipam/mapping" ) @@ -117,7 +118,7 @@ func forgeIPTarget(ctx context.Context, cl clientctrl.Client, localIPRemapped ma return nil, fmt.Errorf("failed to parse IP: %s", ip) } - _, cidrtarget, err := net.ParseCIDR(cfgs.Items[i].Status.Remote.CIDR.External.String()) + _, cidrtarget, err := net.ParseCIDR(cidrutils.GetPrimary(cfgs.Items[i].Status.Remote.CIDR.External).String()) if err != nil { return nil, fmt.Errorf("failed to parse CIDR: %w", err) } diff --git a/pkg/liqoctl/test/network/info/info.go b/pkg/liqoctl/test/network/info/info.go index 162459420f..df1f4851f7 100644 --- a/pkg/liqoctl/test/network/info/info.go +++ b/pkg/liqoctl/test/network/info/info.go @@ -23,6 +23,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/liqoctl/test/network/client" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" ) // Info prints the configurations of the clusters. @@ -72,8 +73,8 @@ func PrintConfigurations(ctx context.Context, cl ctrlclient.Client, table *pterm func AppendLocalConfigurationTableData(cfg *networkingv1beta1.Configuration, td pterm.TableData) pterm.TableData { return append(td, []string{ "local", - cfg.Spec.Local.CIDR.Pod.String(), "N/R", - cfg.Spec.Local.CIDR.External.String(), "N/R", + cidrutils.GetPrimary(cfg.Spec.Local.CIDR.Pod).String(), "N/R", + cidrutils.GetPrimary(cfg.Spec.Local.CIDR.External).String(), "N/R", }) } @@ -81,7 +82,7 @@ func AppendLocalConfigurationTableData(cfg *networkingv1beta1.Configuration, td func AppendRemoteConfigurationTableData(cfg *networkingv1beta1.Configuration, td pterm.TableData) pterm.TableData { return append(td, []string{ cfg.Name, - cfg.Spec.Remote.CIDR.Pod.String(), cfg.Status.Remote.CIDR.Pod.String(), - cfg.Spec.Remote.CIDR.External.String(), cfg.Status.Remote.CIDR.External.String(), + cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod).String(), cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String(), + cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External).String(), cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String(), }) } diff --git a/pkg/utils/cidr/cidr.go b/pkg/utils/cidr/cidr.go new file mode 100644 index 0000000000..2464d7cbbf --- /dev/null +++ b/pkg/utils/cidr/cidr.go @@ -0,0 +1,38 @@ +// Copyright 2019-2025 The Liqo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cidr + +import networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + +// GetPrimary returns the primary CIDR from a list of CIDRs. +func GetPrimary(cidrs []networkingv1beta1.CIDR) *networkingv1beta1.CIDR { + if len(cidrs) == 0 { + return nil + } + return &cidrs[0] +} + +// SetPrimary sets the primary CIDR in a list of CIDRs. +func SetPrimary(cidr networkingv1beta1.CIDR) []networkingv1beta1.CIDR { + return []networkingv1beta1.CIDR{cidr} +} + +// IsVoid checks if a CIDR is void. +func IsVoid(cidr *networkingv1beta1.CIDR) bool { + if cidr == nil { + panic("CIDR is nil") + } + return cidr.String() == "" +} diff --git a/pkg/utils/cidr/doc.go b/pkg/utils/cidr/doc.go new file mode 100644 index 0000000000..2ea14beb53 --- /dev/null +++ b/pkg/utils/cidr/doc.go @@ -0,0 +1,16 @@ +// Copyright 2019-2025 The Liqo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package cidr provides utility functions for working with CIDR type defined in networking API. +package cidr diff --git a/pkg/utils/ipam/mapping/ips.go b/pkg/utils/ipam/mapping/ips.go index 5e88d3880e..406dc6f019 100644 --- a/pkg/utils/ipam/mapping/ips.go +++ b/pkg/utils/ipam/mapping/ips.go @@ -27,6 +27,7 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/utils/getters" "github.com/liqotech/liqo/pkg/utils/resource" ) @@ -137,27 +138,27 @@ func MapAddressWithConfiguration(cfg *networkingv1beta1.Configuration, address s err error ) - podNeedsRemap := cfg.Spec.Remote.CIDR.Pod.String() != cfg.Status.Remote.CIDR.Pod.String() - extNeedsRemap := cfg.Spec.Remote.CIDR.External.String() != cfg.Status.Remote.CIDR.External.String() + podNeedsRemap := cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod).String() != cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String() + extNeedsRemap := cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External).String() != cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String() - _, podnet, err = net.ParseCIDR(cfg.Spec.Remote.CIDR.Pod.String()) + _, podnet, err = net.ParseCIDR(cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.Pod).String()) if err != nil { return "", err } if podNeedsRemap { - _, podnetMapped, err = net.ParseCIDR(cfg.Status.Remote.CIDR.Pod.String()) + _, podnetMapped, err = net.ParseCIDR(cidrutils.GetPrimary(cfg.Status.Remote.CIDR.Pod).String()) if err != nil { return "", err } podNetMaskLen, _ = podnetMapped.Mask.Size() } - _, extnet, err = net.ParseCIDR(cfg.Spec.Remote.CIDR.External.String()) + _, extnet, err = net.ParseCIDR(cidrutils.GetPrimary(cfg.Spec.Remote.CIDR.External).String()) if err != nil { return "", err } if extNeedsRemap { - _, extnetMapped, err = net.ParseCIDR(cfg.Status.Remote.CIDR.External.String()) + _, extnetMapped, err = net.ParseCIDR(cidrutils.GetPrimary(cfg.Status.Remote.CIDR.External).String()) if err != nil { return "", err } diff --git a/pkg/utils/testutil/liqo.go b/pkg/utils/testutil/liqo.go index d15b5b7a0c..dbb2f2e882 100644 --- a/pkg/utils/testutil/liqo.go +++ b/pkg/utils/testutil/liqo.go @@ -29,6 +29,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" liqoconsts "github.com/liqotech/liqo/pkg/consts" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" "github.com/liqotech/liqo/pkg/virtualKubelet/forge" ) @@ -265,22 +266,22 @@ func FakeConfiguration(remoteClusterID, podCIDR, extCIDR, remotePodCIDR, remoteE Spec: networkingv1beta1.ConfigurationSpec{ Local: &networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: networkingv1beta1.CIDR(podCIDR), - External: networkingv1beta1.CIDR(extCIDR), + Pod: cidrutils.SetPrimary(networkingv1beta1.CIDR(podCIDR)), + External: cidrutils.SetPrimary(networkingv1beta1.CIDR(extCIDR)), }, }, Remote: networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: networkingv1beta1.CIDR(remotePodCIDR), - External: networkingv1beta1.CIDR(remoteExtCIDR), + Pod: cidrutils.SetPrimary(networkingv1beta1.CIDR(remotePodCIDR)), + External: cidrutils.SetPrimary(networkingv1beta1.CIDR(remoteExtCIDR)), }, }, }, Status: networkingv1beta1.ConfigurationStatus{ Remote: &networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: networkingv1beta1.CIDR(remoteRemappedPodCIDR), - External: networkingv1beta1.CIDR(remoteRemappedExtCIDR), + Pod: cidrutils.SetPrimary(networkingv1beta1.CIDR(remoteRemappedPodCIDR)), + External: cidrutils.SetPrimary(networkingv1beta1.CIDR(remoteRemappedExtCIDR)), }, }, }, diff --git a/pkg/virtualKubelet/reflection/workload/pod_test.go b/pkg/virtualKubelet/reflection/workload/pod_test.go index 443832e263..1a3d4af9d3 100644 --- a/pkg/virtualKubelet/reflection/workload/pod_test.go +++ b/pkg/virtualKubelet/reflection/workload/pod_test.go @@ -33,6 +33,7 @@ import ( networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" "github.com/liqotech/liqo/cmd/virtual-kubelet/root" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" . "github.com/liqotech/liqo/pkg/utils/testutil" "github.com/liqotech/liqo/pkg/virtualKubelet/forge" "github.com/liqotech/liqo/pkg/virtualKubelet/reflection/manager" @@ -75,16 +76,16 @@ var _ = Describe("Pod Reflection Tests", func() { Spec: networkingv1beta1.ConfigurationSpec{ Remote: networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: "192.168.200.0/24", - External: "192.168.100.0/24", + Pod: cidrutils.SetPrimary("192.168.200.0/24"), + External: cidrutils.SetPrimary("192.168.100.0/24"), }, }, }, Status: networkingv1beta1.ConfigurationStatus{ Remote: &networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: "192.168.201.0/24", - External: "192.168.101.0/24", + Pod: cidrutils.SetPrimary("192.168.201.0/24"), + External: cidrutils.SetPrimary("192.168.101.0/24"), }, }, }, diff --git a/pkg/virtualKubelet/reflection/workload/podns_test.go b/pkg/virtualKubelet/reflection/workload/podns_test.go index c5b9536232..4d1043a08a 100644 --- a/pkg/virtualKubelet/reflection/workload/podns_test.go +++ b/pkg/virtualKubelet/reflection/workload/podns_test.go @@ -40,6 +40,7 @@ import ( liqoclientfake "github.com/liqotech/liqo/pkg/client/clientset/versioned/fake" liqoinformers "github.com/liqotech/liqo/pkg/client/informers/externalversions" "github.com/liqotech/liqo/pkg/consts" + cidrutils "github.com/liqotech/liqo/pkg/utils/cidr" . "github.com/liqotech/liqo/pkg/utils/testutil" "github.com/liqotech/liqo/pkg/virtualKubelet/forge" "github.com/liqotech/liqo/pkg/virtualKubelet/reflection/manager" @@ -78,16 +79,16 @@ var _ = Describe("Namespaced Pod Reflection Tests", func() { Spec: networkingv1beta1.ConfigurationSpec{ Remote: networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: "192.168.200.0/24", - External: "192.168.100.0/24", + Pod: cidrutils.SetPrimary("192.168.200.0/24"), + External: cidrutils.SetPrimary("192.168.100.0/24"), }, }, }, Status: networkingv1beta1.ConfigurationStatus{ Remote: &networkingv1beta1.ClusterConfig{ CIDR: networkingv1beta1.ClusterConfigCIDR{ - Pod: "192.168.201.0/24", - External: "192.168.101.0/24", + Pod: cidrutils.SetPrimary("192.168.201.0/24"), + External: cidrutils.SetPrimary("192.168.101.0/24"), }, }, },