Add constraint package to let us reject invalid assignments.

This commit is contained in:
Daniel Smith
2014-08-21 14:30:49 -07:00
parent 0a1dfa366e
commit ddba004ad0
8 changed files with 196 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/constraint"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
@@ -149,6 +150,9 @@ func (r *Registry) assignPod(podID string, machine string) error {
err = r.AtomicUpdate(contKey, &api.ContainerManifestList{}, func(in interface{}) (interface{}, error) {
manifests := *in.(*api.ContainerManifestList)
manifests.Items = append(manifests.Items, manifest)
if !constraint.Allowed(manifests.Items) {
return nil, fmt.Errorf("The assignment would cause a constraint violation")
}
return manifests, nil
})
if err != nil {

View File

@@ -418,7 +418,7 @@ func TestFillPodInfo(t *testing.T) {
storage := RegistryStorage{
podCache: &fakeGetter,
}
pod := api.Pod{}
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}
storage.fillPodInfo(&pod)
if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) {
t.Errorf("Expected: %#v, Got %#v", fakeGetter.info, pod.CurrentState.Info)
@@ -441,7 +441,7 @@ func TestFillPodInfoNoData(t *testing.T) {
storage := RegistryStorage{
podCache: &fakeGetter,
}
pod := api.Pod{}
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}
storage.fillPodInfo(&pod)
if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) {
t.Errorf("Expected %#v, Got %#v", fakeGetter.info, pod.CurrentState.Info)