From 7bf1343fb71aa11eae4c7f34053a34b0792a68f8 Mon Sep 17 00:00:00 2001 From: bobz965 Date: Tue, 20 Feb 2024 14:23:29 +0800 Subject: [PATCH] fix: should use domain-qualified finalizer name Signed-off-by: bobz965 --- pkg/controller/init.go | 2 +- pkg/controller/ip.go | 4 ++-- pkg/controller/ovn_dnat.go | 4 ++-- pkg/controller/ovn_eip.go | 4 ++-- pkg/controller/ovn_fip.go | 4 ++-- pkg/controller/ovn_snat.go | 4 ++-- pkg/controller/qos_policy.go | 6 +++--- pkg/controller/subnet.go | 6 +++--- pkg/controller/vip.go | 6 +++--- pkg/controller/vpc_nat_gw_eip.go | 6 +++--- pkg/controller/vpc_nat_gw_nat.go | 18 +++++++++--------- pkg/util/const.go | 2 +- test/e2e/kube-ovn/subnet/subnet.go | 16 ++++++++-------- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/pkg/controller/init.go b/pkg/controller/init.go index b89fa91e2079..43ef8dc0649c 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -578,7 +578,7 @@ func (c *Controller) syncIPCR() error { for _, ipCR := range ips { ip := ipCR.DeepCopy() - if ip.DeletionTimestamp != nil && slices.Contains(ip.Finalizers, util.ControllerName) { + if ip.DeletionTimestamp != nil && slices.Contains(ip.Finalizers, util.FinalizerName) { klog.Infof("enqueue update for deleting ip %s", ip.Name) c.updateIPQueue.Add(ip.Name) } diff --git a/pkg/controller/ip.go b/pkg/controller/ip.go index acea7b7fe6ab..793a43dcd651 100644 --- a/pkg/controller/ip.go +++ b/pkg/controller/ip.go @@ -323,7 +323,7 @@ func (c *Controller) handleUpdateIP(key string) error { klog.Infof("ip cr %s release ipam pod key %s from subnet %s", cachedIP.Name, podKey, cachedIP.Spec.Subnet) c.ipam.ReleaseAddressByPod(podKey, cachedIP.Spec.Subnet) } - if err = c.handleDelIPFinalizer(cachedIP, util.ControllerName); err != nil { + if err = c.handleDelIPFinalizer(cachedIP, util.FinalizerName); err != nil { klog.Errorf("failed to handle del ip finalizer %v", err) return err } @@ -535,7 +535,7 @@ func (c *Controller) createOrUpdateIPCR(ipCRName, podName, ip, mac, subnetName, } } - if err := c.handleAddIPFinalizer(ipCR, util.ControllerName); err != nil { + if err := c.handleAddIPFinalizer(ipCR, util.FinalizerName); err != nil { klog.Errorf("failed to handle add ip finalizer %v", err) return err } diff --git a/pkg/controller/ovn_dnat.go b/pkg/controller/ovn_dnat.go index 77b6bbf5f890..4dc04b4060b1 100644 --- a/pkg/controller/ovn_dnat.go +++ b/pkg/controller/ovn_dnat.go @@ -301,7 +301,7 @@ func (c *Controller) handleAddOvnDnatRule(key string) error { return err } - if err := c.handleAddOvnDnatFinalizer(cachedDnat, util.ControllerName); err != nil { + if err := c.handleAddOvnDnatFinalizer(cachedDnat, util.FinalizerName); err != nil { klog.Errorf("failed to add finalizer for ovn dnat %s, %v", cachedDnat.Name, err) return err } @@ -348,7 +348,7 @@ func (c *Controller) handleDelOvnDnatRule(key string) error { return err } } - if err = c.handleDelOvnDnatFinalizer(cachedDnat, util.ControllerName); err != nil { + if err = c.handleDelOvnDnatFinalizer(cachedDnat, util.FinalizerName); err != nil { klog.Errorf("failed to remove finalizer for ovn dnat %s, %v", cachedDnat.Name, err) return err } diff --git a/pkg/controller/ovn_eip.go b/pkg/controller/ovn_eip.go index a18fcc465d0e..3e69c97ba48e 100644 --- a/pkg/controller/ovn_eip.go +++ b/pkg/controller/ovn_eip.go @@ -268,7 +268,7 @@ func (c *Controller) handleAddOvnEip(key string) error { return err } } - if err = c.handleAddOvnEipFinalizer(cachedEip, util.ControllerName); err != nil { + if err = c.handleAddOvnEipFinalizer(cachedEip, util.FinalizerName); err != nil { klog.Errorf("failed to add finalizer for ovn eip, %v", err) return err } @@ -343,7 +343,7 @@ func (c *Controller) handleDelOvnEip(key string) error { } } - if err = c.handleDelOvnEipFinalizer(eip, util.ControllerName); err != nil { + if err = c.handleDelOvnEipFinalizer(eip, util.FinalizerName); err != nil { klog.Errorf("failed to handle remove ovn eip finalizer , %v", err) return err } diff --git a/pkg/controller/ovn_fip.go b/pkg/controller/ovn_fip.go index a78a6d37b1b5..358c12255f3f 100644 --- a/pkg/controller/ovn_fip.go +++ b/pkg/controller/ovn_fip.go @@ -296,7 +296,7 @@ func (c *Controller) handleAddOvnFip(key string) error { return err } - if err = c.handleAddOvnFipFinalizer(cachedFip, util.ControllerName); err != nil { + if err = c.handleAddOvnFipFinalizer(cachedFip, util.FinalizerName); err != nil { klog.Errorf("failed to add finalizer for ovn fip, %v", err) return err } @@ -463,7 +463,7 @@ func (c *Controller) handleDelOvnFip(key string) error { return err } } - if err = c.handleDelOvnFipFinalizer(cachedFip, util.ControllerName); err != nil { + if err = c.handleDelOvnFipFinalizer(cachedFip, util.FinalizerName); err != nil { klog.Errorf("failed to remove finalizer for ovn fip %s, %v", cachedFip.Name, err) return err } diff --git a/pkg/controller/ovn_snat.go b/pkg/controller/ovn_snat.go index a49b3af2a1a2..3cdd66424190 100644 --- a/pkg/controller/ovn_snat.go +++ b/pkg/controller/ovn_snat.go @@ -257,7 +257,7 @@ func (c *Controller) handleAddOvnSnatRule(key string) error { klog.Errorf("failed to create snat, %v", err) return err } - if err := c.handleAddOvnSnatFinalizer(cachedSnat, util.ControllerName); err != nil { + if err := c.handleAddOvnSnatFinalizer(cachedSnat, util.FinalizerName); err != nil { klog.Errorf("failed to add finalizer for ovn snat %s, %v", cachedSnat.Name, err) return err } @@ -419,7 +419,7 @@ func (c *Controller) handleDelOvnSnatRule(key string) error { return err } } - if err = c.handleDelOvnSnatFinalizer(cachedSnat, util.ControllerName); err != nil { + if err = c.handleDelOvnSnatFinalizer(cachedSnat, util.FinalizerName); err != nil { klog.Errorf("failed to remove finalizer for ovn snat %s, %v", cachedSnat.Name, err) return err } diff --git a/pkg/controller/qos_policy.go b/pkg/controller/qos_policy.go index a0f667f55cd6..5e27a0568930 100644 --- a/pkg/controller/qos_policy.go +++ b/pkg/controller/qos_policy.go @@ -265,7 +265,7 @@ func (c *Controller) handleDelQoSPoliciesFinalizer(key string) error { return nil } newQoSPolicies := cachedQoSPolicies.DeepCopy() - controllerutil.RemoveFinalizer(newQoSPolicies, util.ControllerName) + controllerutil.RemoveFinalizer(newQoSPolicies, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedQoSPolicies, newQoSPolicies) if err != nil { klog.Errorf("failed to generate patch payload for qos '%s', %v", cachedQoSPolicies.Name, err) @@ -521,12 +521,12 @@ func (c *Controller) handleAddQoSPolicyFinalizer(key string) error { return err } if cachedQoSPolicy.DeletionTimestamp.IsZero() { - if slices.Contains(cachedQoSPolicy.Finalizers, util.ControllerName) { + if slices.Contains(cachedQoSPolicy.Finalizers, util.FinalizerName) { return nil } } newQoSPolicy := cachedQoSPolicy.DeepCopy() - controllerutil.AddFinalizer(newQoSPolicy, util.ControllerName) + controllerutil.AddFinalizer(newQoSPolicy, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedQoSPolicy, newQoSPolicy) if err != nil { klog.Errorf("failed to generate patch payload for qos '%s', %v", cachedQoSPolicy.Name, err) diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index f95994d18f21..7faba89d9125 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -480,9 +480,9 @@ func checkAndUpdateExcludeIPs(subnet *kubeovnv1.Subnet) bool { } func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, error) { - if subnet.DeletionTimestamp.IsZero() && !slices.Contains(subnet.Finalizers, util.ControllerName) { + if subnet.DeletionTimestamp.IsZero() && !slices.Contains(subnet.Finalizers, util.FinalizerName) { newSubnet := subnet.DeepCopy() - newSubnet.Finalizers = append(newSubnet.Finalizers, util.ControllerName) + newSubnet.Finalizers = append(newSubnet.Finalizers, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(subnet, newSubnet) if err != nil { klog.Errorf("failed to generate patch payload for subnet '%s', %v", subnet.Name, err) @@ -506,7 +506,7 @@ func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, erro u2oInterconnIP := subnet.Status.U2OInterconnectionIP if !subnet.DeletionTimestamp.IsZero() && (usingIPs == 0 || (usingIPs == 1 && u2oInterconnIP != "")) { newSubnet := subnet.DeepCopy() - newSubnet.Finalizers = util.RemoveString(newSubnet.Finalizers, util.ControllerName) + newSubnet.Finalizers = util.RemoveString(newSubnet.Finalizers, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(subnet, newSubnet) if err != nil { klog.Errorf("failed to generate patch payload for subnet '%s', %v", subnet.Name, err) diff --git a/pkg/controller/vip.go b/pkg/controller/vip.go index 6ce1aebbd856..85eb3e32179b 100644 --- a/pkg/controller/vip.go +++ b/pkg/controller/vip.go @@ -637,12 +637,12 @@ func (c *Controller) handleAddVipFinalizer(key string) error { return err } if cachedVip.DeletionTimestamp.IsZero() { - if slices.Contains(cachedVip.Finalizers, util.ControllerName) { + if slices.Contains(cachedVip.Finalizers, util.FinalizerName) { return nil } } newVip := cachedVip.DeepCopy() - controllerutil.AddFinalizer(newVip, util.ControllerName) + controllerutil.AddFinalizer(newVip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedVip, newVip) if err != nil { klog.Errorf("failed to generate patch payload for ovn eip '%s', %v", cachedVip.Name, err) @@ -672,7 +672,7 @@ func (c *Controller) handleDelVipFinalizer(key string) error { return nil } newVip := cachedVip.DeepCopy() - controllerutil.RemoveFinalizer(newVip, util.ControllerName) + controllerutil.RemoveFinalizer(newVip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedVip, newVip) if err != nil { klog.Errorf("failed to generate patch payload for ovn eip '%s', %v", cachedVip.Name, err) diff --git a/pkg/controller/vpc_nat_gw_eip.go b/pkg/controller/vpc_nat_gw_eip.go index 017a4eacfdb8..fa1efbef5612 100644 --- a/pkg/controller/vpc_nat_gw_eip.go +++ b/pkg/controller/vpc_nat_gw_eip.go @@ -760,12 +760,12 @@ func (c *Controller) handleAddIptablesEipFinalizer(key string) error { return err } if cachedIptablesEip.DeletionTimestamp.IsZero() { - if slices.Contains(cachedIptablesEip.Finalizers, util.ControllerName) { + if slices.Contains(cachedIptablesEip.Finalizers, util.FinalizerName) { return nil } } newIptablesEip := cachedIptablesEip.DeepCopy() - controllerutil.AddFinalizer(newIptablesEip, util.ControllerName) + controllerutil.AddFinalizer(newIptablesEip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesEip, newIptablesEip) if err != nil { klog.Errorf("failed to generate patch payload for iptables eip '%s', %v", cachedIptablesEip.Name, err) @@ -795,7 +795,7 @@ func (c *Controller) handleDelIptablesEipFinalizer(key string) error { return nil } newIptablesEip := cachedIptablesEip.DeepCopy() - controllerutil.RemoveFinalizer(newIptablesEip, util.ControllerName) + controllerutil.RemoveFinalizer(newIptablesEip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesEip, newIptablesEip) if err != nil { klog.Errorf("failed to generate patch payload for iptables eip '%s', %v", cachedIptablesEip.Name, err) diff --git a/pkg/controller/vpc_nat_gw_nat.go b/pkg/controller/vpc_nat_gw_nat.go index 443282543946..ce1a021f2c69 100644 --- a/pkg/controller/vpc_nat_gw_nat.go +++ b/pkg/controller/vpc_nat_gw_nat.go @@ -1054,12 +1054,12 @@ func (c *Controller) handleAddIptablesFipFinalizer(key string) error { return err } if cachedIptablesFip.DeletionTimestamp.IsZero() { - if slices.Contains(cachedIptablesFip.Finalizers, util.ControllerName) { + if slices.Contains(cachedIptablesFip.Finalizers, util.FinalizerName) { return nil } } newIptablesFip := cachedIptablesFip.DeepCopy() - controllerutil.AddFinalizer(newIptablesFip, util.ControllerName) + controllerutil.AddFinalizer(newIptablesFip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesFip, newIptablesFip) if err != nil { klog.Errorf("failed to generate patch payload for iptables fip '%s', %v", cachedIptablesFip.Name, err) @@ -1089,7 +1089,7 @@ func (c *Controller) handleDelIptablesFipFinalizer(key string) error { return nil } newIptablesFip := cachedIptablesFip.DeepCopy() - controllerutil.RemoveFinalizer(newIptablesFip, util.ControllerName) + controllerutil.RemoveFinalizer(newIptablesFip, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesFip, newIptablesFip) if err != nil { klog.Errorf("failed to generate patch payload for iptables fip '%s', %v", cachedIptablesFip.Name, err) @@ -1116,12 +1116,12 @@ func (c *Controller) handleAddIptablesDnatFinalizer(key string) error { return err } if cachedIptablesDnat.DeletionTimestamp.IsZero() { - if slices.Contains(cachedIptablesDnat.Finalizers, util.ControllerName) { + if slices.Contains(cachedIptablesDnat.Finalizers, util.FinalizerName) { return nil } } newIptablesDnat := cachedIptablesDnat.DeepCopy() - controllerutil.AddFinalizer(newIptablesDnat, util.ControllerName) + controllerutil.AddFinalizer(newIptablesDnat, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesDnat, newIptablesDnat) if err != nil { klog.Errorf("failed to generate patch payload for iptables dnat '%s', %v", cachedIptablesDnat.Name, err) @@ -1151,7 +1151,7 @@ func (c *Controller) handleDelIptablesDnatFinalizer(key string) error { return nil } newIptablesDnat := cachedIptablesDnat.DeepCopy() - controllerutil.RemoveFinalizer(newIptablesDnat, util.ControllerName) + controllerutil.RemoveFinalizer(newIptablesDnat, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesDnat, newIptablesDnat) if err != nil { klog.Errorf("failed to generate patch payload for iptables dnat '%s', %v", cachedIptablesDnat.Name, err) @@ -1229,12 +1229,12 @@ func (c *Controller) handleAddIptablesSnatFinalizer(key string) error { return err } if cachedIptablesSnat.DeletionTimestamp.IsZero() { - if slices.Contains(cachedIptablesSnat.Finalizers, util.ControllerName) { + if slices.Contains(cachedIptablesSnat.Finalizers, util.FinalizerName) { return nil } } newIptablesSnat := cachedIptablesSnat.DeepCopy() - controllerutil.AddFinalizer(newIptablesSnat, util.ControllerName) + controllerutil.AddFinalizer(newIptablesSnat, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesSnat, newIptablesSnat) if err != nil { klog.Errorf("failed to generate patch payload for iptables snat '%s', %v", cachedIptablesSnat.Name, err) @@ -1264,7 +1264,7 @@ func (c *Controller) handleDelIptablesSnatFinalizer(key string) error { return nil } newIptablesSnat := cachedIptablesSnat.DeepCopy() - controllerutil.RemoveFinalizer(newIptablesSnat, util.ControllerName) + controllerutil.RemoveFinalizer(newIptablesSnat, util.FinalizerName) patch, err := util.GenerateMergePatchPayload(cachedIptablesSnat, newIptablesSnat) if err != nil { klog.Errorf("failed to generate patch payload for iptables snat '%s', %v", cachedIptablesSnat.Name, err) diff --git a/pkg/util/const.go b/pkg/util/const.go index 30cc990e3132..d81be7d658fe 100644 --- a/pkg/util/const.go +++ b/pkg/util/const.go @@ -3,7 +3,7 @@ package util const ( CniTypeName = "kube-ovn" - ControllerName = "kube-ovn-controller" + FinalizerName = "kubeovn.io/finalizer" AllocatedAnnotation = "ovn.kubernetes.io/allocated" RoutedAnnotation = "ovn.kubernetes.io/routed" diff --git a/test/e2e/kube-ovn/subnet/subnet.go b/test/e2e/kube-ovn/subnet/subnet.go index cddea940ee44..395de008ea43 100644 --- a/test/e2e/kube-ovn/subnet/subnet.go +++ b/test/e2e/kube-ovn/subnet/subnet.go @@ -148,7 +148,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -206,7 +206,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -251,7 +251,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -301,7 +301,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -345,7 +345,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -388,7 +388,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.PatchSync(subnet, modifiedSubnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.ObjectMeta.Finalizers, util.FinalizerName) ginkgo.By("Validating subnet spec fields") framework.ExpectFalse(subnet.Spec.Default) @@ -444,7 +444,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet finalizers") - framework.ExpectContainElement(subnet.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.Finalizers, util.FinalizerName) ginkgo.By("Validating centralized subnet with active-standby mode") framework.ExpectFalse(subnet.Spec.EnableEcmp) @@ -947,7 +947,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.CreateSync(subnet) ginkgo.By("Validating subnet load-balancer records exist") - framework.ExpectContainElement(subnet.Finalizers, util.ControllerName) + framework.ExpectContainElement(subnet.Finalizers, util.FinalizerName) execCmd := "kubectl ko nbctl --format=csv --data=bare --no-heading --columns=load_balancer find logical-switch " + fmt.Sprintf("name=%s", subnetName) output, err := exec.Command("bash", "-c", execCmd).CombinedOutput() framework.ExpectNoError(err)