Remove cloneset scale race condition on bool (#356)

* Remove cloneset scale race condition on bool
* Change bool to int64 comparison
This commit is contained in:
Robert Everson 2020-08-30 19:30:18 -07:00 committed by GitHub
parent f7fc13185c
commit 7dc927e01e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sync"
"sync/atomic"
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
clonesetcore "github.com/openkruise/kruise/pkg/controller/cloneset/core"
@ -126,7 +127,7 @@ func (r *realControl) createPods(
podsCreationChan <- p
}
var created bool
var created int64
successPodNames := sync.Map{}
_, err = clonesetutils.DoItSlowly(len(newPods), initialBatchSize, func() error {
pod := <-podsCreationChan
@ -140,7 +141,9 @@ func (r *realControl) createPods(
if createErr = r.createOnePod(cs, pod, existingPVCNames); createErr != nil {
return createErr
}
created = true
atomic.AddInt64(&created, 1)
successPodNames.Store(pod.Name, struct{}{})
return nil
})
@ -152,7 +155,10 @@ func (r *realControl) createPods(
}
}
return created, err
if created == 0 {
return false, err
}
return true, err
}
func (r *realControl) createOnePod(cs *appsv1alpha1.CloneSet, pod *v1.Pod, existingPVCNames sets.String) error {