From 37ef320fc4a9f3166e1cc64e239c809b61752e94 Mon Sep 17 00:00:00 2001 From: iiiceoo Date: Fri, 24 Feb 2023 20:17:00 +0800 Subject: [PATCH] fix: Event loss for updating 'spec.ips' of SpiderIPPool Signed-off-by: iiiceoo --- cmd/spiderpool-controller/cmd/config.go | 2 +- pkg/metric/metrics_instance.go | 13 ++++++------- pkg/subnetmanager/subnet_informer.go | 12 ++++-------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cmd/spiderpool-controller/cmd/config.go b/cmd/spiderpool-controller/cmd/config.go index a4978801cf..16f92cd207 100644 --- a/cmd/spiderpool-controller/cmd/config.go +++ b/cmd/spiderpool-controller/cmd/config.go @@ -57,7 +57,7 @@ var envInfo = []envConf{ {"SPIDERPOOL_IPPOOL_MAX_ALLOCATED_IPS", "5000", false, nil, nil, &controllerContext.Cfg.IPPoolMaxAllocatedIPs}, {"SPIDERPOOL_SUBNET_RESYNC_PERIOD", "300", false, nil, nil, &controllerContext.Cfg.SubnetResyncPeriod}, {"SPIDERPOOL_SUBNET_APPLICATION_CONTROLLER_WORKERS", "5", true, nil, nil, &controllerContext.Cfg.SubnetAppControllerWorkers}, - {"SPIDERPOOL_SUBNET_INFORMER_WORKERS", "3", true, nil, nil, &controllerContext.Cfg.SubnetInformerWorkers}, + {"SPIDERPOOL_SUBNET_INFORMER_WORKERS", "5", true, nil, nil, &controllerContext.Cfg.SubnetInformerWorkers}, {"SPIDERPOOL_SUBNET_INFORMER_MAX_WORKQUEUE_LENGTH", "10000", false, nil, nil, &controllerContext.Cfg.SubnetInformerMaxWorkqueueLength}, {"SPIDERPOOL_UPDATE_CR_MAX_RETRIES", "4", false, nil, nil, &controllerContext.Cfg.UpdateCRMaxRetries}, {"SPIDERPOOL_UPDATE_CR_RETRY_UNIT_TIME", "50", false, nil, nil, &controllerContext.Cfg.UpdateCRRetryUnitTime}, diff --git a/pkg/metric/metrics_instance.go b/pkg/metric/metrics_instance.go index 8db781d436..a3b847fb7d 100644 --- a/pkg/metric/metrics_instance.go +++ b/pkg/metric/metrics_instance.go @@ -244,7 +244,7 @@ func InitSpiderpoolAgentMetrics(ctx context.Context) error { return fmt.Errorf("failed to new spiderpool agent metric '%s', error: %v", auto_pool_waited_for_available_counts, err) } AutoPoolWaitedForAvailableCounts = autoPoolWaitedForAvailableCounts - AutoPoolWaitedForAvailableCounts.Add(ctx, 0) + return nil } @@ -276,8 +276,6 @@ func InitSpiderpoolControllerMetrics(ctx context.Context) error { } IPPoolInformerConflictCounts = poolInformerConflictCounts - IPPoolInformerConflictCounts.Add(ctx, 0) - return nil } @@ -520,8 +518,11 @@ func initSpiderpoolControllerGCMetrics(ctx context.Context) error { } IPGCFailureCounts = ipGCFailureCounts - IPGCTotalCounts.Add(ctx, 0) - IPGCFailureCounts.Add(ctx, 0) + releaseUpdateIPPoolConflictCounts, err := NewMetricInt64Counter(ipam_release_update_ippool_conflict_counts, "spiderpool controller gc release update IPPool conflict counts") + if nil != err { + return fmt.Errorf("failed to new spiderpool agent metric '%s', error: %v", ipam_release_update_ippool_conflict_counts, err) + } + IpamReleaseUpdateIPPoolConflictCounts = releaseUpdateIPPoolConflictCounts return nil } @@ -592,7 +593,5 @@ func initAutoPoolScaleMetrics(ctx context.Context) error { } AutoPoolScaleConflictCounts = autoPoolScaleConflictCounts - AutoPoolScaleConflictCounts.Add(ctx, 0) - return nil } diff --git a/pkg/subnetmanager/subnet_informer.go b/pkg/subnetmanager/subnet_informer.go index 8f3568960d..ae36212b4d 100644 --- a/pkg/subnetmanager/subnet_informer.go +++ b/pkg/subnetmanager/subnet_informer.go @@ -65,10 +65,10 @@ type SubnetController struct { func (sc *SubnetController) SetupInformer(ctx context.Context, client clientset.Interface, leader election.SpiderLeaseElector) error { if client == nil { - return fmt.Errorf("spiderpool clientset must be specified") + return fmt.Errorf("spiderpoolv1 clientset %w", constant.ErrMissingRequiredParam) } if leader == nil { - return fmt.Errorf("controller leader must be specified") + return fmt.Errorf("controller leader %w", constant.ErrMissingRequiredParam) } InformerLogger = logutils.Logger.Named("Subnet-Informer") @@ -141,12 +141,6 @@ func (sc *SubnetController) addEventHandlers(subnetInformer informers.SpiderSubn ipPoolInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: sc.enqueueSubnetOnIPPoolChange, UpdateFunc: func(old, new interface{}) { - oldIPPool := old.(*spiderpoolv1.SpiderIPPool) - newIPPool := new.(*spiderpoolv1.SpiderIPPool) - if reflect.DeepEqual(newIPPool.Spec.IPs, oldIPPool.Spec.IPs) && - reflect.DeepEqual(newIPPool.Spec.ExcludeIPs, oldIPPool.Spec.ExcludeIPs) { - return - } sc.enqueueSubnetOnIPPoolChange(new) }, DeleteFunc: sc.enqueueSubnetOnIPPoolChange, @@ -253,6 +247,8 @@ func (sc *SubnetController) processNextWorkItem(ctx context.Context) bool { sc.Workqueue.AddRateLimited(obj) return true } + logger.Info("Succeed to SYNC") + sc.Workqueue.Forget(obj) return true