
There are three values that uniquely identify a pod on a host - the configuration source (etcd, file, http), the pod name, and the pod namespace. This change ensures that configuration properly makes those names unique by changing podFullName to contain both name (currently ID in v1beta1, Name in v1beta3) and namespace. The Kubelet does not properly handle information requests for pods not in the default namespace at this time.
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
/*
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
|
)
|
|
|
|
func TestEventToPods(t *testing.T) {
|
|
tests := []struct {
|
|
input watch.Event
|
|
pods []api.BoundPod
|
|
fail bool
|
|
}{
|
|
{
|
|
input: watch.Event{Object: nil},
|
|
pods: []api.BoundPod{},
|
|
fail: true,
|
|
},
|
|
{
|
|
input: watch.Event{Object: &api.BoundPods{}},
|
|
pods: []api.BoundPod{},
|
|
fail: false,
|
|
},
|
|
{
|
|
input: watch.Event{
|
|
Object: &api.BoundPods{
|
|
Items: []api.BoundPod{
|
|
{TypeMeta: api.TypeMeta{ID: "foo"}},
|
|
{TypeMeta: api.TypeMeta{ID: "bar"}},
|
|
},
|
|
},
|
|
},
|
|
pods: []api.BoundPod{
|
|
{TypeMeta: api.TypeMeta{ID: "foo", Namespace: "default"}, Spec: api.PodSpec{}},
|
|
{TypeMeta: api.TypeMeta{ID: "bar", Namespace: "default"}, Spec: api.PodSpec{}},
|
|
},
|
|
fail: false,
|
|
},
|
|
{
|
|
input: watch.Event{
|
|
Object: &api.BoundPods{
|
|
Items: []api.BoundPod{
|
|
{TypeMeta: api.TypeMeta{ID: "1"}},
|
|
{TypeMeta: api.TypeMeta{ID: "2", Namespace: "foo"}},
|
|
},
|
|
},
|
|
},
|
|
pods: []api.BoundPod{
|
|
{TypeMeta: api.TypeMeta{ID: "1", Namespace: "default"}, Spec: api.PodSpec{}},
|
|
{TypeMeta: api.TypeMeta{ID: "2", Namespace: "foo"}, Spec: api.PodSpec{}},
|
|
},
|
|
fail: false,
|
|
},
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
pods, err := eventToPods(tt.input)
|
|
if !reflect.DeepEqual(tt.pods, pods) {
|
|
t.Errorf("case %d: expected output %#v, got %#v", i, tt.pods, pods)
|
|
}
|
|
if tt.fail != (err != nil) {
|
|
t.Errorf("case %d: got fail=%t but err=%v", i, tt.fail, err)
|
|
}
|
|
}
|
|
}
|