mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
Add constraint package to let us reject invalid assignments.
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user