mirror of https://github.com/openkruise/kruise.git
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:
parent
f7fc13185c
commit
7dc927e01e
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
|
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
|
||||||
clonesetcore "github.com/openkruise/kruise/pkg/controller/cloneset/core"
|
clonesetcore "github.com/openkruise/kruise/pkg/controller/cloneset/core"
|
||||||
|
@ -126,7 +127,7 @@ func (r *realControl) createPods(
|
||||||
podsCreationChan <- p
|
podsCreationChan <- p
|
||||||
}
|
}
|
||||||
|
|
||||||
var created bool
|
var created int64
|
||||||
successPodNames := sync.Map{}
|
successPodNames := sync.Map{}
|
||||||
_, err = clonesetutils.DoItSlowly(len(newPods), initialBatchSize, func() error {
|
_, err = clonesetutils.DoItSlowly(len(newPods), initialBatchSize, func() error {
|
||||||
pod := <-podsCreationChan
|
pod := <-podsCreationChan
|
||||||
|
@ -140,7 +141,9 @@ func (r *realControl) createPods(
|
||||||
if createErr = r.createOnePod(cs, pod, existingPVCNames); createErr != nil {
|
if createErr = r.createOnePod(cs, pod, existingPVCNames); createErr != nil {
|
||||||
return createErr
|
return createErr
|
||||||
}
|
}
|
||||||
created = true
|
|
||||||
|
atomic.AddInt64(&created, 1)
|
||||||
|
|
||||||
successPodNames.Store(pod.Name, struct{}{})
|
successPodNames.Store(pod.Name, struct{}{})
|
||||||
return nil
|
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 {
|
func (r *realControl) createOnePod(cs *appsv1alpha1.CloneSet, pod *v1.Pod, existingPVCNames sets.String) error {
|
||||||
|
|
Loading…
Reference in New Issue