Skip to content

Commit

Permalink
Merge pull request kubernetes#618 from brendandburns/async
Browse files Browse the repository at this point in the history
Make replication controller synchronizations independent.
  • Loading branch information
lavalamp committed Jul 25, 2014
2 parents 28b41dd + ae0baf3 commit e3927b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/controller/replication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"encoding/json"
"fmt"
"sync"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -203,10 +204,16 @@ func (rm *ReplicationManager) synchronize() {
glog.Errorf("Synchronization error: %v (%#v)", err, err)
return
}
for _, controllerSpec := range controllerSpecs {
err = rm.syncHandler(controllerSpec)
if err != nil {
glog.Errorf("Error synchronizing: %#v", err)
}
wg := sync.WaitGroup{}
wg.Add(len(controllerSpecs))
for ix := range controllerSpecs {
go func(ix int) {
defer wg.Done()
err := rm.syncHandler(controllerSpecs[ix])
if err != nil {
glog.Errorf("Error synchronizing: %#v", err)
}
}(ix)
}
wg.Wait()
}
6 changes: 6 additions & 0 deletions pkg/controller/replication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http/httptest"
"reflect"
"sync"
"testing"
"time"

Expand All @@ -41,13 +42,18 @@ func makeURL(suffix string) string {
type FakePodControl struct {
controllerSpec []api.ReplicationController
deletePodID []string
lock sync.Mutex
}

func (f *FakePodControl) createReplica(spec api.ReplicationController) {
f.lock.Lock()
defer f.lock.Unlock()
f.controllerSpec = append(f.controllerSpec, spec)
}

func (f *FakePodControl) deletePod(podID string) error {
f.lock.Lock()
defer f.lock.Unlock()
f.deletePodID = append(f.deletePodID, podID)
return nil
}
Expand Down

0 comments on commit e3927b4

Please sign in to comment.