From 0b7fb29b9f7fca9d68698eb469be569910e63d6d Mon Sep 17 00:00:00 2001 From: abstractmj Date: Thu, 29 Jul 2021 14:29:24 +0800 Subject: [PATCH] fix: fix nil pointer error when clbingress is invalid; issue #953 --- bcs-services/bcs-clb-controller/pkg/processor/updater.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bcs-services/bcs-clb-controller/pkg/processor/updater.go b/bcs-services/bcs-clb-controller/pkg/processor/updater.go index 10d3fc88a8..96dcbf65c4 100644 --- a/bcs-services/bcs-clb-controller/pkg/processor/updater.go +++ b/bcs-services/bcs-clb-controller/pkg/processor/updater.go @@ -410,6 +410,7 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress for _, tmpTCPRule := range tmpIngress.Spec.TCP { err := tmpTCPRule.Validate() if err != nil { + blog.Errorf("rule %s validate failed, err %s", tmpTCPRule.ToString(), err.Error()) tmpIngress.SetStatusMessage(ingressType.ClbIngressStatusAbnormal, fmt.Sprintf("rule %s validate failed, err %s", tmpTCPRule.ToString(), err.Error())) err = updater.ingressRegistry.SetIngress(tmpIngress) @@ -417,7 +418,6 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress blog.Warnf("set ingress %s/%s failed, err %s", tmpIngress.GetNamespace(), tmpIngress.GetName(), err.Error()) } - blog.Errorf("rule %s validate failed, err %s", tmpTCPRule.ToString(), err.Error()) return false } err = updater.validateFourLayerRuleConflict(tmpTCPRule, fourLayerMap, sevenLayerMap) @@ -435,6 +435,7 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress for _, tmpUDPRule := range tmpIngress.Spec.UDP { err := tmpUDPRule.Validate() if err != nil { + blog.Errorf("rule %s validate failed, err %s", tmpUDPRule.ToString(), err.Error()) tmpIngress.SetStatusMessage(ingressType.ClbIngressStatusAbnormal, fmt.Sprintf("rule %s validate failed, err %s", tmpUDPRule.ToString(), err.Error())) err = updater.ingressRegistry.SetIngress(tmpIngress) @@ -442,7 +443,6 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress blog.Warnf("set ingress %s/%s failed, err %s", tmpIngress.GetNamespace(), tmpIngress.GetName(), err.Error()) } - blog.Errorf("rule %s validate failed, err %s", tmpUDPRule.ToString(), err.Error()) return false } err = updater.validateFourLayerRuleConflict(tmpUDPRule, fourLayerMap, sevenLayerMap) @@ -460,6 +460,7 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress for _, tmpHTTPRule := range tmpIngress.Spec.HTTP { err := tmpHTTPRule.ValidateHTTP() if err != nil { + blog.Errorf("rule %s validate failed, err %s", tmpHTTPRule.ToString(), err.Error()) tmpIngress.SetStatusMessage(ingressType.ClbIngressStatusAbnormal, fmt.Sprintf("rule %s validate failed, err %s", tmpHTTPRule.ToString(), err.Error())) err = updater.ingressRegistry.SetIngress(tmpIngress) @@ -467,7 +468,6 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress blog.Warnf("set ingress %s/%s failed, err %s", tmpIngress.GetNamespace(), tmpIngress.GetName(), err.Error()) } - blog.Errorf("rule %s validate failed, err %s", tmpHTTPRule.ToString(), err.Error()) return false } err = updater.validateSevenLayerRuleConflict(tmpHTTPRule, fourLayerMap, sevenLayerMap) @@ -485,6 +485,7 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress for _, tmpHTTPSRule := range tmpIngress.Spec.HTTPS { err := tmpHTTPSRule.ValidateHTTPS() if err != nil { + blog.Errorf("rule %s validate failed, err %s", tmpHTTPSRule.ToString(), err.Error()) tmpIngress.SetStatusMessage(ingressType.ClbIngressStatusAbnormal, fmt.Sprintf("rule %s validate failed, err %s", tmpHTTPSRule.ToString(), err.Error())) err = updater.ingressRegistry.SetIngress(tmpIngress) @@ -492,7 +493,6 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress blog.Warnf("set ingress %s/%s failed, err %s", tmpIngress.GetNamespace(), tmpIngress.GetName(), err.Error()) } - blog.Errorf("rule %s validate failed, err %s", tmpHTTPSRule.ToString(), err.Error()) return false } err = updater.validateSevenLayerRuleConflict(tmpHTTPSRule, fourLayerMap, sevenLayerMap) @@ -508,7 +508,6 @@ func (updater *Updater) validateClbIngress(ingressList []*ingressType.ClbIngress } if err := updater.validateStatefulSetIngress( tmpIngress.Spec.StatefulSet, fourLayerMap, sevenLayerMap); err != nil { - tmpIngress.SetStatusMessage(ingressType.ClbIngressStatusAbnormal, err.Error()) err = updater.ingressRegistry.SetIngress(tmpIngress) if err != nil {