From 07d121021e794ab8e4d8d34aaa276c2be954d60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Tue, 26 Mar 2024 14:22:10 +0800 Subject: [PATCH] fix reference to nil pointer (#3872) Signed-off-by: zhangzujian --- pkg/controller/init.go | 6 +++--- pkg/controller/subnet.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller/init.go b/pkg/controller/init.go index c2482159dca..423097f5c78 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -622,15 +622,15 @@ func (c *Controller) syncSubnetCR() error { klog.Error(err) return err } - for _, orisubnet := range subnets { - subnet := orisubnet.DeepCopy() + for _, cachedSubnet := range subnets { + subnet := cachedSubnet.DeepCopy() if util.CheckProtocol(subnet.Spec.CIDRBlock) == kubeovnv1.ProtocolDual { subnet, err = c.calcDualSubnetStatusIP(subnet) } else { subnet, err = c.calcSubnetStatusIP(subnet) } if err != nil { - klog.Errorf("failed to calculate subnet %s used ip: %v", subnet.Name, err) + klog.Errorf("failed to calculate subnet %s used ip: %v", cachedSubnet.Name, err) return err } diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 441f0e20587..a7879c37d31 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -746,7 +746,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error { subnet, err = c.calcSubnetStatusIP(subnet) } if err != nil { - klog.Errorf("calculate subnet %s used ip failed, %v", subnet.Name, err) + klog.Errorf("calculate subnet %s used ip failed, %v", cachedSubnet.Name, err) return err }