Skip to content

Commit

Permalink
Merge pull request #1368 from iiiceoo/testc
Browse files Browse the repository at this point in the history
fix: Event loss for updating 'spec.ips' of SpiderIPPool
  • Loading branch information
Icarus9913 authored Feb 24, 2023
2 parents b8fc57d + 37ef320 commit dfa9533
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/spiderpool-controller/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
13 changes: 6 additions & 7 deletions pkg/metric/metrics_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -276,8 +276,6 @@ func InitSpiderpoolControllerMetrics(ctx context.Context) error {
}
IPPoolInformerConflictCounts = poolInformerConflictCounts

IPPoolInformerConflictCounts.Add(ctx, 0)

return nil
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -592,7 +593,5 @@ func initAutoPoolScaleMetrics(ctx context.Context) error {
}
AutoPoolScaleConflictCounts = autoPoolScaleConflictCounts

AutoPoolScaleConflictCounts.Add(ctx, 0)

return nil
}
12 changes: 4 additions & 8 deletions pkg/subnetmanager/subnet_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dfa9533

Please sign in to comment.