From eb90123412bf002f90f1d178c869f891b7e2e2f1 Mon Sep 17 00:00:00 2001 From: cmssczy Date: Mon, 7 Mar 2022 23:48:30 +0800 Subject: [PATCH] fix: fix ep resourceVersion comparison and clean up (#901) --- pkg/ingress/apisix_tls.go | 2 +- pkg/ingress/endpoint.go | 2 +- pkg/ingress/endpointslice.go | 2 +- pkg/ingress/secret.go | 2 +- pkg/ingress/status.go | 5 ++--- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/ingress/apisix_tls.go b/pkg/ingress/apisix_tls.go index dfad187367..ab6e6e81dc 100644 --- a/pkg/ingress/apisix_tls.go +++ b/pkg/ingress/apisix_tls.go @@ -206,7 +206,7 @@ func (c *apisixTlsController) onAdd(obj interface{}) { func (c *apisixTlsController) onUpdate(prev, curr interface{}) { oldTls := prev.(*configv2beta3.ApisixTls) newTls := curr.(*configv2beta3.ApisixTls) - if oldTls.GetResourceVersion() == newTls.GetResourceVersion() { + if oldTls.GetResourceVersion() >= newTls.GetResourceVersion() { return } key, err := cache.MetaNamespaceKeyFunc(curr) diff --git a/pkg/ingress/endpoint.go b/pkg/ingress/endpoint.go index db2c51eee7..2b37607bf8 100644 --- a/pkg/ingress/endpoint.go +++ b/pkg/ingress/endpoint.go @@ -133,7 +133,7 @@ func (c *endpointsController) onUpdate(prev, curr interface{}) { prevEp := prev.(*corev1.Endpoints) currEp := curr.(*corev1.Endpoints) - if prevEp.GetResourceVersion() == currEp.GetResourceVersion() { + if prevEp.GetResourceVersion() >= currEp.GetResourceVersion() { return } key, err := cache.MetaNamespaceKeyFunc(currEp) diff --git a/pkg/ingress/endpointslice.go b/pkg/ingress/endpointslice.go index aece7ced0c..1b204a6c9a 100644 --- a/pkg/ingress/endpointslice.go +++ b/pkg/ingress/endpointslice.go @@ -157,7 +157,7 @@ func (c *endpointSliceController) onUpdate(prev, curr interface{}) { prevEp := prev.(*discoveryv1.EndpointSlice) currEp := curr.(*discoveryv1.EndpointSlice) - if prevEp.GetResourceVersion() == currEp.GetResourceVersion() { + if prevEp.GetResourceVersion() >= currEp.GetResourceVersion() { return } key, err := cache.MetaNamespaceKeyFunc(currEp) diff --git a/pkg/ingress/secret.go b/pkg/ingress/secret.go index c42719a665..295671a85e 100644 --- a/pkg/ingress/secret.go +++ b/pkg/ingress/secret.go @@ -254,7 +254,7 @@ func (c *secretController) onUpdate(prev, curr interface{}) { prevSec := prev.(*corev1.Secret) currSec := curr.(*corev1.Secret) - if prevSec.GetResourceVersion() == currSec.GetResourceVersion() { + if prevSec.GetResourceVersion() >= currSec.GetResourceVersion() { return } key, err := cache.MetaNamespaceKeyFunc(currSec) diff --git a/pkg/ingress/status.go b/pkg/ingress/status.go index acd7bbcf0d..2bbac5be85 100644 --- a/pkg/ingress/status.go +++ b/pkg/ingress/status.go @@ -28,7 +28,6 @@ import ( networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/cache" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" @@ -55,7 +54,7 @@ func (c *Controller) verifyGeneration(conditions *[]metav1.Condition, newConditi } // recordStatus record resources status -func (c *Controller) recordStatus(at interface{}, reason string, err error, status v1.ConditionStatus, generation int64) { +func (c *Controller) recordStatus(at interface{}, reason string, err error, status metav1.ConditionStatus, generation int64) { // build condition message := _commonSuccessMessage if err != nil { @@ -335,7 +334,7 @@ func (c *Controller) ingressPublishAddresses() ([]string, error) { switch svc.Spec.Type { case apiv1.ServiceTypeLoadBalancer: if len(svc.Status.LoadBalancer.Ingress) < 1 { - return addrs, fmt.Errorf(_gatewayLBNotReadyMessage) + return addrs, fmt.Errorf("%s", _gatewayLBNotReadyMessage) } for _, ip := range svc.Status.LoadBalancer.Ingress {