mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-26 20:54:08 +00:00
Added integration test, fixed a validation issue
This commit is contained in:
@@ -39,6 +39,7 @@ type PersistentVolumeClaimBinder struct {
|
||||
volumeController *framework.Controller
|
||||
claimController *framework.Controller
|
||||
client binderClient
|
||||
stopChannels map[string]chan struct{}
|
||||
}
|
||||
|
||||
// NewPersistentVolumeClaimBinder creates a new PersistentVolumeClaimBinder
|
||||
@@ -234,8 +235,27 @@ func syncClaim(volumeIndex *persistentVolumeOrderedIndex, binderClient binderCli
|
||||
|
||||
func (controller *PersistentVolumeClaimBinder) Run() {
|
||||
glog.V(5).Infof("Starting PersistentVolumeClaimBinder\n")
|
||||
go controller.claimController.Run(make(chan struct{}))
|
||||
go controller.volumeController.Run(make(chan struct{}))
|
||||
if controller.stopChannels == nil {
|
||||
controller.stopChannels = make(map[string]chan struct{})
|
||||
}
|
||||
|
||||
if _, exists := controller.stopChannels["volumes"]; !exists {
|
||||
controller.stopChannels["volumes"] = make(chan struct{})
|
||||
go controller.volumeController.Run(controller.stopChannels["volumes"])
|
||||
}
|
||||
|
||||
if _, exists := controller.stopChannels["claims"]; !exists {
|
||||
controller.stopChannels["claims"] = make(chan struct{})
|
||||
go controller.claimController.Run(controller.stopChannels["claims"])
|
||||
}
|
||||
}
|
||||
|
||||
func (controller *PersistentVolumeClaimBinder) Stop() {
|
||||
glog.V(5).Infof("Stopping PersistentVolumeClaimBinder\n")
|
||||
for name, stopChan := range controller.stopChannels {
|
||||
close(stopChan)
|
||||
delete(controller.stopChannels, name)
|
||||
}
|
||||
}
|
||||
|
||||
// binderClient abstracts access to PVs and PVCs
|
||||
|
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@@ -27,6 +28,28 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
|
||||
)
|
||||
|
||||
func TestRunStop(t *testing.T) {
|
||||
o := testclient.NewObjects(api.Scheme)
|
||||
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
|
||||
binder := NewPersistentVolumeClaimBinder(client, 1*time.Second)
|
||||
|
||||
if len(binder.stopChannels) != 0 {
|
||||
t.Errorf("Non-running binder should not have any stopChannels. Got %v", len(binder.stopChannels))
|
||||
}
|
||||
|
||||
binder.Run()
|
||||
|
||||
if len(binder.stopChannels) != 2 {
|
||||
t.Errorf("Running binder should have exactly 2 stopChannels. Got %v", len(binder.stopChannels))
|
||||
}
|
||||
|
||||
binder.Stop()
|
||||
|
||||
if len(binder.stopChannels) != 0 {
|
||||
t.Errorf("Non-running binder should not have any stopChannels. Got %v", len(binder.stopChannels))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExampleObjects(t *testing.T) {
|
||||
|
||||
scenarios := map[string]struct {
|
||||
|
Reference in New Issue
Block a user