diff --git a/go-controller/pkg/allocator/pod/pod_annotation.go b/go-controller/pkg/allocator/pod/pod_annotation.go index d174a5e3d9..84e9f33df0 100644 --- a/go-controller/pkg/allocator/pod/pod_annotation.go +++ b/go-controller/pkg/allocator/pod/pod_annotation.go @@ -272,7 +272,7 @@ func allocatePodAnnotationWithRollback( err error) { nadName := types.DefaultNetworkName - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { nadName = util.GetNADName(network.Namespace, network.Name) } podDesc := fmt.Sprintf("%s/%s/%s", nadName, pod.Namespace, pod.Name) @@ -510,7 +510,7 @@ func AddRoutesGatewayIP( // generate the nodeSubnets from the allocated IPs nodeSubnets := util.IPsToNetworkIPs(podAnnotation.IPs...) - if netinfo.IsSecondary() { + if netinfo.IsUserDefinedNetwork() { // for secondary network, see if its network-attachment's annotation has default-route key. // If present, then we need to add default route for it podAnnotation.Gateways = append(podAnnotation.Gateways, network.GatewayRequest...) diff --git a/go-controller/pkg/clustermanager/clustermanager.go b/go-controller/pkg/clustermanager/clustermanager.go index 281fb000ec..b382cb5212 100644 --- a/go-controller/pkg/clustermanager/clustermanager.go +++ b/go-controller/pkg/clustermanager/clustermanager.go @@ -27,13 +27,13 @@ import ( // ClusterManager structure is the object which manages the cluster nodes. // It creates a default network controller for the default network and a -// secondary network cluster controller manager to manage the multi networks. +// user-defined network cluster controller manager to manage the multi networks. type ClusterManager struct { client clientset.Interface defaultNetClusterController *networkClusterController zoneClusterController *zoneClusterController wf *factory.WatchFactory - secondaryNetClusterManager *secondaryNetworkClusterManager + udnClusterManager *userDefinedNetworkClusterManager // Controller used for programming node allocation for egress IP // The OVN DB setup is handled by egressIPZoneController that runs in ovnkube-controller eIPC *egressIPClusterController @@ -90,7 +90,7 @@ func NewClusterManager( return nil, err } - cm.secondaryNetClusterManager, err = newSecondaryNetworkClusterManager(ovnClient, wf, cm.networkManager.Interface(), recorder) + cm.udnClusterManager, err = newUserDefinedNetworkClusterManager(ovnClient, wf, cm.networkManager.Interface(), recorder) if err != nil { return nil, err } @@ -152,8 +152,8 @@ func NewClusterManager( cm.recorder, ) cm.userDefinedNetworkController = udnController - if cm.secondaryNetClusterManager != nil { - cm.secondaryNetClusterManager.SetNetworkStatusReporter(udnController.UpdateSubsystemCondition) + if cm.udnClusterManager != nil { + cm.udnClusterManager.SetNetworkStatusReporter(udnController.UpdateSubsystemCondition) } } @@ -258,7 +258,7 @@ func (cm *ClusterManager) Stop() { } func (cm *ClusterManager) NewNetworkController(netInfo util.NetInfo) (networkmanager.NetworkController, error) { - return cm.secondaryNetClusterManager.NewNetworkController(netInfo) + return cm.udnClusterManager.NewNetworkController(netInfo) } func (cm *ClusterManager) GetDefaultNetworkController() networkmanager.ReconcilableNetworkController { @@ -266,7 +266,7 @@ func (cm *ClusterManager) GetDefaultNetworkController() networkmanager.Reconcila } func (cm *ClusterManager) CleanupStaleNetworks(validNetworks ...util.NetInfo) error { - return cm.secondaryNetClusterManager.CleanupStaleNetworks(validNetworks...) + return cm.udnClusterManager.CleanupStaleNetworks(validNetworks...) } func (cm *ClusterManager) Reconcile(name string, old, new util.NetInfo) error { diff --git a/go-controller/pkg/clustermanager/network_cluster_controller.go b/go-controller/pkg/clustermanager/network_cluster_controller.go index f8241aadca..219fb6d9d9 100644 --- a/go-controller/pkg/clustermanager/network_cluster_controller.go +++ b/go-controller/pkg/clustermanager/network_cluster_controller.go @@ -154,7 +154,7 @@ func (ncc *networkClusterController) hasNodeAllocation() bool { return config.OVNKubernetesFeature.EnableInterconnect default: // we need to allocate network IDs and subnets - return !ncc.IsSecondary() + return !ncc.IsUserDefinedNetwork() } } @@ -452,10 +452,10 @@ func (ncc *networkClusterController) newRetryFramework(objectType reflect.Type, return objretry.NewRetryFramework(ncc.stopChan, ncc.wg, ncc.watchFactory, resourceHandler) } -// Cleanup the subnet annotations from the node for the secondary networks +// Cleanup the subnet annotations from the node for the User Defined Networks func (ncc *networkClusterController) Cleanup() error { - if !ncc.IsSecondary() { - return fmt.Errorf("default network can't be cleaned up") + if !ncc.IsUserDefinedNetwork() { + return fmt.Errorf("default network cannot be cleaned up") } if ncc.hasNodeAllocation() { diff --git a/go-controller/pkg/clustermanager/node/node_allocator.go b/go-controller/pkg/clustermanager/node/node_allocator.go index ab4f950035..e31625b725 100644 --- a/go-controller/pkg/clustermanager/node/node_allocator.go +++ b/go-controller/pkg/clustermanager/node/node_allocator.go @@ -124,11 +124,11 @@ func (na *NodeAllocator) CleanupStaleAnnotation() { func (na *NodeAllocator) hasHybridOverlayAllocation() bool { // When config.HybridOverlay.ClusterSubnets is empty, assume the subnet allocation will be managed by an external component. - return config.HybridOverlay.Enabled && !na.netInfo.IsSecondary() && len(config.HybridOverlay.ClusterSubnets) > 0 + return config.HybridOverlay.Enabled && !na.netInfo.IsUserDefinedNetwork() && len(config.HybridOverlay.ClusterSubnets) > 0 } func (na *NodeAllocator) hasHybridOverlayAllocationUnmanaged() bool { - return config.HybridOverlay.Enabled && !na.netInfo.IsSecondary() && len(config.HybridOverlay.ClusterSubnets) == 0 + return config.HybridOverlay.Enabled && !na.netInfo.IsUserDefinedNetwork() && len(config.HybridOverlay.ClusterSubnets) == 0 } func (na *NodeAllocator) recordSubnetCount() { @@ -595,7 +595,7 @@ func (na *NodeAllocator) allocateNodeSubnets(allocator SubnetAllocator, nodeName func (na *NodeAllocator) hasNodeSubnetAllocation() bool { // we only allocate subnets for L3 secondary network or default network - return na.netInfo.TopologyType() == types.Layer3Topology || !na.netInfo.IsSecondary() + return na.netInfo.TopologyType() == types.Layer3Topology || !na.netInfo.IsUserDefinedNetwork() } func (na *NodeAllocator) markAllocatedNetworksForUnmanagedHONode(node *corev1.Node) error { diff --git a/go-controller/pkg/clustermanager/secondary_network_cluster_manager.go b/go-controller/pkg/clustermanager/user_defined_network_cluster_manager.go similarity index 81% rename from go-controller/pkg/clustermanager/secondary_network_cluster_manager.go rename to go-controller/pkg/clustermanager/user_defined_network_cluster_manager.go index f77aafd7bc..bae096a6d4 100644 --- a/go-controller/pkg/clustermanager/secondary_network_cluster_manager.go +++ b/go-controller/pkg/clustermanager/user_defined_network_cluster_manager.go @@ -14,10 +14,10 @@ import ( "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" ) -// secondaryNetworkClusterManager object manages the multi net-attach-def controllers. +// userDefinedNetworkClusterManager object manages the multi net-attach-def controllers. // It implements networkmanager.ControllerManager interface and can be used // by network manager to create and delete network controllers. -type secondaryNetworkClusterManager struct { +type userDefinedNetworkClusterManager struct { // networkManager creates and deletes network controllers networkManager networkmanager.Interface ovnClient *util.OVNClusterManagerClientset @@ -29,14 +29,14 @@ type secondaryNetworkClusterManager struct { errorReporter NetworkStatusReporter } -func newSecondaryNetworkClusterManager( +func newUserDefinedNetworkClusterManager( ovnClient *util.OVNClusterManagerClientset, wf *factory.WatchFactory, networkManager networkmanager.Interface, recorder record.EventRecorder, -) (*secondaryNetworkClusterManager, error) { - klog.Infof("Creating secondary network cluster manager") - sncm := &secondaryNetworkClusterManager{ +) (*userDefinedNetworkClusterManager, error) { + klog.Infof("Creating user-defined network cluster manager") + sncm := &userDefinedNetworkClusterManager{ ovnClient: ovnClient, watchFactory: wf, networkManager: networkManager, @@ -45,17 +45,17 @@ func newSecondaryNetworkClusterManager( return sncm, nil } -func (sncm *secondaryNetworkClusterManager) SetNetworkStatusReporter(errorReporter NetworkStatusReporter) { +func (sncm *userDefinedNetworkClusterManager) SetNetworkStatusReporter(errorReporter NetworkStatusReporter) { sncm.errorReporter = errorReporter } -func (sncm *secondaryNetworkClusterManager) GetDefaultNetworkController() networkmanager.ReconcilableNetworkController { +func (sncm *userDefinedNetworkClusterManager) GetDefaultNetworkController() networkmanager.ReconcilableNetworkController { return nil } // NewNetworkController implements the networkmanager.ControllerManager // interface called by network manager to create or delete a network controller. -func (sncm *secondaryNetworkClusterManager) NewNetworkController(nInfo util.NetInfo) (networkmanager.NetworkController, error) { +func (sncm *userDefinedNetworkClusterManager) NewNetworkController(nInfo util.NetInfo) (networkmanager.NetworkController, error) { if !sncm.isTopologyManaged(nInfo) { return nil, networkmanager.ErrNetworkControllerTopologyNotManaged } @@ -73,7 +73,7 @@ func (sncm *secondaryNetworkClusterManager) NewNetworkController(nInfo util.NetI return sncc, nil } -func (sncm *secondaryNetworkClusterManager) isTopologyManaged(nInfo util.NetInfo) bool { +func (sncm *userDefinedNetworkClusterManager) isTopologyManaged(nInfo util.NetInfo) bool { switch nInfo.TopologyType() { case ovntypes.Layer3Topology: // we need to allocate subnets to each node regardless of configuration @@ -93,7 +93,7 @@ func (sncm *secondaryNetworkClusterManager) isTopologyManaged(nInfo util.NetInfo // CleanupStaleNetworks cleans of stale data from the OVN database // corresponding to networks not included in validNetworks, which are considered // stale. -func (sncm *secondaryNetworkClusterManager) CleanupStaleNetworks(validNetworks ...util.NetInfo) error { +func (sncm *userDefinedNetworkClusterManager) CleanupStaleNetworks(validNetworks ...util.NetInfo) error { existingNetworksMap := map[string]struct{}{} for _, network := range validNetworks { existingNetworksMap[network.GetNetworkName()] = struct{}{} @@ -147,7 +147,7 @@ func (sncm *secondaryNetworkClusterManager) CleanupStaleNetworks(validNetworks . } // newDummyNetworkController creates a dummy network controller used to clean up specific network -func (sncm *secondaryNetworkClusterManager) newDummyLayer3NetworkController(netName string) (networkmanager.NetworkController, error) { +func (sncm *userDefinedNetworkClusterManager) newDummyLayer3NetworkController(netName string) (networkmanager.NetworkController, error) { netInfo, _ := util.NewNetInfo(&ovncnitypes.NetConf{NetConf: types.NetConf{Name: netName}, Topology: ovntypes.Layer3Topology}) nc := newNetworkClusterController( netInfo, diff --git a/go-controller/pkg/clustermanager/secondary_network_unit_test.go b/go-controller/pkg/clustermanager/user_defined_network_unit_test.go similarity index 95% rename from go-controller/pkg/clustermanager/secondary_network_unit_test.go rename to go-controller/pkg/clustermanager/user_defined_network_unit_test.go index 14c2cbaa8d..a3a9af59e8 100644 --- a/go-controller/pkg/clustermanager/secondary_network_unit_test.go +++ b/go-controller/pkg/clustermanager/user_defined_network_unit_test.go @@ -57,8 +57,8 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { wg.Wait() }) - ginkgo.Context("Secondary networks", func() { - ginkgo.It("Attach secondary layer3 network", func() { + ginkgo.Context("User-Defined Networks", func() { + ginkgo.It("Attach layer3 UDN", func() { app.Action = func(ctx *cli.Context) error { kubeFakeClient := fake.NewSimpleClientset(&corev1.NodeList{Items: nodes()}) fakeClient := &util.OVNClusterManagerClientset{ @@ -74,7 +74,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { err = f.Start() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) netInfo, err := util.NewNetInfo(&ovncnitypes.NetConf{NetConf: types.NetConf{Name: "blue"}, Topology: ovntypes.Layer3Topology, Subnets: "192.168.0.0/16/24"}) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -130,7 +130,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) - ginkgo.It("The secondary network controller starts successfully", func() { + ginkgo.It("The UDN controller starts successfully", func() { app.Action = func(ctx *cli.Context) error { gomega.Expect( initConfig(ctx, config.OVNKubernetesFeatureConfig{ @@ -143,7 +143,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { err = f.Start() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) config.OVNKubernetesFeature.EnableInterconnect = false @@ -181,7 +181,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).NotTo(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -226,7 +226,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { }) ginkgo.DescribeTable( - "the secondary network controller", + "the UDN controller", func(netConf *ovncnitypes.NetConf, featureConfig config.OVNKubernetesFeatureConfig, expectedError error) { var err error netInfo, err = util.NewNetInfo(netConf) @@ -240,7 +240,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { err = f.Start() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) _, err = sncm.NewNetworkController(netInfo) @@ -378,7 +378,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Eventually(checkNodeAnnotations).ShouldNot(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) // Create a fake nad controller for blue network so that the red network gets cleared @@ -476,7 +476,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).To(gomega.Succeed()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -529,7 +529,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).To(gomega.Succeed()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -578,7 +578,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).To(gomega.Succeed()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -647,7 +647,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).To(gomega.Succeed()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -719,7 +719,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).To(gomega.Succeed()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( @@ -785,7 +785,7 @@ var _ = ginkgo.Describe("Cluster Controller Manager", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(f.Start()).NotTo(gomega.HaveOccurred()) - sncm, err := newSecondaryNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) + sncm, err := newUserDefinedNetworkClusterManager(fakeClient, f, networkmanager.Default().Interface(), recorder) gomega.Expect(err).NotTo(gomega.HaveOccurred()) nc := newNetworkClusterController( diff --git a/go-controller/pkg/cni/helper_linux.go b/go-controller/pkg/cni/helper_linux.go index fdad828cab..dca3bfaa09 100644 --- a/go-controller/pkg/cni/helper_linux.go +++ b/go-controller/pkg/cni/helper_linux.go @@ -434,7 +434,7 @@ func ConfigureOVS(ctx context.Context, namespace, podName, hostIfaceName string, ifaceID := util.GetIfaceId(namespace, podName) if ifInfo.NetName != types.DefaultNetworkName { - ifaceID = util.GetSecondaryNetworkIfaceId(namespace, podName, ifInfo.NADName) + ifaceID = util.GetUDNIfaceId(namespace, podName, ifInfo.NADName) } initialPodUID := ifInfo.PodUID ipStrs := make([]string, len(ifInfo.IPs)) diff --git a/go-controller/pkg/cni/types.go b/go-controller/pkg/cni/types.go index 332898ac03..f405954721 100644 --- a/go-controller/pkg/cni/types.go +++ b/go-controller/pkg/cni/types.go @@ -164,7 +164,7 @@ type PodRequest struct { // network name, for default network, this will be types.DefaultNetworkName netName string - // for ovs interfaces plumbed for secondary networks, their iface-id's prefix is derived from the specific nadName; + // for ovs interfaces plumbed for UDNs, their iface-id's prefix is derived from the specific nadName; // also, need to find the pod annotation, dpu pod connection/status annotations of the given NAD ("default" // for default network). nadName string diff --git a/go-controller/pkg/cni/utils.go b/go-controller/pkg/cni/utils.go index 2f063c6aea..542f1813d3 100644 --- a/go-controller/pkg/cni/utils.go +++ b/go-controller/pkg/cni/utils.go @@ -139,7 +139,7 @@ func PodAnnotation2PodInfo(podAnnotation map[string]string, podNADAnnotation *ut podInterfaceInfo := &PodInterfaceInfo{ PodAnnotation: *podNADAnnotation, MTU: mtu, - RoutableMTU: config.Default.RoutableMTU, // TBD, configurable for secondary network? + RoutableMTU: config.Default.RoutableMTU, // TBD, configurable for UDNs? Ingress: ingress, Egress: egress, IsDPUHostMode: config.OvnKubeNode.Mode == types.NodeModeDPUHost, diff --git a/go-controller/pkg/controllermanager/controller_manager.go b/go-controller/pkg/controllermanager/controller_manager.go index 55aaec6831..6597e381ca 100644 --- a/go-controller/pkg/controllermanager/controller_manager.go +++ b/go-controller/pkg/controllermanager/controller_manager.go @@ -70,7 +70,7 @@ type ControllerManager struct { func (cm *ControllerManager) NewNetworkController(nInfo util.NetInfo) (networkmanager.NetworkController, error) { // Pass a shallow clone of the watch factory, this allows multiplexing - // informers for secondary networks. + // informers for user-defined networks. cnci, err := cm.newCommonNetworkControllerInfo(cm.watchFactory.ShallowClone()) if err != nil { return nil, fmt.Errorf("failed to create network controller info %w", err) @@ -78,11 +78,11 @@ func (cm *ControllerManager) NewNetworkController(nInfo util.NetInfo) (networkma topoType := nInfo.TopologyType() switch topoType { case ovntypes.Layer3Topology: - return ovn.NewSecondaryLayer3NetworkController(cnci, nInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.eIPController, cm.portCache) + return ovn.NewLayer3UserDefinedNetworkController(cnci, nInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.eIPController, cm.portCache) case ovntypes.Layer2Topology: - return ovn.NewSecondaryLayer2NetworkController(cnci, nInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.portCache, cm.eIPController) + return ovn.NewLayer2UserDefinedNetworkController(cnci, nInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.portCache, cm.eIPController) case ovntypes.LocalnetTopology: - return ovn.NewSecondaryLocalnetNetworkController(cnci, nInfo, cm.networkManager.Interface()), nil + return ovn.NewLocalnetUserDefinedNetworkController(cnci, nInfo, cm.networkManager.Interface()), nil } return nil, fmt.Errorf("topology type %s not supported", topoType) } @@ -90,7 +90,7 @@ func (cm *ControllerManager) NewNetworkController(nInfo util.NetInfo) (networkma // newDummyNetworkController creates a dummy network controller used to clean up specific network func (cm *ControllerManager) newDummyNetworkController(topoType, netName string) (networkmanager.NetworkController, error) { // Pass a shallow clone of the watch factory, this allows multiplexing - // informers for secondary networks. + // informers for user-defined Networks. cnci, err := cm.newCommonNetworkControllerInfo(cm.watchFactory.ShallowClone()) if err != nil { return nil, fmt.Errorf("failed to create network controller info %w", err) @@ -98,11 +98,11 @@ func (cm *ControllerManager) newDummyNetworkController(topoType, netName string) netInfo, _ := util.NewNetInfo(&ovncnitypes.NetConf{NetConf: types.NetConf{Name: netName}, Topology: topoType}) switch topoType { case ovntypes.Layer3Topology: - return ovn.NewSecondaryLayer3NetworkController(cnci, netInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.eIPController, cm.portCache) + return ovn.NewLayer3UserDefinedNetworkController(cnci, netInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.eIPController, cm.portCache) case ovntypes.Layer2Topology: - return ovn.NewSecondaryLayer2NetworkController(cnci, netInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.portCache, cm.eIPController) + return ovn.NewLayer2UserDefinedNetworkController(cnci, netInfo, cm.networkManager.Interface(), cm.routeImportManager, cm.portCache, cm.eIPController) case ovntypes.LocalnetTopology: - return ovn.NewSecondaryLocalnetNetworkController(cnci, netInfo, cm.networkManager.Interface()), nil + return ovn.NewLocalnetUserDefinedNetworkController(cnci, netInfo, cm.networkManager.Interface()), nil } return nil, fmt.Errorf("topology type %s not supported", topoType) } diff --git a/go-controller/pkg/controllermanager/node_controller_manager.go b/go-controller/pkg/controllermanager/node_controller_manager.go index 716cb76869..e183e3b3fc 100644 --- a/go-controller/pkg/controllermanager/node_controller_manager.go +++ b/go-controller/pkg/controllermanager/node_controller_manager.go @@ -41,7 +41,7 @@ type NodeControllerManager struct { defaultNodeNetworkController *node.DefaultNodeNetworkController - // networkManager creates and deletes secondary network controllers + // networkManager creates and deletes user-defined network controllers networkManager networkmanager.Controller // vrf manager that creates and manages vrfs for all UDNs vrfManager *vrfmanager.Controller @@ -53,14 +53,14 @@ type NodeControllerManager struct { ovsClient client.Client } -// NewNetworkController create secondary node network controllers for the given NetInfo +// NewNetworkController create node user-defined network controllers for the given NetInfo func (ncm *NodeControllerManager) NewNetworkController(nInfo util.NetInfo) (networkmanager.NetworkController, error) { topoType := nInfo.TopologyType() switch topoType { case ovntypes.Layer3Topology, ovntypes.Layer2Topology, ovntypes.LocalnetTopology: // Pass a shallow clone of the watch factory, this allows multiplexing - // informers for secondary networks. - return node.NewSecondaryNodeNetworkController(ncm.newCommonNetworkControllerInfo(ncm.watchFactory.(*factory.WatchFactory).ShallowClone()), + // informers for UDNs. + return node.NewUserDefinedNodeNetworkController(ncm.newCommonNetworkControllerInfo(ncm.watchFactory.(*factory.WatchFactory).ShallowClone()), nInfo, ncm.networkManager.Interface(), ncm.vrfManager, ncm.ruleManager, ncm.defaultNodeNetworkController.Gateway) } return nil, fmt.Errorf("topology type %s not supported", topoType) @@ -70,7 +70,7 @@ func (ncm *NodeControllerManager) GetDefaultNetworkController() networkmanager.R return ncm.defaultNodeNetworkController } -// CleanupStaleNetworks cleans up all stale entities giving list of all existing secondary network controllers +// CleanupStaleNetworks cleans up all stale entities giving list of all existing node UDN controllers func (ncm *NodeControllerManager) CleanupStaleNetworks(validNetworks ...util.NetInfo) error { if !util.IsNetworkSegmentationSupportEnabled() { return nil @@ -92,8 +92,8 @@ func (ncm *NodeControllerManager) newCommonNetworkControllerInfo(wf factory.Node // isNetworkManagerRequiredForNode checks if network manager should be started // on the node side, which requires any of the following conditions: -// (1) dpu mode is enabled when secondary networks feature is enabled -// (2) primary user defined networks is enabled (all modes) +// (1) dpu mode is enabled when multiple networks feature is enabled +// (2) primary user-defined networks is enabled (all modes) func isNetworkManagerRequiredForNode() bool { return (config.OVNKubernetesFeature.EnableMultiNetwork && config.OvnKubeNode.Mode == ovntypes.NodeModeDPU) || util.IsNetworkSegmentationSupportEnabled() || @@ -115,7 +115,7 @@ func NewNodeControllerManager(ovnClient *util.OVNClientset, wf factory.NodeWatch ovsClient: ovsClient, } - // need to configure OVS interfaces for Pods on secondary networks in the DPU mode + // need to configure OVS interfaces for Pods on UDNs in the DPU mode // need to start NAD controller on node side for programming gateway pieces for UDNs // need to start NAD controller on node side for VRF awareness with BGP var err error diff --git a/go-controller/pkg/metrics/ovnkube_controller.go b/go-controller/pkg/metrics/ovnkube_controller.go index 30c846d07c..dd0d559450 100644 --- a/go-controller/pkg/metrics/ovnkube_controller.go +++ b/go-controller/pkg/metrics/ovnkube_controller.go @@ -512,8 +512,8 @@ func RunTimestamp(stopChan <-chan struct{}, sbClient, nbClient libovsdbclient.Cl // RecordPodCreated extracts the scheduled timestamp and records how long it took // us to notice this and set up the pod's scheduling. func RecordPodCreated(pod *corev1.Pod, netInfo util.NetInfo) { - if netInfo.IsSecondary() { - // TBD: no op for secondary network for now, TBD + if netInfo.IsUserDefinedNetwork() { + // TBD: noop for UDN for now return } t := time.Now() @@ -761,8 +761,8 @@ func (pr *PodRecorder) CleanPod(podUID kapimtypes.UID) { } func (pr *PodRecorder) AddLSP(podUID kapimtypes.UID, netInfo util.NetInfo) { - if netInfo.IsSecondary() { - // TBD: no op for secondary network for now, TBD + if netInfo.IsUserDefinedNetwork() { + // TBD: noop for UDN for now return } if pr.queue != nil && !pr.queueFull() { diff --git a/go-controller/pkg/node/base_node_network_controller_dpu.go b/go-controller/pkg/node/base_node_network_controller_dpu.go index 26de1386c1..179a54c148 100644 --- a/go-controller/pkg/node/base_node_network_controller_dpu.go +++ b/go-controller/pkg/node/base_node_network_controller_dpu.go @@ -115,7 +115,7 @@ func (bnnc *BaseNodeNetworkController) watchPodsDPU() (*factory.Handler, error) // add all the Pod's NADs into Pod's nadToDPUCDMap // For default network, NAD name is DefaultNetworkName. nadToDPUCDMap := map[string]*util.DPUConnectionDetails{} - if bnnc.IsSecondary() { + if bnnc.IsUserDefinedNetwork() { if bnnc.IsPrimaryNetwork() { activeNetwork, err = bnnc.networkManager.GetActiveNetworkForNamespace(pod.Namespace) if err != nil { diff --git a/go-controller/pkg/node/controllers/egressip/egressip.go b/go-controller/pkg/node/controllers/egressip/egressip.go index 63a8477122..dd1f15f3c9 100644 --- a/go-controller/pkg/node/controllers/egressip/egressip.go +++ b/go-controller/pkg/node/controllers/egressip/egressip.go @@ -567,7 +567,7 @@ func (c *Controller) processEIP(eip *eipv1.EgressIP) (*eIPConfig, sets.Set[strin if err != nil { return nil, selectedNamespaces, selectedPods, selectedNamespacesPodIPs, fmt.Errorf("failed to get active network for namespace %s: %v", namespace.Name, err) } - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { // EIP for secondary host interfaces is not supported for secondary networks continue } @@ -1036,7 +1036,7 @@ func (c *Controller) repairNode() error { if err != nil { return fmt.Errorf("failed to get active network for namespace %s: %v", namespace.Name, err) } - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { // EIP for secondary host interfaces is not supported for secondary networks continue } diff --git a/go-controller/pkg/node/default_node_network_controller.go b/go-controller/pkg/node/default_node_network_controller.go index 5f0878f64e..9e0d28b582 100644 --- a/go-controller/pkg/node/default_node_network_controller.go +++ b/go-controller/pkg/node/default_node_network_controller.go @@ -854,8 +854,8 @@ func portExists(namespace, name string) bool { /** HACK END **/ // Init executes the first steps to start the DefaultNodeNetworkController. -// It is split from Start() and executed before SecondaryNodeNetworkController (SNNC), -// to allow SNNC to reference the openflow manager created in Init. +// It is split from Start() and executed before UserDefinedNodeNetworkController (UDNNC) +// to allow UDNNC to reference the openflow manager created in Init. func (nc *DefaultNodeNetworkController) Init(ctx context.Context) error { klog.Infof("Initializing the default node network controller") diff --git a/go-controller/pkg/node/secondary_node_network_controller.go b/go-controller/pkg/node/user_defined_node_network_controller.go similarity index 78% rename from go-controller/pkg/node/secondary_node_network_controller.go rename to go-controller/pkg/node/user_defined_node_network_controller.go index e5c4eba83f..4b814c4253 100644 --- a/go-controller/pkg/node/secondary_node_network_controller.go +++ b/go-controller/pkg/node/user_defined_node_network_controller.go @@ -16,9 +16,9 @@ import ( "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" ) -// SecondaryNodeNetworkController structure is the object which holds the controls for starting -// and reacting upon the watched resources (e.g. pods, endpoints) for secondary network -type SecondaryNodeNetworkController struct { +// UserDefinedNodeNetworkController structure is the object which holds the controls for starting +// and reacting upon the watched resources (e.g. pods, endpoints) for user-defined networks +type UserDefinedNodeNetworkController struct { BaseNodeNetworkController // pod events factory handler podHandler *factory.Handler @@ -26,19 +26,19 @@ type SecondaryNodeNetworkController struct { gateway *UserDefinedNetworkGateway } -// NewSecondaryNodeNetworkController creates a new OVN controller for creating logical network +// NewUserDefinedNodeNetworkController creates a new OVN controller for creating logical network // infrastructure and policy for the given secondary network. It supports layer3, layer2 and // localnet topology types. -func NewSecondaryNodeNetworkController( +func NewUserDefinedNodeNetworkController( cnnci *CommonNodeNetworkControllerInfo, netInfo util.NetInfo, networkManager networkmanager.Interface, vrfManager *vrfmanager.Controller, ruleManager *iprulemanager.Controller, defaultNetworkGateway Gateway, -) (*SecondaryNodeNetworkController, error) { +) (*UserDefinedNodeNetworkController, error) { - snnc := &SecondaryNodeNetworkController{ + snnc := &UserDefinedNodeNetworkController{ BaseNodeNetworkController: BaseNodeNetworkController{ CommonNodeNetworkControllerInfo: *cnnci, ReconcilableNetInfo: util.NewReconcilableNetInfo(netInfo), @@ -64,10 +64,10 @@ func NewSecondaryNodeNetworkController( } // Start starts the default controller; handles all events and creates all needed logical entities -func (nc *SecondaryNodeNetworkController) Start(_ context.Context) error { - klog.Infof("Start secondary node network controller of network %s", nc.GetNetworkName()) +func (nc *UserDefinedNodeNetworkController) Start(_ context.Context) error { + klog.Infof("Starting UDN node network controller for network %s", nc.GetNetworkName()) - // enable adding ovs ports for dpu pods in both primary and secondary user defined networks + // enable adding ovs ports for dpu pods in both primary and secondary user-defined networks if (config.OVNKubernetesFeature.EnableMultiNetwork || util.IsNetworkSegmentationSupportEnabled()) && config.OvnKubeNode.Mode == types.NodeModeDPU { handler, err := nc.watchPodsDPU() if err != nil { @@ -85,8 +85,8 @@ func (nc *SecondaryNodeNetworkController) Start(_ context.Context) error { } // Stop gracefully stops the controller -func (nc *SecondaryNodeNetworkController) Stop() { - klog.Infof("Stop secondary node network controller of network %s", nc.GetNetworkName()) +func (nc *UserDefinedNodeNetworkController) Stop() { + klog.Infof("Stopping UDN node network controller for network %s", nc.GetNetworkName()) close(nc.stopChan) nc.wg.Wait() @@ -95,15 +95,15 @@ func (nc *SecondaryNodeNetworkController) Stop() { } } -// Cleanup cleans up node entities for the given secondary network -func (nc *SecondaryNodeNetworkController) Cleanup() error { +// Cleanup cleans up node entities for the given user-defined network +func (nc *UserDefinedNodeNetworkController) Cleanup() error { if nc.gateway != nil { return nc.gateway.DelNetwork() } return nil } -func (nc *SecondaryNodeNetworkController) shouldReconcileNetworkChange(old, new util.NetInfo) bool { +func (nc *UserDefinedNodeNetworkController) shouldReconcileNetworkChange(old, new util.NetInfo) bool { wasUDNNetworkAdvertisedAtNode := util.IsPodNetworkAdvertisedAtNode(old, nc.name) isUDNNetworkAdvertisedAtNode := util.IsPodNetworkAdvertisedAtNode(new, nc.name) return wasUDNNetworkAdvertisedAtNode != isUDNNetworkAdvertisedAtNode @@ -113,7 +113,7 @@ func (nc *SecondaryNodeNetworkController) shouldReconcileNetworkChange(old, new // and the gateway mode: // 1. IP rules // 2. OpenFlows on br-ex bridge to forward traffic to correct ofports -func (nc *SecondaryNodeNetworkController) Reconcile(netInfo util.NetInfo) error { +func (nc *UserDefinedNodeNetworkController) Reconcile(netInfo util.NetInfo) error { reconcilePodNetwork := nc.shouldReconcileNetworkChange(nc.ReconcilableNetInfo, netInfo) err := util.ReconcileNetInfo(nc.ReconcilableNetInfo, netInfo) diff --git a/go-controller/pkg/node/secondary_node_network_controller_test.go b/go-controller/pkg/node/user_defined_node_network_controller_test.go similarity index 96% rename from go-controller/pkg/node/secondary_node_network_controller_test.go rename to go-controller/pkg/node/user_defined_node_network_controller_test.go index bd0fbaab09..3c79c227fd 100644 --- a/go-controller/pkg/node/secondary_node_network_controller_test.go +++ b/go-controller/pkg/node/user_defined_node_network_controller_test.go @@ -41,7 +41,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("SecondaryNodeNetworkController", func() { +var _ = Describe("UserDefinedNodeNetworkController", func() { var ( networkID = "3" nad = ovntest.GenerateNAD("bluenet", "rednad", "greenamespace", @@ -85,7 +85,7 @@ var _ = Describe("SecondaryNodeNetworkController", func() { factoryMock.On("GetNodes").Return(nodeList, nil) NetInfo, err := util.ParseNADInfo(nad) Expect(err).NotTo(HaveOccurred()) - controller, err := NewSecondaryNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{}) + controller, err := NewUserDefinedNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{}) Expect(err).NotTo(HaveOccurred()) err = controller.Start(context.Background()) Expect(err).NotTo(HaveOccurred()) @@ -116,7 +116,7 @@ var _ = Describe("SecondaryNodeNetworkController", func() { Expect(err).NotTo(HaveOccurred()) getCreationFakeCommands(fexec, "ovn-k8s-mp3", mgtPortMAC, NetInfo.GetNetworkName(), "worker1", NetInfo.MTU()) ofm := getDummyOpenflowManager() - controller, err := NewSecondaryNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{openflowManager: ofm}) + controller, err := NewUserDefinedNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{openflowManager: ofm}) Expect(err).NotTo(HaveOccurred()) err = controller.Start(context.Background()) Expect(err).To(HaveOccurred()) // we don't have the gateway pieces setup so its expected to fail here @@ -144,7 +144,7 @@ var _ = Describe("SecondaryNodeNetworkController", func() { types.Layer3Topology, "100.128.0.0/16", types.NetworkRoleSecondary) NetInfo, err := util.ParseNADInfo(nad) Expect(err).NotTo(HaveOccurred()) - controller, err := NewSecondaryNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{}) + controller, err := NewUserDefinedNodeNetworkController(&cnnci, NetInfo, nil, nil, nil, &gateway{}) Expect(err).NotTo(HaveOccurred()) err = controller.Start(context.Background()) Expect(err).NotTo(HaveOccurred()) @@ -152,7 +152,7 @@ var _ = Describe("SecondaryNodeNetworkController", func() { }) }) -var _ = Describe("SecondaryNodeNetworkController: UserDefinedPrimaryNetwork Gateway functionality", func() { +var _ = Describe("UserDefinedNodeNetworkController: UserDefinedPrimaryNetwork Gateway functionality", func() { var ( nad = ovntest.GenerateNAD("bluenet", "rednad", "greenamespace", types.Layer3Topology, "100.128.0.0/16", types.NetworkRolePrimary) @@ -418,15 +418,15 @@ var _ = Describe("SecondaryNodeNetworkController: UserDefinedPrimaryNetwork Gate Expect(err).NotTo(HaveOccurred()) localGw.openflowManager.syncFlows() - By("creating secondary network controller for user defined primary network") + By("creating a UDN controller for user-defined primary network") cnnci := CommonNodeNetworkControllerInfo{name: nodeName, watchFactory: &factoryMock} - controller, err := NewSecondaryNodeNetworkController(&cnnci, NetInfo, nil, vrf, ipRulesManager, localGw) + controller, err := NewUserDefinedNodeNetworkController(&cnnci, NetInfo, nil, vrf, ipRulesManager, localGw) Expect(err).NotTo(HaveOccurred()) Expect(controller.gateway).To(Not(BeNil())) Expect(controller.gateway.ruleManager).To(Not(BeNil())) controller.gateway.kubeInterface = &kubeMock - By("starting secondary network controller for user defined primary network") + By("starting UDN controller for user-defined primary network") err = controller.Start(context.Background()) Expect(err).NotTo(HaveOccurred()) diff --git a/go-controller/pkg/ovn/base_network_controller.go b/go-controller/pkg/ovn/base_network_controller.go index 491899184e..ea72526b10 100644 --- a/go-controller/pkg/ovn/base_network_controller.go +++ b/go-controller/pkg/ovn/base_network_controller.go @@ -283,9 +283,9 @@ func (oc *BaseNetworkController) doReconcile(reconcileRoutes, reconcilePendingPo } } -// BaseSecondaryNetworkController structure holds per-network fields and network specific -// configuration for secondary network controller -type BaseSecondaryNetworkController struct { +// BaseUserDefinedNetworkController structure holds per-network fields and network specific +// configuration for UDN controller +type BaseUserDefinedNetworkController struct { BaseNetworkController // network policy events factory handler @@ -294,7 +294,7 @@ type BaseSecondaryNetworkController struct { multiNetPolicyHandler *factory.Handler } -func (oc *BaseSecondaryNetworkController) FilterOutResource(objType reflect.Type, obj interface{}) bool { +func (oc *BaseUserDefinedNetworkController) FilterOutResource(objType reflect.Type, obj interface{}) bool { switch objType { case factory.NamespaceType: ns, ok := obj.(*corev1.Namespace) @@ -343,19 +343,19 @@ func NewCommonNetworkControllerInfo(client clientset.Interface, kube *kube.KubeO } func (bnc *BaseNetworkController) GetLogicalPortName(pod *corev1.Pod, nadName string) string { - if !bnc.IsSecondary() { + if !bnc.IsUserDefinedNetwork() { return util.GetLogicalPortName(pod.Namespace, pod.Name) } else { - return util.GetSecondaryNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) + return util.GetUserDefinedNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) } } func (bnc *BaseNetworkController) AddConfigDurationRecord(kind, namespace, name string) ( []ovsdb.Operation, func(), time.Time, error) { - if !bnc.IsSecondary() { + if !bnc.IsUserDefinedNetwork() { return recorders.GetConfigDurationRecorder().AddOVN(bnc.nbClient, kind, namespace, name) } - // TBD: no op for secondary network for now + // TBD: no-op for UDN for now return []ovsdb.Operation{}, func() {}, time.Time{}, nil } @@ -799,7 +799,7 @@ func (bnc *BaseNetworkController) syncNodeManagementPort(node *corev1.Node, swit IPPrefix: hostSubnet.String(), Nexthop: mgmtIfAddr.IP.String(), } - if bnc.IsSecondary() { + if bnc.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: bnc.GetNetworkName(), types.TopologyExternalID: bnc.TopologyType(), @@ -878,8 +878,8 @@ func (bnc *BaseNetworkController) WatchNodes() error { } func (bnc *BaseNetworkController) recordNodeErrorEvent(node *corev1.Node, nodeErr error) { - if bnc.IsSecondary() { - // TBD, no op for secondary network for now + if bnc.IsUserDefinedNetwork() { + // TBD, noop for UDN for now return } nodeRef, err := ref.GetReference(scheme.Scheme, node) @@ -908,7 +908,7 @@ func (bnc *BaseNetworkController) doesNetworkRequireIPAM() bool { } func (bnc *BaseNetworkController) getPodNADNames(pod *corev1.Pod) []string { - if !bnc.IsSecondary() { + if !bnc.IsUserDefinedNetwork() { return []string{types.DefaultNetworkName} } podNadNames, _ := util.PodNadNames(pod, bnc.GetNetInfo()) @@ -1000,8 +1000,8 @@ func (bnc *BaseNetworkController) nodeZoneClusterChanged(oldNode, newNode *corev } func (bnc *BaseNetworkController) findMigratablePodIPsForSubnets(subnets []*net.IPNet) ([]*net.IPNet, error) { - // live migration is not supported in combination with secondary networks - if bnc.IsSecondary() { + // live migration is not supported in combination with UDNs + if bnc.IsUserDefinedNetwork() { return nil, nil } diff --git a/go-controller/pkg/ovn/base_network_controller_multicast.go b/go-controller/pkg/ovn/base_network_controller_multicast.go index 6f413177d5..0bfd7e3764 100644 --- a/go-controller/pkg/ovn/base_network_controller_multicast.go +++ b/go-controller/pkg/ovn/base_network_controller_multicast.go @@ -199,7 +199,7 @@ func (bnc *BaseNetworkController) createDefaultDenyMulticastPolicy() error { return err } - if !bnc.IsSecondary() { + if !bnc.IsUserDefinedNetwork() { // Remove old multicastDefaultDeny port group now that all ports // have been added to the clusterPortGroup by WatchPods() ops, err = libovsdbops.DeletePortGroupsOps(bnc.nbClient, ops, legacyMulticastDefaultDenyPortGroup) diff --git a/go-controller/pkg/ovn/base_network_controller_multipolicy.go b/go-controller/pkg/ovn/base_network_controller_multipolicy.go index d6ab0d984f..1c22ff0fb9 100644 --- a/go-controller/pkg/ovn/base_network_controller_multipolicy.go +++ b/go-controller/pkg/ovn/base_network_controller_multipolicy.go @@ -14,7 +14,7 @@ import ( const PolicyForAnnotation = "k8s.v1.cni.cncf.io/policy-for" -func (bsnc *BaseSecondaryNetworkController) syncMultiNetworkPolicies(multiPolicies []interface{}) error { +func (bsnc *BaseUserDefinedNetworkController) syncMultiNetworkPolicies(multiPolicies []interface{}) error { expectedPolicies := make(map[string]map[string]bool) for _, npInterface := range multiPolicies { policy, ok := npInterface.(*mnpapi.MultiNetworkPolicy) @@ -38,7 +38,7 @@ func (bsnc *BaseSecondaryNetworkController) syncMultiNetworkPolicies(multiPolici return bsnc.syncNetworkPoliciesCommon(expectedPolicies) } -func (bsnc *BaseSecondaryNetworkController) shouldApplyMultiPolicy(mpolicy *mnpapi.MultiNetworkPolicy) bool { +func (bsnc *BaseUserDefinedNetworkController) shouldApplyMultiPolicy(mpolicy *mnpapi.MultiNetworkPolicy) bool { policyForAnnot, ok := mpolicy.Annotations[PolicyForAnnotation] if !ok { klog.V(5).Infof("%s annotation not defined in multi-policy %s/%s", PolicyForAnnotation, diff --git a/go-controller/pkg/ovn/base_network_controller_namespace.go b/go-controller/pkg/ovn/base_network_controller_namespace.go index 7bc86f0bab..f980cd35b7 100644 --- a/go-controller/pkg/ovn/base_network_controller_namespace.go +++ b/go-controller/pkg/ovn/base_network_controller_namespace.go @@ -75,7 +75,7 @@ func (bnc *BaseNetworkController) shouldWatchNamespaces() bool { // - The network is secondary, and multi NetworkPolicies are enabled. return bnc.IsDefault() || bnc.IsPrimaryNetwork() && util.IsNetworkSegmentationSupportEnabled() || - bnc.IsSecondary() && util.IsMultiNetworkPoliciesSupportEnabled() + bnc.IsUserDefinedNetwork() && util.IsMultiNetworkPoliciesSupportEnabled() } // WatchNamespaces starts the watching of namespace resource and calls @@ -466,7 +466,7 @@ func (bsnc *BaseNetworkController) removeRemoteZonePodFromNamespaceAddressSet(po // tracked within the zone, nodeName will be empty which will force // canReleasePodIPs to lookup all nodes. nodeName := pod.Spec.NodeName - if !bsnc.IsSecondary() && kubevirt.IsPodLiveMigratable(pod) { + if !bsnc.IsUserDefinedNetwork() && kubevirt.IsPodLiveMigratable(pod) { nodeName, _ = bsnc.lsManager.GetSubnetName(podIfAddrs) } diff --git a/go-controller/pkg/ovn/base_network_controller_pods.go b/go-controller/pkg/ovn/base_network_controller_pods.go index 4427b17b63..7600e228da 100644 --- a/go-controller/pkg/ovn/base_network_controller_pods.go +++ b/go-controller/pkg/ovn/base_network_controller_pods.go @@ -105,7 +105,7 @@ func (bnc *BaseNetworkController) deleteStaleLogicalSwitchPorts(expectedLogicalP // get all switches that Pod logical port would be reside on. topoType := bnc.TopologyType() - if !bnc.IsSecondary() || topoType == ovntypes.Layer3Topology { + if !bnc.IsUserDefinedNetwork() || topoType == ovntypes.Layer3Topology { // for default network and layer3 topology type networks, get all local zone node switches nodes, err := bnc.GetLocalZoneNodes() if err != nil { @@ -404,7 +404,7 @@ func (bnc *BaseNetworkController) podExpectedInLogicalCache(pod *corev1.Pod) boo func (bnc *BaseNetworkController) getExpectedSwitchName(pod *corev1.Pod) (string, error) { switchName := pod.Spec.NodeName - if bnc.IsSecondary() { + if bnc.IsUserDefinedNetwork() { topoType := bnc.TopologyType() switch topoType { case ovntypes.Layer3Topology: @@ -552,14 +552,14 @@ func (bnc *BaseNetworkController) addLogicalPortToNetwork(pod *corev1.Pod, nadNa } // Although we have different code to allocate the pod annotation for the - // default network and secondary networks, at the time of this writing they + // default network and user-defined networks, at the time of this writing they // are functionally equivalent and the only reason to keep them separated is - // to make sure the secondary network code has no bugs before we switch to + // to make sure the UDN code has no bugs before we switch to // it for the default network as well. If at all possible, keep them // functionally equivalent going forward. var annotationUpdated bool - if bnc.IsSecondary() { - podAnnotation, annotationUpdated, err = bnc.allocatePodAnnotationForSecondaryNetwork(pod, existingLSP, nadName, network, networkRole) + if bnc.IsUserDefinedNetwork() { + podAnnotation, annotationUpdated, err = bnc.allocatePodAnnotationForUserDefinedNetwork(pod, existingLSP, nadName, network, networkRole) } else { podAnnotation, annotationUpdated, err = bnc.allocatePodAnnotation(pod, existingLSP, podDesc, nadName, network, networkRole) } @@ -590,7 +590,7 @@ func (bnc *BaseNetworkController) addLogicalPortToNetwork(pod *corev1.Pod, nadNa // add external ids lsp.ExternalIDs = map[string]string{"namespace": pod.Namespace, "pod": "true"} - if bnc.IsSecondary() { + if bnc.IsUserDefinedNetwork() { lsp.ExternalIDs[ovntypes.NetworkExternalID] = bnc.GetNetworkName() lsp.ExternalIDs[ovntypes.NADExternalID] = nadName lsp.ExternalIDs[ovntypes.TopologyExternalID] = bnc.TopologyType() @@ -708,7 +708,7 @@ func (bnc *BaseNetworkController) delLSPOps(logicalPort, switchName, } func (bnc *BaseNetworkController) deletePodFromNamespace(ns string, podIfAddrs []*net.IPNet, portUUID string) ([]ovsdb.Operation, error) { - // for secondary network, namespace may be not managed + // for UDN, namespace may be not managed nsInfo, nsUnlock := bnc.getNamespaceLocked(ns, true) if nsInfo == nil { return nil, nil @@ -935,9 +935,9 @@ func (bnc *BaseNetworkController) allocatePodAnnotation(pod *corev1.Pod, existin return podAnnotation, true, nil } -// allocatePodAnnotationForSecondaryNetwork and update the corresponding pod +// allocatePodAnnotationForUserDefinedNetwork and update the corresponding pod // annotation. -func (bnc *BaseNetworkController) allocatePodAnnotationForSecondaryNetwork(pod *corev1.Pod, lsp *nbdb.LogicalSwitchPort, +func (bnc *BaseNetworkController) allocatePodAnnotationForUserDefinedNetwork(pod *corev1.Pod, lsp *nbdb.LogicalSwitchPort, nadName string, network *nadapi.NetworkSelectionElement, networkRole string) (*util.PodAnnotation, bool, error) { switchName, err := bnc.getExpectedSwitchName(pod) if err != nil { @@ -1032,20 +1032,21 @@ func (bnc *BaseNetworkController) allocatesPodAnnotation() bool { func (bnc *BaseNetworkController) shouldReleaseDeletedPod(pod *corev1.Pod, switchName, nad string, podIfAddrs []*net.IPNet) (bool, error) { var err error - var isMigratedSourcePodStale bool - if !bnc.IsSecondary() { - isMigratedSourcePodStale, err = kubevirt.IsMigratedSourcePodStale(bnc.watchFactory, pod) + if !bnc.IsUserDefinedNetwork() && kubevirt.IsPodLiveMigratable(pod) { + allVMPodsAreCompleted, err := kubevirt.AllVMPodsAreCompleted(bnc.watchFactory, pod) if err != nil { return false, err } - } - // Removing the the kubevirt stale pods should not de allocate the IPs - // to ensure that new pods do not take them - if isMigratedSourcePodStale { - return false, nil + // Removing the the kubevirt stale pods should not de allocate the IPs + // to ensure that new pods do not take them + if !allVMPodsAreCompleted { + return false, nil + } } + // this pod is being deleted before completion so there is no risk (and no + // need to check) that its IPs are being used by other pod if !util.PodCompleted(pod) { return true, nil } @@ -1059,16 +1060,21 @@ func (bnc *BaseNetworkController) shouldReleaseDeletedPod(pod *corev1.Pod, switc return false, nil } - shouldReleasePodIPs := func() (bool, error) { - // If this pod applies to live migration it could have migrated so get the - // correct node name corresponding with the subnet. If the subnet is not - // tracked within the zone, nodeName will be empty which will force - // canReleasePodIPs to lookup all nodes. - nodeName := pod.Spec.NodeName - if !bnc.IsSecondary() && kubevirt.IsPodLiveMigratable(pod) { - nodeName, _ = bnc.lsManager.GetSubnetName(podIfAddrs) - } + // If this pod applies to live migration it could have migrated within the + // zone so get the correct node name corresponding with the subnet. If the + // subnet is not tracked within the zone, nodeName will be empty which + // will force a lookup for all nodes. + zoneOwnsSubnet := true + nodeName := pod.Spec.NodeName + if !bnc.IsUserDefinedNetwork() && kubevirt.IsPodLiveMigratable(pod) { + switchName, zoneOwnsSubnet = bnc.lsManager.GetSubnetName(podIfAddrs) + } + if !zoneOwnsSubnet { + // force shouldReleasePodIPs to search all nodes + nodeName = "" + } + shouldReleasePodIPs := func() (bool, error) { shouldRelease, err := bnc.canReleasePodIPs(podIfAddrs, nodeName) if err != nil { return false, err @@ -1078,11 +1084,11 @@ func (bnc *BaseNetworkController) shouldReleaseDeletedPod(pod *corev1.Pod, switc } var shouldRelease bool - // for secondary network IPs allocated from cluster manager, we will check + // for user-defined network IPs allocated from cluster manager, we will check // if other pods are using the same IPs just in case we are processing // events in different order than cluster manager did (best effort, there // can still be issues with this) - if !bnc.allocatesPodAnnotation() { + if !bnc.allocatesPodAnnotation() || !zoneOwnsSubnet { shouldRelease, err = shouldReleasePodIPs() } else { shouldRelease, err = bnc.lsManager.ConditionalIPRelease(switchName, podIfAddrs, shouldReleasePodIPs) diff --git a/go-controller/pkg/ovn/base_network_controller_pods_test.go b/go-controller/pkg/ovn/base_network_controller_pods_test.go index 4d1a6393c4..2987a1ebe2 100644 --- a/go-controller/pkg/ovn/base_network_controller_pods_test.go +++ b/go-controller/pkg/ovn/base_network_controller_pods_test.go @@ -234,3 +234,41 @@ func TestBaseNetworkController_trackPodsReleasedBeforeStartup(t *testing.T) { }) } } + +func TestBaseNetworkController_shouldReleaseDeletedPod(t *testing.T) { + tests := []struct { + name string // description of this test case + // Named input parameters for target function. + pod *corev1.Pod + switchName string + nad string + podIfAddrs []*net.IPNet + want bool + wantErr bool + }{ + { + name: "should release a running pod", + pod: &corev1.Pod{Status: corev1.PodStatus{Phase: corev1.PodRunning}}, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var bnc BaseNetworkController + bnc.ReconcilableNetInfo = &util.DefaultNetInfo{} + got, gotErr := bnc.shouldReleaseDeletedPod(tt.pod, tt.switchName, tt.nad, tt.podIfAddrs) + if gotErr != nil { + if !tt.wantErr { + t.Errorf("shouldReleaseDeletedPod() failed: %v", gotErr) + } + return + } + if tt.wantErr { + t.Fatal("shouldReleaseDeletedPod() succeeded unexpectedly") + } + if got != tt.want { + t.Errorf("shouldReleaseDeletedPod() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/go-controller/pkg/ovn/base_network_controller_policy.go b/go-controller/pkg/ovn/base_network_controller_policy.go index 3be9b444f8..8ee14de88a 100644 --- a/go-controller/pkg/ovn/base_network_controller_policy.go +++ b/go-controller/pkg/ovn/base_network_controller_policy.go @@ -786,7 +786,7 @@ func (bnc *BaseNetworkController) denyPGDeletePorts(np *networkPolicy, portNames // handleLocalPodSelectorAddFunc adds a new pod to an existing NetworkPolicy, should be retriable. func (bnc *BaseNetworkController) handleLocalPodSelectorAddFunc(np *networkPolicy, objs ...interface{}) error { - if !bnc.IsSecondary() && config.Metrics.EnableScaleMetrics { + if !bnc.IsUserDefinedNetwork() && config.Metrics.EnableScaleMetrics { start := time.Now() defer func() { duration := time.Since(start) @@ -832,7 +832,7 @@ func (bnc *BaseNetworkController) handleLocalPodSelectorAddFunc(np *networkPolic // handleLocalPodSelectorDelFunc handles delete event for local pod, should be retriable func (bnc *BaseNetworkController) handleLocalPodSelectorDelFunc(np *networkPolicy, objs ...interface{}) error { - if !bnc.IsSecondary() && config.Metrics.EnableScaleMetrics { + if !bnc.IsUserDefinedNetwork() && config.Metrics.EnableScaleMetrics { start := time.Now() defer func() { duration := time.Since(start) @@ -1177,7 +1177,7 @@ func (bnc *BaseNetworkController) setupGressPolicy(np *networkPolicy, gp *gressP // if addNetworkPolicy fails, create or delete operation can be retried func (bnc *BaseNetworkController) addNetworkPolicy(policy *knet.NetworkPolicy) error { klog.Infof("Adding network policy %s for network %s", getPolicyKey(policy), bnc.GetNetworkName()) - if !bnc.IsSecondary() && config.Metrics.EnableScaleMetrics { + if !bnc.IsUserDefinedNetwork() && config.Metrics.EnableScaleMetrics { start := time.Now() defer func() { duration := time.Since(start) @@ -1384,7 +1384,7 @@ type NetworkPolicyExtraParameters struct { } func (bnc *BaseNetworkController) handlePeerNamespaceSelectorAdd(np *networkPolicy, gp *gressPolicy, objs ...interface{}) error { - if !bnc.IsSecondary() && config.Metrics.EnableScaleMetrics { + if !bnc.IsUserDefinedNetwork() && config.Metrics.EnableScaleMetrics { start := time.Now() defer func() { duration := time.Since(start) @@ -1421,7 +1421,7 @@ func (bnc *BaseNetworkController) handlePeerNamespaceSelectorAdd(np *networkPoli } func (bnc *BaseNetworkController) handlePeerNamespaceSelectorDel(np *networkPolicy, gp *gressPolicy, objs ...interface{}) error { - if !bnc.IsSecondary() && config.Metrics.EnableScaleMetrics { + if !bnc.IsUserDefinedNetwork() && config.Metrics.EnableScaleMetrics { start := time.Now() defer func() { duration := time.Since(start) diff --git a/go-controller/pkg/ovn/base_network_controller_secondary.go b/go-controller/pkg/ovn/base_network_controller_user_defined.go similarity index 87% rename from go-controller/pkg/ovn/base_network_controller_secondary.go rename to go-controller/pkg/ovn/base_network_controller_user_defined.go index 106155b76e..da26a58350 100644 --- a/go-controller/pkg/ovn/base_network_controller_secondary.go +++ b/go-controller/pkg/ovn/base_network_controller_user_defined.go @@ -36,7 +36,7 @@ import ( utilerrors "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util/errors" ) -func (bsnc *BaseSecondaryNetworkController) getPortInfoForSecondaryNetwork(pod *corev1.Pod) map[string]*lpInfo { +func (bsnc *BaseUserDefinedNetworkController) getPortInfoForUserDefinedNetwork(pod *corev1.Pod) map[string]*lpInfo { if util.PodWantsHostNetwork(pod) { return nil } @@ -44,35 +44,35 @@ func (bsnc *BaseSecondaryNetworkController) getPortInfoForSecondaryNetwork(pod * return portInfoMap } -// GetInternalCacheEntryForSecondaryNetwork returns the internal cache entry for this object, given an object and its type. +// GetInternalCacheEntryForUserDefinedNetwork returns the internal cache entry for this object, given an object and its type. // This is now used only for pods, which will get their the logical port cache entry. -func (bsnc *BaseSecondaryNetworkController) GetInternalCacheEntryForSecondaryNetwork(objType reflect.Type, obj interface{}) interface{} { +func (bsnc *BaseUserDefinedNetworkController) GetInternalCacheEntryForUserDefinedNetwork(objType reflect.Type, obj interface{}) interface{} { switch objType { case factory.PodType: pod := obj.(*corev1.Pod) - return bsnc.getPortInfoForSecondaryNetwork(pod) + return bsnc.getPortInfoForUserDefinedNetwork(pod) default: return nil } } -// AddSecondaryNetworkResourceCommon adds the specified object to the cluster according to its type and returns the error, -// if any, yielded during object creation. This function is called for secondary network only. -func (bsnc *BaseSecondaryNetworkController) AddSecondaryNetworkResourceCommon(objType reflect.Type, obj interface{}) error { +// AddUserDefinedNetworkResourceCommon adds the specified object to the cluster according to its type and returns the error, +// if any, yielded during object creation. This function is called for User Defined Networks only. +func (bsnc *BaseUserDefinedNetworkController) AddUserDefinedNetworkResourceCommon(objType reflect.Type, obj interface{}) error { switch objType { case factory.PodType: pod, ok := obj.(*corev1.Pod) if !ok { return fmt.Errorf("could not cast %T object to *knet.Pod", obj) } - return bsnc.ensurePodForSecondaryNetwork(pod, true) + return bsnc.ensurePodForUserDefinedNetwork(pod, true) case factory.NamespaceType: ns, ok := obj.(*corev1.Namespace) if !ok { return fmt.Errorf("could not cast %T object to *kapi.Namespace", obj) } - return bsnc.AddNamespaceForSecondaryNetwork(ns) + return bsnc.AddNamespaceForUserDefinedNetwork(ns) case factory.MultiNetworkPolicyType: mp, ok := obj.(*mnpapi.MultiNetworkPolicy) @@ -102,22 +102,22 @@ func (bsnc *BaseSecondaryNetworkController) AddSecondaryNetworkResourceCommon(ob return nil } -// UpdateSecondaryNetworkResourceCommon updates the specified object in the cluster to its version in newObj +// UpdateUserDefinedNetworkResourceCommon updates the specified object in the cluster to its version in newObj // according to its type and returns the error, if any, yielded during the object update. This function is -// called for secondary network only. +// called for User Defined Networks only. // Given an old and a new object; The inRetryCache boolean argument is to indicate if the given resource // is in the retryCache or not. -func (bsnc *BaseSecondaryNetworkController) UpdateSecondaryNetworkResourceCommon(objType reflect.Type, oldObj, newObj interface{}, inRetryCache bool) error { +func (bsnc *BaseUserDefinedNetworkController) UpdateUserDefinedNetworkResourceCommon(objType reflect.Type, oldObj, newObj interface{}, inRetryCache bool) error { switch objType { case factory.PodType: oldPod := oldObj.(*corev1.Pod) newPod := newObj.(*corev1.Pod) - return bsnc.ensurePodForSecondaryNetwork(newPod, shouldAddPort(oldPod, newPod, inRetryCache)) + return bsnc.ensurePodForUserDefinedNetwork(newPod, shouldAddPort(oldPod, newPod, inRetryCache)) case factory.NamespaceType: oldNs, newNs := oldObj.(*corev1.Namespace), newObj.(*corev1.Namespace) - return bsnc.updateNamespaceForSecondaryNetwork(oldNs, newNs) + return bsnc.updateNamespaceForUserDefinedNetwork(oldNs, newNs) case factory.MultiNetworkPolicyType: oldMp, ok := oldObj.(*mnpapi.MultiNetworkPolicy) @@ -164,11 +164,11 @@ func (bsnc *BaseSecondaryNetworkController) UpdateSecondaryNetworkResourceCommon return nil } -// DeleteResource deletes the object from the cluster according to the delete logic of its resource type. +// DeleteUserDefinedNetworkResourceCommon deletes the object from the cluster according to the delete logic of its resource type. // Given an object and optionally a cachedObj; cachedObj is the internal cache entry for this object, // used for now for pods. -// This function is called for secondary network only. -func (bsnc *BaseSecondaryNetworkController) DeleteSecondaryNetworkResourceCommon(objType reflect.Type, obj, cachedObj interface{}) error { +// This function is called for User Defined Networks only. +func (bsnc *BaseUserDefinedNetworkController) DeleteUserDefinedNetworkResourceCommon(objType reflect.Type, obj, cachedObj interface{}) error { switch objType { case factory.PodType: var portInfoMap map[string]*lpInfo @@ -177,11 +177,11 @@ func (bsnc *BaseSecondaryNetworkController) DeleteSecondaryNetworkResourceCommon if cachedObj != nil { portInfoMap = cachedObj.(map[string]*lpInfo) } - return bsnc.removePodForSecondaryNetwork(pod, portInfoMap) + return bsnc.removePodForUserDefinedNetwork(pod, portInfoMap) case factory.NamespaceType: ns := obj.(*corev1.Namespace) - return bsnc.deleteNamespace4SecondaryNetwork(ns) + return bsnc.deleteNamespaceForUserDefinedNetwork(ns) case factory.MultiNetworkPolicyType: mp, ok := obj.(*mnpapi.MultiNetworkPolicy) @@ -224,9 +224,9 @@ func (bsnc *BaseSecondaryNetworkController) DeleteSecondaryNetworkResourceCommon return nil } -// ensurePodForSecondaryNetwork tries to set up secondary network for a pod. It returns nil on success and error +// ensurePodForUserDefinedNetwork tries to set up the User Defined Network for a pod. It returns nil on success and error // on failure; failure indicates the pod set up should be retried later. -func (bsnc *BaseSecondaryNetworkController) ensurePodForSecondaryNetwork(pod *corev1.Pod, addPort bool) error { +func (bsnc *BaseUserDefinedNetworkController) ensurePodForUserDefinedNetwork(pod *corev1.Pod, addPort bool) error { // Try unscheduled pods later if !util.PodScheduled(pod) { @@ -301,7 +301,7 @@ func (bsnc *BaseSecondaryNetworkController) ensurePodForSecondaryNetwork(pod *co return nil } -func (bsnc *BaseSecondaryNetworkController) addLogicalPortToNetworkForNAD(pod *corev1.Pod, nadName, switchName string, +func (bsnc *BaseUserDefinedNetworkController) addLogicalPortToNetworkForNAD(pod *corev1.Pod, nadName, switchName string, network *nadapi.NetworkSelectionElement, kubevirtLiveMigrationStatus *kubevirt.LiveMigrationStatus) error { var libovsdbExecuteTime time.Duration @@ -381,7 +381,7 @@ func (bsnc *BaseSecondaryNetworkController) addLogicalPortToNetworkForNAD(pod *c if lsp != nil { portUUID = lsp.UUID } - addOps, err := bsnc.addPodToNamespaceForSecondaryNetwork(pod.Namespace, podAnnotation.IPs, portUUID) + addOps, err := bsnc.addPodToNamespaceForUserDefinedNetwork(pod.Namespace, podAnnotation.IPs, portUUID) if err != nil { return err } @@ -421,9 +421,9 @@ func (bsnc *BaseSecondaryNetworkController) addLogicalPortToNetworkForNAD(pod *c return nil } -// removePodForSecondaryNetwork tried to tear down a pod. It returns nil on success and error on failure; +// removePodForUserDefinedNetwork tried to tear down a pod. It returns nil on success and error on failure; // failure indicates the pod tear down should be retried later. -func (bsnc *BaseSecondaryNetworkController) removePodForSecondaryNetwork(pod *corev1.Pod, portInfoMap map[string]*lpInfo) error { +func (bsnc *BaseUserDefinedNetworkController) removePodForUserDefinedNetwork(pod *corev1.Pod, portInfoMap map[string]*lpInfo) error { if util.PodWantsHostNetwork(pod) || !util.PodScheduled(pod) { return nil } @@ -526,7 +526,7 @@ func (bsnc *BaseSecondaryNetworkController) removePodForSecondaryNetwork(pod *co // hasIPAMClaim determines whether a pod's IPAM is being handled by IPAMClaim CR. // pod passed should already be validated as having a network connection to nadName -func (bsnc *BaseSecondaryNetworkController) hasIPAMClaim(pod *corev1.Pod, nadNamespacedName string) (bool, error) { +func (bsnc *BaseUserDefinedNetworkController) hasIPAMClaim(pod *corev1.Pod, nadNamespacedName string) (bool, error) { if !bsnc.AllowsPersistentIPs() { return false, nil } @@ -577,7 +577,7 @@ func (bsnc *BaseSecondaryNetworkController) hasIPAMClaim(pod *corev1.Pod, nadNam return hasIPAMClaim, nil } -func (bsnc *BaseSecondaryNetworkController) syncPodsForSecondaryNetwork(pods []interface{}) error { +func (bsnc *BaseUserDefinedNetworkController) syncPodsForUserDefinedNetwork(pods []interface{}) error { annotatedLocalPods := map[*corev1.Pod]map[string]*util.PodAnnotation{} // get the list of logical switch ports (equivalent to pods). Reserve all existing Pod IPs to // avoid subsequent new Pods getting the same duplicate Pod IP. @@ -655,10 +655,10 @@ func (bsnc *BaseSecondaryNetworkController) syncPodsForSecondaryNetwork(pods []i return bsnc.deleteStaleLogicalSwitchPorts(expectedLogicalPorts) } -// addPodToNamespaceForSecondaryNetwork returns the ops needed to add pod's IP to the namespace's address set. -func (bsnc *BaseSecondaryNetworkController) addPodToNamespaceForSecondaryNetwork(ns string, ips []*net.IPNet, portUUID string) ([]ovsdb.Operation, error) { +// addPodToNamespaceForUserDefinedNetwork returns the ops needed to add pod's IP to the namespace's address set. +func (bsnc *BaseUserDefinedNetworkController) addPodToNamespaceForUserDefinedNetwork(ns string, ips []*net.IPNet, portUUID string) ([]ovsdb.Operation, error) { var err error - nsInfo, nsUnlock, err := bsnc.ensureNamespaceLockedForSecondaryNetwork(ns, true, nil) + nsInfo, nsUnlock, err := bsnc.ensureNamespaceLockedForUserDefinedNetwork(ns, true, nil) if err != nil { return nil, fmt.Errorf("failed to ensure namespace locked: %v", err) } @@ -668,8 +668,8 @@ func (bsnc *BaseSecondaryNetworkController) addPodToNamespaceForSecondaryNetwork return bsnc.addLocalPodToNamespaceLocked(nsInfo, ips, portUUID) } -// AddNamespaceForSecondaryNetwork creates corresponding addressset in ovn db for secondary network -func (bsnc *BaseSecondaryNetworkController) AddNamespaceForSecondaryNetwork(ns *corev1.Namespace) error { +// AddNamespaceForUserDefinedNetwork creates corresponding addressset in ovn db for User Defined Network +func (bsnc *BaseUserDefinedNetworkController) AddNamespaceForUserDefinedNetwork(ns *corev1.Namespace) error { klog.Infof("[%s] adding namespace for network %s", ns.Name, bsnc.GetNetworkName()) // Keep track of how long syncs take. start := time.Now() @@ -677,7 +677,7 @@ func (bsnc *BaseSecondaryNetworkController) AddNamespaceForSecondaryNetwork(ns * klog.Infof("[%s] adding namespace took %v for network %s", ns.Name, time.Since(start), bsnc.GetNetworkName()) }() - _, nsUnlock, err := bsnc.ensureNamespaceLockedForSecondaryNetwork(ns.Name, false, ns) + _, nsUnlock, err := bsnc.ensureNamespaceLockedForUserDefinedNetwork(ns.Name, false, ns) if err != nil { return fmt.Errorf("failed to ensure namespace locked: %v", err) } @@ -693,14 +693,14 @@ func (bsnc *BaseSecondaryNetworkController) AddNamespaceForSecondaryNetwork(ns * return nil } -// ensureNamespaceLockedForSecondaryNetwork locks namespacesMutex, gets/creates an entry for ns, configures OVN nsInfo, +// ensureNamespaceLockedForUserDefinedNetwork locks namespacesMutex, gets/creates an entry for ns, configures OVN nsInfo, // and returns it with its mutex locked. // ns is the name of the namespace, while namespace is the optional k8s namespace object -func (bsnc *BaseSecondaryNetworkController) ensureNamespaceLockedForSecondaryNetwork(ns string, readOnly bool, namespace *corev1.Namespace) (*namespaceInfo, func(), error) { +func (bsnc *BaseUserDefinedNetworkController) ensureNamespaceLockedForUserDefinedNetwork(ns string, readOnly bool, namespace *corev1.Namespace) (*namespaceInfo, func(), error) { return bsnc.ensureNamespaceLockedCommon(ns, readOnly, namespace, bsnc.getAllNamespacePodAddresses, bsnc.configureNamespaceCommon) } -func (bsnc *BaseSecondaryNetworkController) updateNamespaceForSecondaryNetwork(old, newer *corev1.Namespace) error { +func (bsnc *BaseUserDefinedNetworkController) updateNamespaceForUserDefinedNetwork(old, newer *corev1.Namespace) error { var errors []error klog.Infof("[%s] updating namespace for network %s", old.Name, bsnc.GetNetworkName()) @@ -726,7 +726,7 @@ func (bsnc *BaseSecondaryNetworkController) updateNamespaceForSecondaryNetwork(o return utilerrors.Join(errors...) } -func (bsnc *BaseSecondaryNetworkController) deleteNamespace4SecondaryNetwork(ns *corev1.Namespace) error { +func (bsnc *BaseUserDefinedNetworkController) deleteNamespaceForUserDefinedNetwork(ns *corev1.Namespace) error { klog.Infof("[%s] deleting namespace for network %s", ns.Name, bsnc.GetNetworkName()) nsInfo, err := bsnc.deleteNamespaceLocked(ns.Name) @@ -746,7 +746,7 @@ func (bsnc *BaseSecondaryNetworkController) deleteNamespace4SecondaryNetwork(ns // WatchNetworkPolicy starts the watching of networkpolicy resource and calls // back the appropriate handler logic -func (bsnc *BaseSecondaryNetworkController) WatchNetworkPolicy() error { +func (bsnc *BaseUserDefinedNetworkController) WatchNetworkPolicy() error { if bsnc.netPolicyHandler != nil { return nil } @@ -760,7 +760,7 @@ func (bsnc *BaseSecondaryNetworkController) WatchNetworkPolicy() error { // WatchMultiNetworkPolicy starts the watching of multinetworkpolicy resource and calls // back the appropriate handler logic -func (bsnc *BaseSecondaryNetworkController) WatchMultiNetworkPolicy() error { +func (bsnc *BaseUserDefinedNetworkController) WatchMultiNetworkPolicy() error { if bsnc.multiNetPolicyHandler != nil { return nil } @@ -795,7 +795,7 @@ func cleanupPolicyLogicalEntities(nbClient libovsdbclient.Client, ops []ovsdb.Op // WatchIPAMClaims starts the watching of IPAMClaim resources and calls // back the appropriate handler logic -func (bsnc *BaseSecondaryNetworkController) WatchIPAMClaims() error { +func (bsnc *BaseUserDefinedNetworkController) WatchIPAMClaims() error { if bsnc.ipamClaimsHandler != nil { return nil } @@ -806,7 +806,7 @@ func (bsnc *BaseSecondaryNetworkController) WatchIPAMClaims() error { return err } -func (oc *BaseSecondaryNetworkController) allowPersistentIPs() bool { +func (oc *BaseUserDefinedNetworkController) allowPersistentIPs() bool { return config.OVNKubernetesFeature.EnablePersistentIPs && util.DoesNetworkRequireIPAM(oc.GetNetInfo()) && util.AllowsPersistentIPs(oc.GetNetInfo()) @@ -814,7 +814,7 @@ func (oc *BaseSecondaryNetworkController) allowPersistentIPs() bool { // buildUDNEgressSNAT is used to build the conditional SNAT required on L3 and L2 UDNs to // steer traffic correctly via mp0 when leaving OVN to the host -func (bsnc *BaseSecondaryNetworkController) buildUDNEgressSNAT(localPodSubnets []*net.IPNet, outputPort string, isUDNAdvertised bool) ([]*nbdb.NAT, error) { +func (bsnc *BaseUserDefinedNetworkController) buildUDNEgressSNAT(localPodSubnets []*net.IPNet, outputPort string, isUDNAdvertised bool) ([]*nbdb.NAT, error) { if len(localPodSubnets) == 0 { return nil, nil // nothing to do } @@ -920,7 +920,7 @@ func getClusterNodesDestinationBasedSNATMatch(ipFamily utilnet.IPFamily, address } } -func (bsnc *BaseSecondaryNetworkController) ensureDHCP(pod *corev1.Pod, podAnnotation *util.PodAnnotation, lsp *nbdb.LogicalSwitchPort) error { +func (bsnc *BaseUserDefinedNetworkController) ensureDHCP(pod *corev1.Pod, podAnnotation *util.PodAnnotation, lsp *nbdb.LogicalSwitchPort) error { opts := []kubevirt.DHCPConfigsOpt{} ipv4DNSServer, ipv6DNSServer, err := kubevirt.RetrieveDNSServiceClusterIPs(bsnc.watchFactory) @@ -942,7 +942,7 @@ func (bsnc *BaseSecondaryNetworkController) ensureDHCP(pod *corev1.Pod, podAnnot return kubevirt.EnsureDHCPOptionsForLSP(bsnc.controllerName, bsnc.nbClient, pod, podAnnotation.IPs, lsp, opts...) } -func (bsnc *BaseSecondaryNetworkController) requireDHCP(pod *corev1.Pod) bool { +func (bsnc *BaseUserDefinedNetworkController) requireDHCP(pod *corev1.Pod) bool { // Configure DHCP only for kubevirt VMs layer2 primary udn with subnets return kubevirt.IsPodOwnedByVirtualMachine(pod) && util.IsNetworkSegmentationSupportEnabled() && @@ -950,7 +950,7 @@ func (bsnc *BaseSecondaryNetworkController) requireDHCP(pod *corev1.Pod) bool { bsnc.TopologyType() == types.Layer2Topology } -func (bsnc *BaseSecondaryNetworkController) setPodLogicalSwitchPortAddressesAndEnabledField( +func (bsnc *BaseUserDefinedNetworkController) setPodLogicalSwitchPortAddressesAndEnabledField( pod *corev1.Pod, nadName string, mac string, ips []string, enabled bool, ops []ovsdb.Operation) ([]ovsdb.Operation, *nbdb.LogicalSwitchPort, error) { lsp := &nbdb.LogicalSwitchPort{Name: bsnc.GetLogicalPortName(pod, nadName)} lsp.Enabled = ptr.To(enabled) @@ -985,7 +985,7 @@ func (bsnc *BaseSecondaryNetworkController) setPodLogicalSwitchPortAddressesAndE return ops, lsp, nil } -func (bsnc *BaseSecondaryNetworkController) disableLiveMigrationSourceLSPOps( +func (bsnc *BaseUserDefinedNetworkController) disableLiveMigrationSourceLSPOps( kubevirtLiveMigrationStatus *kubevirt.LiveMigrationStatus, nadName string, ops []ovsdb.Operation) ([]ovsdb.Operation, error) { // closing the sourcePod lsp to ensure traffic goes to the now ready targetPod. @@ -993,7 +993,7 @@ func (bsnc *BaseSecondaryNetworkController) disableLiveMigrationSourceLSPOps( return ops, err } -func (bsnc *BaseSecondaryNetworkController) enableSourceLSPFailedLiveMigration(pod *corev1.Pod, nadName string, mac string, ips []string) error { +func (bsnc *BaseUserDefinedNetworkController) enableSourceLSPFailedLiveMigration(pod *corev1.Pod, nadName string, mac string, ips []string) error { kubevirtLiveMigrationStatus, err := kubevirt.DiscoverLiveMigrationStatus(bsnc.watchFactory, pod) if err != nil { return fmt.Errorf("failed to discover Live-migration status after pod termination: %w", err) diff --git a/go-controller/pkg/ovn/base_network_controller_secondary_test.go b/go-controller/pkg/ovn/base_network_controller_user_defined_test.go similarity index 95% rename from go-controller/pkg/ovn/base_network_controller_secondary_test.go rename to go-controller/pkg/ovn/base_network_controller_user_defined_test.go index 94e6347c28..7c38669c14 100644 --- a/go-controller/pkg/ovn/base_network_controller_secondary_test.go +++ b/go-controller/pkg/ovn/base_network_controller_user_defined_test.go @@ -20,7 +20,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("BaseSecondaryNetworkController", func() { +var _ = Describe("BaseUserDefinedNetworkController", func() { var ( nad = ovntest.GenerateNAD("bluenet", "rednad", "greenamespace", types.Layer3Topology, "100.128.0.0/16", types.NetworkRolePrimary) @@ -79,8 +79,8 @@ var _ = Describe("BaseSecondaryNetworkController", func() { ) defer fakeOVN.shutdown() - Expect(fakeOVN.NewSecondaryNetworkController(layer2NAD)).To(Succeed()) - controller, ok := fakeOVN.secondaryControllers["bluenet"] + Expect(fakeOVN.NewUserDefinedNetworkController(layer2NAD)).To(Succeed()) + controller, ok := fakeOVN.userDefinedNetworkControllers["bluenet"] Expect(ok).To(BeTrue()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -221,8 +221,8 @@ var _ = Describe("BaseSecondaryNetworkController", func() { }, }, ) - Expect(fakeOVN.NewSecondaryNetworkController(nad)).To(Succeed()) - controller, ok := fakeOVN.secondaryControllers["bluenet"] + Expect(fakeOVN.NewUserDefinedNetworkController(nad)).To(Succeed()) + controller, ok := fakeOVN.userDefinedNetworkControllers["bluenet"] Expect(ok).To(BeTrue()) // inject a real networkManager instead of a fake one, so getActiveNetworkForNamespace will get called nadController, err := networkmanager.NewForZone("dummyZone", nil, fakeOVN.watcher) @@ -240,7 +240,7 @@ var _ = Describe("BaseSecondaryNetworkController", func() { var initialPodList []interface{} initialPodList = append(initialPodList, podWithNoNamespace) - err = controller.bnc.syncPodsForSecondaryNetwork(initialPodList) + err = controller.bnc.syncPodsForUserDefinedNetwork(initialPodList) Expect(err).NotTo(HaveOccurred()) }) diff --git a/go-controller/pkg/ovn/base_secondary_layer2_network_controller.go b/go-controller/pkg/ovn/base_secondary_layer2_network_controller.go index 83676df950..421314586b 100644 --- a/go-controller/pkg/ovn/base_secondary_layer2_network_controller.go +++ b/go-controller/pkg/ovn/base_secondary_layer2_network_controller.go @@ -18,14 +18,14 @@ import ( // method/structure shared by all layer 2 network controller, including localnet and layer2 network controllres. -// BaseSecondaryLayer2NetworkController structure holds per-network fields and network specific +// BaseLayer2UserDefinedNetworkController structure holds per-network fields and network specific // configuration for secondary layer2/localnet network controller -type BaseSecondaryLayer2NetworkController struct { - BaseSecondaryNetworkController +type BaseLayer2UserDefinedNetworkController struct { + BaseUserDefinedNetworkController } // stop gracefully stops the controller, and delete all logical entities for this network if requested -func (oc *BaseSecondaryLayer2NetworkController) stop() { +func (oc *BaseLayer2UserDefinedNetworkController) stop() { klog.Infof("Stop secondary %s network controller of network %s", oc.TopologyType(), oc.GetNetworkName()) close(oc.stopChan) oc.cancelableCtx.Cancel() @@ -56,7 +56,7 @@ func (oc *BaseSecondaryLayer2NetworkController) stop() { // cleanup cleans up logical entities for the given network, called from net-attach-def routine // could be called from a dummy Controller (only has CommonNetworkControllerInfo set) -func (oc *BaseSecondaryLayer2NetworkController) cleanup() error { +func (oc *BaseLayer2UserDefinedNetworkController) cleanup() error { netName := oc.GetNetworkName() klog.Infof("Delete OVN logical entities for network %s", netName) // delete layer 2 logical switches @@ -97,7 +97,7 @@ func (oc *BaseSecondaryLayer2NetworkController) cleanup() error { return nil } -func (oc *BaseSecondaryLayer2NetworkController) run() error { +func (oc *BaseLayer2UserDefinedNetworkController) run() error { // WatchNamespaces() should be started first because it has no other // dependencies, and WatchNodes() depends on it if err := oc.WatchNamespaces(); err != nil { @@ -161,7 +161,7 @@ func (oc *BaseSecondaryLayer2NetworkController) run() error { return nil } -func (oc *BaseSecondaryLayer2NetworkController) initializeLogicalSwitch(switchName string, clusterSubnets []config.CIDRNetworkEntry, excludeSubnets, reservedSubnets []*net.IPNet, clusterLoadBalancerGroupUUID, switchLoadBalancerGroupUUID string) (*nbdb.LogicalSwitch, error) { +func (oc *BaseLayer2UserDefinedNetworkController) initializeLogicalSwitch(switchName string, clusterSubnets []config.CIDRNetworkEntry, excludeSubnets, reservedSubnets []*net.IPNet, clusterLoadBalancerGroupUUID, switchLoadBalancerGroupUUID string) (*nbdb.LogicalSwitch, error) { logicalSwitch := nbdb.LogicalSwitch{ Name: switchName, ExternalIDs: util.GenerateExternalIDsForSwitchOrRouter(oc.GetNetInfo()), @@ -201,14 +201,14 @@ func (oc *BaseSecondaryLayer2NetworkController) initializeLogicalSwitch(switchNa return &logicalSwitch, nil } -func (oc *BaseSecondaryLayer2NetworkController) addUpdateNodeEvent(node *corev1.Node) error { +func (oc *BaseLayer2UserDefinedNetworkController) addUpdateNodeEvent(node *corev1.Node) error { if oc.isLocalZoneNode(node) { return oc.addUpdateLocalNodeEvent(node) } return oc.addUpdateRemoteNodeEvent(node) } -func (oc *BaseSecondaryLayer2NetworkController) addUpdateLocalNodeEvent(node *corev1.Node) error { +func (oc *BaseLayer2UserDefinedNetworkController) addUpdateLocalNodeEvent(node *corev1.Node) error { _, present := oc.localZoneNodes.LoadOrStore(node.Name, true) if !present { @@ -223,7 +223,7 @@ func (oc *BaseSecondaryLayer2NetworkController) addUpdateLocalNodeEvent(node *co return nil } -func (oc *BaseSecondaryLayer2NetworkController) addUpdateRemoteNodeEvent(node *corev1.Node) error { +func (oc *BaseLayer2UserDefinedNetworkController) addUpdateRemoteNodeEvent(node *corev1.Node) error { _, present := oc.localZoneNodes.Load(node.Name) if present { @@ -243,12 +243,12 @@ func (oc *BaseSecondaryLayer2NetworkController) addUpdateRemoteNodeEvent(node *c return nil } -func (oc *BaseSecondaryLayer2NetworkController) deleteNodeEvent(node *corev1.Node) error { +func (oc *BaseLayer2UserDefinedNetworkController) deleteNodeEvent(node *corev1.Node) error { oc.localZoneNodes.Delete(node.Name) return nil } -func (oc *BaseSecondaryLayer2NetworkController) syncNodes(nodes []interface{}) error { +func (oc *BaseLayer2UserDefinedNetworkController) syncNodes(nodes []interface{}) error { for _, tmp := range nodes { node, ok := tmp.(*corev1.Node) if !ok { @@ -264,7 +264,7 @@ func (oc *BaseSecondaryLayer2NetworkController) syncNodes(nodes []interface{}) e return nil } -func (oc *BaseSecondaryLayer2NetworkController) syncIPAMClaims(ipamClaims []interface{}) error { +func (oc *BaseLayer2UserDefinedNetworkController) syncIPAMClaims(ipamClaims []interface{}) error { switchName, err := oc.getExpectedSwitchName(dummyPod()) if err != nil { return err diff --git a/go-controller/pkg/ovn/controller/admin_network_policy/admin_network_policy_controller.go b/go-controller/pkg/ovn/controller/admin_network_policy/admin_network_policy_controller.go index 080dd22d19..ed0ad36356 100644 --- a/go-controller/pkg/ovn/controller/admin_network_policy/admin_network_policy_controller.go +++ b/go-controller/pkg/ovn/controller/admin_network_policy/admin_network_policy_controller.go @@ -43,7 +43,6 @@ const ( // taken from k8s controller guidelines type Controller struct { // name of the controller that starts the ANP controller - // (values are default-network-controller, secondary-network-controller etc..) controllerName string sync.RWMutex anpClientSet anpclientset.Interface diff --git a/go-controller/pkg/ovn/controller/network_qos/network_qos.go b/go-controller/pkg/ovn/controller/network_qos/network_qos.go index 6f8f247541..04b9ceef9d 100644 --- a/go-controller/pkg/ovn/controller/network_qos/network_qos.go +++ b/go-controller/pkg/ovn/controller/network_qos/network_qos.go @@ -337,7 +337,7 @@ func (c *Controller) networkManagedByMe(networkSelectors crdtypes.NetworkSelecto return false, err } case crdtypes.SecondaryUserDefinedNetworks: - if !c.IsSecondary() { + if !c.IsUserDefinedNetwork() { return false, nil } if networkSelector.SecondaryUserDefinedNetworkSelector == nil { @@ -395,7 +395,7 @@ func (c *Controller) getLogicalSwitchName(nodeName string) string { return c.GetNetworkScopedSwitchName(types.OVNLayer2Switch) case c.TopologyType() == types.LocalnetTopology: return c.GetNetworkScopedSwitchName(types.OVNLocalnetSwitch) - case !c.IsSecondary() || c.TopologyType() == types.Layer3Topology: + case !c.IsUserDefinedNetwork() || c.TopologyType() == types.Layer3Topology: return c.GetNetworkScopedSwitchName(nodeName) default: return "" diff --git a/go-controller/pkg/ovn/controller/network_qos/network_qos_ovnnb.go b/go-controller/pkg/ovn/controller/network_qos/network_qos_ovnnb.go index febc4d1953..06d75719b5 100644 --- a/go-controller/pkg/ovn/controller/network_qos/network_qos_ovnnb.go +++ b/go-controller/pkg/ovn/controller/network_qos/network_qos_ovnnb.go @@ -45,7 +45,7 @@ func (c *Controller) addQoSToLogicalSwitch(qosState *networkQoSState, switchName Match: generateNetworkQoSMatch(qosState, rule, ipv4Enabled, ipv6Enabled), Priority: rule.Priority, } - if c.IsSecondary() { + if c.IsUserDefinedNetwork() { qos.ExternalIDs[types.NetworkExternalID] = c.GetNetworkName() } if rule.Dscp >= 0 { diff --git a/go-controller/pkg/ovn/controller/network_qos/network_qos_test.go b/go-controller/pkg/ovn/controller/network_qos/network_qos_test.go index 4d771825ed..4b79f1198b 100644 --- a/go-controller/pkg/ovn/controller/network_qos/network_qos_test.go +++ b/go-controller/pkg/ovn/controller/network_qos/network_qos_test.go @@ -44,7 +44,7 @@ func (n *primaryNetInfoWrapper) IsPrimaryNetwork() bool { return true } -func (n *primaryNetInfoWrapper) IsSecondary() bool { +func (n *primaryNetInfoWrapper) IsUserDefinedNetwork() bool { return false } @@ -64,7 +64,7 @@ func (n *secondaryNetInfoWrapper) IsPrimaryNetwork() bool { return false } -func (n *secondaryNetInfoWrapper) IsSecondary() bool { +func (n *secondaryNetInfoWrapper) IsUserDefinedNetwork() bool { return true } @@ -1011,7 +1011,7 @@ var _ = Describe("NetworkQoS Controller", func() { err = libovsdbops.CreateOrUpdateLogicalSwitch(nbClient, secondarySwitch) Expect(err).NotTo(HaveOccurred()) - // Wrap the NetInfo with our custom implementation that returns true for IsSecondary() + // Wrap the NetInfo with our custom implementation that returns true for IsUserDefinedNetwork() secNetWrapper := &secondaryNetInfoWrapper{NetInfo: secondaryNadInfo} initNetworkQoSController(secNetWrapper, addressset.NewFakeAddressSetFactory("secondary-controller"), "secondary-controller", enableInterconnect) diff --git a/go-controller/pkg/ovn/egressip.go b/go-controller/pkg/ovn/egressip.go index 9bc430d1fd..31a48d0c99 100644 --- a/go-controller/pkg/ovn/egressip.go +++ b/go-controller/pkg/ovn/egressip.go @@ -809,7 +809,7 @@ func (e *EgressIPController) addPodEgressIPAssignments(ni util.NetInfo, name str } var remainingAssignments []egressipv1.EgressIPStatusItem nadName := ni.GetNetworkName() - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { nadNames := ni.GetNADs() if len(nadNames) == 0 { return fmt.Errorf("expected at least one NAD name for Namespace %s", pod.Namespace) @@ -1160,7 +1160,7 @@ type egressIPCache struct { egressNodeRedirectsCache nodeNetworkRedirects // network name -> OVN cluster router name networkToRouter map[string]string - // packet mark for primary secondary networks + // packet mark for primary UDNs // EgressIP name -> mark markCache map[string]string } @@ -2002,7 +2002,7 @@ func (e *EgressIPController) generateCacheForEgressIP() (egressIPCache, error) { egressRemotePods: map[string]sets.Set[string]{}, } nadName := types.DefaultNetworkName - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { nadNames := ni.GetNADs() if len(nadNames) == 0 { klog.Errorf("Network %s: error build egress IP sync cache, expected at least one NAD name for Namespace %s", ni.GetNetworkName(), namespace.Name) @@ -2306,7 +2306,7 @@ func (e *EgressIPController) addStandByEgressIPAssignment(ni util.NetInfo, podKe continue } eipToAssign = eipName // use the first EIP we find successfully - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { mark = getEgressIPPktMark(eip.Name, eip.Annotations) } break @@ -2317,7 +2317,7 @@ func (e *EgressIPController) addStandByEgressIPAssignment(ni util.NetInfo, podKe } // get IPs nadName := ni.GetNetworkName() - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { nadNames := ni.GetNADs() if len(nadNames) == 0 { return fmt.Errorf("expected at least one NAD name for Namespace %s", pod.Namespace) @@ -2400,7 +2400,7 @@ func (e *EgressIPController) addPodEgressIPAssignment(ni util.NetInfo, egressIPN return fmt.Errorf("unable to create NAT rule ops for status: %v, err: %v", status, err) } - } else if ni.IsSecondary() && ni.TopologyType() == types.Layer3Topology { + } else if ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer3Topology { // not required for L2 because we always have LRPs using reroute action to pkt mark ops, err = e.createGWMarkPolicyOps(ni, ops, podIPs, status, mark, pod.Namespace, pod.Name, egressIPName) if err != nil { @@ -2424,7 +2424,7 @@ func (e *EgressIPController) addPodEgressIPAssignment(ni util.NetInfo, egressIPN // For L2, we always attach an LRP with reroute action to the Nodes gateway router. If the pod is remote, use the local zone Node name to generate the GW router name. nodeName := pod.Spec.NodeName - if loadedEgressNode && loadedPodNode && !isLocalZonePod && isLocalZoneEgressNode && ni.IsSecondary() && ni.TopologyType() == types.Layer2Topology { + if loadedEgressNode && loadedPodNode && !isLocalZonePod && isLocalZoneEgressNode && ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer2Topology { nodeName = status.Node } routerName, err := getTopologyScopedRouterName(ni, nodeName) @@ -2435,7 +2435,7 @@ func (e *EgressIPController) addPodEgressIPAssignment(ni util.NetInfo, egressIPN // exec when node is local OR when pods are local or L2 UDN // don't add a reroute policy if the egress node towards which we are adding this doesn't exist if loadedEgressNode && loadedPodNode { - if isLocalZonePod || (isLocalZoneEgressNode && ni.IsSecondary() && ni.TopologyType() == types.Layer2Topology) { + if isLocalZonePod || (isLocalZoneEgressNode && ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer2Topology) { ops, err = e.createReroutePolicyOps(ni, ops, podIPs, status, mark, egressIPName, nextHopIP, routerName, pod.Namespace, pod.Name) if err != nil { return fmt.Errorf("unable to create logical router policy ops, err: %v", err) @@ -2492,7 +2492,7 @@ func (e *EgressIPController) deletePodEgressIPAssignment(ni util.NetInfo, egress } // For L2, we always attach an LRP with reroute action to the Nodes gateway router. If the pod is remote, use the local zone Node name to generate the GW router name. nodeName := pod.Spec.NodeName - if !isLocalZonePod && isLocalZoneEgressNode && ni.IsSecondary() && ni.TopologyType() == types.Layer2Topology { + if !isLocalZonePod && isLocalZoneEgressNode && ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer2Topology { nodeName = status.Node } routerName, err := getTopologyScopedRouterName(ni, nodeName) @@ -2511,7 +2511,7 @@ func (e *EgressIPController) deletePodEgressIPAssignment(ni util.NetInfo, egress // Case 1 - node where pod is hosted is not known // Case 2 - pod is within the local zone // case 3 - a local zone node is egress node and pod is attached to layer 2. For layer2, there is always an LRP attached to the egress Node GW router - if !loadedPodNode || isLocalZonePod || (isLocalZoneEgressNode && ni.IsSecondary() && ni.TopologyType() == types.Layer2Topology) { + if !loadedPodNode || isLocalZonePod || (isLocalZoneEgressNode && ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer2Topology) { ops, err = e.deleteReroutePolicyOps(ni, ops, status, egressIPName, nextHopIP, routerName, pod.Namespace, pod.Name) if errors.Is(err, libovsdbclient.ErrNotFound) { // if the gateway router join IP setup is already gone, then don't count it as error. @@ -2534,7 +2534,7 @@ func (e *EgressIPController) deletePodEgressIPAssignment(ni util.NetInfo, egress if err != nil { return fmt.Errorf("unable to delete NAT rule for status: %v, err: %v", status, err) } - } else if ni.IsSecondary() && ni.TopologyType() == types.Layer3Topology { + } else if ni.IsUserDefinedNetwork() && ni.TopologyType() == types.Layer3Topology { ops, err = e.deleteGWMarkPolicyOps(ni, ops, status, pod.Namespace, pod.Name, egressIPName) if err != nil { return fmt.Errorf("unable to create GW router packet mark LRPs delete ops for pod %s/%s: %v", pod.Namespace, pod.Name, err) @@ -2797,7 +2797,7 @@ func (e *EgressIPController) getNextHop(ni util.NetInfo, egressNodeName, egressI return gatewayRouterIP.String(), nil } else { // for an egress IP assigned to a host secondary interface, next hop IP is the networks management port IP - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { return "", fmt.Errorf("egress IP assigned to a host secondary interface for a user defined network (network name %s) is unsupported", ni.GetNetworkName()) } return e.getLocalMgmtPortNextHop(ni, egressNodeName, egressIPName, egressIP, isEgressIPv6) @@ -2835,7 +2835,7 @@ func (e *EgressIPController) createReroutePolicyOps(ni util.NetInfo, ops []ovsdb isEgressIPv6 := utilnet.IsIPv6String(status.EgressIP) ipFamily := getEIPIPFamily(isEgressIPv6) options := make(map[string]string) - if ni.IsSecondary() { + if ni.IsUserDefinedNetwork() { if !mark.IsAvailable() { return nil, fmt.Errorf("egressIP %s object must contain a mark for user defined networks", egressIPName) } @@ -3034,7 +3034,7 @@ func (e *EgressIPController) deleteEgressIPStatusSetup(ni util.NetInfo, name str if err != nil { return fmt.Errorf("error removing egress ip %s nats on router %s: %v", name, routerName, err) } - } else if ni.IsSecondary() { + } else if ni.IsUserDefinedNetwork() { if ops, err = e.deleteGWMarkPolicyForStatusOps(ni, ops, status, name); err != nil { return fmt.Errorf("failed to delete gateway mark policy: %v", err) } @@ -3591,7 +3591,7 @@ func (e *EgressIPController) getPodIPs(ni util.NetInfo, pod *corev1.Pod, nadName return nil, fmt.Errorf("failed to get pod %s/%s IPs", pod.Namespace, pod.Name) } podIPs = getIPFromIPNetFn(podIPNets) - } else if ni.IsSecondary() { + } else if ni.IsUserDefinedNetwork() { podIPNets := util.GetPodCIDRsWithFullMaskOfNetwork(pod, nadName) if len(podIPNets) == 0 { return nil, fmt.Errorf("failed to get pod %s/%s IPs", pod.Namespace, pod.Name) diff --git a/go-controller/pkg/ovn/egressip_udn_l2_test.go b/go-controller/pkg/ovn/egressip_udn_l2_test.go index 577e9d7646..581992ab6b 100644 --- a/go-controller/pkg/ovn/egressip_udn_l2_test.go +++ b/go-controller/pkg/ovn/egressip_udn_l2_test.go @@ -61,7 +61,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol layer2SwitchName = "ovn_layer2_switch" gwIP = "192.168.126.1" gwIP2 = "192.168.127.1" - secondaryNetworkID = "2" + userDefinedNetworkID = "2" ) getEgressIPStatusLen := func(egressIPName string) func() int { @@ -156,7 +156,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -524,7 +524,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -662,14 +662,14 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol fakeOvn.controller.zone = node1.Name fakeOvn.eIPController.zone = node1.Name fakeOvn.controller.logicalPortCache.add(&egressPodCDNLocal, "", ovntypes.DefaultNetworkName, "", nil, []*net.IPNet{nCDN}) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) fakeOvn.controller.eIPC.nodeZoneState.Store(node1Name, true) fakeOvn.controller.eIPC.nodeZoneState.Store(node2Name, false) err = fakeOvn.networkManager.Start() gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer fakeOvn.networkManager.Stop() - // simulate Start() of secondary network controller + // simulate Start() of UDN controller err = fakeOvn.eIPController.ensureRouterPoliciesForNetwork(secConInfo.bnc.GetNetInfo(), &node1) gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.eIPController.ensureSwitchPoliciesForNode(secConInfo.bnc.GetNetInfo(), node1Name) @@ -1030,7 +1030,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -1181,7 +1181,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) // Add pod IPs to UDN cache iUDN, nUDN, _ := net.ParseCIDR(v4Pod1IPNode1Net1 + "/23") @@ -1512,7 +1512,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -1672,7 +1672,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) // Add pod IPs to UDN cache iUDN, nUDN, _ := net.ParseCIDR(v4Pod1IPNode1Net1 + "/23") @@ -1876,7 +1876,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -2229,7 +2229,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -2383,7 +2383,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) // Add pod IPs to UDN cache iUDN, nUDN, _ := net.ParseCIDR(v4Pod1IPNode1Net1 + "/23") @@ -2597,7 +2597,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -2734,7 +2734,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol fakeOvn.controller.logicalPortCache.add(&egressPodCDNLocal, "", ovntypes.DefaultNetworkName, "", nil, []*net.IPNet{nCDN}) fakeOvn.controller.zone = node1Name fakeOvn.eIPController.zone = node1Name - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) err = fakeOvn.eIPController.SyncLocalNodeZonesCache() gomega.Expect(err).NotTo(gomega.HaveOccurred()) diff --git a/go-controller/pkg/ovn/egressip_udn_l3_test.go b/go-controller/pkg/ovn/egressip_udn_l3_test.go index 02b04f938d..28035e8374 100644 --- a/go-controller/pkg/ovn/egressip_udn_l3_test.go +++ b/go-controller/pkg/ovn/egressip_udn_l3_test.go @@ -41,26 +41,26 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol ) const ( - nadName1 = "nad1" - networkName1 = "network1" - networkName1_ = networkName1 + "_" - node1Name = "node1" - v4Net1 = "20.128.0.0/14" - v4Node1Net1 = "20.128.0.0/16" - v4Pod1IPNode1Net1 = "20.128.0.5" - podName3 = "egress-pod3" - v4Pod2IPNode1Net1 = "20.128.0.6" - v4Node1Tsp = "100.88.0.2" - node2Name = "node2" - v4Node2Net1 = "20.129.0.0/16" - v4Node2Tsp = "100.88.0.3" - podName4 = "egress-pod4" - v4Pod1IPNode2Net1 = "20.129.0.2" - v4Pod2IPNode2Net1 = "20.129.0.3" - eIP1Mark = 50000 - eIP2Mark = 50001 - secondaryNetworkID = "2" - //tnlKey = zoneinterconnect.BaseTransitSwitchTunnelKey + secondaryNetworkID + nadName1 = "nad1" + networkName1 = "network1" + networkName1_ = networkName1 + "_" + node1Name = "node1" + v4Net1 = "20.128.0.0/14" + v4Node1Net1 = "20.128.0.0/16" + v4Pod1IPNode1Net1 = "20.128.0.5" + podName3 = "egress-pod3" + v4Pod2IPNode1Net1 = "20.128.0.6" + v4Node1Tsp = "100.88.0.2" + node2Name = "node2" + v4Node2Net1 = "20.129.0.0/16" + v4Node2Tsp = "100.88.0.3" + podName4 = "egress-pod4" + v4Pod1IPNode2Net1 = "20.129.0.2" + v4Pod2IPNode2Net1 = "20.129.0.3" + eIP1Mark = 50000 + eIP2Mark = 50001 + userDefinedNetworkID = "2" + //tnlKey = zoneinterconnect.BaseTransitSwitchTunnelKey + userDefinedNetworkID tnlKey = "16711685" ) @@ -157,7 +157,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -534,7 +534,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -672,14 +672,14 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol fakeOvn.controller.zone = node1.Name fakeOvn.eIPController.zone = node1.Name fakeOvn.controller.logicalPortCache.add(&egressPodCDNLocal, "", ovntypes.DefaultNetworkName, "", nil, []*net.IPNet{nCDN}) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) fakeOvn.controller.eIPC.nodeZoneState.Store(node1Name, true) fakeOvn.controller.eIPC.nodeZoneState.Store(node2Name, false) err = fakeOvn.networkManager.Start() gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer fakeOvn.networkManager.Stop() - // simulate Start() of secondary network controller + // simulate Start() of UDN controller err = fakeOvn.eIPController.ensureRouterPoliciesForNetwork(secConInfo.bnc.GetNetInfo(), &node1) gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.eIPController.ensureSwitchPoliciesForNode(secConInfo.bnc.GetNetInfo(), node1Name) @@ -1055,7 +1055,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -1204,7 +1204,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) // Add pod IPs to UDN cache iUDN, nUDN, _ := net.ParseCIDR(v4Pod1IPNode1Net1 + "/23") @@ -1791,7 +1791,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -1949,7 +1949,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) // Add pod IPs to UDN cache iUDN, nUDN, _ := net.ParseCIDR(v4Pod1IPNode1Net1 + "/23") @@ -2161,7 +2161,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -2522,7 +2522,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol netconf, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} netInfo, err := util.NewNetInfo(&netconf) gomega.Expect(err).NotTo(gomega.HaveOccurred()) @@ -2674,7 +2674,7 @@ var _ = ginkgo.Describe("EgressIP Operations for user defined network with topol gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchEgressIP() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - secConInfo, ok := fakeOvn.secondaryControllers[networkName1] + secConInfo, ok := fakeOvn.userDefinedNetworkControllers[networkName1] gomega.Expect(ok).To(gomega.BeTrue()) secConInfo.bnc.zone = node1.Name gomega.Expect(secConInfo.bnc.WatchNodes()).To(gomega.Succeed()) diff --git a/go-controller/pkg/ovn/external_ids_syncer/logical_router_policy/logical_router_policy_sync.go b/go-controller/pkg/ovn/external_ids_syncer/logical_router_policy/logical_router_policy_sync.go index 01808d3927..84586aa6b4 100644 --- a/go-controller/pkg/ovn/external_ids_syncer/logical_router_policy/logical_router_policy_sync.go +++ b/go-controller/pkg/ovn/external_ids_syncer/logical_router_policy/logical_router_policy_sync.go @@ -139,7 +139,7 @@ func (ps podsNetInfo) getPod(ip net.IP) (podNetInfo, error) { func (syncer *LRPSyncer) buildCDNPodCache() (podsNetInfo, podsNetInfo, error) { p := func(item *nbdb.LogicalSwitchPort) bool { - return item.ExternalIDs["pod"] == "true" && item.ExternalIDs[ovntypes.NADExternalID] == "" // ignore secondary network LSPs + return item.ExternalIDs["pod"] == "true" && item.ExternalIDs[ovntypes.NADExternalID] == "" // ignore UDN LSPs } lsps, err := libovsdbops.FindLogicalSwitchPortWithPredicate(syncer.nbClient, p) if err != nil { diff --git a/go-controller/pkg/ovn/external_ids_syncer/nat/nat_sync.go b/go-controller/pkg/ovn/external_ids_syncer/nat/nat_sync.go index ba81787817..f93862cb3a 100644 --- a/go-controller/pkg/ovn/external_ids_syncer/nat/nat_sync.go +++ b/go-controller/pkg/ovn/external_ids_syncer/nat/nat_sync.go @@ -124,7 +124,7 @@ func (n *NATSyncer) syncEgressIPNATs() error { func (n *NATSyncer) buildPodCache() (podsNetInfo, podsNetInfo, error) { p := func(item *nbdb.LogicalSwitchPort) bool { - return item.ExternalIDs["pod"] == "true" && item.ExternalIDs[ovntypes.NADExternalID] == "" // ignore secondary network LSPs + return item.ExternalIDs["pod"] == "true" && item.ExternalIDs[ovntypes.NADExternalID] == "" // ignore UDN LSPs } lsps, err := libovsdbops.FindLogicalSwitchPortWithPredicate(n.nbClient, p) if err != nil { diff --git a/go-controller/pkg/ovn/gateway.go b/go-controller/pkg/ovn/gateway.go index a6ce3704fb..4c4f63d3fa 100644 --- a/go-controller/pkg/ovn/gateway.go +++ b/go-controller/pkg/ovn/gateway.go @@ -282,7 +282,7 @@ func (gw *GatewayManager) createGWRouter(l3GatewayConfig *util.L3GatewayConfig, "physical_ips": strings.Join(physicalIPs, ","), } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { maps.Copy(logicalRouterExternalIDs, util.GenerateExternalIDsForSwitchOrRouter(gw.netInfo)) } @@ -344,7 +344,7 @@ func (gw *GatewayManager) createGWRouterPeerPort(nodeName string) error { libovsdbops.RouterPort: gwRouterPortName, }, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { logicalSwitchPort.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -408,7 +408,7 @@ func (gw *GatewayManager) createGWRouterPort(hostSubnets []*net.IPNet, gwLRPJoin Networks: gwLRPNetworks, Options: options, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { gwRouterPort.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -465,7 +465,7 @@ func (gw *GatewayManager) updateGWRouterStaticRoutes(clusterIPSubnet, drLRPIfAdd IPPrefix: entry.String(), Nexthop: drLRPIfAddr.IP.String(), } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -495,7 +495,7 @@ func (gw *GatewayManager) updateGWRouterStaticRoutes(clusterIPSubnet, drLRPIfAdd OutputPort: &externalRouterPort, ExternalIDs: map[string]string{util.OvnNodeMasqCIDR: ""}, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -527,7 +527,7 @@ func (gw *GatewayManager) updateGWRouterStaticRoutes(clusterIPSubnet, drLRPIfAdd Nexthop: nextHop.String(), OutputPort: &externalRouterPort, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -559,7 +559,7 @@ func (gw *GatewayManager) updateClusterRouterStaticRoutes(hostSubnets []*net.IPN IPPrefix: gwLRPIP.String(), Nexthop: gwLRPIP.String(), } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -599,7 +599,7 @@ func (gw *GatewayManager) updateClusterRouterStaticRoutes(hostSubnets []*net.IPN } if config.Gateway.Mode != config.GatewayModeLocal { - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { lrsr.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -651,8 +651,8 @@ func (gw *GatewayManager) updateClusterRouterStaticRoutes(hostSubnets []*net.IPN // - DefaultNetworkController.updateNamespace // - EgressIPController.addExternalGWPodSNATOps // - EgressIPController.addPodEgressIPAssignment -// - SecondaryLayer2NetworkController.buildUDNEgressSNAT -// - SecondaryLayer3NetworkController.addUDNNodeSubnetEgressSNAT +// - Layer2UserDefinedNetworkController.buildUDNEgressSNAT +// - Layer3UserDefinedNetworkController.addUDNNodeSubnetEgressSNAT // use gateway config parameters to create SNAT rules on the gateway router, but some of them (not all) don't watch // gateway config changes and rely on the GatewayManager to update their SNAT rules. // Is it racy? Yes! @@ -736,7 +736,7 @@ func (gw *GatewayManager) updateGWRouterNAT(nodeName string, clusterIPSubnet []* externalIPs, gwLRPIPs []net.IP, gwRouter *nbdb.LogicalRouter) error { // REMOVEME(trozet) workaround - create join subnet SNAT to handle ICMP needs frag return var extIDs map[string]string - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { extIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -967,7 +967,7 @@ func (gw *GatewayManager) addExternalSwitch(prefix, interfaceID, gatewayRouter, Networks: externalRouterPortNetworks, Name: externalRouterPort, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { externalLogicalRouterPort.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -996,7 +996,7 @@ func (gw *GatewayManager) addExternalSwitch(prefix, interfaceID, gatewayRouter, }, Name: interfaceID, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { externalLogicalSwitchPort.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), @@ -1033,14 +1033,14 @@ func (gw *GatewayManager) addExternalSwitch(prefix, interfaceID, gatewayRouter, Addresses: []string{macAddress}, } - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { externalLogicalSwitchPortToRouter.ExternalIDs = map[string]string{ types.NetworkExternalID: gw.netInfo.GetNetworkName(), types.TopologyExternalID: gw.netInfo.TopologyType(), } } sw := nbdb.LogicalSwitch{Name: externalSwitch} - if gw.netInfo.IsSecondary() { + if gw.netInfo.IsUserDefinedNetwork() { sw.ExternalIDs = util.GenerateExternalIDsForSwitchOrRouter(gw.netInfo) } @@ -1281,8 +1281,8 @@ func (gw *GatewayManager) staticRouteCleanup(nextHops []net.IP, ipPrefix *net.IP ips.Insert(nextHop.String()) } p := func(item *nbdb.LogicalRouterStaticRoute) bool { - networkName, isSecondaryNetwork := item.ExternalIDs[types.NetworkExternalID] - if !isSecondaryNetwork { + networkName, isUserDefinedNetwork := item.ExternalIDs[types.NetworkExternalID] + if !isUserDefinedNetwork { networkName = types.DefaultNetworkName } if networkName != gw.netInfo.GetNetworkName() { @@ -1309,8 +1309,8 @@ func (gw *GatewayManager) policyRouteCleanup(nextHops []net.IP) { for _, nextHop := range nextHops { gwIP := nextHop.String() policyPred := func(item *nbdb.LogicalRouterPolicy) bool { - networkName, isSecondaryNetwork := item.ExternalIDs[types.NetworkExternalID] - if !isSecondaryNetwork { + networkName, isUserDefinedNetwork := item.ExternalIDs[types.NetworkExternalID] + if !isUserDefinedNetwork { networkName = types.DefaultNetworkName } if networkName != gw.netInfo.GetNetworkName() { @@ -1343,8 +1343,8 @@ func (gw *GatewayManager) removeLRPolicies(nodeName string) { managedNetworkName := gw.netInfo.GetNetworkName() p := func(item *nbdb.LogicalRouterPolicy) bool { - networkName, isSecondaryNetwork := item.ExternalIDs[types.NetworkExternalID] - if !isSecondaryNetwork { + networkName, isUserDefinedNetwork := item.ExternalIDs[types.NetworkExternalID] + if !isUserDefinedNetwork { networkName = types.DefaultNetworkName } if networkName != managedNetworkName { diff --git a/go-controller/pkg/ovn/gatewayrouter/policybasedroutes.go b/go-controller/pkg/ovn/gatewayrouter/policybasedroutes.go index 4f61101282..c0acb16214 100644 --- a/go-controller/pkg/ovn/gatewayrouter/policybasedroutes.go +++ b/go-controller/pkg/ovn/gatewayrouter/policybasedroutes.go @@ -238,7 +238,7 @@ func (pbr *PolicyBasedRoutesManager) createPolicyBasedRoutes(match, priority, ne Nexthops: []string{nexthops}, Action: nbdb.LogicalRouterPolicyActionReroute, } - if pbr.netInfo.IsSecondary() { + if pbr.netInfo.IsUserDefinedNetwork() { lrp.ExternalIDs = map[string]string{ ovntypes.NetworkExternalID: pbr.netInfo.GetNetworkName(), ovntypes.TopologyExternalID: pbr.netInfo.TopologyType(), diff --git a/go-controller/pkg/ovn/gatewayrouter/policybasedroutes_test.go b/go-controller/pkg/ovn/gatewayrouter/policybasedroutes_test.go index 5c2f479607..6eadb8e2ee 100644 --- a/go-controller/pkg/ovn/gatewayrouter/policybasedroutes_test.go +++ b/go-controller/pkg/ovn/gatewayrouter/policybasedroutes_test.go @@ -47,7 +47,7 @@ func (n network) generateTestData(nodeName string) []libovsdbtest.TestData { for _, lrp := range n.initialLRPs { lrpUUIDs = append(lrpUUIDs, lrp.UUID) var extID map[string]string - if n.info.IsSecondary() { + if n.info.IsUserDefinedNetwork() { extID = map[string]string{ types.NetworkExternalID: n.info.GetNetworkName(), types.TopologyExternalID: n.info.TopologyType(), diff --git a/go-controller/pkg/ovn/kubevirt_test.go b/go-controller/pkg/ovn/kubevirt_test.go index 061b9fc5f6..c311ad657b 100644 --- a/go-controller/pkg/ovn/kubevirt_test.go +++ b/go-controller/pkg/ovn/kubevirt_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net" + "slices" "strings" "time" @@ -20,6 +21,7 @@ import ( "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kubevirt" libovsdbops "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/ops" "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb" + "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing" "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing/libovsdb" ovntypes "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types" "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" @@ -41,6 +43,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { dnsServiceIPv6 = "fd7b:6b4d:7b25:d22f::3" clusterCIDRIPv4 = "10.128.0.0/16" clusterCIDRIPv6 = "fe00::/64" + subnetSuffixIPv4 = "/24" + subnetSuffixIPv6 = "/64" ) type testDHCPOptions struct { cidr string @@ -104,6 +108,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { subnetIPv6 string transitSwitchPortIPv4 string transitSwitchPortIPv6 string + addressIPv4 string + addressIPv6 string } type testVM struct { @@ -124,6 +130,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { lrpNetworkIPv6: "fd98::4/64", transitSwitchPortIPv4: "100.65.0.4/24", transitSwitchPortIPv6: "fd13::4/64", + addressIPv4: "10.89.0.1/24", + addressIPv6: "fc00:f853:ccd:e793::1/64", }, node2: { nodeID: "5", @@ -133,6 +141,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { lrpNetworkIPv6: "fd98::5/64", transitSwitchPortIPv4: "100.65.0.5/24", transitSwitchPortIPv6: "fd13::5/64", + addressIPv4: "10.89.0.2/24", + addressIPv6: "fc00:f853:ccd:e793::2/64", }, node3: { nodeID: "6", @@ -142,6 +152,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { lrpNetworkIPv6: "fd98::6/64", transitSwitchPortIPv4: "100.65.0.6/24", transitSwitchPortIPv6: "fd13::6/64", + addressIPv4: "10.89.0.3/24", + addressIPv6: "fc00:f853:ccd:e793::3/64", }, } vmByName = map[string]testVM{ @@ -245,6 +257,27 @@ var _ = Describe("OVN Kubevirt Operations", func() { return append(previousData, data...) } + filterOutStaleVirtLauncherExpectedTestData = func(namespace, name string, previousData []libovsdb.TestData) []libovsdb.TestData { + var data []libovsdb.TestData + lspUUID := util.GetLogicalPortName(namespace, name) + "-UUID" + for _, d := range previousData { + switch model := d.(type) { + case *nbdb.LogicalSwitch: + lsp := *model + lsp.Ports = slices.Clone(lsp.Ports) + lsp.Ports = slices.DeleteFunc(lsp.Ports, func(port string) bool { return port == lspUUID }) + d = &lsp + case *nbdb.LogicalSwitchPort: + if model.UUID == lspUUID { + continue + } + } + data = append(data, d) + + } + return data + } + newPodFromTestVirtLauncherPod = func(t testVirtLauncherPod) *corev1.Pod { if t.podName == "" { return nil @@ -342,8 +375,35 @@ var _ = Describe("OVN Kubevirt Operations", func() { ExternalIDs: ids, } } + composeNats = func(pod testVirtLauncherPod) ([]string, []*nbdb.NAT) { + var ids []string + var nats []*nbdb.NAT + if config.IPv4Mode { + id := pod.podName + "-IPv4-NAD-UUID" + nats = append(nats, &nbdb.NAT{ + UUID: id, + LogicalIP: pod.addressIPv4, + ExternalIP: testing.MustParseIPNet(nodeByName[pod.nodeName].addressIPv4).IP.String(), + Options: map[string]string{"stateless": "false"}, + Type: "snat", + }) + ids = append(ids, id) + } + if config.IPv6Mode { + id := pod.podName + "-IPv6-NAD-UUID" + nats = append(nats, &nbdb.NAT{ + UUID: id, + LogicalIP: pod.addressIPv6, + ExternalIP: testing.MustParseIPNet(nodeByName[pod.nodeName].addressIPv6).IP.String(), + Options: map[string]string{"stateless": "false"}, + Type: "snat", + }) + ids = append(ids, id) + } + return ids, nats + } - expectedNBDBAfterCleanup = func(expectedStaticRoutes []*nbdb.LogicalRouterStaticRoute) []libovsdb.TestData { + expectedNBDBAfterCleanup = func(expectedStaticRoutes []*nbdb.LogicalRouterStaticRoute, expectedNATs map[string][]*nbdb.NAT) []libovsdb.TestData { data := []libovsdb.TestData{} expectedPoliciesAfterCleanup := []string{} expectedStaticRoutesAfterCleanup := []string{} @@ -366,6 +426,11 @@ var _ = Describe("OVN Kubevirt Operations", func() { continue } else if lr, ok := nbData.(*nbdb.LogicalRouter); ok && lr.Name == ovntypes.OVNClusterRouter { expectedOvnClusterRouterAfterCleanup = lr + } else if lr, ok := nbData.(*nbdb.LogicalRouter); ok && expectedNATs[lr.Name] != nil { + for _, nat := range expectedNATs[lr.Name] { + lr.Nat = append(lr.Nat, nat.UUID) + data = append(data, nat) + } } data = append(data, nbData) } @@ -487,6 +552,7 @@ var _ = Describe("OVN Kubevirt Operations", func() { // To skip port group not found error config.EnableMulticast = false + config.Gateway.DisableSNATMultipleGWs = true fakeOvn = NewFakeOVN(true) }) @@ -671,6 +737,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { Annotations: map[string]string{ "k8s.ovn.org/node-transit-switch-port-ifaddr": fmt.Sprintf(`{"ipv4": %q, "ipv6": %q}`, nodeByName[node1].transitSwitchPortIPv4, nodeByName[node1].transitSwitchPortIPv6), "k8s.ovn.org/node-subnets": fmt.Sprintf(`{"default":[%q,%q]}`, nodeByName[node1].subnetIPv4, nodeByName[node1].subnetIPv6), + "k8s.ovn.org/l3-gateway-config": fmt.Sprintf(`{"default": {"mode": "local", "mac-address":"7e:57:f8:f0:3c:51", "ip-addresses":[%q, %q]}}`, nodeByName[node1].addressIPv4, nodeByName[node1].addressIPv6), + "k8s.ovn.org/node-chassis-id": "1", util.OvnNodeID: nodeByName[node1].nodeID, }, }, @@ -681,6 +749,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { Annotations: map[string]string{ "k8s.ovn.org/node-transit-switch-port-ifaddr": fmt.Sprintf(`{"ipv4": %q, "ipv6": %q}`, nodeByName[node2].transitSwitchPortIPv4, nodeByName[node2].transitSwitchPortIPv6), "k8s.ovn.org/node-subnets": fmt.Sprintf(`{"default":[%q,%q]}`, nodeByName[node2].subnetIPv4, nodeByName[node2].subnetIPv6), + "k8s.ovn.org/l3-gateway-config": fmt.Sprintf(`{"default": {"mode": "local", "mac-address":"7e:57:f8:f0:3c:52", "ip-addresses":[%q, %q]}}`, nodeByName[node2].addressIPv4, nodeByName[node2].addressIPv6), + "k8s.ovn.org/node-chassis-id": "2", util.OvnNodeID: nodeByName[node2].nodeID, }, }, @@ -691,6 +761,8 @@ var _ = Describe("OVN Kubevirt Operations", func() { Annotations: map[string]string{ "k8s.ovn.org/node-transit-switch-port-ifaddr": fmt.Sprintf(`{"ipv4": %q, "ipv6": %q}`, nodeByName[node3].transitSwitchPortIPv4, nodeByName[node3].transitSwitchPortIPv6), "k8s.ovn.org/node-subnets": fmt.Sprintf(`{"default":[%q,%q]}`, nodeByName[node3].subnetIPv4, nodeByName[node3].subnetIPv6), + "k8s.ovn.org/l3-gateway-config": fmt.Sprintf(`{"default": {"mode": "local", "mac-address":"7e:57:f8:f0:3c:53", "ip-addresses":[%q, %q]}}`, nodeByName[node3].addressIPv4, nodeByName[node3].addressIPv6), + "k8s.ovn.org/node-chassis-id": "3", util.OvnNodeID: nodeByName[node3].nodeID, }, }, @@ -749,6 +821,7 @@ var _ = Describe("OVN Kubevirt Operations", func() { } expectedOVN := []libovsdb.TestData{} + ovnClusterRouter.Policies = []string{} expectedOVNClusterRouter := ovnClusterRouter.DeepCopy() expectedOVNClusterRouter.Policies = []string{} @@ -781,23 +854,38 @@ var _ = Describe("OVN Kubevirt Operations", func() { expectedOVN = append(expectedOVN, ComposeDHCPv6Options(dhcpv6OptionsUUID+d.hostname, t.namespace, &d)) } expectedSourceLSRP := migrationSourceLSRP.DeepCopy() + expectedGWRouter := gwRouter.DeepCopy() expectedOVN = append(expectedOVN, expectedOVNClusterRouter, - gwRouter, + expectedGWRouter, logicalRouterPort, expectedSourceLSRP, ) expectedOVN = kubevirtOVNTestData(t, expectedOVN) + var expectedMigrationTargetGWRouter *nbdb.LogicalRouter if t.migrationTarget.nodeName != "" { expectedTargetLSRP := migrationTargetLSRP.DeepCopy() + expectedMigrationTargetGWRouter = migrationTargetGWRouter.DeepCopy() expectedOVN = append(expectedOVN, migrationTargetLRP, expectedTargetLSRP, - migrationTargetGWRouter, + expectedMigrationTargetGWRouter, ) } + + for router, testpod := range map[*nbdb.LogicalRouter]testVirtLauncherPod{expectedGWRouter: t.testVirtLauncherPod, expectedMigrationTargetGWRouter: t.migrationTarget.testVirtLauncherPod} { + if _, isLocal := fakeOvn.controller.localZoneNodes.Load(testpod.nodeName); isLocal && router != nil && testpod.podName != "" { + natIDs, nats := composeNats(testpod) + router.Nat = append(router.Nat, natIDs...) + for _, nat := range nats { + expectedOVN = append(expectedOVN, nat) + } + } + } + Eventually(fakeOvn.nbClient).Should(libovsdb.HaveData(expectedOVN), "should populate ovn") + if t.replaceNode != "" { By("Replace vm node with newNode at the logical switch manager") newNode := &corev1.Node{ @@ -830,26 +918,87 @@ var _ = Describe("OVN Kubevirt Operations", func() { Expect(err).ToNot(HaveOccurred()) } - if t.podName != "" { - pod, err := fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).Get(context.TODO(), t.podName, metav1.GetOptions{}) + var vmIPs []string + if t.addressIPv4 != "" { + vmIPs = append(vmIPs, t.addressIPv4+subnetSuffixIPv4) + } + if t.addressIPv6 != "" { + vmIPs = append(vmIPs, t.addressIPv6+subnetSuffixIPv6) + } + vmIPNets := testing.MustParseIPNets(vmIPs...) + subnet, checkRelease := fakeOvn.controller.lsManager.GetSubnetName(vmIPNets) + + if t.podName == "" { + return nil + } + + completeAndDeletePod := func(namespace, name string) { + GinkgoHelper() + pod, err := fakeOvn.fakeClient.KubeClient.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{}) Expect(err).NotTo(HaveOccurred()) pod.Status.Phase = corev1.PodSucceeded - _, err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).UpdateStatus(context.TODO(), pod, metav1.UpdateOptions{}) + _, err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(namespace).UpdateStatus(context.TODO(), pod, metav1.UpdateOptions{}) Expect(err).NotTo(HaveOccurred()) - err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).Delete(context.TODO(), t.podName, metav1.DeleteOptions{}) + err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{}) Expect(err).NotTo(HaveOccurred()) + } - if t.migrationTarget.nodeName != "" { - pod, err := fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).Get(context.TODO(), t.migrationTarget.podName, metav1.GetOptions{}) - Expect(err).NotTo(HaveOccurred()) - pod.Status.Phase = corev1.PodSucceeded - _, err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).UpdateStatus(context.TODO(), pod, metav1.UpdateOptions{}) - Expect(err).NotTo(HaveOccurred()) - err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(t.namespace).Delete(context.TODO(), t.migrationTarget.podName, metav1.DeleteOptions{}) - Expect(err).NotTo(HaveOccurred()) + deleteFirst := t.testVirtLauncherPod + deleteSecond := t.migrationTarget.testVirtLauncherPod + deleteFirstRouter := gwRouter + hasMigration := t.migrationTarget.nodeName != "" + hasUnsuccesfulMigration := hasMigration && t.migrationTarget.updatePhase != nil + if hasUnsuccesfulMigration { + deleteFirst = t.migrationTarget.testVirtLauncherPod + deleteFirstRouter = migrationTargetGWRouter + deleteSecond = t.testVirtLauncherPod + } + + completeAndDeletePod(t.namespace, deleteFirst.podName) + if !hasMigration { + if checkRelease { + Eventually(fakeOvn.controller.lsManager.AllocateIPs). + WithArguments(subnet, vmIPNets). + Should(Succeed(), "should have de-allocated VM IP after termination") } - Eventually(fakeOvn.nbClient).Should(libovsdb.HaveData(expectedNBDBAfterCleanup(expectedStaticRoutes)), "should cleanup ovn") + Eventually(fakeOvn.nbClient).Should( + libovsdb.HaveData(expectedNBDBAfterCleanup(expectedStaticRoutes, nil)), + "should cleanup terminated pod data from ovn", + ) + return nil } + if checkRelease { + Consistently(fakeOvn.controller.lsManager.AllocateIPs). + WithArguments(subnet, vmIPNets). + ShouldNot(Succeed(), "should have not de-allocated VM IP after migration") + } + + Eventually(fakeOvn.nbClient).Should( + libovsdb.HaveData(filterOutStaleVirtLauncherExpectedTestData(t.namespace, deleteFirst.podName, expectedOVN)), + "should cleanup source pod data from ovn", + ) + + completeAndDeletePod(t.namespace, deleteSecond.podName) + if checkRelease { + Eventually(fakeOvn.controller.lsManager.AllocateIPs). + WithArguments(subnet, vmIPNets). + Should(Succeed(), "should have de-allocated target VM IP after termination") + } + + // FIXME: for some reason we don't remove stale NATs of migrated + // VMs. One possible reason is if VMs can migrate within the + // same node and we can race between creation and deletion. Can + // it happen? + // https://github.com/ovn-kubernetes/ovn-kubernetes/issues/5627 + expectedNATs := map[string][]*nbdb.NAT{} + if _, isLocal := fakeOvn.controller.localZoneNodes.Load(deleteFirst.nodeName); isLocal { + _, nats := composeNats(deleteFirst) + expectedNATs[deleteFirstRouter.Name] = nats + } + Eventually(fakeOvn.nbClient).Should( + libovsdb.HaveData(expectedNBDBAfterCleanup(expectedStaticRoutes, expectedNATs)), + "should cleanup terminated target pod data from ovn", + ) return nil } @@ -1261,7 +1410,18 @@ var _ = Describe("OVN Kubevirt Operations", func() { zone: kubevirt.OvnRemoteZone, }, }, - testVirtLauncherPod: virtLauncher2(node1, vm1), + testVirtLauncherPod: testVirtLauncherPod{ + suffix: "1", + testPod: testPod{ + nodeName: node2, + }, + vmName: vm1, + skipPodAnnotations: false, /* add ovn pod annotation */ + }, + migrationTarget: testMigrationTarget{ + lrpNetworks: []string{nodeByName[node1].lrpNetworkIPv4, nodeByName[node1].lrpNetworkIPv6}, + testVirtLauncherPod: virtLauncher2(node1, vm1), + }, expectedDhcpv4: []testDHCPOptions{{ cidr: nodeByName[node1].subnetIPv4, dns: dnsServiceIPv4, diff --git a/go-controller/pkg/ovn/secondary_layer2_network_controller.go b/go-controller/pkg/ovn/layer2_user_defined_network_controller.go similarity index 84% rename from go-controller/pkg/ovn/secondary_layer2_network_controller.go rename to go-controller/pkg/ovn/layer2_user_defined_network_controller.go index 58679c448c..eb7bb05abd 100644 --- a/go-controller/pkg/ovn/secondary_layer2_network_controller.go +++ b/go-controller/pkg/ovn/layer2_user_defined_network_controller.go @@ -37,15 +37,15 @@ import ( // method/structure shared by all layer 2 network controller, including localnet and layer2 network controllres. -type secondaryLayer2NetworkControllerEventHandler struct { +type layer2UserDefinedNetworkControllerEventHandler struct { baseHandler baseNetworkControllerEventHandler watchFactory *factory.WatchFactory objType reflect.Type - oc *SecondaryLayer2NetworkController + oc *Layer2UserDefinedNetworkController syncFunc func([]interface{}) error } -func (h *secondaryLayer2NetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { +func (h *layer2UserDefinedNetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { return h.oc.FilterOutResource(h.objType, obj) } @@ -53,56 +53,56 @@ func (h *secondaryLayer2NetworkControllerEventHandler) FilterOutResource(obj int // type considers them equal and therefore no update is needed. It returns false when the two objects are not considered // equal and an update needs be executed. This is regardless of how the update is carried out (whether with a dedicated update // function or with a delete on the old obj followed by an add on the new obj). -func (h *secondaryLayer2NetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { +func (h *layer2UserDefinedNetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { return h.baseHandler.areResourcesEqual(h.objType, obj1, obj2) } // GetInternalCacheEntry returns the internal cache entry for this object, given an object and its type. // This is now used only for pods, which will get their the logical port cache entry. -func (h *secondaryLayer2NetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { - return h.oc.GetInternalCacheEntryForSecondaryNetwork(h.objType, obj) +func (h *layer2UserDefinedNetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { + return h.oc.GetInternalCacheEntryForUserDefinedNetwork(h.objType, obj) } // GetResourceFromInformerCache returns the latest state of the object, given an object key and its type. // from the informers cache. -func (h *secondaryLayer2NetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { +func (h *layer2UserDefinedNetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { return h.baseHandler.getResourceFromInformerCache(h.objType, h.watchFactory, key) } // RecordAddEvent records the add event on this given object. -func (h *secondaryLayer2NetworkControllerEventHandler) RecordAddEvent(obj interface{}) { +func (h *layer2UserDefinedNetworkControllerEventHandler) RecordAddEvent(obj interface{}) { h.baseHandler.recordAddEvent(h.objType, obj) } // RecordUpdateEvent records the udpate event on this given object. -func (h *secondaryLayer2NetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { +func (h *layer2UserDefinedNetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { h.baseHandler.recordUpdateEvent(h.objType, obj) } // RecordDeleteEvent records the delete event on this given object. -func (h *secondaryLayer2NetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { +func (h *layer2UserDefinedNetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { h.baseHandler.recordDeleteEvent(h.objType, obj) } // RecordSuccessEvent records the success event on this given object. -func (h *secondaryLayer2NetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { +func (h *layer2UserDefinedNetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { h.baseHandler.recordSuccessEvent(h.objType, obj) } // RecordErrorEvent records the error event on this given object. -func (h *secondaryLayer2NetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { +func (h *layer2UserDefinedNetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { } // IsResourceScheduled returns true if the given object has been scheduled. // Only applied to pods for now. Returns true for all other types. -func (h *secondaryLayer2NetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { +func (h *layer2UserDefinedNetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { return h.baseHandler.isResourceScheduled(h.objType, obj) } // AddResource adds the specified object to the cluster according to its type and returns the error, // if any, yielded during object creation. // Given an object to add and a boolean specifying if the function was executed from iterateRetryResources -func (h *secondaryLayer2NetworkControllerEventHandler) AddResource(obj interface{}, fromRetryLoop bool) error { +func (h *layer2UserDefinedNetworkControllerEventHandler) AddResource(obj interface{}, fromRetryLoop bool) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -131,14 +131,14 @@ func (h *secondaryLayer2NetworkControllerEventHandler) AddResource(obj interface } return h.oc.addUpdateRemoteNodeEvent(node, config.OVNKubernetesFeature.EnableInterconnect) default: - return h.oc.AddSecondaryNetworkResourceCommon(h.objType, obj) + return h.oc.AddUserDefinedNetworkResourceCommon(h.objType, obj) } } // DeleteResource deletes the object from the cluster according to the delete logic of its resource type. // Given an object and optionally a cachedObj; cachedObj is the internal cache entry for this object, // used for now for pods and network policies. -func (h *secondaryLayer2NetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { +func (h *layer2UserDefinedNetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -147,7 +147,7 @@ func (h *secondaryLayer2NetworkControllerEventHandler) DeleteResource(obj, cache } return h.oc.deleteNodeEvent(node) default: - return h.oc.DeleteSecondaryNetworkResourceCommon(h.objType, obj, cachedObj) + return h.oc.DeleteUserDefinedNetworkResourceCommon(h.objType, obj, cachedObj) } } @@ -155,7 +155,7 @@ func (h *secondaryLayer2NetworkControllerEventHandler) DeleteResource(obj, cache // type and returns the error, if any, yielded during the object update. // Given an old and a new object; The inRetryCache boolean argument is to indicate if the given resource // is in the retryCache or not. -func (h *secondaryLayer2NetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { +func (h *layer2UserDefinedNetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { switch h.objType { case factory.NodeType: newNode, ok := newObj.(*corev1.Node) @@ -205,7 +205,7 @@ func (h *secondaryLayer2NetworkControllerEventHandler) UpdateResource(oldObj, ne case factory.PodType: newPod := newObj.(*corev1.Pod) oldPod := oldObj.(*corev1.Pod) - if err := h.oc.ensurePodForSecondaryNetwork(newPod, shouldAddPort(oldPod, newPod, inRetryCache)); err != nil { + if err := h.oc.ensurePodForUserDefinedNetwork(newPod, shouldAddPort(oldPod, newPod, inRetryCache)); err != nil { return err } @@ -214,11 +214,11 @@ func (h *secondaryLayer2NetworkControllerEventHandler) UpdateResource(oldObj, ne } return nil default: - return h.oc.UpdateSecondaryNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) + return h.oc.UpdateUserDefinedNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) } } -func (h *secondaryLayer2NetworkControllerEventHandler) SyncFunc(objs []interface{}) error { +func (h *layer2UserDefinedNetworkControllerEventHandler) SyncFunc(objs []interface{}) error { var syncFunc func([]interface{}) error if h.syncFunc != nil { @@ -230,7 +230,7 @@ func (h *secondaryLayer2NetworkControllerEventHandler) SyncFunc(objs []interface syncFunc = h.oc.syncNodes case factory.PodType: - syncFunc = h.oc.syncPodsForSecondaryNetwork + syncFunc = h.oc.syncPodsForUserDefinedNetwork case factory.NamespaceType: syncFunc = h.oc.syncNamespaces @@ -256,14 +256,14 @@ func (h *secondaryLayer2NetworkControllerEventHandler) SyncFunc(objs []interface // IsObjectInTerminalState returns true if the given object is a in terminal state. // This is used now for pods that are either in a PodSucceeded or in a PodFailed state. -func (h *secondaryLayer2NetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { +func (h *layer2UserDefinedNetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { return h.baseHandler.isObjectInTerminalState(h.objType, obj) } -// SecondaryLayer2NetworkController is created for logical network infrastructure and policy -// for a secondary layer2 network -type SecondaryLayer2NetworkController struct { - BaseSecondaryLayer2NetworkController +// Layer2UserDefinedNetworkController is created for logical network infrastructure and policy +// for a layer2 UDN +type Layer2UserDefinedNetworkController struct { + BaseLayer2UserDefinedNetworkController // Node-specific syncMaps used by node event handler mgmtPortFailed sync.Map @@ -298,14 +298,14 @@ type SecondaryLayer2NetworkController struct { defaultGatewayReconciler *kubevirt.DefaultGatewayReconciler } -// NewSecondaryLayer2NetworkController create a new OVN controller for the given secondary layer2 nad -func NewSecondaryLayer2NetworkController( +// NewLayer2UserDefinedNetworkController create a new OVN controller for the given layer2 NAD +func NewLayer2UserDefinedNetworkController( cnci *CommonNetworkControllerInfo, netInfo util.NetInfo, networkManager networkmanager.Interface, routeImportManager routeimport.Manager, portCache *PortCache, - eIPController *EgressIPController) (*SecondaryLayer2NetworkController, error) { + eIPController *EgressIPController) (*Layer2UserDefinedNetworkController, error) { stopChan := make(chan struct{}) @@ -327,10 +327,10 @@ func NewSecondaryLayer2NetworkController( lsManager = lsm.NewL2SwitchManagerForUserDefinedPrimaryNetwork(gatewayIPs, mgmtIPs) } - oc := &SecondaryLayer2NetworkController{ - BaseSecondaryLayer2NetworkController: BaseSecondaryLayer2NetworkController{ + oc := &Layer2UserDefinedNetworkController{ + BaseLayer2UserDefinedNetworkController: BaseLayer2UserDefinedNetworkController{ - BaseSecondaryNetworkController: BaseSecondaryNetworkController{ + BaseUserDefinedNetworkController: BaseUserDefinedNetworkController{ BaseNetworkController: BaseNetworkController{ CommonNetworkControllerInfo: *cnci, controllerName: getNetworkControllerName(netInfo.GetNetworkName()), @@ -405,13 +405,13 @@ func NewSecondaryLayer2NetworkController( return oc, nil } -// Start starts the secondary layer2 controller, handles all events and creates all needed logical entities -func (oc *SecondaryLayer2NetworkController) Start(_ context.Context) error { - klog.Infof("Starting controller for secondary network %s", oc.GetNetworkName()) +// Start starts the layer2 UDN controller, handles all events and creates all needed logical entities +func (oc *Layer2UserDefinedNetworkController) Start(_ context.Context) error { + klog.Infof("Starting controller for UDN %s", oc.GetNetworkName()) start := time.Now() defer func() { - klog.Infof("Starting controller for secondary network %s took %v", oc.GetNetworkName(), time.Since(start)) + klog.Infof("Starting controller for UDN %s took %v", oc.GetNetworkName(), time.Since(start)) }() if err := oc.init(); err != nil { @@ -421,8 +421,8 @@ func (oc *SecondaryLayer2NetworkController) Start(_ context.Context) error { return oc.run() } -func (oc *SecondaryLayer2NetworkController) run() error { - err := oc.BaseSecondaryLayer2NetworkController.run() +func (oc *Layer2UserDefinedNetworkController) run() error { + err := oc.BaseLayer2UserDefinedNetworkController.run() if err != nil { return err } @@ -442,9 +442,9 @@ func (oc *SecondaryLayer2NetworkController) run() error { // Cleanup cleans up logical entities for the given network, called from net-attach-def routine // could be called from a dummy Controller (only has CommonNetworkControllerInfo set) -func (oc *SecondaryLayer2NetworkController) Cleanup() error { +func (oc *Layer2UserDefinedNetworkController) Cleanup() error { networkName := oc.GetNetworkName() - if err := oc.BaseSecondaryLayer2NetworkController.cleanup(); err != nil { + if err := oc.BaseLayer2UserDefinedNetworkController.cleanup(); err != nil { return fmt.Errorf("failed to cleanup network %q: %w", networkName, err) } @@ -476,7 +476,7 @@ func (oc *SecondaryLayer2NetworkController) Cleanup() error { return nil } -func (oc *SecondaryLayer2NetworkController) init() error { +func (oc *Layer2UserDefinedNetworkController) init() error { // Create default Control Plane Protection (COPP) entry for routers defaultCOPPUUID, err := EnsureDefaultCOPP(oc.nbClient) if err != nil { @@ -520,19 +520,19 @@ func (oc *SecondaryLayer2NetworkController) init() error { return err } -func (oc *SecondaryLayer2NetworkController) Stop() { - klog.Infof("Stoping controller for secondary network %s", oc.GetNetworkName()) - oc.BaseSecondaryLayer2NetworkController.stop() +func (oc *Layer2UserDefinedNetworkController) Stop() { + klog.Infof("Stoping controller for UDN %s", oc.GetNetworkName()) + oc.BaseLayer2UserDefinedNetworkController.stop() } -func (oc *SecondaryLayer2NetworkController) Reconcile(netInfo util.NetInfo) error { +func (oc *Layer2UserDefinedNetworkController) Reconcile(netInfo util.NetInfo) error { return oc.BaseNetworkController.reconcile( netInfo, func(node string) { oc.gatewaysFailed.Store(node, true) }, ) } -func (oc *SecondaryLayer2NetworkController) initRetryFramework() { +func (oc *Layer2UserDefinedNetworkController) initRetryFramework() { oc.retryNodes = oc.newRetryFramework(factory.NodeType) oc.retryPods = oc.newRetryFramework(factory.PodType) if oc.allocatesPodAnnotation() && oc.AllowsPersistentIPs() { @@ -556,9 +556,9 @@ func (oc *SecondaryLayer2NetworkController) initRetryFramework() { } // newRetryFramework builds and returns a retry framework for the input resource type; -func (oc *SecondaryLayer2NetworkController) newRetryFramework( +func (oc *Layer2UserDefinedNetworkController) newRetryFramework( objectType reflect.Type) *retry.RetryFramework { - eventHandler := &secondaryLayer2NetworkControllerEventHandler{ + eventHandler := &layer2UserDefinedNetworkControllerEventHandler{ baseHandler: baseNetworkControllerEventHandler{}, objType: objectType, watchFactory: oc.watchFactory, @@ -579,7 +579,7 @@ func (oc *SecondaryLayer2NetworkController) newRetryFramework( ) } -func (oc *SecondaryLayer2NetworkController) addUpdateLocalNodeEvent(node *corev1.Node, nSyncs *nodeSyncs) error { +func (oc *Layer2UserDefinedNetworkController) addUpdateLocalNodeEvent(node *corev1.Node, nSyncs *nodeSyncs) error { var errs []error if util.IsNetworkSegmentationSupportEnabled() && oc.IsPrimaryNetwork() { @@ -659,7 +659,7 @@ func (oc *SecondaryLayer2NetworkController) addUpdateLocalNodeEvent(node *corev1 } } - errs = append(errs, oc.BaseSecondaryLayer2NetworkController.addUpdateLocalNodeEvent(node)) + errs = append(errs, oc.BaseLayer2UserDefinedNetworkController.addUpdateLocalNodeEvent(node)) err := utilerrors.Join(errs...) if err != nil { @@ -668,7 +668,7 @@ func (oc *SecondaryLayer2NetworkController) addUpdateLocalNodeEvent(node *corev1 return err } -func (oc *SecondaryLayer2NetworkController) addUpdateRemoteNodeEvent(node *corev1.Node, syncZoneIC bool) error { +func (oc *Layer2UserDefinedNetworkController) addUpdateRemoteNodeEvent(node *corev1.Node, syncZoneIC bool) error { var errs []error if util.IsNetworkSegmentationSupportEnabled() && oc.IsPrimaryNetwork() { @@ -683,7 +683,7 @@ func (oc *SecondaryLayer2NetworkController) addUpdateRemoteNodeEvent(node *corev } } - errs = append(errs, oc.BaseSecondaryLayer2NetworkController.addUpdateRemoteNodeEvent(node)) + errs = append(errs, oc.BaseLayer2UserDefinedNetworkController.addUpdateRemoteNodeEvent(node)) err := utilerrors.Join(errs...) if err != nil { @@ -692,7 +692,7 @@ func (oc *SecondaryLayer2NetworkController) addUpdateRemoteNodeEvent(node *corev return err } -func (oc *SecondaryLayer2NetworkController) addPortForRemoteNodeGR(node *corev1.Node) error { +func (oc *Layer2UserDefinedNetworkController) addPortForRemoteNodeGR(node *corev1.Node) error { nodeJoinSubnetIPs, err := udn.GetGWRouterIPs(node, oc.GetNetInfo()) if err != nil { if util.IsAnnotationNotSetError(err) { @@ -745,7 +745,7 @@ func (oc *SecondaryLayer2NetworkController) addPortForRemoteNodeGR(node *corev1. return nil } -func (oc *SecondaryLayer2NetworkController) deleteNodeEvent(node *corev1.Node) error { +func (oc *Layer2UserDefinedNetworkController) deleteNodeEvent(node *corev1.Node) error { if err := oc.gatewayManagerForNode(node.Name).Cleanup(); err != nil { return fmt.Errorf("failed to cleanup gateway on node %q: %w", node.Name, err) } @@ -770,7 +770,7 @@ func (oc *SecondaryLayer2NetworkController) deleteNodeEvent(node *corev1.Node) e // If isUDNAdvertised is true, then we want to SNAT all packets that are coming from pods on this network // leaving towards nodeIPs on the cluster to masqueradeIP. If network is advertise then the SNAT looks like this: // "eth.dst == 0a:58:5d:5d:00:02 && (ip4.dst == $a712973235162149816)" "169.254.0.36" "93.93.0.0/16" -func (oc *SecondaryLayer2NetworkController) addOrUpdateUDNClusterSubnetEgressSNAT(localPodSubnets []*net.IPNet, gwRouterName string, isUDNAdvertised bool) error { +func (oc *Layer2UserDefinedNetworkController) addOrUpdateUDNClusterSubnetEgressSNAT(localPodSubnets []*net.IPNet, gwRouterName string, isUDNAdvertised bool) error { outputPort := types.GWRouterToJoinSwitchPrefix + gwRouterName nats, err := oc.buildUDNEgressSNAT(localPodSubnets, outputPort, isUDNAdvertised) if err != nil { @@ -789,7 +789,7 @@ func (oc *SecondaryLayer2NetworkController) addOrUpdateUDNClusterSubnetEgressSNA return nil } -func (oc *SecondaryLayer2NetworkController) nodeGatewayConfig(node *corev1.Node) (*GatewayConfig, error) { +func (oc *Layer2UserDefinedNetworkController) nodeGatewayConfig(node *corev1.Node) (*GatewayConfig, error) { l3GatewayConfig, err := util.ParseNodeL3GatewayAnnotation(node) if err != nil { return nil, fmt.Errorf("failed to get node %s network %s L3 gateway config: %v", node.Name, oc.GetNetworkName(), err) @@ -840,7 +840,7 @@ func (oc *SecondaryLayer2NetworkController) nodeGatewayConfig(node *corev1.Node) }, nil } -func (oc *SecondaryLayer2NetworkController) newGatewayManager(nodeName string) *GatewayManager { +func (oc *Layer2UserDefinedNetworkController) newGatewayManager(nodeName string) *GatewayManager { return NewGatewayManagerForLayer2Topology( nodeName, oc.defaultCOPPUUID, @@ -852,7 +852,7 @@ func (oc *SecondaryLayer2NetworkController) newGatewayManager(nodeName string) * ) } -func (oc *SecondaryLayer2NetworkController) gatewayManagerForNode(nodeName string) *GatewayManager { +func (oc *Layer2UserDefinedNetworkController) gatewayManagerForNode(nodeName string) *GatewayManager { obj, isFound := oc.gatewayManagers.Load(nodeName) if !isFound { return oc.newGatewayManager(nodeName) @@ -870,7 +870,7 @@ func (oc *SecondaryLayer2NetworkController) gatewayManagerForNode(nodeName strin } } -func (oc *SecondaryLayer2NetworkController) gatewayOptions() []GatewayOption { +func (oc *Layer2UserDefinedNetworkController) gatewayOptions() []GatewayOption { var opts []GatewayOption if oc.clusterLoadBalancerGroupUUID != "" { opts = append(opts, WithLoadBalancerGroups( @@ -882,7 +882,7 @@ func (oc *SecondaryLayer2NetworkController) gatewayOptions() []GatewayOption { return opts } -func (oc *SecondaryLayer2NetworkController) StartServiceController(wg *sync.WaitGroup, runRepair bool) error { +func (oc *Layer2UserDefinedNetworkController) StartServiceController(wg *sync.WaitGroup, runRepair bool) error { useLBGroups := oc.clusterLoadBalancerGroupUUID != "" // use 5 workers like most of the kubernetes controllers in the kubernetes controller-manager // do not use LB templates for UDNs - OVN bug https://issues.redhat.com/browse/FDP-988 @@ -893,7 +893,7 @@ func (oc *SecondaryLayer2NetworkController) StartServiceController(wg *sync.Wait return nil } -func (oc *SecondaryLayer2NetworkController) updateLocalPodEvent(pod *corev1.Pod) error { +func (oc *Layer2UserDefinedNetworkController) updateLocalPodEvent(pod *corev1.Pod) error { if kubevirt.IsPodAllowedForMigration(pod, oc.GetNetInfo()) { kubevirtLiveMigrationStatus, err := kubevirt.DiscoverLiveMigrationStatus(oc.watchFactory, pod) if err != nil { @@ -908,7 +908,7 @@ func (oc *SecondaryLayer2NetworkController) updateLocalPodEvent(pod *corev1.Pod) return nil } -func (oc *SecondaryLayer2NetworkController) reconcileLiveMigrationTargetZone(kubevirtLiveMigrationStatus *kubevirt.LiveMigrationStatus) error { +func (oc *Layer2UserDefinedNetworkController) reconcileLiveMigrationTargetZone(kubevirtLiveMigrationStatus *kubevirt.LiveMigrationStatus) error { if oc.defaultGatewayReconciler == nil { return nil } diff --git a/go-controller/pkg/ovn/secondary_layer2_network_controller_test.go b/go-controller/pkg/ovn/layer2_user_defined_network_controller_test.go similarity index 90% rename from go-controller/pkg/ovn/secondary_layer2_network_controller_test.go rename to go-controller/pkg/ovn/layer2_user_defined_network_controller_test.go index 1079a14198..352ef1497f 100644 --- a/go-controller/pkg/ovn/secondary_layer2_network_controller_test.go +++ b/go-controller/pkg/ovn/layer2_user_defined_network_controller_test.go @@ -81,7 +81,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { DescribeTable( "reconciles a new", - func(netInfo secondaryNetInfo, testConfig testConfiguration, gatewayMode config.GatewayMode) { + func(netInfo userDefinedNetInfo, testConfig testConfiguration, gatewayMode config.GatewayMode) { const podIdx = 0 podInfo := dummyL2TestPod(ns, netInfo, podIdx, podIdx) setupConfig(netInfo, testConfig, gatewayMode) @@ -90,7 +90,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { const nodeIPv4CIDR = "192.168.126.202/24" By(fmt.Sprintf("Creating a node named %q, with IP: %s", nodeName, nodeIPv4CIDR)) - testNode, err := newNodeWithSecondaryNets(nodeName, nodeIPv4CIDR) + testNode, err := newNodeWithUserDefinedNetworks(nodeName, nodeIPv4CIDR) Expect(err).NotTo(HaveOccurred()) Expect(setupFakeOvnForLayer2Topology(fakeOvn, initialDB, netInfo, testNode, podInfo, pod)).To(Succeed()) @@ -122,7 +122,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { By("asserting the OVN entities provisioned in the NBDB are the expected ones") Eventually(fakeOvn.nbClient).Should( libovsdbtest.HaveData( - newSecondaryNetworkExpectationMachine( + newUserDefinedNetworkExpectationMachine( fakeOvn, []testPod{podInfo}, expectationOptions..., @@ -181,7 +181,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { DescribeTable( "reconciles a new kubevirt-related pod during its live-migration phases", - func(netInfo secondaryNetInfo, testConfig testConfiguration, migrationInfo *liveMigrationInfo) { + func(netInfo userDefinedNetInfo, testConfig testConfiguration, migrationInfo *liveMigrationInfo) { ipamClaim := ipamclaimsapi.IPAMClaim{ ObjectMeta: metav1.ObjectMeta{ Namespace: ns, @@ -196,11 +196,11 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { netInfo.ipamClaimReference = ipamClaim.Name const ( - sourcePodInfoIdx = 0 - targetPodInfoIdx = 1 - secondaryNetworkIdx = 0 + sourcePodInfoIdx = 0 + targetPodInfoIdx = 1 + userDefinedNetworkIdx = 0 ) - sourcePodInfo := dummyL2TestPod(ns, netInfo, sourcePodInfoIdx, secondaryNetworkIdx) + sourcePodInfo := dummyL2TestPod(ns, netInfo, sourcePodInfoIdx, userDefinedNetworkIdx) setupConfig(netInfo, testConfig, config.GatewayModeShared) app.Action = func(*cli.Context) error { sourcePod := newMultiHomedKubevirtPod( @@ -211,7 +211,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { const nodeIPv4CIDR = "192.168.126.202/24" By(fmt.Sprintf("Creating a node named %q, with IP: %s", nodeName, nodeIPv4CIDR)) - testNode, err := newNodeWithSecondaryNets(nodeName, nodeIPv4CIDR) + testNode, err := newNodeWithUserDefinedNetworks(nodeName, nodeIPv4CIDR) Expect(err).NotTo(HaveOccurred()) Expect(setupFakeOvnForLayer2Topology(fakeOvn, initialDB, netInfo, testNode, sourcePodInfo, sourcePod, @@ -245,13 +245,13 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { By("asserting the OVN entities provisioned in the NBDB are the expected ones before migration started") Eventually(fakeOvn.nbClient).Should( libovsdbtest.HaveData( - newSecondaryNetworkExpectationMachine( + newUserDefinedNetworkExpectationMachine( fakeOvn, []testPod{sourcePodInfo}, expectationOptions..., ).expectedLogicalSwitchesAndPorts(netInfo.isPrimary)...)) - targetPodInfo := dummyL2TestPod(ns, netInfo, targetPodInfoIdx, secondaryNetworkIdx) + targetPodInfo := dummyL2TestPod(ns, netInfo, targetPodInfoIdx, userDefinedNetworkIdx) targetKvPod := newMultiHomedKubevirtPod( migrationInfo.vmName, migrationInfo.targetPodInfo, @@ -272,7 +272,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { } Eventually(fakeOvn.nbClient).Should( libovsdbtest.HaveData( - newSecondaryNetworkExpectationMachine( + newUserDefinedNetworkExpectationMachine( fakeOvn, testPods, expectationOptions..., @@ -345,8 +345,8 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { ) DescribeTable( - "secondary network controller DB entities are properly cleaned up", - func(netInfo secondaryNetInfo, testConfig testConfiguration) { + "user-defined network controller DB entities are properly cleaned up", + func(netInfo userDefinedNetInfo, testConfig testConfiguration) { podInfo := dummyTestPod(ns, netInfo) if testConfig.configToOverride != nil { config.OVNKubernetesFeature = *testConfig.configToOverride @@ -370,10 +370,10 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { *netConf, ) Expect(err).NotTo(HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} const nodeIPv4CIDR = "192.168.126.202/24" - testNode, err := newNodeWithSecondaryNets(nodeName, nodeIPv4CIDR) + testNode, err := newNodeWithUserDefinedNetworks(nodeName, nodeIPv4CIDR) Expect(err).NotTo(HaveOccurred()) gwConfig, err := util.ParseNodeL3GatewayAnnotation(testNode) @@ -429,23 +429,23 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { Expect(fakeOvn.networkManager.Start()).To(Succeed()) defer fakeOvn.networkManager.Stop() - secondaryNetController, ok := fakeOvn.secondaryControllers[secondaryNetworkName] + udnNetController, ok := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] Expect(ok).To(BeTrue()) - fullSecondaryController, ok := fakeOvn.fullSecondaryL2Controllers[secondaryNetworkName] + fullUDNController, ok := fakeOvn.fullL2UDNControllers[userDefinedNetworkName] Expect(ok).To(BeTrue()) - err = fullSecondaryController.init() + err = fullUDNController.init() Expect(err).NotTo(HaveOccurred()) - secondaryNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() - podInfo.populateSecondaryNetworkLogicalSwitchCache(secondaryNetController) - Expect(secondaryNetController.bnc.WatchNodes()).To(Succeed()) - Expect(secondaryNetController.bnc.WatchPods()).To(Succeed()) + udnNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() + podInfo.populateUserDefinedNetworkLogicalSwitchCache(udnNetController) + Expect(udnNetController.bnc.WatchNodes()).To(Succeed()) + Expect(udnNetController.bnc.WatchPods()).To(Succeed()) Expect(fakeOvn.fakeClient.KubeClient.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})).To(Succeed()) Expect(fakeOvn.fakeClient.NetworkAttchDefClient.K8sCniCncfIoV1().NetworkAttachmentDefinitions(nad.Namespace).Delete(context.Background(), nad.Name, metav1.DeleteOptions{})).To(Succeed()) - err = fullSecondaryController.Cleanup() + err = fullUDNController.Cleanup() Expect(err).NotTo(HaveOccurred()) Eventually(fakeOvn.nbClient).Should(libovsdbtest.HaveData(generateUDNPostInitDB([]libovsdbtest.TestData{nbZone}))) @@ -471,22 +471,22 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 2 network", func() { }) -func dummySecondaryLayer2UserDefinedNetwork(subnets string) secondaryNetInfo { - return secondaryNetInfo{ - netName: secondaryNetworkName, +func dummySecondaryLayer2UserDefinedNetwork(subnets string) userDefinedNetInfo { + return userDefinedNetInfo{ + netName: userDefinedNetworkName, nadName: namespacedName(ns, nadName), topology: ovntypes.Layer2Topology, clustersubnets: subnets, } } -func dummyPrimaryLayer2UserDefinedNetwork(subnets string) secondaryNetInfo { - secondaryNet := dummySecondaryLayer2UserDefinedNetwork(subnets) - secondaryNet.isPrimary = true - return secondaryNet +func dummyPrimaryLayer2UserDefinedNetwork(subnets string) userDefinedNetInfo { + udnNetInfo := dummySecondaryLayer2UserDefinedNetwork(subnets) + udnNetInfo.isPrimary = true + return udnNetInfo } -func dummyL2TestPod(nsName string, info secondaryNetInfo, podIdx, secondaryNetIdx int) testPod { +func dummyL2TestPod(nsName string, info userDefinedNetInfo, podIdx, udnNetIdx int) testPod { const nodeSubnet = "10.128.1.0/24" if info.isPrimary { @@ -509,8 +509,8 @@ func dummyL2TestPod(nsName string, info secondaryNetInfo, podIdx, secondaryNetId info.clustersubnets, "", "100.200.0.1", - fmt.Sprintf("100.200.0.%d/16", secondaryNetIdx+3), - fmt.Sprintf("0a:58:64:c8:00:%0.2d", secondaryNetIdx+3), + fmt.Sprintf("100.200.0.%d/16", udnNetIdx+3), + fmt.Sprintf("0a:58:64:c8:00:%0.2d", udnNetIdx+3), "primary", 0, []util.PodRoute{ @@ -533,8 +533,8 @@ func dummyL2TestPod(nsName string, info secondaryNetInfo, podIdx, secondaryNetId info.clustersubnets, "", "", - fmt.Sprintf("100.200.0.%d/16", secondaryNetIdx+1), - fmt.Sprintf("0a:58:64:c8:00:%0.2d", secondaryNetIdx+1), + fmt.Sprintf("100.200.0.%d/16", udnNetIdx+1), + fmt.Sprintf("0a:58:64:c8:00:%0.2d", udnNetIdx+1), "secondary", 0, []util.PodRoute{}, @@ -650,16 +650,16 @@ func ipv4DefaultRoute() *net.IPNet { } } -func dummyLayer2SecondaryUserDefinedNetwork(subnets string) secondaryNetInfo { - return secondaryNetInfo{ - netName: secondaryNetworkName, +func dummyLayer2SecondaryUserDefinedNetwork(subnets string) userDefinedNetInfo { + return userDefinedNetInfo{ + netName: userDefinedNetworkName, nadName: namespacedName(ns, nadName), topology: ovntypes.Layer2Topology, clustersubnets: subnets, } } -func dummyLayer2PrimaryUserDefinedNetwork(subnets string) secondaryNetInfo { +func dummyLayer2PrimaryUserDefinedNetwork(subnets string) userDefinedNetInfo { secondaryNet := dummyLayer2SecondaryUserDefinedNetwork(subnets) secondaryNet.isPrimary = true return secondaryNet @@ -679,7 +679,7 @@ func nodeCIDR() *net.IPNet { } } -func setupFakeOvnForLayer2Topology(fakeOvn *FakeOVN, initialDB libovsdbtest.TestSetup, netInfo secondaryNetInfo, testNode *corev1.Node, podInfo testPod, pod *corev1.Pod, extraObjects ...runtime.Object) error { +func setupFakeOvnForLayer2Topology(fakeOvn *FakeOVN, initialDB libovsdbtest.TestSetup, netInfo userDefinedNetInfo, testNode *corev1.Node, podInfo testPod, pod *corev1.Pod, extraObjects ...runtime.Object) error { By(fmt.Sprintf("creating a network attachment definition for network: %s", netInfo.netName)) nad, err := newNetworkAttachmentDefinition( ns, @@ -687,7 +687,7 @@ func setupFakeOvnForLayer2Topology(fakeOvn *FakeOVN, initialDB libovsdbtest.Test *netInfo.netconf(), ) Expect(err).NotTo(HaveOccurred()) - nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{ovntypes.OvnNetworkIDAnnotation: userDefinedNetworkID} By("setting up the OVN DB without any entities in it") Expect(netInfo.setupOVNDependencies(&initialDB)).To(Succeed()) @@ -755,24 +755,24 @@ func setupFakeOvnForLayer2Topology(fakeOvn *FakeOVN, initialDB libovsdbtest.Test return err } By("asserting the pod (once reconciled) *features* the OVN pod networks annotation") - secondaryNetController, doesControllerExist := fakeOvn.secondaryControllers[secondaryNetworkName] + userDefinedNetController, doesControllerExist := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] if !doesControllerExist { - return fmt.Errorf("expected secondary network controller to exist") + return fmt.Errorf("expected user-defined network controller to exist") } - secondaryNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() - podInfo.populateSecondaryNetworkLogicalSwitchCache(secondaryNetController) - if err = secondaryNetController.bnc.WatchNodes(); err != nil { + userDefinedNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() + podInfo.populateUserDefinedNetworkLogicalSwitchCache(userDefinedNetController) + if err = userDefinedNetController.bnc.WatchNodes(); err != nil { return err } - if err = secondaryNetController.bnc.WatchPods(); err != nil { + if err = userDefinedNetController.bnc.WatchPods(); err != nil { return err } return nil } -func setupConfig(netInfo secondaryNetInfo, testConfig testConfiguration, gatewayMode config.GatewayMode) { +func setupConfig(netInfo userDefinedNetInfo, testConfig testConfiguration, gatewayMode config.GatewayMode) { if testConfig.configToOverride != nil { config.OVNKubernetesFeature = *testConfig.configToOverride if testConfig.gatewayConfig != nil { diff --git a/go-controller/pkg/ovn/secondary_layer3_network_controller.go b/go-controller/pkg/ovn/layer3_user_defined_network_controller.go similarity index 88% rename from go-controller/pkg/ovn/secondary_layer3_network_controller.go rename to go-controller/pkg/ovn/layer3_user_defined_network_controller.go index da57187694..815a8b4c9c 100644 --- a/go-controller/pkg/ovn/secondary_layer3_network_controller.go +++ b/go-controller/pkg/ovn/layer3_user_defined_network_controller.go @@ -35,15 +35,15 @@ import ( utilerrors "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util/errors" ) -type secondaryLayer3NetworkControllerEventHandler struct { +type Layer3UserDefinedNetworkControllerEventHandler struct { baseHandler baseNetworkControllerEventHandler watchFactory *factory.WatchFactory objType reflect.Type - oc *SecondaryLayer3NetworkController + oc *Layer3UserDefinedNetworkController syncFunc func([]interface{}) error } -func (h *secondaryLayer3NetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { +func (h *Layer3UserDefinedNetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { return h.oc.FilterOutResource(h.objType, obj) } @@ -51,56 +51,56 @@ func (h *secondaryLayer3NetworkControllerEventHandler) FilterOutResource(obj int // type considers them equal and therefore no update is needed. It returns false when the two objects are not considered // equal and an update needs be executed. This is regardless of how the update is carried out (whether with a dedicated update // function or with a delete on the old obj followed by an add on the new obj). -func (h *secondaryLayer3NetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { return h.baseHandler.areResourcesEqual(h.objType, obj1, obj2) } // GetInternalCacheEntry returns the internal cache entry for this object, given an object and its type. // This is now used only for pods, which will get their the logical port cache entry. -func (h *secondaryLayer3NetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { - return h.oc.GetInternalCacheEntryForSecondaryNetwork(h.objType, obj) +func (h *Layer3UserDefinedNetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { + return h.oc.GetInternalCacheEntryForUserDefinedNetwork(h.objType, obj) } // GetResourceFromInformerCache returns the latest state of the object, given an object key and its type. // from the informers cache. -func (h *secondaryLayer3NetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { return h.baseHandler.getResourceFromInformerCache(h.objType, h.watchFactory, key) } // RecordAddEvent records the add event on this given object. -func (h *secondaryLayer3NetworkControllerEventHandler) RecordAddEvent(obj interface{}) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) RecordAddEvent(obj interface{}) { h.baseHandler.recordAddEvent(h.objType, obj) } // RecordUpdateEvent records the udpate event on this given object. -func (h *secondaryLayer3NetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { h.baseHandler.recordUpdateEvent(h.objType, obj) } // RecordDeleteEvent records the delete event on this given object. -func (h *secondaryLayer3NetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { h.baseHandler.recordDeleteEvent(h.objType, obj) } // RecordSuccessEvent records the success event on this given object. -func (h *secondaryLayer3NetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { h.baseHandler.recordSuccessEvent(h.objType, obj) } // RecordErrorEvent records the error event on this given object. -func (h *secondaryLayer3NetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { +func (h *Layer3UserDefinedNetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { } // IsResourceScheduled returns true if the given object has been scheduled. // Only applied to pods for now. Returns true for all other types. -func (h *secondaryLayer3NetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { +func (h *Layer3UserDefinedNetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { return h.baseHandler.isResourceScheduled(h.objType, obj) } // AddResource adds the specified object to the cluster according to its type and returns the error, // if any, yielded during object creation. // Given an object to add and a boolean specifying if the function was executed from iterateRetryResources -func (h *secondaryLayer3NetworkControllerEventHandler) AddResource(obj interface{}, fromRetryLoop bool) error { +func (h *Layer3UserDefinedNetworkControllerEventHandler) AddResource(obj interface{}, fromRetryLoop bool) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -145,7 +145,7 @@ func (h *secondaryLayer3NetworkControllerEventHandler) AddResource(obj interface } } default: - return h.oc.AddSecondaryNetworkResourceCommon(h.objType, obj) + return h.oc.AddUserDefinedNetworkResourceCommon(h.objType, obj) } return nil } @@ -154,7 +154,7 @@ func (h *secondaryLayer3NetworkControllerEventHandler) AddResource(obj interface // type and returns the error, if any, yielded during the object update. // Given an old and a new object; The inRetryCache boolean argument is to indicate if the given resource // is in the retryCache or not. -func (h *secondaryLayer3NetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { +func (h *Layer3UserDefinedNetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { switch h.objType { case factory.NodeType: newNode, ok := newObj.(*corev1.Node) @@ -223,14 +223,14 @@ func (h *secondaryLayer3NetworkControllerEventHandler) UpdateResource(oldObj, ne return h.oc.addUpdateRemoteNodeEvent(newNode, syncZoneIC) } default: - return h.oc.UpdateSecondaryNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) + return h.oc.UpdateUserDefinedNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) } } // DeleteResource deletes the object from the cluster according to the delete logic of its resource type. // Given an object and optionally a cachedObj; cachedObj is the internal cache entry for this object, // used for now for pods and network policies. -func (h *secondaryLayer3NetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { +func (h *Layer3UserDefinedNetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -240,11 +240,11 @@ func (h *secondaryLayer3NetworkControllerEventHandler) DeleteResource(obj, cache return h.oc.deleteNodeEvent(node) default: - return h.oc.DeleteSecondaryNetworkResourceCommon(h.objType, obj, cachedObj) + return h.oc.DeleteUserDefinedNetworkResourceCommon(h.objType, obj, cachedObj) } } -func (h *secondaryLayer3NetworkControllerEventHandler) SyncFunc(objs []interface{}) error { +func (h *Layer3UserDefinedNetworkControllerEventHandler) SyncFunc(objs []interface{}) error { var syncFunc func([]interface{}) error if h.syncFunc != nil { @@ -253,7 +253,7 @@ func (h *secondaryLayer3NetworkControllerEventHandler) SyncFunc(objs []interface } else { switch h.objType { case factory.PodType: - syncFunc = h.oc.syncPodsForSecondaryNetwork + syncFunc = h.oc.syncPodsForUserDefinedNetwork case factory.NodeType: syncFunc = h.oc.syncNodes @@ -279,14 +279,14 @@ func (h *secondaryLayer3NetworkControllerEventHandler) SyncFunc(objs []interface // IsObjectInTerminalState returns true if the given object is a in terminal state. // This is used now for pods that are either in a PodSucceeded or in a PodFailed state. -func (h *secondaryLayer3NetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { +func (h *Layer3UserDefinedNetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { return h.baseHandler.isObjectInTerminalState(h.objType, obj) } -// SecondaryLayer3NetworkController is created for logical network infrastructure and policy -// for a secondary l3 network -type SecondaryLayer3NetworkController struct { - BaseSecondaryNetworkController +// Layer3UserDefinedNetworkController is created for logical network infrastructure and policy +// for a l3 UDN +type Layer3UserDefinedNetworkController struct { + BaseUserDefinedNetworkController // Node-specific syncMaps used by node event handler mgmtPortFailed sync.Map @@ -321,23 +321,23 @@ type SecondaryLayer3NetworkController struct { eIPController *EgressIPController } -// NewSecondaryLayer3NetworkController create a new OVN controller for the given secondary layer3 NAD -func NewSecondaryLayer3NetworkController( +// NewLayer3UserDefinedNetworkController create a new OVN controller for the given layer3 NAD +func NewLayer3UserDefinedNetworkController( cnci *CommonNetworkControllerInfo, netInfo util.NetInfo, networkManager networkmanager.Interface, routeImportManager routeimport.Manager, eIPController *EgressIPController, portCache *PortCache, -) (*SecondaryLayer3NetworkController, error) { +) (*Layer3UserDefinedNetworkController, error) { stopChan := make(chan struct{}) ipv4Mode, ipv6Mode := netInfo.IPMode() addressSetFactory := addressset.NewOvnAddressSetFactory(cnci.nbClient, ipv4Mode, ipv6Mode) - oc := &SecondaryLayer3NetworkController{ - BaseSecondaryNetworkController: BaseSecondaryNetworkController{ + oc := &Layer3UserDefinedNetworkController{ + BaseUserDefinedNetworkController: BaseUserDefinedNetworkController{ BaseNetworkController: BaseNetworkController{ CommonNetworkControllerInfo: *cnci, controllerName: getNetworkControllerName(netInfo.GetNetworkName()), @@ -405,7 +405,7 @@ func NewSecondaryLayer3NetworkController( return oc, nil } -func (oc *SecondaryLayer3NetworkController) initRetryFramework() { +func (oc *Layer3UserDefinedNetworkController) initRetryFramework() { oc.retryPods = oc.newRetryFramework(factory.PodType) oc.retryNodes = oc.newRetryFramework(factory.NodeType) @@ -426,9 +426,9 @@ func (oc *SecondaryLayer3NetworkController) initRetryFramework() { } // newRetryFramework builds and returns a retry framework for the input resource type; -func (oc *SecondaryLayer3NetworkController) newRetryFramework( +func (oc *Layer3UserDefinedNetworkController) newRetryFramework( objectType reflect.Type) *retry.RetryFramework { - eventHandler := &secondaryLayer3NetworkControllerEventHandler{ + eventHandler := &Layer3UserDefinedNetworkControllerEventHandler{ baseHandler: baseNetworkControllerEventHandler{}, objType: objectType, watchFactory: oc.watchFactory, @@ -449,9 +449,9 @@ func (oc *SecondaryLayer3NetworkController) newRetryFramework( ) } -// Start starts the secondary layer3 controller, handles all events and creates all needed logical entities -func (oc *SecondaryLayer3NetworkController) Start(_ context.Context) error { - klog.Infof("Start secondary %s network controller of network %s", oc.TopologyType(), oc.GetNetworkName()) +// Start starts the UDN layer3 controller, handles all events and creates all needed logical entities +func (oc *Layer3UserDefinedNetworkController) Start(_ context.Context) error { + klog.Infof("Start %s UDN controller for network %s", oc.TopologyType(), oc.GetNetworkName()) if err := oc.init(); err != nil { return err } @@ -459,8 +459,8 @@ func (oc *SecondaryLayer3NetworkController) Start(_ context.Context) error { } // Stop gracefully stops the controller, and delete all logical entities for this network if requested -func (oc *SecondaryLayer3NetworkController) Stop() { - klog.Infof("Stop secondary %s network controller of network %s", oc.TopologyType(), oc.GetNetworkName()) +func (oc *Layer3UserDefinedNetworkController) Stop() { + klog.Infof("Stop %s UDN controller of network %s", oc.TopologyType(), oc.GetNetworkName()) close(oc.stopChan) oc.cancelableCtx.Cancel() oc.wg.Wait() @@ -487,7 +487,7 @@ func (oc *SecondaryLayer3NetworkController) Stop() { // Cleanup cleans up logical entities for the given network, called from net-attach-def routine // could be called from a dummy Controller (only has CommonNetworkControllerInfo set) -func (oc *SecondaryLayer3NetworkController) Cleanup() error { +func (oc *Layer3UserDefinedNetworkController) Cleanup() error { // cleans up related OVN logical entities var ops []ovsdb.Operation var err error @@ -557,7 +557,7 @@ func (oc *SecondaryLayer3NetworkController) Cleanup() error { return nil } -func (oc *SecondaryLayer3NetworkController) run() error { +func (oc *Layer3UserDefinedNetworkController) run() error { klog.Infof("Starting all the Watchers for network %s ...", oc.GetNetworkName()) start := time.Now() @@ -628,7 +628,7 @@ func (oc *SecondaryLayer3NetworkController) run() error { return nil } -func (oc *SecondaryLayer3NetworkController) Reconcile(netInfo util.NetInfo) error { +func (oc *Layer3UserDefinedNetworkController) Reconcile(netInfo util.NetInfo) error { return oc.BaseNetworkController.reconcile( netInfo, func(node string) { @@ -640,7 +640,7 @@ func (oc *SecondaryLayer3NetworkController) Reconcile(netInfo util.NetInfo) erro // WatchNodes starts the watching of node resource and calls // back the appropriate handler logic -func (oc *SecondaryLayer3NetworkController) WatchNodes() error { +func (oc *Layer3UserDefinedNetworkController) WatchNodes() error { if oc.nodeHandler != nil { return nil } @@ -651,7 +651,7 @@ func (oc *SecondaryLayer3NetworkController) WatchNodes() error { return err } -func (oc *SecondaryLayer3NetworkController) init() error { +func (oc *Layer3UserDefinedNetworkController) init() error { if err := oc.gatherJoinSwitchIPs(); err != nil { return fmt.Errorf("failed to gather join switch IPs for network %s: %v", oc.GetNetworkName(), err) } @@ -699,7 +699,7 @@ func (oc *SecondaryLayer3NetworkController) init() error { return nil } -func (oc *SecondaryLayer3NetworkController) addUpdateLocalNodeEvent(node *corev1.Node, nSyncs *nodeSyncs) error { +func (oc *Layer3UserDefinedNetworkController) addUpdateLocalNodeEvent(node *corev1.Node, nSyncs *nodeSyncs) error { var hostSubnets []*net.IPNet var errs []error var err error @@ -835,7 +835,7 @@ func (oc *SecondaryLayer3NetworkController) addUpdateLocalNodeEvent(node *corev1 return err } -func (oc *SecondaryLayer3NetworkController) addUpdateRemoteNodeEvent(node *corev1.Node, syncZoneIc bool) error { +func (oc *Layer3UserDefinedNetworkController) addUpdateRemoteNodeEvent(node *corev1.Node, syncZoneIc bool) error { _, present := oc.localZoneNodes.Load(node.Name) if present { @@ -870,7 +870,7 @@ func (oc *SecondaryLayer3NetworkController) addUpdateRemoteNodeEvent(node *corev // If isUDNAdvertised is true, then we want to SNAT all packets that are coming from pods on this network // leaving towards nodeIPs on the cluster to masqueradeIP. If network is advertise then the SNAT looks like this: // "eth.dst == 0a:58:5d:5d:00:02 && (ip4.dst == $a712973235162149816)" "169.254.0.36" "93.93.0.0/24" -func (oc *SecondaryLayer3NetworkController) addOrUpdateUDNNodeSubnetEgressSNAT(localPodSubnets []*net.IPNet, node *corev1.Node, isUDNAdvertised bool) error { +func (oc *Layer3UserDefinedNetworkController) addOrUpdateUDNNodeSubnetEgressSNAT(localPodSubnets []*net.IPNet, node *corev1.Node, isUDNAdvertised bool) error { outputPort := types.RouterToSwitchPrefix + oc.GetNetworkScopedName(node.Name) nats, err := oc.buildUDNEgressSNAT(localPodSubnets, outputPort, isUDNAdvertised) if err != nil { @@ -890,13 +890,13 @@ func (oc *SecondaryLayer3NetworkController) addOrUpdateUDNNodeSubnetEgressSNAT(l return nil } -func (oc *SecondaryLayer3NetworkController) addNode(node *corev1.Node) ([]*net.IPNet, error) { - // Node subnet for the secondary layer3 network is allocated by cluster manager. +func (oc *Layer3UserDefinedNetworkController) addNode(node *corev1.Node) ([]*net.IPNet, error) { + // Node subnet for the layer3 UDN is allocated by cluster manager. // Make sure that the node is allocated with the subnet before proceeding // to create OVN Northbound resources. hostSubnets, err := util.ParseNodeHostSubnetAnnotation(node, oc.GetNetworkName()) if err != nil || len(hostSubnets) < 1 { - return nil, fmt.Errorf("subnet annotation in the node %q for the layer3 secondary network %s is missing : %w", node.Name, oc.GetNetworkName(), err) + return nil, fmt.Errorf("subnet annotation in the node %q for the layer3 UDN %s is missing : %w", node.Name, oc.GetNetworkName(), err) } err = oc.createNodeLogicalSwitch(node.Name, hostSubnets, oc.clusterLoadBalancerGroupUUID, oc.switchLoadBalancerGroupUUID) @@ -922,7 +922,7 @@ func (oc *SecondaryLayer3NetworkController) addNode(node *corev1.Node) ([]*net.I return hostSubnets, nil } -func (oc *SecondaryLayer3NetworkController) deleteNodeEvent(node *corev1.Node) error { +func (oc *Layer3UserDefinedNetworkController) deleteNodeEvent(node *corev1.Node) error { klog.V(5).Infof("Deleting Node %q for network %s. Removing the node from "+ "various caches", node.Name, oc.GetNetworkName()) @@ -950,7 +950,7 @@ func (oc *SecondaryLayer3NetworkController) deleteNodeEvent(node *corev1.Node) e return nil } -func (oc *SecondaryLayer3NetworkController) deleteNode(nodeName string) error { +func (oc *Layer3UserDefinedNetworkController) deleteNode(nodeName string) error { if err := oc.deleteNodeLogicalNetwork(nodeName); err != nil { return fmt.Errorf("error deleting node %s logical network: %v", nodeName, err) } @@ -962,7 +962,7 @@ func (oc *SecondaryLayer3NetworkController) deleteNode(nodeName string) error { // watchNodes() will be called for all existing nodes at startup anyway. // Note that this list will include the 'join' cluster switch, which we // do not want to delete. -func (oc *SecondaryLayer3NetworkController) syncNodes(nodes []interface{}) error { +func (oc *Layer3UserDefinedNetworkController) syncNodes(nodes []interface{}) error { foundNodes := sets.New[string]() for _, tmp := range nodes { node, ok := tmp.(*corev1.Node) @@ -1005,7 +1005,7 @@ func (oc *SecondaryLayer3NetworkController) syncNodes(nodes []interface{}) error return nil } -func (oc *SecondaryLayer3NetworkController) gatherJoinSwitchIPs() error { +func (oc *Layer3UserDefinedNetworkController) gatherJoinSwitchIPs() error { // Allocate IPs for logical router port prefixed with // `GwRouterToJoinSwitchPrefix` for the network managed by this controller. // This should always allocate the first IPs in the join switch subnets. @@ -1017,7 +1017,7 @@ func (oc *SecondaryLayer3NetworkController) gatherJoinSwitchIPs() error { return nil } -func (oc *SecondaryLayer3NetworkController) nodeGatewayConfig(node *corev1.Node) (*GatewayConfig, error) { +func (oc *Layer3UserDefinedNetworkController) nodeGatewayConfig(node *corev1.Node) (*GatewayConfig, error) { l3GatewayConfig, err := util.ParseNodeL3GatewayAnnotation(node) if err != nil { return nil, fmt.Errorf("failed to get node %s network %s L3 gateway config: %v", node.Name, oc.GetNetworkName(), err) @@ -1078,7 +1078,7 @@ func (oc *SecondaryLayer3NetworkController) nodeGatewayConfig(node *corev1.Node) }, nil } -func (oc *SecondaryLayer3NetworkController) newClusterRouter() (*nbdb.LogicalRouter, error) { +func (oc *Layer3UserDefinedNetworkController) newClusterRouter() (*nbdb.LogicalRouter, error) { if oc.multicastSupport { return oc.gatewayTopologyFactory.NewClusterRouterWithMulticastSupport( oc.GetNetworkScopedClusterRouterName(), @@ -1093,7 +1093,7 @@ func (oc *SecondaryLayer3NetworkController) newClusterRouter() (*nbdb.LogicalRou ) } -func (oc *SecondaryLayer3NetworkController) newGatewayManager(nodeName string) *GatewayManager { +func (oc *Layer3UserDefinedNetworkController) newGatewayManager(nodeName string) *GatewayManager { return NewGatewayManager( nodeName, oc.defaultCOPPUUID, @@ -1105,7 +1105,7 @@ func (oc *SecondaryLayer3NetworkController) newGatewayManager(nodeName string) * ) } -func (oc *SecondaryLayer3NetworkController) gatewayOptions() []GatewayOption { +func (oc *Layer3UserDefinedNetworkController) gatewayOptions() []GatewayOption { var opts []GatewayOption if oc.clusterLoadBalancerGroupUUID != "" { opts = append(opts, WithLoadBalancerGroups( @@ -1117,7 +1117,7 @@ func (oc *SecondaryLayer3NetworkController) gatewayOptions() []GatewayOption { return opts } -func (oc *SecondaryLayer3NetworkController) gatewayManagerForNode(nodeName string) *GatewayManager { +func (oc *Layer3UserDefinedNetworkController) gatewayManagerForNode(nodeName string) *GatewayManager { obj, isFound := oc.gatewayManagers.Load(nodeName) if !isFound { return oc.newGatewayManager(nodeName) @@ -1135,7 +1135,7 @@ func (oc *SecondaryLayer3NetworkController) gatewayManagerForNode(nodeName strin } } -func (oc *SecondaryLayer3NetworkController) StartServiceController(wg *sync.WaitGroup, runRepair bool) error { +func (oc *Layer3UserDefinedNetworkController) StartServiceController(wg *sync.WaitGroup, runRepair bool) error { useLBGroups := oc.clusterLoadBalancerGroupUUID != "" // use 5 workers like most of the kubernetes controllers in the kubernetes controller-manager // do not use LB templates for UDNs - OVN bug https://issues.redhat.com/browse/FDP-988 diff --git a/go-controller/pkg/ovn/secondary_layer3_network_controller_test.go b/go-controller/pkg/ovn/layer3_user_defined_network_controller_test.go similarity index 92% rename from go-controller/pkg/ovn/secondary_layer3_network_controller_test.go rename to go-controller/pkg/ovn/layer3_user_defined_network_controller_test.go index fe667417ec..f9cec964ae 100644 --- a/go-controller/pkg/ovn/secondary_layer3_network_controller_test.go +++ b/go-controller/pkg/ovn/layer3_user_defined_network_controller_test.go @@ -33,7 +33,7 @@ import ( . "github.com/onsi/gomega" ) -type secondaryNetInfo struct { +type userDefinedNetInfo struct { netName string nadName string clustersubnets string @@ -45,12 +45,12 @@ type secondaryNetInfo struct { } const ( - nadName = "blue-net" - ns = "namespace1" - secondaryNetworkName = "isolatednet" - secondaryNetworkID = "2" - denyPolicyName = "deny-all-policy" - denyPG = "deny-port-group" + nadName = "blue-net" + ns = "namespace1" + userDefinedNetworkName = "isolatednet" + userDefinedNetworkID = "2" + denyPolicyName = "deny-all-policy" + denyPG = "deny-port-group" ) type testConfiguration struct { @@ -92,7 +92,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { DescribeTable( "reconciles a new", - func(netInfo secondaryNetInfo, testConfig testConfiguration, gwMode config.GatewayMode) { + func(netInfo userDefinedNetInfo, testConfig testConfiguration, gwMode config.GatewayMode) { podInfo := dummyTestPod(ns, netInfo) if testConfig.configToOverride != nil { config.OVNKubernetesFeature = *testConfig.configToOverride @@ -113,7 +113,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { *netInfo.netconf(), ) Expect(err).NotTo(HaveOccurred()) - nad.Annotations = map[string]string{types.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{types.OvnNetworkIDAnnotation: userDefinedNetworkID} Expect(netInfo.setupOVNDependencies(&initialDB)).To(Succeed()) n := newNamespace(ns) if netInfo.isPrimary { @@ -139,7 +139,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { } const nodeIPv4CIDR = "192.168.126.202/24" - testNode, err := newNodeWithSecondaryNets(nodeName, nodeIPv4CIDR, netInfo) + testNode, err := newNodeWithUserDefinedNetworks(nodeName, nodeIPv4CIDR, netInfo) Expect(err).NotTo(HaveOccurred()) networkPolicy := getMatchLabelsNetworkPolicy(denyPolicyName, ns, "", "", false, false) fakeOvn.startWithDBSetup( @@ -180,16 +180,16 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { if netInfo.isPrimary { Expect(fakeOvn.controller.WatchNetworkPolicy()).NotTo(HaveOccurred()) } - secondaryNetController, ok := fakeOvn.secondaryControllers[secondaryNetworkName] + userDefinedNetController, ok := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] Expect(ok).To(BeTrue()) - secondaryNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() - podInfo.populateSecondaryNetworkLogicalSwitchCache(secondaryNetController) - Expect(secondaryNetController.bnc.WatchNodes()).To(Succeed()) - Expect(secondaryNetController.bnc.WatchPods()).To(Succeed()) + userDefinedNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() + podInfo.populateUserDefinedNetworkLogicalSwitchCache(userDefinedNetController) + Expect(userDefinedNetController.bnc.WatchNodes()).To(Succeed()) + Expect(userDefinedNetController.bnc.WatchPods()).To(Succeed()) if netInfo.isPrimary { - Expect(secondaryNetController.bnc.WatchNetworkPolicy()).To(Succeed()) + Expect(userDefinedNetController.bnc.WatchNetworkPolicy()).To(Succeed()) ninfo, err := fakeOvn.networkManager.Interface().GetActiveNetworkForNamespace(ns) Expect(err).NotTo(HaveOccurred()) Expect(ninfo.GetNetworkName()).To(Equal(netInfo.netName)) @@ -211,24 +211,24 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { if testConfig.configToOverride != nil && testConfig.configToOverride.EnableEgressFirewall { defaultNetExpectations = append(defaultNetExpectations, buildNamespacedPortGroup(podInfo.namespace, DefaultNetworkControllerName)) - secNetPG := buildNamespacedPortGroup(podInfo.namespace, secondaryNetController.bnc.controllerName) - portName := util.GetSecondaryNetworkLogicalPortName(podInfo.namespace, podInfo.podName, netInfo.nadName) + "-UUID" + secNetPG := buildNamespacedPortGroup(podInfo.namespace, userDefinedNetController.bnc.controllerName) + portName := util.GetUserDefinedNetworkLogicalPortName(podInfo.namespace, podInfo.podName, netInfo.nadName) + "-UUID" secNetPG.Ports = []string{portName} defaultNetExpectations = append(defaultNetExpectations, secNetPG) } networkConfig, err := util.NewNetInfo(netInfo.netconf()) Expect(err).NotTo(HaveOccurred()) // Add NetPol hairpin ACLs and PGs for the validation. - mgmtPortName := managementPortName(secondaryNetController.bnc.GetNetworkScopedName(nodeName)) + mgmtPortName := managementPortName(userDefinedNetController.bnc.GetNetworkScopedName(nodeName)) mgmtPortUUID := mgmtPortName + "-UUID" defaultNetExpectations = append(defaultNetExpectations, getHairpinningACLsV4AndPortGroup()...) defaultNetExpectations = append(defaultNetExpectations, getHairpinningACLsV4AndPortGroupForNetwork(networkConfig, []string{mgmtPortUUID})...) // Add Netpol deny policy ACLs and PGs for the validation. - podLPortName := util.GetSecondaryNetworkLogicalPortName(podInfo.namespace, podInfo.podName, netInfo.nadName) + "-UUID" + podLPortName := util.GetUserDefinedNetworkLogicalPortName(podInfo.namespace, podInfo.podName, netInfo.nadName) + "-UUID" dataParams := newNetpolDataParams(networkPolicy).withLocalPortUUIDs(podLPortName).withNetInfo(networkConfig) defaultDenyExpectedData := getDefaultDenyData(dataParams) - pgDbIDs := getNetworkPolicyPortGroupDbIDs(ns, secondaryNetController.bnc.controllerName, denyPolicyName) + pgDbIDs := getNetworkPolicyPortGroupDbIDs(ns, userDefinedNetController.bnc.controllerName, denyPolicyName) ingressPG := libovsdbutil.BuildPortGroup(pgDbIDs, nil, nil) ingressPG.UUID = denyPG ingressPG.Ports = []string{podLPortName} @@ -239,7 +239,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { libovsdbtest.HaveData( append( defaultNetExpectations, - newSecondaryNetworkExpectationMachine( + newUserDefinedNetworkExpectationMachine( fakeOvn, []testPod{podInfo}, expectationOptions..., @@ -293,7 +293,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { DescribeTable( "the gateway is properly cleaned up", - func(netInfo secondaryNetInfo, testConfig testConfiguration) { + func(netInfo userDefinedNetInfo, testConfig testConfiguration) { config.OVNKubernetesFeature.EnableMultiNetwork = true config.OVNKubernetesFeature.EnableNetworkSegmentation = true podInfo := dummyTestPod(ns, netInfo) @@ -314,7 +314,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { *netConf, ) Expect(err).NotTo(HaveOccurred()) - nad.Annotations = map[string]string{types.OvnNetworkIDAnnotation: secondaryNetworkID} + nad.Annotations = map[string]string{types.OvnNetworkIDAnnotation: userDefinedNetworkID} mutableNetworkConfig := util.NewMutableNetInfo(networkConfig) mutableNetworkConfig.SetNADs(util.GetNADName(nad.Namespace, nad.Name)) @@ -326,7 +326,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { fakeNetworkManager.PrimaryNetworks[ns] = networkConfig const nodeIPv4CIDR = "192.168.126.202/24" - testNode, err := newNodeWithSecondaryNets(nodeName, nodeIPv4CIDR, netInfo) + testNode, err := newNodeWithUserDefinedNetworks(nodeName, nodeIPv4CIDR, netInfo) Expect(err).NotTo(HaveOccurred()) nbZone := &nbdb.NBGlobal{Name: types.OvnDefaultZone, UUID: types.OvnDefaultZone} @@ -390,16 +390,16 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { Expect(fakeOvn.controller.WatchNamespaces()).To(Succeed()) Expect(fakeOvn.controller.WatchPods()).To(Succeed()) - secondaryNetController, ok := fakeOvn.secondaryControllers[secondaryNetworkName] + userDefinedNetController, ok := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] Expect(ok).To(BeTrue()) - secondaryNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() - podInfo.populateSecondaryNetworkLogicalSwitchCache(secondaryNetController) - Expect(secondaryNetController.bnc.WatchNodes()).To(Succeed()) - Expect(secondaryNetController.bnc.WatchPods()).To(Succeed()) + userDefinedNetController.bnc.ovnClusterLRPToJoinIfAddrs = dummyJoinIPs() + podInfo.populateUserDefinedNetworkLogicalSwitchCache(userDefinedNetController) + Expect(userDefinedNetController.bnc.WatchNodes()).To(Succeed()) + Expect(userDefinedNetController.bnc.WatchPods()).To(Succeed()) if netInfo.isPrimary { - Expect(secondaryNetController.bnc.WatchNetworkPolicy()).To(Succeed()) + Expect(userDefinedNetController.bnc.WatchNetworkPolicy()).To(Succeed()) } Expect(fakeOvn.fakeClient.KubeClient.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})).To(Succeed()) @@ -407,8 +407,8 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { // we must access the layer3 controller to be able to issue its cleanup function (to remove the GW related stuff). Expect( - newSecondaryLayer3NetworkController( - &secondaryNetController.bnc.CommonNetworkControllerInfo, + newLayer3UserDefinedNetworkController( + &userDefinedNetController.bnc.CommonNetworkControllerInfo, networkConfig, nodeName, fakeNetworkManager, @@ -446,7 +446,7 @@ var _ = Describe("OVN Multi-Homed pod operations for layer 3 network", func() { func newPodWithPrimaryUDN( nodeName, nodeSubnet, nodeMgtIP, nodeGWIP, podName, podIPs, podMAC, namespace string, - primaryUDNConfig secondaryNetInfo, + primaryUDNConfig userDefinedNetInfo, ) testPod { pod := newTPod(nodeName, nodeSubnet, nodeMgtIP, "", podName, podIPs, podMAC, namespace) if primaryUDNConfig.isPrimary { @@ -493,7 +493,7 @@ func newPodWithPrimaryUDN( func namespacedName(ns, name string) string { return fmt.Sprintf("%s/%s", ns, name) } -func (sni *secondaryNetInfo) getNetworkRole() string { +func (sni *userDefinedNetInfo) getNetworkRole() string { return util.GetUserDefinedNetworkRole(sni.isPrimary) } @@ -501,7 +501,7 @@ func getNetworkRole(netInfo util.NetInfo) string { return util.GetUserDefinedNetworkRole(netInfo.IsPrimaryNetwork()) } -func (sni *secondaryNetInfo) setupOVNDependencies(dbData *libovsdbtest.TestSetup) error { +func (sni *userDefinedNetInfo) setupOVNDependencies(dbData *libovsdbtest.TestSetup) error { netInfo, err := util.NewNetInfo(sni.netconf()) if err != nil { return err @@ -536,7 +536,7 @@ func (sni *secondaryNetInfo) setupOVNDependencies(dbData *libovsdbtest.TestSetup return nil } -func (sni *secondaryNetInfo) netconf() *ovncnitypes.NetConf { +func (sni *userDefinedNetInfo) netconf() *ovncnitypes.NetConf { const plugin = "ovn-k8s-cni-overlay" role := types.NetworkRoleSecondary @@ -556,7 +556,7 @@ func (sni *secondaryNetInfo) netconf() *ovncnitypes.NetConf { } } -func dummyTestPod(nsName string, info secondaryNetInfo) testPod { +func dummyTestPod(nsName string, info userDefinedNetInfo) testPod { const nodeSubnet = "10.128.1.0/24" if info.isPrimary { return newPodWithPrimaryUDN( @@ -592,9 +592,9 @@ func dummyTestPod(nsName string, info secondaryNetInfo) testPod { return pod } -func dummySecondaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets string) secondaryNetInfo { - return secondaryNetInfo{ - netName: secondaryNetworkName, +func dummySecondaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets string) userDefinedNetInfo { + return userDefinedNetInfo{ + netName: userDefinedNetworkName, nadName: namespacedName(ns, nadName), topology: types.Layer3Topology, clustersubnets: clustersubnets, @@ -602,18 +602,18 @@ func dummySecondaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets string) } } -func dummyPrimaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets string) secondaryNetInfo { +func dummyPrimaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets string) userDefinedNetInfo { secondaryNet := dummySecondaryLayer3UserDefinedNetwork(clustersubnets, hostsubnets) secondaryNet.isPrimary = true return secondaryNet } // This util is returning a network-name/hostSubnet for the node's node-subnets annotation -func (sni *secondaryNetInfo) String() string { +func (sni *userDefinedNetInfo) String() string { return fmt.Sprintf("%q: %q", sni.netName, sni.hostsubnets) } -func newNodeWithSecondaryNets(nodeName string, nodeIPv4CIDR string, netInfos ...secondaryNetInfo) (*corev1.Node, error) { +func newNodeWithUserDefinedNetworks(nodeName string, nodeIPv4CIDR string, netInfos ...userDefinedNetInfo) (*corev1.Node, error) { var nodeSubnetInfo []string for _, info := range netInfos { nodeSubnetInfo = append(nodeSubnetInfo, info.String()) @@ -641,7 +641,7 @@ func newNodeWithSecondaryNets(nodeName string, nodeIPv4CIDR string, netInfos ... "k8s.ovn.org/zone-name": "global", "k8s.ovn.org/l3-gateway-config": fmt.Sprintf("{\"default\":{\"mode\":\"shared\",\"bridge-id\":\"breth0\",\"interface-id\":\"breth0_ovn-worker\",\"mac-address\":%q,\"ip-addresses\":[%[2]q],\"ip-address\":%[2]q,\"next-hops\":[%[3]q],\"next-hop\":%[3]q,\"node-port-enable\":\"true\",\"vlan-id\":\"0\"}}", util.IPAddrToHWAddr(nodeIP), nodeCIDR, nextHopIP), util.OvnNodeChassisID: "abdcef", - "k8s.ovn.org/network-ids": fmt.Sprintf("{\"default\":\"0\",\"isolatednet\":\"%s\"}", secondaryNetworkID), + "k8s.ovn.org/network-ids": fmt.Sprintf("{\"default\":\"0\",\"isolatednet\":\"%s\"}", userDefinedNetworkID), util.OvnNodeID: "4", "k8s.ovn.org/udn-layer2-node-gateway-router-lrp-tunnel-ids": "{\"isolatednet\":\"25\"}", }, @@ -1043,15 +1043,15 @@ func standardNonDefaultNetworkExtIDsForLogicalSwitch(netInfo util.NetInfo) map[s return externalIDs } -func newSecondaryLayer3NetworkController( +func newLayer3UserDefinedNetworkController( cnci *CommonNetworkControllerInfo, netInfo util.NetInfo, nodeName string, networkManager networkmanager.Interface, eIPController *EgressIPController, portCache *PortCache, -) *SecondaryLayer3NetworkController { - layer3NetworkController, err := NewSecondaryLayer3NetworkController(cnci, netInfo, networkManager, nil, eIPController, portCache) +) *Layer3UserDefinedNetworkController { + layer3NetworkController, err := NewLayer3UserDefinedNetworkController(cnci, netInfo, networkManager, nil, eIPController, portCache) Expect(err).NotTo(HaveOccurred()) layer3NetworkController.gatewayManagers.Store( nodeName, diff --git a/go-controller/pkg/ovn/secondary_localnet_network_controller.go b/go-controller/pkg/ovn/localnet_user_defined_network_controller.go similarity index 72% rename from go-controller/pkg/ovn/secondary_localnet_network_controller.go rename to go-controller/pkg/ovn/localnet_user_defined_network_controller.go index 24cb69f631..5904c689b9 100644 --- a/go-controller/pkg/ovn/secondary_localnet_network_controller.go +++ b/go-controller/pkg/ovn/localnet_user_defined_network_controller.go @@ -27,15 +27,15 @@ import ( "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" ) -type secondaryLocalnetNetworkControllerEventHandler struct { +type LocalnetUserDefinedNetworkControllerEventHandler struct { baseHandler baseNetworkControllerEventHandler watchFactory *factory.WatchFactory objType reflect.Type - oc *SecondaryLocalnetNetworkController + oc *LocalnetUserDefinedNetworkController syncFunc func([]interface{}) error } -func (h *secondaryLocalnetNetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) FilterOutResource(obj interface{}) bool { return h.oc.FilterOutResource(h.objType, obj) } @@ -43,24 +43,24 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) FilterOutResource(obj i // type considers them equal and therefore no update is needed. It returns false when the two objects are not considered // equal and an update needs be executed. This is regardless of how the update is carried out (whether with a dedicated update // function or with a delete on the old obj followed by an add on the new obj). -func (h *secondaryLocalnetNetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error) { return h.baseHandler.areResourcesEqual(h.objType, obj1, obj2) } // GetInternalCacheEntry returns the internal cache entry for this object, given an object and its type. // This is now used only for pods, which will get their the logical port cache entry. -func (h *secondaryLocalnetNetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { - return h.oc.GetInternalCacheEntryForSecondaryNetwork(h.objType, obj) +func (h *LocalnetUserDefinedNetworkControllerEventHandler) GetInternalCacheEntry(obj interface{}) interface{} { + return h.oc.GetInternalCacheEntryForUserDefinedNetwork(h.objType, obj) } // GetResourceFromInformerCache returns the latest state of the object, given an object key and its type. // from the informers cache. -func (h *secondaryLocalnetNetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) GetResourceFromInformerCache(key string) (interface{}, error) { return h.baseHandler.getResourceFromInformerCache(h.objType, h.watchFactory, key) } // RecordAddEvent records the add event on this given object. -func (h *secondaryLocalnetNetworkControllerEventHandler) RecordAddEvent(obj interface{}) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) RecordAddEvent(obj interface{}) { switch h.objType { case factory.MultiNetworkPolicyType: mnp := obj.(*mnpapi.MultiNetworkPolicy) @@ -70,34 +70,34 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) RecordAddEvent(obj inte } // RecordUpdateEvent records the udpate event on this given object. -func (h *secondaryLocalnetNetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) RecordUpdateEvent(obj interface{}) { h.baseHandler.recordAddEvent(h.objType, obj) } // RecordDeleteEvent records the delete event on this given object. -func (h *secondaryLocalnetNetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) RecordDeleteEvent(obj interface{}) { h.baseHandler.recordAddEvent(h.objType, obj) } // RecordSuccessEvent records the success event on this given object. -func (h *secondaryLocalnetNetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) RecordSuccessEvent(obj interface{}) { h.baseHandler.recordAddEvent(h.objType, obj) } // RecordErrorEvent records the error event on this given object. -func (h *secondaryLocalnetNetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) RecordErrorEvent(_ interface{}, _ string, _ error) { } // IsResourceScheduled returns true if the given object has been scheduled. // Only applied to pods for now. Returns true for all other types. -func (h *secondaryLocalnetNetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) IsResourceScheduled(obj interface{}) bool { return h.baseHandler.isResourceScheduled(h.objType, obj) } // AddResource adds the specified object to the cluster according to its type and returns the error, // if any, yielded during object creation. // Given an object to add and a boolean specifying if the function was executed from iterateRetryResources -func (h *secondaryLocalnetNetworkControllerEventHandler) AddResource(obj interface{}, _ bool) error { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) AddResource(obj interface{}, _ bool) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -106,7 +106,7 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) AddResource(obj interfa } return h.oc.addUpdateNodeEvent(node) default: - return h.oc.AddSecondaryNetworkResourceCommon(h.objType, obj) + return h.oc.AddUserDefinedNetworkResourceCommon(h.objType, obj) } } @@ -114,7 +114,7 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) AddResource(obj interfa // type and returns the error, if any, yielded during the object update. // Given an old and a new object; The inRetryCache boolean argument is to indicate if the given resource // is in the retryCache or not. -func (h *secondaryLocalnetNetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error { switch h.objType { case factory.NodeType: node, ok := newObj.(*corev1.Node) @@ -123,14 +123,14 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) UpdateResource(oldObj, } return h.oc.addUpdateNodeEvent(node) default: - return h.oc.UpdateSecondaryNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) + return h.oc.UpdateUserDefinedNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache) } } // DeleteResource deletes the object from the cluster according to the delete logic of its resource type. // Given an object and optionally a cachedObj; cachedObj is the internal cache entry for this object, // used for now for pods and network policies. -func (h *secondaryLocalnetNetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) DeleteResource(obj, cachedObj interface{}) error { switch h.objType { case factory.NodeType: node, ok := obj.(*corev1.Node) @@ -139,11 +139,11 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) DeleteResource(obj, cac } return h.oc.deleteNodeEvent(node) default: - return h.oc.DeleteSecondaryNetworkResourceCommon(h.objType, obj, cachedObj) + return h.oc.DeleteUserDefinedNetworkResourceCommon(h.objType, obj, cachedObj) } } -func (h *secondaryLocalnetNetworkControllerEventHandler) SyncFunc(objs []interface{}) error { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) SyncFunc(objs []interface{}) error { var syncFunc func([]interface{}) error if h.syncFunc != nil { @@ -155,7 +155,7 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) SyncFunc(objs []interfa syncFunc = h.oc.syncNodes case factory.PodType: - syncFunc = h.oc.syncPodsForSecondaryNetwork + syncFunc = h.oc.syncPodsForUserDefinedNetwork case factory.NamespaceType: syncFunc = h.oc.syncNamespaces @@ -178,30 +178,30 @@ func (h *secondaryLocalnetNetworkControllerEventHandler) SyncFunc(objs []interfa // IsObjectInTerminalState returns true if the given object is a in terminal state. // This is used now for pods that are either in a PodSucceeded or in a PodFailed state. -func (h *secondaryLocalnetNetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { +func (h *LocalnetUserDefinedNetworkControllerEventHandler) IsObjectInTerminalState(obj interface{}) bool { return h.baseHandler.isObjectInTerminalState(h.objType, obj) } -// SecondaryLocalnetNetworkController is created for logical network infrastructure and policy -// for a secondary localnet network -type SecondaryLocalnetNetworkController struct { - BaseSecondaryLayer2NetworkController +// LocalnetUserDefinedNetworkController is created for logical network infrastructure and policy +// for a localnet user-defined network +type LocalnetUserDefinedNetworkController struct { + BaseLayer2UserDefinedNetworkController } -// NewSecondaryLocalnetNetworkController create a new OVN controller for the given secondary localnet NAD -func NewSecondaryLocalnetNetworkController( +// NewLocalnetUserDefinedNetworkController create a new OVN controller for the given localnet NAD +func NewLocalnetUserDefinedNetworkController( cnci *CommonNetworkControllerInfo, netInfo util.NetInfo, networkManager networkmanager.Interface, -) *SecondaryLocalnetNetworkController { +) *LocalnetUserDefinedNetworkController { stopChan := make(chan struct{}) ipv4Mode, ipv6Mode := netInfo.IPMode() addressSetFactory := addressset.NewOvnAddressSetFactory(cnci.nbClient, ipv4Mode, ipv6Mode) - oc := &SecondaryLocalnetNetworkController{ - BaseSecondaryLayer2NetworkController{ - BaseSecondaryNetworkController: BaseSecondaryNetworkController{ + oc := &LocalnetUserDefinedNetworkController{ + BaseLayer2UserDefinedNetworkController{ + BaseUserDefinedNetworkController: BaseUserDefinedNetworkController{ BaseNetworkController: BaseNetworkController{ CommonNetworkControllerInfo: *cnci, controllerName: getNetworkControllerName(netInfo.GetNetworkName()), @@ -242,21 +242,21 @@ func NewSecondaryLocalnetNetworkController( claimsReconciler) } - // disable multicast support for secondary networks - // TBD: changes needs to be made to support multicast in secondary networks + // disable multicast support for UDNs + // TBD: changes needs to be made to support multicast in UDNs oc.multicastSupport = false oc.initRetryFramework() return oc } -// Start starts the secondary localnet controller, handles all events and creates all needed logical entities -func (oc *SecondaryLocalnetNetworkController) Start(_ context.Context) error { - klog.Infof("Starting controller for secondary network network %s", oc.GetNetworkName()) +// Start starts the localnet UDN controller, handles all events and creates all needed logical entities +func (oc *LocalnetUserDefinedNetworkController) Start(_ context.Context) error { + klog.Infof("Starting controller for UDN %s", oc.GetNetworkName()) start := time.Now() defer func() { - klog.Infof("Starting controller for secondary network network %s took %v", oc.GetNetworkName(), time.Since(start)) + klog.Infof("Starting controller for UDN %s took %v", oc.GetNetworkName(), time.Since(start)) }() if err := oc.init(); err != nil { @@ -266,17 +266,17 @@ func (oc *SecondaryLocalnetNetworkController) Start(_ context.Context) error { return oc.run() } -func (oc *SecondaryLocalnetNetworkController) run() error { - return oc.BaseSecondaryLayer2NetworkController.run() +func (oc *LocalnetUserDefinedNetworkController) run() error { + return oc.BaseLayer2UserDefinedNetworkController.run() } // Cleanup cleans up logical entities for the given network, called from net-attach-def routine // could be called from a dummy Controller (only has CommonNetworkControllerInfo set) -func (oc *SecondaryLocalnetNetworkController) Cleanup() error { - return oc.BaseSecondaryLayer2NetworkController.cleanup() +func (oc *LocalnetUserDefinedNetworkController) Cleanup() error { + return oc.BaseLayer2UserDefinedNetworkController.cleanup() } -func (oc *SecondaryLocalnetNetworkController) init() error { +func (oc *LocalnetUserDefinedNetworkController) init() error { switchName := oc.GetNetworkScopedSwitchName(types.OVNLocalnetSwitch) logicalSwitch, err := oc.initializeLogicalSwitch(switchName, oc.Subnets(), oc.ExcludeSubnets(), oc.ReservedSubnets(), "", "") @@ -307,19 +307,19 @@ func (oc *SecondaryLocalnetNetworkController) init() error { return nil } -func (oc *SecondaryLocalnetNetworkController) Stop() { - klog.Infof("Stoping controller for secondary network %s", oc.GetNetworkName()) - oc.BaseSecondaryLayer2NetworkController.stop() +func (oc *LocalnetUserDefinedNetworkController) Stop() { + klog.Infof("Stoping controller for UDN %s", oc.GetNetworkName()) + oc.BaseLayer2UserDefinedNetworkController.stop() } -func (oc *SecondaryLocalnetNetworkController) Reconcile(netInfo util.NetInfo) error { +func (oc *LocalnetUserDefinedNetworkController) Reconcile(netInfo util.NetInfo) error { return oc.BaseNetworkController.reconcile( netInfo, func(_ string) {}, ) } -func (oc *SecondaryLocalnetNetworkController) initRetryFramework() { +func (oc *LocalnetUserDefinedNetworkController) initRetryFramework() { oc.retryNodes = oc.newRetryFramework(factory.NodeType) oc.retryPods = oc.newRetryFramework(factory.PodType) if oc.allocatesPodAnnotation() && oc.AllowsPersistentIPs() { @@ -336,9 +336,9 @@ func (oc *SecondaryLocalnetNetworkController) initRetryFramework() { } // newRetryFramework builds and returns a retry framework for the input resource type; -func (oc *SecondaryLocalnetNetworkController) newRetryFramework( +func (oc *LocalnetUserDefinedNetworkController) newRetryFramework( objectType reflect.Type) *retry.RetryFramework { - eventHandler := &secondaryLocalnetNetworkControllerEventHandler{ + eventHandler := &LocalnetUserDefinedNetworkControllerEventHandler{ baseHandler: baseNetworkControllerEventHandler{}, objType: objectType, watchFactory: oc.watchFactory, @@ -359,7 +359,7 @@ func (oc *SecondaryLocalnetNetworkController) newRetryFramework( ) } -func (oc *SecondaryLocalnetNetworkController) localnetPortNetworkNameOptions() map[string]string { +func (oc *LocalnetUserDefinedNetworkController) localnetPortNetworkNameOptions() map[string]string { localnetLSPOptions := map[string]string{ "network_name": oc.GetNetworkName(), } diff --git a/go-controller/pkg/ovn/multicast_test.go b/go-controller/pkg/ovn/multicast_test.go index 11e319214c..d40cc618e4 100644 --- a/go-controller/pkg/ovn/multicast_test.go +++ b/go-controller/pkg/ovn/multicast_test.go @@ -320,8 +320,8 @@ func startBaseNetworkController(fakeOvn *FakeOVN, nad *nadapi.NetworkAttachmentD if nad != nil { netInfo, err := util.ParseNADInfo(nad) Expect(err).ToNot(HaveOccurred()) - Expect(fakeOvn.NewSecondaryNetworkController(nad)).To(Succeed()) - controller, ok := fakeOvn.secondaryControllers[netInfo.GetNetworkName()] + Expect(fakeOvn.NewUserDefinedNetworkController(nad)).To(Succeed()) + controller, ok := fakeOvn.userDefinedNetworkControllers[netInfo.GetNetworkName()] Expect(ok).To(BeTrue()) return &controller.bnc.BaseNetworkController, controller.asf } else { diff --git a/go-controller/pkg/ovn/multihoming_test.go b/go-controller/pkg/ovn/multihoming_test.go index bfcdcd1a75..cd4f07137a 100644 --- a/go-controller/pkg/ovn/multihoming_test.go +++ b/go-controller/pkg/ovn/multihoming_test.go @@ -29,9 +29,9 @@ func (p testPod) addNetwork( tunnelID int, routes []util.PodRoute, ) { - podInfo, ok := p.secondaryPodInfos[netName] + podInfo, ok := p.udnPodInfos[netName] if !ok { - podInfo = &secondaryPodInfo{ + podInfo = &udnPodInfo{ nodeSubnet: nodeSubnet, nodeMgtIP: nodeMgtIP, nodeGWIP: nodeGWIP, @@ -39,12 +39,12 @@ func (p testPod) addNetwork( routes: routes, allportInfo: map[string]portInfo{}, } - p.secondaryPodInfos[netName] = podInfo + p.udnPodInfos[netName] = podInfo } prefixLen, ip := splitPodIPMaskLength(podIP) - portName := util.GetSecondaryNetworkLogicalPortName(p.namespace, p.podName, nadName) + portName := util.GetUserDefinedNetworkLogicalPortName(p.namespace, p.podName, nadName) podInfo.allportInfo[nadName] = portInfo{ portUUID: portName + "-UUID", podIP: ip, @@ -56,7 +56,7 @@ func (p testPod) addNetwork( } func (p testPod) getNetworkPortInfo(netName, nadName string) *portInfo { - podInfo, ok := p.secondaryPodInfos[netName] + podInfo, ok := p.udnPodInfos[netName] if !ok { return nil } @@ -78,9 +78,9 @@ func splitPodIPMaskLength(podIP string) (int, string) { return prefixLen, ip.String() } -type option func(machine *secondaryNetworkExpectationMachine) +type option func(machine *userDefinedNetworkExpectationMachine) -type secondaryNetworkExpectationMachine struct { +type userDefinedNetworkExpectationMachine struct { fakeOvn *FakeOVN pods []testPod gatewayConfig *util.L3GatewayConfig @@ -88,8 +88,8 @@ type secondaryNetworkExpectationMachine struct { hasClusterPortGroup bool } -func newSecondaryNetworkExpectationMachine(fakeOvn *FakeOVN, pods []testPod, opts ...option) *secondaryNetworkExpectationMachine { - machine := &secondaryNetworkExpectationMachine{ +func newUserDefinedNetworkExpectationMachine(fakeOvn *FakeOVN, pods []testPod, opts ...option) *userDefinedNetworkExpectationMachine { + machine := &userDefinedNetworkExpectationMachine{ fakeOvn: fakeOvn, pods: pods, } @@ -101,37 +101,37 @@ func newSecondaryNetworkExpectationMachine(fakeOvn *FakeOVN, pods []testPod, opt } func withGatewayConfig(config *util.L3GatewayConfig) option { - return func(machine *secondaryNetworkExpectationMachine) { + return func(machine *userDefinedNetworkExpectationMachine) { machine.gatewayConfig = config } } func withInterconnectCluster() option { - return func(machine *secondaryNetworkExpectationMachine) { + return func(machine *userDefinedNetworkExpectationMachine) { machine.isInterconnectCluster = true } } func withClusterPortGroup() option { - return func(machine *secondaryNetworkExpectationMachine) { + return func(machine *userDefinedNetworkExpectationMachine) { machine.hasClusterPortGroup = true } } -func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(isPrimary bool) []libovsdbtest.TestData { +func (em *userDefinedNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(isPrimary bool) []libovsdbtest.TestData { return em.expectedLogicalSwitchesAndPortsWithLspEnabled(isPrimary, nil) } -func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPortsWithLspEnabled(isPrimary bool, expectedPodLspEnabled map[string]*bool) []libovsdbtest.TestData { +func (em *userDefinedNetworkExpectationMachine) expectedLogicalSwitchesAndPortsWithLspEnabled(isPrimary bool, expectedPodLspEnabled map[string]*bool) []libovsdbtest.TestData { data := []libovsdbtest.TestData{} - for _, ocInfo := range em.fakeOvn.secondaryControllers { + for _, ocInfo := range em.fakeOvn.userDefinedNetworkControllers { nodeslsps := make(map[string][]string) acls := make(map[string][]string) var switchName string switchNodeMap := make(map[string]*nbdb.LogicalSwitch) alreadyAddedManagementElements := make(map[string]struct{}) for _, pod := range em.pods { - podInfo, ok := pod.secondaryPodInfos[ocInfo.bnc.GetNetworkName()] + podInfo, ok := pod.udnPodInfos[ocInfo.bnc.GetNetworkName()] if !ok { continue } @@ -252,7 +252,7 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPortsWit } } - // TODO: once we start the "full" SecondaryLayer2NetworkController (instead of just Base) + // TODO: once we start the "full" Layer2UserDefinedNetworkController (instead of just Base) // we can drop this, and compare all objects created by the controller (right now we're // missing all the meters, and the COPP) if ocInfo.bnc.TopologyType() == ovntypes.Layer2Topology { @@ -453,7 +453,7 @@ func nonICClusterTestConfiguration(opts ...testConfigOpt) testConfiguration { return config } -func newMultiHomedKubevirtPod(vmName string, liveMigrationInfo liveMigrationPodInfo, testPod testPod, multiHomingConfigs ...secondaryNetInfo) *corev1.Pod { +func newMultiHomedKubevirtPod(vmName string, liveMigrationInfo liveMigrationPodInfo, testPod testPod, multiHomingConfigs ...userDefinedNetInfo) *corev1.Pod { pod := newMultiHomedPod(testPod, multiHomingConfigs...) pod.Labels[kubevirtv1.VirtualMachineNameLabel] = vmName pod.Status.Phase = liveMigrationInfo.podPhase @@ -464,7 +464,7 @@ func newMultiHomedKubevirtPod(vmName string, liveMigrationInfo liveMigrationPodI return pod } -func newMultiHomedPod(testPod testPod, multiHomingConfigs ...secondaryNetInfo) *corev1.Pod { +func newMultiHomedPod(testPod testPod, multiHomingConfigs ...userDefinedNetInfo) *corev1.Pod { pod := newPod(testPod.namespace, testPod.podName, testPod.nodeName, testPod.podIP) var secondaryNetworks []nadapi.NetworkSelectionElement if len(pod.Annotations) == 0 { @@ -494,7 +494,7 @@ func newMultiHomedPod(testPod testPod, multiHomingConfigs ...secondaryNetInfo) * serializedNetworkSelectionElements, _ := json.Marshal(secondaryNetworks) pod.Annotations[nadapi.NetworkAttachmentAnnot] = string(serializedNetworkSelectionElements) if config.OVNKubernetesFeature.EnableInterconnect { - dummyOVNNetAnnotations := dummyOVNPodNetworkAnnotations(testPod.secondaryPodInfos, multiHomingConfigs) + dummyOVNNetAnnotations := dummyOVNPodNetworkAnnotations(testPod.udnPodInfos, multiHomingConfigs) if dummyOVNNetAnnotations != "{}" { pod.Annotations["k8s.ovn.org/pod-networks"] = dummyOVNNetAnnotations } @@ -502,7 +502,7 @@ func newMultiHomedPod(testPod testPod, multiHomingConfigs ...secondaryNetInfo) * return pod } -func dummyOVNPodNetworkAnnotations(secondaryPodInfos map[string]*secondaryPodInfo, multiHomingConfigs []secondaryNetInfo) string { +func dummyOVNPodNetworkAnnotations(secondaryPodInfos map[string]*udnPodInfo, multiHomingConfigs []userDefinedNetInfo) string { var ovnPodNetworksAnnotations []byte podAnnotations := map[string]podAnnotation{} for i, netConfig := range multiHomingConfigs { @@ -523,7 +523,7 @@ func dummyOVNPodNetworkAnnotations(secondaryPodInfos map[string]*secondaryPodInf return string(ovnPodNetworksAnnotations) } -func dummyOVNPodNetworkAnnotationForNetwork(portInfo portInfo, netConfig secondaryNetInfo, tunnelID int) podAnnotation { +func dummyOVNPodNetworkAnnotationForNetwork(portInfo portInfo, netConfig userDefinedNetInfo, tunnelID int) podAnnotation { role := ovntypes.NetworkRoleSecondary if netConfig.isPrimary { role = ovntypes.NetworkRolePrimary diff --git a/go-controller/pkg/ovn/multipolicy_test.go b/go-controller/pkg/ovn/multipolicy_test.go index fc50dea5dd..240fd6b1a6 100644 --- a/go-controller/pkg/ovn/multipolicy_test.go +++ b/go-controller/pkg/ovn/multipolicy_test.go @@ -91,9 +91,9 @@ func convertNetPolicyToMultiNetPolicy(policy *knet.NetworkPolicy) *mnpapi.MultiN return &mpolicy } -func addPodNetwork(pod *corev1.Pod, secondaryPodInfos map[string]*secondaryPodInfo) { +func addPodNetwork(pod *corev1.Pod, udnPodInfos map[string]*udnPodInfo) { nadNames := []string{} - for _, podInfo := range secondaryPodInfos { + for _, podInfo := range udnPodInfos { for nadName := range podInfo.allportInfo { nadNames = append(nadNames, nadName) } @@ -104,11 +104,11 @@ func addPodNetwork(pod *corev1.Pod, secondaryPodInfos map[string]*secondaryPodIn pod.Annotations[nettypes.NetworkAttachmentAnnot] = strings.Join(nadNames, ",") } -func (p testPod) populateSecondaryNetworkLogicalSwitchCache(ocInfo secondaryControllerInfo) { +func (p testPod) populateUserDefinedNetworkLogicalSwitchCache(ocInfo userDefinedNetworkControllerInfo) { var err error switch ocInfo.bnc.TopologyType() { case ovntypes.Layer3Topology: - podInfo := p.secondaryPodInfos[ocInfo.bnc.GetNetworkName()] + podInfo := p.udnPodInfos[ocInfo.bnc.GetNetworkName()] err = ocInfo.bnc.lsManager.AddOrUpdateSwitch(ocInfo.bnc.GetNetworkScopedName(p.nodeName), []*net.IPNet{ovntest.MustParseIPNet(podInfo.nodeSubnet)}, nil) case ovntypes.Layer2Topology: subnet := ocInfo.bnc.Subnets()[0] @@ -120,13 +120,13 @@ func (p testPod) populateSecondaryNetworkLogicalSwitchCache(ocInfo secondaryCont gomega.Expect(err).NotTo(gomega.HaveOccurred()) } -func getExpectedDataPodsAndSwitchesForSecondaryNetwork(fakeOvn *FakeOVN, pods []testPod, netInfo util.NetInfo) []libovsdb.TestData { +func getExpectedDataPodsAndSwitchesForUserDefinedNetwork(fakeOvn *FakeOVN, pods []testPod, netInfo util.NetInfo) []libovsdb.TestData { data := []libovsdb.TestData{} - for _, ocInfo := range fakeOvn.secondaryControllers { + for _, ocInfo := range fakeOvn.userDefinedNetworkControllers { nodeslsps := make(map[string][]string) var switchName string for _, pod := range pods { - podInfo, ok := pod.secondaryPodInfos[ocInfo.bnc.GetNetworkName()] + podInfo, ok := pod.udnPodInfos[ocInfo.bnc.GetNetworkName()] if !ok { continue } @@ -187,15 +187,15 @@ func getExpectedDataPodsAndSwitchesForSecondaryNetwork(fakeOvn *FakeOVN, pods [] var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { const ( - namespaceName1 = "namespace1" - namespaceName2 = "namespace2" - netPolicyName1 = "networkpolicy1" - nodeName = "node1" - secondaryNetworkName = "network1" - nadName = "nad1" - labelName string = "pod-name" - labelVal string = "server" - portNum int32 = 81 + namespaceName1 = "namespace1" + namespaceName2 = "namespace2" + netPolicyName1 = "networkpolicy1" + nodeName = "node1" + userDefinedNetworkName = "network1" + nadName = "nad1" + labelName string = "pod-name" + labelVal string = "server" + portNum int32 = 81 ) var ( app *cli.App @@ -238,14 +238,14 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { format.MaxLength = gomegaFormatMaxLength }) - // setSecondaryNetworkTestData sets relevant test data (NAD, NetInfo & NB DB - // initial data) assuming a secondary network of the given topoloy and + // setUserDefinedNetworkTestData sets relevant test data (NAD, NetInfo & NB DB + // initial data) assuming a user-defined network of the given topology and // subnet - setSecondaryNetworkTestData := func(topology, subnets string) { + setUserDefinedNetworkTestData := func(topology, subnets string) { nadNamespacedName = util.GetNADName(namespaceName1, nadName) netconf := ovncnitypes.NetConf{ NetConf: cnitypes.NetConf{ - Name: secondaryNetworkName, + Name: userDefinedNetworkName, Type: "ovn-k8s-cni-overlay", }, Topology: topology, @@ -278,7 +278,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { Name: netInfo.GetNetworkScopedName(ovntypes.OVNLayer2Switch), UUID: netInfo.GetNetworkScopedName(ovntypes.OVNLayer2Switch) + "_UUID", ExternalIDs: map[string]string{ - ovntypes.NetworkExternalID: secondaryNetworkName, + ovntypes.NetworkExternalID: userDefinedNetworkName, ovntypes.NetworkRoleExternalID: getNetworkRole(netInfo), }, }) @@ -287,7 +287,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { Name: netInfo.GetNetworkScopedName(ovntypes.OVNLocalnetSwitch), UUID: netInfo.GetNetworkScopedName(ovntypes.OVNLocalnetSwitch) + "_UUID", ExternalIDs: map[string]string{ - ovntypes.NetworkExternalID: secondaryNetworkName, + ovntypes.NetworkExternalID: userDefinedNetworkName, ovntypes.NetworkRoleExternalID: getNetworkRole(netInfo), }, }) @@ -303,7 +303,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { if len(podLabels) > 0 { knetPod.Labels = podLabels } - addPodNetwork(knetPod, testPod.secondaryPodInfos) + addPodNetwork(knetPod, testPod.udnPodInfos) setPodAnnotations(knetPod, testPod) podsList = append(podsList, *knetPod) } @@ -357,13 +357,13 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { err = fakeOvn.controller.WatchNetworkPolicy() gomega.Expect(err).NotTo(gomega.HaveOccurred()) - ocInfo, ok := fakeOvn.secondaryControllers[secondaryNetworkName] + ocInfo, ok := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] gomega.Expect(ok).To(gomega.BeTrue()) asf := ocInfo.asf gomega.Expect(asf).NotTo(gomega.BeNil()) - gomega.Expect(asf.ControllerName).To(gomega.Equal(getNetworkControllerName(secondaryNetworkName))) + gomega.Expect(asf.ControllerName).To(gomega.Equal(getNetworkControllerName(userDefinedNetworkName))) - for _, ocInfo := range fakeOvn.secondaryControllers { + for _, ocInfo := range fakeOvn.userDefinedNetworkControllers { // localnet topology can't watch for nodes if watchNodes && ocInfo.bnc.TopologyType() != ovntypes.LocalnetTopology { if ocInfo.bnc.TopologyType() == ovntypes.Layer3Topology && config.OVNKubernetesFeature.EnableInterconnect { @@ -385,7 +385,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { } for _, testPod := range pods { - testPod.populateSecondaryNetworkLogicalSwitchCache(ocInfo) + testPod.populateUserDefinedNetworkLogicalSwitchCache(ocInfo) } if pods != nil { err = ocInfo.bnc.WatchPods() @@ -399,9 +399,9 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { getUpdatedInitialDB := func(tPods []testPod) []libovsdb.TestData { updatedSwitchAndPods := getDefaultNetExpectedPodsAndSwitches(tPods, []string{nodeName}) - secondarySwitchAndPods := getExpectedDataPodsAndSwitchesForSecondaryNetwork(fakeOvn, tPods, netInfo) - if len(secondarySwitchAndPods) != 0 { - updatedSwitchAndPods = append(updatedSwitchAndPods, secondarySwitchAndPods...) + udnSwitchesAndPods := getExpectedDataPodsAndSwitchesForUserDefinedNetwork(fakeOvn, tPods, netInfo) + if len(udnSwitchesAndPods) != 0 { + updatedSwitchAndPods = append(updatedSwitchAndPods, udnSwitchesAndPods...) } return append(getHairpinningACLsV4AndPortGroup(), updatedSwitchAndPods...) } @@ -413,7 +413,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { topology := ovntypes.Layer2Topology subnets := "10.1.0.0/24" - setSecondaryNetworkTestData(topology, subnets) + setUserDefinedNetworkTestData(topology, subnets) namespace1 := *newNamespace(namespaceName1) namespace2 := *newNamespace(namespaceName2) @@ -436,7 +436,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { Get(context.TODO(), mpolicy.Name, metav1.GetOptions{}) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - ocInfo := fakeOvn.secondaryControllers[secondaryNetworkName] + ocInfo := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] ocInfo.asf.EventuallyExpectEmptyAddressSetExist(namespaceName1) ocInfo.asf.EventuallyExpectEmptyAddressSetExist(namespaceName2) @@ -459,11 +459,11 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { topology := ovntypes.Layer2Topology subnets := "10.1.0.0/24" - setSecondaryNetworkTestData(topology, subnets) + setUserDefinedNetworkTestData(topology, subnets) namespace1 := *newNamespace(namespaceName1) nPodTest := getTestPod(namespace1.Name, nodeName) - nPodTest.addNetwork(secondaryNetworkName, nadNamespacedName, "", "", "", "10.1.1.1", "0a:58:0a:01:01:01", "secondary", 1, nil) + nPodTest.addNetwork(userDefinedNetworkName, nadNamespacedName, "", "", "", "10.1.1.1", "0a:58:0a:01:01:01", "secondary", 1, nil) networkPolicy := getPortNetworkPolicy(netPolicyName1, namespace1.Name, labelName, labelVal, portNum) watchNodes := false @@ -504,8 +504,8 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { Get(context.TODO(), mpolicy.Name, metav1.GetOptions{}) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - ocInfo := fakeOvn.secondaryControllers[secondaryNetworkName] - portInfo := nPodTest.getNetworkPortInfo(secondaryNetworkName, nadNamespacedName) + ocInfo := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] + portInfo := nPodTest.getNetworkPortInfo(userDefinedNetworkName, nadNamespacedName) gomega.Expect(portInfo).NotTo(gomega.BeNil()) ocInfo.asf.ExpectAddressSetWithAddresses(namespaceName1, []string{portInfo.podIP}) @@ -551,7 +551,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { nodeSubnet = "10.1.1.0/24" } - setSecondaryNetworkTestData(topology, subnets) // here I set network role if layer2 + setUserDefinedNetworkTestData(topology, subnets) // here I set network role if layer2 watchNodes := true node := *newNode(nodeName, "192.168.126.202/24") @@ -561,7 +561,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { node.Annotations, err = util.UpdateNodeHostSubnetAnnotation( node.Annotations, ovntest.MustParseIPNets(nodeSubnet), - secondaryNetworkName, + userDefinedNetworkName, ) gomega.Expect(err).NotTo(gomega.HaveOccurred()) } @@ -574,7 +574,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { node.Annotations, err = util.UpdateNetworkIDAnnotation(node.Annotations, ovntypes.DefaultNetworkName, 0) gomega.Expect(err).NotTo(gomega.HaveOccurred()) if topology != ovntypes.LocalnetTopology { - node.Annotations, err = util.UpdateNetworkIDAnnotation(node.Annotations, secondaryNetworkName, 2) + node.Annotations, err = util.UpdateNetworkIDAnnotation(node.Annotations, userDefinedNetworkName, 2) gomega.Expect(err).NotTo(gomega.HaveOccurred()) } } @@ -585,7 +585,7 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { startOvn(initialDB, watchNodes, []corev1.Node{node}, []corev1.Namespace{namespace1}, nil, nil, []nettypes.NetworkAttachmentDefinition{*nad}, []testPod{}, map[string]string{labelName: labelVal}) - ocInfo := fakeOvn.secondaryControllers[secondaryNetworkName] + ocInfo := fakeOvn.userDefinedNetworkControllers[userDefinedNetworkName] // check that the node zone is tracked as expected if topology != ovntypes.LocalnetTopology { @@ -596,12 +596,12 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { ocInfo.asf.EventuallyExpectEmptyAddressSetExist(namespaceName1) nPodTest := getTestPod(namespace1.Name, nodeName) - nPodTest.addNetwork(secondaryNetworkName, nadNamespacedName, nodeSubnet, "", "", "10.1.1.1", "0a:58:0a:01:01:01", "secondary", 1, nil) + nPodTest.addNetwork(userDefinedNetworkName, nadNamespacedName, nodeSubnet, "", "", "10.1.1.1", "0a:58:0a:01:01:01", "secondary", 1, nil) knetPod := newPod(nPodTest.namespace, nPodTest.podName, nPodTest.nodeName, nPodTest.podIP) - addPodNetwork(knetPod, nPodTest.secondaryPodInfos) + addPodNetwork(knetPod, nPodTest.udnPodInfos) setPodAnnotations(knetPod, nPodTest) nPodTest.populateLogicalSwitchCache(fakeOvn) - nPodTest.populateSecondaryNetworkLogicalSwitchCache(ocInfo) + nPodTest.populateUserDefinedNetworkLogicalSwitchCache(ocInfo) ginkgo.By("Creating a pod attached to the secondary network") _, err = fakeOvn.fakeClient.KubeClient.CoreV1().Pods(nPodTest.namespace).Create(context.TODO(), knetPod, metav1.CreateOptions{}) @@ -609,8 +609,8 @@ var _ = ginkgo.Describe("OVN MultiNetworkPolicy Operations", func() { if topology == ovntypes.Layer2Topology && remote { // add the transit switch port bindings on behalf of ovn-controller - // so that the added pod is eventually processed succesfuly - transistSwitchPortName := util.GetSecondaryNetworkLogicalPortName(nPodTest.namespace, nPodTest.podName, nadNamespacedName) + // so that the added pod is eventually processed successfully + transistSwitchPortName := util.GetUserDefinedNetworkLogicalPortName(nPodTest.namespace, nPodTest.podName, nadNamespacedName) transistSwitchName := netInfo.GetNetworkScopedName(ovntypes.OVNLayer2Switch) err = libovsdb.CreateTransitSwitchPortBindings(fakeOvn.sbClient, transistSwitchName, transistSwitchPortName) gomega.Expect(err).NotTo(gomega.HaveOccurred()) diff --git a/go-controller/pkg/ovn/ovn.go b/go-controller/pkg/ovn/ovn.go index d935bca85f..280e41eba3 100644 --- a/go-controller/pkg/ovn/ovn.go +++ b/go-controller/pkg/ovn/ovn.go @@ -335,15 +335,27 @@ func (oc *DefaultNetworkController) removeRemoteZonePod(pod *corev1.Pod) error { return fmt.Errorf("failed to remove the remote zone pod: %w", err) } + // FIXME: there are other things we are probably leaving behind and should + // be removed for completed VMs, like per-pod SNAT. Also + // removeRemoteZonePodFromNamespaceAddressSet above should probably not be + // called for migrations. + // https://github.com/ovn-kubernetes/ovn-kubernetes/issues/5627 if kubevirt.IsPodLiveMigratable(pod) { - ips, err := util.GetPodCIDRsWithFullMask(pod, oc.GetNetInfo()) - if err != nil && !errors.Is(err, util.ErrNoPodIPFound) { - return fmt.Errorf("failed to get pod ips for the pod %s/%s: %w", pod.Namespace, pod.Name, err) + allVMPodsAreCompleted, err := kubevirt.AllVMPodsAreCompleted(oc.watchFactory, pod) + if err != nil { + return err } - switchName, zoneContainsPodSubnet := kubevirt.ZoneContainsPodSubnet(oc.lsManager, ips) - if zoneContainsPodSubnet { - if err := oc.lsManager.ReleaseIPs(switchName, ips); err != nil { - return err + + if allVMPodsAreCompleted { + ips, err := util.GetPodCIDRsWithFullMask(pod, oc.GetNetInfo()) + if err != nil && !errors.Is(err, util.ErrNoPodIPFound) { + return fmt.Errorf("failed to get pod ips for the pod %s/%s: %w", pod.Namespace, pod.Name, err) + } + switchName, zoneContainsPodSubnet := kubevirt.ZoneContainsPodSubnet(oc.lsManager, ips) + if zoneContainsPodSubnet { + if err := oc.lsManager.ReleaseIPs(switchName, ips); err != nil { + return err + } } } } diff --git a/go-controller/pkg/ovn/ovn_test.go b/go-controller/pkg/ovn/ovn_test.go index 0a1b9e3c8f..eb0bbf22a5 100644 --- a/go-controller/pkg/ovn/ovn_test.go +++ b/go-controller/pkg/ovn/ovn_test.go @@ -67,8 +67,8 @@ const ( ovnClusterPortGroupUUID = fakePgUUID ) -type secondaryControllerInfo struct { - bnc *BaseSecondaryNetworkController +type userDefinedNetworkControllerInfo struct { + bnc *BaseUserDefinedNetworkController asf *addressset.FakeAddressSetFactory } @@ -91,9 +91,9 @@ type FakeOVN struct { eIPController *EgressIPController portCache *PortCache - // information map of all secondary network controllers - secondaryControllers map[string]secondaryControllerInfo - fullSecondaryL2Controllers map[string]*SecondaryLayer2NetworkController + // information map of all UDN controllers + userDefinedNetworkControllers map[string]userDefinedNetworkControllerInfo + fullL2UDNControllers map[string]*Layer2UserDefinedNetworkController } // NOTE: the FakeAddressSetFactory is no longer needed and should no longer be used. starting to phase out FakeAddressSetFactory @@ -109,8 +109,8 @@ func NewFakeOVN(useFakeAddressSet bool) *FakeOVN { egressSVCWg: &sync.WaitGroup{}, anpWg: &sync.WaitGroup{}, - secondaryControllers: map[string]secondaryControllerInfo{}, - fullSecondaryL2Controllers: map[string]*SecondaryLayer2NetworkController{}, + userDefinedNetworkControllers: map[string]userDefinedNetworkControllerInfo{}, + fullL2UDNControllers: map[string]*Layer2UserDefinedNetworkController{}, } } @@ -196,7 +196,7 @@ func (o *FakeOVN) shutdown() { o.egressSVCWg.Wait() o.anpWg.Wait() o.nbsbCleanup.Cleanup() - for _, ocInfo := range o.secondaryControllers { + for _, ocInfo := range o.userDefinedNetworkControllers { close(ocInfo.bnc.stopChan) ocInfo.bnc.cancelableCtx.Cancel() ocInfo.bnc.wg.Wait() @@ -266,7 +266,7 @@ func (o *FakeOVN) init(nadList []nettypes.NetworkAttachmentDefinition) { setupCOPP := false setupClusterController(o.controller, setupCOPP) for _, n := range nadList { - err := o.NewSecondaryNetworkController(&n) + err := o.NewUserDefinedNetworkController(&n) gomega.Expect(err).NotTo(gomega.HaveOccurred()) } @@ -280,9 +280,9 @@ func (o *FakeOVN) init(nadList []nettypes.NetworkAttachmentDefinition) { if err == nil { for _, node := range existingNodes { o.controller.localZoneNodes.Store(node.Name, true) - for _, secondaryController := range o.secondaryControllers { - if secondaryController.bnc.localZoneNodes != nil { - secondaryController.bnc.localZoneNodes.Store(node.Name, true) + for _, udnController := range o.userDefinedNetworkControllers { + if udnController.bnc.localZoneNodes != nil { + udnController.bnc.localZoneNodes.Store(node.Name, true) } } } @@ -497,9 +497,9 @@ func newNetworkAttachmentDefinition(namespace, name string, netconf ovncnitypes. }, nil } -func (o *FakeOVN) NewSecondaryNetworkController(netattachdef *nettypes.NetworkAttachmentDefinition) error { - var ocInfo secondaryControllerInfo - var secondaryController *BaseSecondaryNetworkController +func (o *FakeOVN) NewUserDefinedNetworkController(netattachdef *nettypes.NetworkAttachmentDefinition) error { + var ocInfo userDefinedNetworkControllerInfo + var userDefinedNetworkController *BaseUserDefinedNetworkController var ok bool nadName := util.GetNADName(netattachdef.Namespace, netattachdef.Name) @@ -509,7 +509,7 @@ func (o *FakeOVN) NewSecondaryNetworkController(netattachdef *nettypes.NetworkAt } netName := nInfo.GetNetworkName() topoType := nInfo.TopologyType() - ocInfo, ok = o.secondaryControllers[netName] + ocInfo, ok = o.userDefinedNetworkControllers[netName] if !ok { nbZoneFailed := false // Try to get the NBZone. If there is an error, create NB_Global record. @@ -548,31 +548,31 @@ func (o *FakeOVN) NewSecondaryNetworkController(netattachdef *nettypes.NetworkAt switch topoType { case types.Layer3Topology: - l3Controller, err := NewSecondaryLayer3NetworkController(cnci, nInfo, o.networkManager.Interface(), nil, o.eIPController, o.portCache) + l3Controller, err := NewLayer3UserDefinedNetworkController(cnci, nInfo, o.networkManager.Interface(), nil, o.eIPController, o.portCache) gomega.Expect(err).NotTo(gomega.HaveOccurred()) if o.asf != nil { // use fake asf only when enabled l3Controller.addressSetFactory = asf } - secondaryController = &l3Controller.BaseSecondaryNetworkController + userDefinedNetworkController = &l3Controller.BaseUserDefinedNetworkController case types.Layer2Topology: - l2Controller, err := NewSecondaryLayer2NetworkController(cnci, nInfo, o.networkManager.Interface(), nil, o.portCache, o.eIPController) + l2Controller, err := NewLayer2UserDefinedNetworkController(cnci, nInfo, o.networkManager.Interface(), nil, o.portCache, o.eIPController) gomega.Expect(err).NotTo(gomega.HaveOccurred()) if o.asf != nil { // use fake asf only when enabled l2Controller.addressSetFactory = asf } - secondaryController = &l2Controller.BaseSecondaryNetworkController - o.fullSecondaryL2Controllers[netName] = l2Controller + userDefinedNetworkController = &l2Controller.BaseUserDefinedNetworkController + o.fullL2UDNControllers[netName] = l2Controller case types.LocalnetTopology: - localnetController := NewSecondaryLocalnetNetworkController(cnci, nInfo, o.networkManager.Interface()) + localnetController := NewLocalnetUserDefinedNetworkController(cnci, nInfo, o.networkManager.Interface()) if o.asf != nil { // use fake asf only when enabled localnetController.addressSetFactory = asf } - secondaryController = &localnetController.BaseSecondaryNetworkController + userDefinedNetworkController = &localnetController.BaseUserDefinedNetworkController default: return fmt.Errorf("topology type %s not supported", topoType) } - ocInfo = secondaryControllerInfo{bnc: secondaryController, asf: asf} - o.secondaryControllers[netName] = ocInfo + ocInfo = userDefinedNetworkControllerInfo{bnc: userDefinedNetworkController, asf: asf} + o.userDefinedNetworkControllers[netName] = ocInfo if nbZoneFailed { // Delete the NBGlobal row as this function created it. Otherwise many tests would fail while @@ -581,13 +581,13 @@ func (o *FakeOVN) NewSecondaryNetworkController(netattachdef *nettypes.NetworkAt gomega.Expect(err).NotTo(gomega.HaveOccurred()) } } else { - secondaryController = ocInfo.bnc + userDefinedNetworkController = ocInfo.bnc } - ginkgo.By(fmt.Sprintf("OVN test init: add NAD %s to secondary network controller of %s network %s", nadName, topoType, netName)) - mutableNetInfo := util.NewMutableNetInfo(secondaryController.GetNetInfo()) + ginkgo.By(fmt.Sprintf("OVN test init: add NAD %s to user-defined network controller of %s network %s", nadName, topoType, netName)) + mutableNetInfo := util.NewMutableNetInfo(userDefinedNetworkController.GetNetInfo()) mutableNetInfo.AddNADs(nadName) - _ = util.ReconcileNetInfo(secondaryController.ReconcilableNetInfo, mutableNetInfo) + _ = util.ReconcileNetInfo(userDefinedNetworkController.ReconcilableNetInfo, mutableNetInfo) return nil } diff --git a/go-controller/pkg/ovn/pods.go b/go-controller/pkg/ovn/pods.go index 0ad9442e3e..80c431ef13 100644 --- a/go-controller/pkg/ovn/pods.go +++ b/go-controller/pkg/ovn/pods.go @@ -211,6 +211,23 @@ func (oc *DefaultNetworkController) deleteLogicalPort(pod *corev1.Pod, portInfo return fmt.Errorf("cannot delete GW Routes for pod %s: %w", podDesc, err) } + if kubevirt.IsPodLiveMigratable(pod) { + switchName, hasLocalIPs := oc.lsManager.GetSubnetName(pInfo.ips) + // don't attempt to release IPs that are not managed by this zone which can + // happen with live migratable pods, otherwise we would get distracting + // error logs on release + if !hasLocalIPs { + klog.V(5).Infof("Inhibiting release of live migratable pod %s/%s IPs %s not managed by this zone", + pod.Namespace, pod.Name, + util.JoinIPNetIPs(pInfo.ips, " "), + ) + return nil + } + // a pod might have migrated from one node to another node in the same + // zone so fix the switch for which the release needs to happen + pInfo.logicalSwitch = switchName + } + // Releasing IPs needs to happen last so that we can deterministically know that if delete failed that // the IP of the pod needs to be released. Otherwise we could have a completed pod failed to be removed // and we dont know if the IP was released or not, and subsequently could accidentally release the IP diff --git a/go-controller/pkg/ovn/pods_test.go b/go-controller/pkg/ovn/pods_test.go index c59a841d75..76383189a5 100644 --- a/go-controller/pkg/ovn/pods_test.go +++ b/go-controller/pkg/ovn/pods_test.go @@ -224,10 +224,10 @@ type testPod struct { noIfaceIdVer bool networkRole string - secondaryPodInfos map[string]*secondaryPodInfo + udnPodInfos map[string]*udnPodInfo } -type secondaryPodInfo struct { +type udnPodInfo struct { nodeSubnet string nodeMgtIP string nodeGWIP string @@ -248,18 +248,18 @@ type portInfo struct { func newTPod(nodeName, nodeSubnet, nodeMgtIP, nodeGWIP, podName, podIPs, podMAC, namespace string) testPod { portName := util.GetLogicalPortName(namespace, podName) to := testPod{ - portUUID: portName + "-UUID", - nodeSubnet: nodeSubnet, - nodeMgtIP: nodeMgtIP, - nodeGWIP: nodeGWIP, - podIP: podIPs, - podMAC: podMAC, - portName: portName, - nodeName: nodeName, - podName: podName, - namespace: namespace, - secondaryPodInfos: map[string]*secondaryPodInfo{}, - networkRole: ovntypes.NetworkRolePrimary, // all tests here run with network-segmentation disabled by default by default + portUUID: portName + "-UUID", + nodeSubnet: nodeSubnet, + nodeMgtIP: nodeMgtIP, + nodeGWIP: nodeGWIP, + podIP: podIPs, + podMAC: podMAC, + portName: portName, + nodeName: nodeName, + podName: podName, + namespace: namespace, + udnPodInfos: map[string]*udnPodInfo{}, + networkRole: ovntypes.NetworkRolePrimary, // all tests here run with network-segmentation disabled by default by default } var routeSources []*net.IPNet @@ -393,11 +393,11 @@ func (p testPod) getAnnotationsJson() string { }, } - for _, portInfos := range p.secondaryPodInfos { - var secondaryIfaceRoutes []podRoute + for _, portInfos := range p.udnPodInfos { + var udnIfaceRoutes []podRoute for _, route := range portInfos.routes { - secondaryIfaceRoutes = append( - secondaryIfaceRoutes, + udnIfaceRoutes = append( + udnIfaceRoutes, podRoute{Dest: route.Dest.String(), NextHop: route.NextHop.String()}, ) } @@ -416,7 +416,7 @@ func (p testPod) getAnnotationsJson() string { IPs: []string{ip}, TunnelID: portInfo.tunnelID, Role: portInfos.role, - Routes: secondaryIfaceRoutes, + Routes: udnIfaceRoutes, } if portInfos.nodeGWIP != "" { podAnnotation.Gateway = portInfos.nodeGWIP @@ -458,7 +458,7 @@ func getExpectedDataPodsSwitchesPortGroup(netInfo util.NetInfo, pods []testPod, if netInfo.IsDefault() { portName = util.GetLogicalPortName(pod.namespace, pod.podName) } else { - portName = util.GetSecondaryNetworkLogicalPortName(pod.namespace, pod.podName, netInfo.GetNADs()[0]) + portName = util.GetUserDefinedNetworkLogicalPortName(pod.namespace, pod.podName, netInfo.GetNADs()[0]) } var lspUUID string if len(pod.portUUID) == 0 { diff --git a/go-controller/pkg/ovn/port_cache.go b/go-controller/pkg/ovn/port_cache.go index 4148e840a5..9dbee646e3 100644 --- a/go-controller/pkg/ovn/port_cache.go +++ b/go-controller/pkg/ovn/port_cache.go @@ -47,7 +47,7 @@ func (c *PortCache) get(pod *corev1.Pod, nadName string) (*lpInfo, error) { if nadName == types.DefaultNetworkName { logicalPort = util.GetLogicalPortName(pod.Namespace, pod.Name) } else { - logicalPort = util.GetSecondaryNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) + logicalPort = util.GetUserDefinedNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) } c.RLock() defer c.RUnlock() @@ -82,7 +82,7 @@ func (c *PortCache) add(pod *corev1.Pod, logicalSwitch, nadName, uuid string, ma if nadName == types.DefaultNetworkName { logicalPort = util.GetLogicalPortName(pod.Namespace, pod.Name) } else { - logicalPort = util.GetSecondaryNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) + logicalPort = util.GetUserDefinedNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) } c.Lock() defer c.Unlock() @@ -112,7 +112,7 @@ func (c *PortCache) remove(pod *corev1.Pod, nadName string) { if nadName == types.DefaultNetworkName { logicalPort = util.GetLogicalPortName(pod.Namespace, pod.Name) } else { - logicalPort = util.GetSecondaryNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) + logicalPort = util.GetUserDefinedNetworkLogicalPortName(pod.Namespace, pod.Name, nadName) } c.Lock() diff --git a/go-controller/pkg/ovn/topology/topologyfactory.go b/go-controller/pkg/ovn/topology/topologyfactory.go index b20743a242..45738cf85f 100644 --- a/go-controller/pkg/ovn/topology/topologyfactory.go +++ b/go-controller/pkg/ovn/topology/topologyfactory.go @@ -55,7 +55,7 @@ func (gtf *GatewayTopologyFactory) newClusterRouter( Options: routerOptions, Copp: &coopUUID, } - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { logicalRouter.ExternalIDs[types.NetworkExternalID] = netInfo.GetNetworkName() logicalRouter.ExternalIDs[types.TopologyExternalID] = netInfo.TopologyType() } @@ -84,7 +84,7 @@ func (gtf *GatewayTopologyFactory) NewJoinSwitch( logicalSwitch := nbdb.LogicalSwitch{ Name: joinSwitchName, } - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { logicalSwitch.ExternalIDs = map[string]string{ types.NetworkExternalID: netInfo.GetNetworkName(), types.TopologyExternalID: netInfo.TopologyType(), @@ -111,7 +111,7 @@ func (gtf *GatewayTopologyFactory) NewJoinSwitch( MAC: gwLRPMAC.String(), Networks: gwLRPNetworks, } - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { logicalRouterPort.ExternalIDs = map[string]string{ types.NetworkExternalID: netInfo.GetNetworkName(), types.TopologyExternalID: netInfo.TopologyType(), diff --git a/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler.go b/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler.go index 4c144d65cc..1549bf5481 100644 --- a/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler.go +++ b/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler.go @@ -34,7 +34,7 @@ const ( /* * ZoneInterconnectHandler manages OVN resources required for interconnecting * multiple zones. This handler exposes functions which a network controller - * (default and secondary) is expected to call on different events. + * (default and UDN) is expected to call on different events. * For routed topologies: * @@ -118,7 +118,7 @@ const ( */ // ZoneInterconnectHandler creates the OVN resources required for interconnecting -// multiple zones for a network (default or secondary layer 3) +// multiple zones for a network (default or layer 3) UDN type ZoneInterconnectHandler struct { watchFactory *factory.WatchFactory // network which is inter-connected @@ -156,8 +156,8 @@ func getTransitSwitchName(nInfo util.NetInfo) string { func (zic *ZoneInterconnectHandler) createOrUpdateTransitSwitch(networkID int) error { externalIDs := make(map[string]string) - if zic.IsSecondary() { - externalIDs = getSecondaryNetTransitSwitchExtIDs(zic.GetNetworkName(), zic.TopologyType(), zic.IsPrimaryNetwork()) + if zic.IsUserDefinedNetwork() { + externalIDs = getUserDefinedNetTransitSwitchExtIDs(zic.GetNetworkName(), zic.TopologyType(), zic.IsPrimaryNetwork()) } ts := &nbdb.LogicalSwitch{ Name: zic.networkTransitSwitchName, @@ -238,7 +238,7 @@ func (zic *ZoneInterconnectHandler) AddRemoteZoneNode(node *corev1.Node) error { var nodeGRPIPs []*net.IPNet // only primary networks have cluster router connected to join switch+GR // used for adding routes to GR - if !zic.IsSecondary() || (util.IsNetworkSegmentationSupportEnabled() && zic.IsPrimaryNetwork()) { + if !zic.IsUserDefinedNetwork() || (util.IsNetworkSegmentationSupportEnabled() && zic.IsPrimaryNetwork()) { nodeGRPIPs, err = udn.GetGWRouterIPs(node, zic.GetNetInfo()) if err != nil { if util.IsAnnotationNotSetError(err) { @@ -647,8 +647,8 @@ func (zic *ZoneInterconnectHandler) deleteLocalNodeStaticRoutes(node *corev1.Nod } } - if zic.IsSecondary() { - // Secondary network cluster router doesn't connect to a join switch + if zic.IsUserDefinedNetwork() { + // UDN cluster router doesn't connect to a join switch // or to a Gateway router. return nil } @@ -719,7 +719,7 @@ func (zic *ZoneInterconnectHandler) getStaticRoutes(ipPrefixes []*net.IPNet, nex return staticRoutes } -func getSecondaryNetTransitSwitchExtIDs(networkName, topology string, isPrimaryUDN bool) map[string]string { +func getUserDefinedNetTransitSwitchExtIDs(networkName, topology string, isPrimaryUDN bool) map[string]string { return map[string]string{ types.NetworkExternalID: networkName, types.NetworkRoleExternalID: util.GetUserDefinedNetworkRole(isPrimaryUDN), diff --git a/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler_test.go b/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler_test.go index 0b6570173f..5f7211b9cf 100644 --- a/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler_test.go +++ b/go-controller/pkg/ovn/zone_interconnect/zone_ic_handler_test.go @@ -72,7 +72,7 @@ func getNetworkScopedName(netName, name string) string { if netName == types.DefaultNetworkName { return name } - return fmt.Sprintf("%s%s", util.GetSecondaryNetworkPrefix(netName), name) + return fmt.Sprintf("%s%s", util.GetUserDefinedNetworkPrefix(netName), name) } func invokeICHandlerAddNodeFunction(zone string, icHandler *ZoneInterconnectHandler, nodes ...*corev1.Node) error { diff --git a/go-controller/pkg/types/const.go b/go-controller/pkg/types/const.go index 523da8e27b..20fdf23d31 100644 --- a/go-controller/pkg/types/const.go +++ b/go-controller/pkg/types/const.go @@ -225,19 +225,19 @@ const ( // RequiredUDNNamespaceLabel is the required namespace label for enabling primary UDNs RequiredUDNNamespaceLabel = "k8s.ovn.org/primary-user-defined-network" - // different secondary network topology type defined in CNI netconf + // different user-defined network topology types defined in CNI netconf Layer3Topology = "layer3" Layer2Topology = "layer2" LocalnetTopology = "localnet" // different types of network roles - // defined in CNI netconf as a user defined network + // defined in CNI netconf as a user-defined network NetworkRolePrimary = "primary" NetworkRoleSecondary = "secondary" NetworkRoleDefault = "default" // NetworkRoleInfrastructure is defined internally by ovnkube to recognize "default" // network's role as an "infrastructure-locked" network - // when a user defined network is the primary network for + // when a user-defined network is the primary network for // the pod which makes "default" network neither primary // nor secondary NetworkRoleInfrastructure = "infrastructure-locked" diff --git a/go-controller/pkg/util/mocks/multinetwork/NetInfo.go b/go-controller/pkg/util/mocks/multinetwork/NetInfo.go index e94a82edd5..42e5808356 100644 --- a/go-controller/pkg/util/mocks/multinetwork/NetInfo.go +++ b/go-controller/pkg/util/mocks/multinetwork/NetInfo.go @@ -651,11 +651,11 @@ func (_m *NetInfo) IsPrimaryNetwork() bool { } // IsSecondary provides a mock function with given fields: -func (_m *NetInfo) IsSecondary() bool { +func (_m *NetInfo) IsUserDefinedNetwork() bool { ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for IsSecondary") + panic("no return value specified for IsUserDefinedNetwork") } var r0 bool diff --git a/go-controller/pkg/util/multi_network.go b/go-controller/pkg/util/multi_network.go index 1073954bc4..68672b3c4a 100644 --- a/go-controller/pkg/util/multi_network.go +++ b/go-controller/pkg/util/multi_network.go @@ -36,7 +36,7 @@ type NetInfo interface { GetNetworkID() int IsDefault() bool IsPrimaryNetwork() bool - IsSecondary() bool + IsUserDefinedNetwork() bool TopologyType() string MTU() int IPMode() (bool, bool) @@ -197,7 +197,7 @@ func copyNetInfo(netInfo NetInfo) any { switch t := netInfo.GetNetInfo().(type) { case *DefaultNetInfo: return t.copy() - case *secondaryNetInfo: + case *userDefinedNetInfo: return t.copy() default: panic(fmt.Errorf("unrecognized type %T", t)) @@ -208,7 +208,7 @@ func reconcilable(netInfo NetInfo) ReconcilableNetInfo { switch t := netInfo.GetNetInfo().(type) { case *DefaultNetInfo: return t - case *secondaryNetInfo: + case *userDefinedNetInfo: return t default: panic(fmt.Errorf("unrecognized type %T", t)) @@ -237,7 +237,7 @@ func mutable(netInfo NetInfo) *mutableNetInfo { switch t := netInfo.GetNetInfo().(type) { case *DefaultNetInfo: return &t.mutableNetInfo - case *secondaryNetInfo: + case *userDefinedNetInfo: return &t.mutableNetInfo default: panic(fmt.Errorf("unrecognized type %T", t)) @@ -482,16 +482,16 @@ func (nInfo *DefaultNetInfo) IsDefault() bool { } // IsPrimaryNetwork always returns false for default network. -// The boolean indicates if this secondary network is +// The boolean indicates if the default network is // meant to be the primary network for the pod. Since default -// network is never a secondary network this is always false. -// This cannot be true if IsSecondary() is not true. +// network is never a User Defined Network this is always false. +// This cannot be true if IsUserDefinedNetwork() is not true. func (nInfo *DefaultNetInfo) IsPrimaryNetwork() bool { return false } -// IsSecondary returns if this network is secondary -func (nInfo *DefaultNetInfo) IsSecondary() bool { +// IsUserDefinedNetwork returns if this network is secondary +func (nInfo *DefaultNetInfo) IsUserDefinedNetwork() bool { return false } @@ -610,7 +610,7 @@ func (nInfo *DefaultNetInfo) JoinSubnetV6() *net.IPNet { return cidr } -// JoinSubnets returns the secondaryNetInfo's joinsubnet values (both v4&v6) +// JoinSubnets returns the userDefinedNetInfo's joinsubnet values (both v4&v6) // used from Equals func (nInfo *DefaultNetInfo) JoinSubnets() []*net.IPNet { var defaultJoinSubnets []*net.IPNet @@ -652,12 +652,12 @@ func (nInfo *DefaultNetInfo) GetNodeManagementIP(hostSubnet *net.IPNet) *net.IPN return GetNodeManagementIfAddr(hostSubnet) } -// SecondaryNetInfo holds the network name information for secondary network if non-nil -type secondaryNetInfo struct { +// userDefinedNetInfo holds the network name information for a User Defined Network if non-nil +type userDefinedNetInfo struct { mutableNetInfo netName string - // Should this secondary network be used + // Should this User Defined Network be used // as the pod's primary network? primaryNetwork bool topology string @@ -677,58 +677,58 @@ type secondaryNetInfo struct { managementIPs []net.IP } -func (nInfo *secondaryNetInfo) GetNetInfo() NetInfo { +func (nInfo *userDefinedNetInfo) GetNetInfo() NetInfo { return nInfo } // GetNetworkName returns the network name -func (nInfo *secondaryNetInfo) GetNetworkName() string { +func (nInfo *userDefinedNetInfo) GetNetworkName() string { return nInfo.netName } -// IsDefault always returns false for all secondary networks. -func (nInfo *secondaryNetInfo) IsDefault() bool { +// IsDefault always returns false for all User Defined Networks. +func (nInfo *userDefinedNetInfo) IsDefault() bool { return false } -// IsPrimaryNetwork returns if this secondary network +// IsPrimaryNetwork returns if this User Defined Network // should be used as the primaryNetwork for the pod // to achieve native network segmentation -func (nInfo *secondaryNetInfo) IsPrimaryNetwork() bool { +func (nInfo *userDefinedNetInfo) IsPrimaryNetwork() bool { return nInfo.primaryNetwork } -// IsSecondary returns if this network is secondary -func (nInfo *secondaryNetInfo) IsSecondary() bool { +// IsUserDefinedNetwork returns if this network is a User Defined Network +func (nInfo *userDefinedNetInfo) IsUserDefinedNetwork() bool { return true } // GetNetworkScopedName returns a network scoped name from the provided one // appropriate to use globally. -func (nInfo *secondaryNetInfo) GetNetworkScopedName(name string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedName(name string) string { return fmt.Sprintf("%s%s", nInfo.getPrefix(), name) } // RemoveNetworkScopeFromName removes the name without the network scope added // by a previous call to GetNetworkScopedName -func (nInfo *secondaryNetInfo) RemoveNetworkScopeFromName(name string) string { +func (nInfo *userDefinedNetInfo) RemoveNetworkScopeFromName(name string) string { // for the default network, names are not scoped return strings.Trim(name, nInfo.getPrefix()) } -func (nInfo *secondaryNetInfo) GetNetworkScopedK8sMgmtIntfName(nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedK8sMgmtIntfName(nodeName string) string { return GetK8sMgmtIntfName(nInfo.GetNetworkScopedName(nodeName)) } -func (nInfo *secondaryNetInfo) GetNetworkScopedClusterRouterName() string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedClusterRouterName() string { return nInfo.GetNetworkScopedName(types.OVNClusterRouter) } -func (nInfo *secondaryNetInfo) GetNetworkScopedGWRouterName(nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedGWRouterName(nodeName string) string { return GetGatewayRouterFromNode(nInfo.GetNetworkScopedName(nodeName)) } -func (nInfo *secondaryNetInfo) GetNetworkScopedSwitchName(nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedSwitchName(nodeName string) string { // In Layer2Topology there is just one global switch if nInfo.TopologyType() == types.Layer2Topology { return nInfo.GetNetworkScopedName(types.OVNLayer2Switch) @@ -736,61 +736,61 @@ func (nInfo *secondaryNetInfo) GetNetworkScopedSwitchName(nodeName string) strin return nInfo.GetNetworkScopedName(nodeName) } -func (nInfo *secondaryNetInfo) GetNetworkScopedJoinSwitchName() string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedJoinSwitchName() string { return nInfo.GetNetworkScopedName(types.OVNJoinSwitch) } -func (nInfo *secondaryNetInfo) GetNetworkScopedExtSwitchName(nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedExtSwitchName(nodeName string) string { return GetExtSwitchFromNode(nInfo.GetNetworkScopedName(nodeName)) } -func (nInfo *secondaryNetInfo) GetNetworkScopedPatchPortName(bridgeID, nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedPatchPortName(bridgeID, nodeName string) string { return GetPatchPortName(bridgeID, nInfo.GetNetworkScopedName(nodeName)) } -func (nInfo *secondaryNetInfo) GetNetworkScopedExtPortName(bridgeID, nodeName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedExtPortName(bridgeID, nodeName string) string { return GetExtPortName(bridgeID, nInfo.GetNetworkScopedName(nodeName)) } -func (nInfo *secondaryNetInfo) GetNetworkScopedLoadBalancerName(lbName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedLoadBalancerName(lbName string) string { return nInfo.GetNetworkScopedName(lbName) } -func (nInfo *secondaryNetInfo) GetNetworkScopedLoadBalancerGroupName(lbGroupName string) string { +func (nInfo *userDefinedNetInfo) GetNetworkScopedLoadBalancerGroupName(lbGroupName string) string { return nInfo.GetNetworkScopedName(lbGroupName) } // getPrefix returns if the logical entities prefix for this network -func (nInfo *secondaryNetInfo) getPrefix() string { - return GetSecondaryNetworkPrefix(nInfo.netName) +func (nInfo *userDefinedNetInfo) getPrefix() string { + return GetUserDefinedNetworkPrefix(nInfo.netName) } // TopologyType returns the topology type -func (nInfo *secondaryNetInfo) TopologyType() string { +func (nInfo *userDefinedNetInfo) TopologyType() string { return nInfo.topology } // MTU returns the layer3NetConfInfo's MTU value -func (nInfo *secondaryNetInfo) MTU() int { +func (nInfo *userDefinedNetInfo) MTU() int { return nInfo.mtu } // Vlan returns the Vlan value -func (nInfo *secondaryNetInfo) Vlan() uint { +func (nInfo *userDefinedNetInfo) Vlan() uint { return nInfo.vlan } // AllowsPersistentIPs returns the defaultNetConfInfo's AllowPersistentIPs value -func (nInfo *secondaryNetInfo) AllowsPersistentIPs() bool { +func (nInfo *userDefinedNetInfo) AllowsPersistentIPs() bool { return nInfo.allowPersistentIPs } // PhysicalNetworkName returns the user provided physical network name value -func (nInfo *secondaryNetInfo) PhysicalNetworkName() string { +func (nInfo *userDefinedNetInfo) PhysicalNetworkName() string { return nInfo.physicalNetworkName } -func (nInfo *secondaryNetInfo) GetNodeGatewayIP(hostSubnet *net.IPNet) *net.IPNet { +func (nInfo *userDefinedNetInfo) GetNodeGatewayIP(hostSubnet *net.IPNet) *net.IPNet { if IsPreconfiguredUDNAddressesEnabled() && nInfo.TopologyType() == types.Layer2Topology && nInfo.IsPrimaryNetwork() { isIPV6 := knet.IsIPv6CIDR(hostSubnet) gwIP, _ := MatchFirstIPFamily(isIPV6, nInfo.defaultGatewayIPs) @@ -802,7 +802,7 @@ func (nInfo *secondaryNetInfo) GetNodeGatewayIP(hostSubnet *net.IPNet) *net.IPNe return GetNodeGatewayIfAddr(hostSubnet) } -func (nInfo *secondaryNetInfo) GetNodeManagementIP(hostSubnet *net.IPNet) *net.IPNet { +func (nInfo *userDefinedNetInfo) GetNodeManagementIP(hostSubnet *net.IPNet) *net.IPNet { if IsPreconfiguredUDNAddressesEnabled() && nInfo.TopologyType() == types.Layer2Topology && nInfo.IsPrimaryNetwork() { isIPV6 := knet.IsIPv6CIDR(hostSubnet) mgmtIP, _ := MatchFirstIPFamily(isIPV6, nInfo.managementIPs) @@ -815,56 +815,56 @@ func (nInfo *secondaryNetInfo) GetNodeManagementIP(hostSubnet *net.IPNet) *net.I } // IPMode returns the ipv4/ipv6 mode -func (nInfo *secondaryNetInfo) IPMode() (bool, bool) { +func (nInfo *userDefinedNetInfo) IPMode() (bool, bool) { return nInfo.ipv4mode, nInfo.ipv6mode } // Subnets returns the Subnets value -func (nInfo *secondaryNetInfo) Subnets() []config.CIDRNetworkEntry { +func (nInfo *userDefinedNetInfo) Subnets() []config.CIDRNetworkEntry { return nInfo.subnets } // ExcludeSubnets returns the ExcludeSubnets value -func (nInfo *secondaryNetInfo) ExcludeSubnets() []*net.IPNet { +func (nInfo *userDefinedNetInfo) ExcludeSubnets() []*net.IPNet { return nInfo.excludeSubnets } // ReservedSubnets returns the ReservedSubnets value -func (nInfo *secondaryNetInfo) ReservedSubnets() []*net.IPNet { +func (nInfo *userDefinedNetInfo) ReservedSubnets() []*net.IPNet { return nInfo.reservedSubnets } // InfrastructureSubnets returns the InfrastructureSubnets value -func (nInfo *secondaryNetInfo) InfrastructureSubnets() []*net.IPNet { +func (nInfo *userDefinedNetInfo) InfrastructureSubnets() []*net.IPNet { return nInfo.infrastructureSubnets } // JoinSubnetV4 returns the defaultNetConfInfo's JoinSubnetV4 value // call when ipv4mode=true -func (nInfo *secondaryNetInfo) JoinSubnetV4() *net.IPNet { +func (nInfo *userDefinedNetInfo) JoinSubnetV4() *net.IPNet { if len(nInfo.joinSubnets) == 0 { return nil // localnet topology } return nInfo.joinSubnets[0] } -// JoinSubnetV6 returns the secondaryNetInfo's JoinSubnetV6 value +// JoinSubnetV6 returns the userDefinedNetInfo's JoinSubnetV6 value // call when ipv6mode=true -func (nInfo *secondaryNetInfo) JoinSubnetV6() *net.IPNet { +func (nInfo *userDefinedNetInfo) JoinSubnetV6() *net.IPNet { if len(nInfo.joinSubnets) <= 1 { return nil // localnet topology } return nInfo.joinSubnets[1] } -// JoinSubnets returns the secondaryNetInfo's joinsubnet values (both v4&v6) +// JoinSubnets returns the userDefinedNetInfo's joinsubnet values (both v4&v6) // used from Equals (since localnet doesn't have joinsubnets to compare nil v/s nil // we need this util) -func (nInfo *secondaryNetInfo) JoinSubnets() []*net.IPNet { +func (nInfo *userDefinedNetInfo) JoinSubnets() []*net.IPNet { return nInfo.joinSubnets } -func (nInfo *secondaryNetInfo) canReconcile(other NetInfo) bool { +func (nInfo *userDefinedNetInfo) canReconcile(other NetInfo) bool { if (nInfo == nil) != (other == nil) { return false } @@ -916,9 +916,9 @@ func (nInfo *secondaryNetInfo) canReconcile(other NetInfo) bool { return cmp.Equal(nInfo.joinSubnets, other.JoinSubnets(), cmpopts.SortSlices(lessIPNet)) } -func (nInfo *secondaryNetInfo) copy() *secondaryNetInfo { +func (nInfo *userDefinedNetInfo) copy() *userDefinedNetInfo { // everything here is immutable - c := &secondaryNetInfo{ + c := &userDefinedNetInfo{ netName: nInfo.netName, primaryNetwork: nInfo.primaryNetwork, topology: nInfo.topology, @@ -951,7 +951,7 @@ func newLayer3NetConfInfo(netconf *ovncnitypes.NetConf) (MutableNetInfo, error) if err != nil { return nil, err } - ni := &secondaryNetInfo{ + ni := &userDefinedNetInfo{ netName: netconf.Name, primaryNetwork: netconf.Role == types.NetworkRolePrimary, topology: types.Layer3Topology, @@ -1014,7 +1014,7 @@ func newLayer2NetConfInfo(netconf *ovncnitypes.NetConf) (MutableNetInfo, error) } } - ni := &secondaryNetInfo{ + ni := &userDefinedNetInfo{ netName: netconf.Name, primaryNetwork: netconf.Role == types.NetworkRolePrimary, topology: types.Layer2Topology, @@ -1051,7 +1051,7 @@ func newLocalnetNetConfInfo(netconf *ovncnitypes.NetConf) (MutableNetInfo, error return nil, err } - ni := &secondaryNetInfo{ + ni := &userDefinedNetInfo{ netName: netconf.Name, topology: types.LocalnetTopology, subnets: subnets, @@ -1175,12 +1175,12 @@ func GetNADName(namespace, name string) string { return fmt.Sprintf("%s/%s", namespace, name) } -// GetSecondaryNetworkPrefix gets the string used as prefix of the logical entities -// of the secondary network of the given network name, in the form of _. +// GetUserDefinedNetworkPrefix gets the string used as prefix of the logical entities +// of the User Defined Network of the given network name, in the form of _. // // Note that for port_group and address_set, it does not allow the '-' character, // which will be replaced with ".". Also replace "/" in the nadName with "." -func GetSecondaryNetworkPrefix(netName string) string { +func GetUserDefinedNetworkPrefix(netName string) string { name := strings.ReplaceAll(netName, "-", ".") name = strings.ReplaceAll(name, "/", ".") return name + "_" @@ -1210,7 +1210,7 @@ func newNetInfo(netconf *ovncnitypes.NetConf) (MutableNetInfo, error) { if err != nil { return nil, err } - if ni.IsPrimaryNetwork() && ni.IsSecondary() { + if ni.IsPrimaryNetwork() && ni.IsUserDefinedNetwork() { ipv4Mode, ipv6Mode := ni.IPMode() if ipv4Mode && !config.IPv4Mode { return nil, fmt.Errorf("network %s is attempting to use ipv4 subnets but the cluster does not support ipv4", ni.GetNetworkName()) @@ -1234,7 +1234,7 @@ func GetAnnotatedNetworkName(netattachdef *nettypes.NetworkAttachmentDefinition) return netattachdef.Annotations[types.OvnNetworkNameAnnotation] } -// ParseNADInfo parses config in NAD spec and return a NetAttachDefInfo object for secondary networks +// ParseNADInfo parses config in NAD spec and return a NetAttachDefInfo object for User Defined Networks func ParseNADInfo(nad *nettypes.NetworkAttachmentDefinition) (NetInfo, error) { netconf, err := ParseNetConf(nad) if err != nil { @@ -1267,7 +1267,7 @@ func ParseNADInfo(nad *nettypes.NetworkAttachmentDefinition) (NetInfo, error) { return n, nil } -// ParseNetConf parses config in NAD spec for secondary networks +// ParseNetConf parses config in NAD spec for User Defined Networks func ParseNetConf(netattachdef *nettypes.NetworkAttachmentDefinition) (*ovncnitypes.NetConf, error) { netconf, err := config.ParseNetConf([]byte(netattachdef.Spec.Config)) if err != nil { @@ -1408,7 +1408,7 @@ func GetPodNADToNetworkMapping(pod *corev1.Pod, nInfo NetInfo) (bool, map[string networkSelections := map[string]*nettypes.NetworkSelectionElement{} podDesc := fmt.Sprintf("%s/%s", pod.Namespace, pod.Name) - if !nInfo.IsSecondary() { + if !nInfo.IsUserDefinedNetwork() { network, err := GetK8sPodDefaultNetworkSelection(pod) if err != nil { // multus won't add this Pod if this fails, should never happen @@ -1561,7 +1561,7 @@ func AllowsPersistentIPs(netInfo NetInfo) bool { case netInfo.IsPrimaryNetwork(): return netInfo.TopologyType() == types.Layer2Topology && netInfo.AllowsPersistentIPs() - case netInfo.IsSecondary(): + case netInfo.IsUserDefinedNetwork(): return (netInfo.TopologyType() == types.Layer2Topology || netInfo.TopologyType() == types.LocalnetTopology) && netInfo.AllowsPersistentIPs() @@ -1702,8 +1702,8 @@ func GetNetworkRole(controllerNetInfo NetInfo, getActiveNetworkForNamespace func // (C)UDN network name generation functions must ensure the absence of name conflicts between all (C)UDNs. // We use underscore as a separator as it is not allowed in k8s namespaces and names. -// Network name is then used by GetSecondaryNetworkPrefix function to generate db object names. -// GetSecondaryNetworkPrefix replaces some characters in the network name to ensure correct db object names, +// Network name is then used by GetUserDefinedNetworkPrefix function to generate db object names. +// GetUserDefinedNetworkPrefix replaces some characters in the network name to ensure correct db object names, // so the network name must be also unique after these replacements. func GenerateUDNNetworkName(namespace, name string) string { diff --git a/go-controller/pkg/util/multi_network_test.go b/go-controller/pkg/util/multi_network_test.go index 24746599de..11dd24fcbe 100644 --- a/go-controller/pkg/util/multi_network_test.go +++ b/go-controller/pkg/util/multi_network_test.go @@ -1582,8 +1582,8 @@ func TestAreNetworksCompatible(t *testing.T) { }{ { desc: "physical network name update", - aNetwork: &secondaryNetInfo{physicalNetworkName: "A"}, - anotherNetwork: &secondaryNetInfo{physicalNetworkName: "B"}, + aNetwork: &userDefinedNetInfo{physicalNetworkName: "A"}, + anotherNetwork: &userDefinedNetInfo{physicalNetworkName: "B"}, expectedResult: false, expectationDescription: "we should reconcile on physical network name updates", }, diff --git a/go-controller/pkg/util/pod_annotation.go b/go-controller/pkg/util/pod_annotation.go index ba565571bc..df89537b30 100644 --- a/go-controller/pkg/util/pod_annotation.go +++ b/go-controller/pkg/util/pod_annotation.go @@ -338,7 +338,7 @@ func GetPodCIDRsWithFullMask(pod *corev1.Pod, nInfo NetInfo) ([]*net.IPNet, erro // and then falling back to the Pod Status IPs. This function is intended to // also return IPs for HostNetwork and other non-OVN-IPAM-ed pods. func GetPodIPsOfNetwork(pod *corev1.Pod, nInfo NetInfo) ([]net.IP, error) { - if nInfo.IsSecondary() { + if nInfo.IsUserDefinedNetwork() { return SecondaryNetworkPodIPs(pod, nInfo) } return DefaultNetworkPodIPs(pod) diff --git a/go-controller/pkg/util/util.go b/go-controller/pkg/util/util.go index 4455de04c9..fda62d3fcd 100644 --- a/go-controller/pkg/util/util.go +++ b/go-controller/pkg/util/util.go @@ -416,7 +416,7 @@ func GetUserDefinedNetworkRole(isPrimary bool) string { // when on the default cluster network, for backward compatibility. func GenerateExternalIDsForSwitchOrRouter(netInfo NetInfo) map[string]string { externalIDs := make(map[string]string) - if netInfo.IsSecondary() { + if netInfo.IsUserDefinedNetwork() { externalIDs[types.NetworkExternalID] = netInfo.GetNetworkName() externalIDs[types.NetworkRoleExternalID] = GetUserDefinedNetworkRole(netInfo.IsPrimaryNetwork()) externalIDs[types.TopologyExternalID] = netInfo.TopologyType() @@ -424,8 +424,8 @@ func GenerateExternalIDsForSwitchOrRouter(netInfo NetInfo) map[string]string { return externalIDs } -func GetSecondaryNetworkLogicalPortName(podNamespace, podName, nadName string) string { - return GetSecondaryNetworkPrefix(nadName) + composePortName(podNamespace, podName) +func GetUserDefinedNetworkLogicalPortName(podNamespace, podName, nadName string) string { + return GetUserDefinedNetworkPrefix(nadName) + composePortName(podNamespace, podName) } func GetLogicalPortName(podNamespace, podName string) string { @@ -436,8 +436,8 @@ func GetNamespacePodFromCDNPortName(portName string) (string, string) { return decomposePortName(portName) } -func GetSecondaryNetworkIfaceId(podNamespace, podName, nadName string) string { - return GetSecondaryNetworkPrefix(nadName) + composePortName(podNamespace, podName) +func GetUDNIfaceId(podNamespace, podName, nadName string) string { + return GetUserDefinedNetworkPrefix(nadName) + composePortName(podNamespace, podName) } func GetIfaceId(podNamespace, podName string) string { diff --git a/test/e2e/kubevirt.go b/test/e2e/kubevirt.go index 507cc6d086..2684d6ade4 100644 --- a/test/e2e/kubevirt.go +++ b/test/e2e/kubevirt.go @@ -998,7 +998,7 @@ var _ = Describe("Kubevirt Virtual Machines", feature.VirtualMachineSupport, fun "kubevirt.io/allow-pod-bridge-network-live-migration": "", } nodeSelector := map[string]string{ - namespace: "", + namespace: "true", } networkSource := kubevirtv1.NetworkSource{ Pod: &kubevirtv1.PodNetwork{}, @@ -1119,7 +1119,7 @@ passwd: by(vm.Name, "Live migrate for the third time to the node owning the subnet") // Patch back the original node with the label and remove it // from the rest of nodes to force live migration target to it. - e2enode.AddOrUpdateLabelOnNode(fr.ClientSet, originalNode, namespace, "") + e2enode.AddOrUpdateLabelOnNode(fr.ClientSet, originalNode, namespace, "true") for _, selectedNode := range selectedNodes { if selectedNode.Name != originalNode { e2enode.RemoveLabelOffNode(fr.ClientSet, selectedNode.Name, namespace) @@ -1405,7 +1405,7 @@ fi // configure VM nodeSelector with it and live migration will take only // them into consideration for _, node := range selectedNodes { - e2enode.AddOrUpdateLabelOnNode(fr.ClientSet, node.Name, namespace, "") + e2enode.AddOrUpdateLabelOnNode(fr.ClientSet, node.Name, namespace, "true") } prepareHTTPServerPods(map[string]string{}, checkPodHasIPAtStatus)