Use go 1.25 waitgroup Go method instead of Add/Wait (#3265)

* Use go 1.25 waitgroup Go method instead of Add/Wait

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Disable java builder test for now

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2025-10-30 14:32:44 +05:30
committed by GitHub
parent 4ebdb077b5
commit ebdce4c0ed
11 changed files with 96 additions and 113 deletions
+10 -12
View File
@@ -154,12 +154,11 @@ func (executor *Executor) serveCreateFuncServices(ctx context.Context) {
// create a waitgroup for other requests for
// the same function to wait on
wg := &sync.WaitGroup{}
wg.Add(1)
executor.fsCreateWg.Store(fnkeyUR, wg)
// launch a goroutine for each request, to parallelize
// the specialization of different functions
go func() {
wg.Go(func() {
// Control overall specialization time by setting function
// specialization time to context. The reason not to use
// context from router requests is because a request maybe
@@ -188,8 +187,7 @@ func (executor *Executor) serveCreateFuncServices(ctx context.Context) {
err: err,
}
executor.fsCreateWg.Delete(fnkeyUR)
wg.Done()
}()
})
} else {
// There's an existing request for this function, wait for it to finish
go func() {
@@ -352,14 +350,14 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
wg := &sync.WaitGroup{}
for _, et := range executorTypes {
wg.Add(1)
go func(et executortype.ExecutorType) {
defer wg.Done()
if adoptExistingResources {
et.AdoptExistingResources(ctx)
}
et.CleanupOldExecutorObjects(ctx)
}(et)
wg.Go(func() {
func(et executortype.ExecutorType) {
if adoptExistingResources {
et.AdoptExistingResources(ctx)
}
et.CleanupOldExecutorObjects(ctx)
}(et)
})
}
// set hard timeout for resource adoption
// TODO: use context to control the waiting time once kubernetes client supports it.
@@ -302,17 +302,14 @@ func (caaf *Container) AdoptExistingResources(ctx context.Context) {
for i := range fnList.Items {
fn := &fnList.Items[i]
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeContainer {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
_, err = caaf.fnCreate(ctx, fn)
if err != nil {
caaf.logger.Warn("failed to adopt resources for function", zap.Error(err))
return
}
caaf.logger.Info("adopt resources for function", zap.String("function", fn.ObjectMeta.Name))
}()
})
}
}
}
@@ -322,17 +322,14 @@ func (deploy *NewDeploy) AdoptExistingResources(ctx context.Context) {
for i := range fnList.Items {
fn := &fnList.Items[i]
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeNewdeploy {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
_, err = deploy.fnCreate(ctx, fn)
if err != nil {
deploy.logger.Warn("failed to adopt resources for function", zap.Error(err))
return
}
deploy.logger.Info("adopt resources for function", zap.String("function", fn.ObjectMeta.Name))
}()
})
}
}
}
+4 -9
View File
@@ -368,9 +368,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
env := envs.Items[i]
if getEnvPoolSize(&env) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
_, created, err := gpm.getPool(ctx, &env)
if err != nil {
gpm.logger.Error("adopt pool failed", zap.Error(err))
@@ -378,7 +376,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
if created {
gpm.logger.Info("created pool for the environment", zap.String("env", env.ObjectMeta.Name), zap.String("namespace", gpm.nsResolver.ResolveNamespace(gpm.nsResolver.FunctionNamespace)))
}
}()
})
}
// create environment map for later use
@@ -407,10 +405,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
// avoid too many requests arrive Kubernetes API server at the same time.
time.Sleep(time.Duration(rand.Intn(30)) * time.Millisecond)
@@ -482,7 +477,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
gpm.logger.Info("adopt function pod",
zap.String("pod", pod.Name), zap.Any("labels", pod.Labels), zap.Any("annotations", pod.Annotations))
}()
})
}
}
+30 -29
View File
@@ -224,32 +224,33 @@ func TestPoolCacheRequests(t *testing.T) {
}
for i := 1; i <= tt.requests; i++ {
reqno := i
wg.Add(1)
go func(reqno int) {
defer wg.Done()
svc, err := p.GetSvcValue(context.Background(), key, tt.rpp, tt.concurrency)
if err != nil {
code, _ := ferror.GetHTTPError(err)
if code == http.StatusNotFound {
atomic.AddUint64(&svcCounter, 1)
address := fmt.Sprintf("svc-%d", atomic.LoadUint64(&svcCounter))
p.SetSvcValue(context.Background(), key, address, &FuncSvc{
Name: address,
}, resource.MustParse("45m"), tt.rpp, tt.retainPods)
wg.Go(func() {
func(reqno int) {
svc, err := p.GetSvcValue(context.Background(), key, tt.rpp, tt.concurrency)
if err != nil {
code, _ := ferror.GetHTTPError(err)
if code == http.StatusNotFound {
atomic.AddUint64(&svcCounter, 1)
address := fmt.Sprintf("svc-%d", atomic.LoadUint64(&svcCounter))
p.SetSvcValue(context.Background(), key, address, &FuncSvc{
Name: address,
}, resource.MustParse("45m"), tt.rpp, tt.retainPods)
} else {
t.Log(reqno, "=>", err)
atomic.AddUint64(&failedRequests, 1)
}
} else {
t.Log(reqno, "=>", err)
atomic.AddUint64(&failedRequests, 1)
if svc == nil {
t.Log(reqno, "=>", "svc is nil")
atomic.AddUint64(&failedRequests, 1)
}
// } else {
// t.Log(reqno, "=>", svc.Name)
// }
}
} else {
if svc == nil {
t.Log(reqno, "=>", "svc is nil")
atomic.AddUint64(&failedRequests, 1)
}
// } else {
// t.Log(reqno, "=>", svc.Name)
// }
}
}(reqno)
}(reqno)
})
if reqno%simultaneous == 0 {
wg.Wait()
}
@@ -261,12 +262,12 @@ func TestPoolCacheRequests(t *testing.T) {
for i := 0; i < tt.concurrency; i++ {
for j := 0; j < tt.rpp; j++ {
wg.Add(1)
svcno := i
go func(svcno int) {
defer wg.Done()
p.MarkAvailable(key, fmt.Sprintf("svc-%d", svcno+1))
}(svcno)
wg.Go(func() {
func(svcno int) {
p.MarkAvailable(key, fmt.Sprintf("svc-%d", svcno+1))
}(svcno)
})
}
}
wg.Wait()
+2 -4
View File
@@ -48,16 +48,14 @@ func TestQueuePushWithConcurrentRequest(t *testing.T) {
q := NewQueue()
noOfRequests := 20
var wg sync.WaitGroup
wg.Add(noOfRequests)
for i := 0; i < noOfRequests; i++ {
go func() {
defer wg.Done()
wg.Go(func() {
item := &svcWait{
svcChannel: make(chan *FuncSvc),
ctx: nil,
}
q.Push(item)
}()
})
}
wg.Wait()