2014-07-15 14:52:39 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
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 (
|
2014-10-08 19:56:02 +00:00
|
|
|
"sort"
|
2014-07-15 14:52:39 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-03 21:40:58 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/record"
|
2015-08-28 22:34:22 +00:00
|
|
|
"k8s.io/kubernetes/pkg/conversion"
|
2015-10-09 17:24:31 +00:00
|
|
|
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/securitycontext"
|
|
|
|
"k8s.io/kubernetes/pkg/types"
|
2014-07-15 14:52:39 +00:00
|
|
|
)
|
|
|
|
|
2014-12-17 05:11:27 +00:00
|
|
|
const (
|
|
|
|
TestSource = "test"
|
|
|
|
)
|
|
|
|
|
2014-07-15 14:52:39 +00:00
|
|
|
func expectEmptyChannel(t *testing.T, ch <-chan interface{}) {
|
|
|
|
select {
|
|
|
|
case update := <-ch:
|
|
|
|
t.Errorf("Expected no update in channel, Got %v", update)
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 22:51:50 +00:00
|
|
|
type sortedPods []*api.Pod
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
func (s sortedPods) Len() int {
|
|
|
|
return len(s)
|
|
|
|
}
|
|
|
|
func (s sortedPods) Swap(i, j int) {
|
|
|
|
s[i], s[j] = s[j], s[i]
|
|
|
|
}
|
|
|
|
func (s sortedPods) Less(i, j int) bool {
|
2014-10-30 13:29:11 +00:00
|
|
|
return s[i].Namespace < s[j].Namespace
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-12 00:18:29 +00:00
|
|
|
func CreateValidPod(name, namespace string) *api.Pod {
|
2015-04-03 22:51:50 +00:00
|
|
|
return &api.Pod{
|
2014-10-23 20:51:34 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
2015-08-28 22:34:22 +00:00
|
|
|
UID: types.UID(name), // for the purpose of testing, this is unique enough
|
|
|
|
Name: name,
|
|
|
|
Namespace: namespace,
|
2014-10-08 19:56:02 +00:00
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
2015-03-14 01:38:07 +00:00
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
2015-01-06 05:44:20 +00:00
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
2015-05-05 23:02:13 +00:00
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "ctr",
|
|
|
|
Image: "image",
|
|
|
|
ImagePullPolicy: "IfNotPresent",
|
|
|
|
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults(),
|
|
|
|
},
|
|
|
|
},
|
2014-07-15 14:52:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
func CreatePodUpdate(op kubetypes.PodOperation, source string, pods ...*api.Pod) kubetypes.PodUpdate {
|
|
|
|
return kubetypes.PodUpdate{Pods: pods, Op: op, Source: source}
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
func createPodConfigTester(mode PodConfigNotificationMode) (chan<- interface{}, <-chan kubetypes.PodUpdate, *PodConfig) {
|
2015-03-17 04:03:07 +00:00
|
|
|
eventBroadcaster := record.NewBroadcaster()
|
|
|
|
config := NewPodConfig(mode, eventBroadcaster.NewRecorder(api.EventSource{Component: "kubelet"}))
|
2014-12-17 05:11:27 +00:00
|
|
|
channel := config.Channel(TestSource)
|
2014-07-15 14:52:39 +00:00
|
|
|
ch := config.Updates()
|
|
|
|
return channel, ch, config
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
func expectPodUpdate(t *testing.T, ch <-chan kubetypes.PodUpdate, expected ...kubetypes.PodUpdate) {
|
2014-07-15 14:52:39 +00:00
|
|
|
for i := range expected {
|
|
|
|
update := <-ch
|
2014-10-08 19:56:02 +00:00
|
|
|
sort.Sort(sortedPods(update.Pods))
|
2015-09-12 00:49:33 +00:00
|
|
|
sort.Sort(sortedPods(expected[i].Pods))
|
|
|
|
// Make copies of the expected/actual update to compare all fields
|
|
|
|
// except for "Pods", which are compared separately below.
|
|
|
|
expectedCopy, updateCopy := expected[i], update
|
|
|
|
expectedCopy.Pods, updateCopy.Pods = nil, nil
|
|
|
|
if !api.Semantic.DeepEqual(expectedCopy, updateCopy) {
|
|
|
|
t.Fatalf("Expected %#v, Got %#v", expectedCopy, updateCopy)
|
2015-06-05 19:42:23 +00:00
|
|
|
}
|
2015-09-12 00:49:33 +00:00
|
|
|
|
|
|
|
if len(expected[i].Pods) != len(update.Pods) {
|
2014-07-15 14:52:39 +00:00
|
|
|
t.Fatalf("Expected %#v, Got %#v", expected[i], update)
|
|
|
|
}
|
2015-09-12 00:49:33 +00:00
|
|
|
// Compare pods one by one. This is necessary beacuse we don't want to
|
|
|
|
// compare local annotations.
|
|
|
|
for j := range expected[i].Pods {
|
|
|
|
if podsDifferSemantically(expected[i].Pods[j], update.Pods[j]) {
|
|
|
|
t.Fatalf("Expected %#v, Got %#v", expected[i].Pods[j], update.Pods[j])
|
|
|
|
}
|
|
|
|
}
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
expectNoPodUpdate(t, ch)
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
func expectNoPodUpdate(t *testing.T, ch <-chan kubetypes.PodUpdate) {
|
2014-07-15 14:52:39 +00:00
|
|
|
select {
|
|
|
|
case update := <-ch:
|
|
|
|
t.Errorf("Expected no update in channel, Got %#v", update)
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAdded(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// see an update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-10-08 19:56:02 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new")))
|
2014-10-08 19:56:02 +00:00
|
|
|
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource, CreateValidPod("foo", "new")))
|
2014-10-08 19:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedInvalidNamespace(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// see an update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", ""))
|
2014-10-08 19:56:02 +00:00
|
|
|
channel <- podUpdate
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource))
|
2014-10-08 19:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedDefaultNamespace(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// see an update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "default"))
|
2014-10-08 19:56:02 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "default")))
|
2014-10-08 19:56:02 +00:00
|
|
|
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource, CreateValidPod("foo", "default")))
|
2014-10-08 19:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedDifferentNamespaces(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// see an update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "default"))
|
2014-10-08 19:56:02 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "default")))
|
2014-10-08 19:56:02 +00:00
|
|
|
|
|
|
|
// see an update in another namespace
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource, CreateValidPod("foo", "default"), CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidPodFiltered(t *testing.T) {
|
|
|
|
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// see an update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
// add an invalid update
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.UPDATE, TestSource, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}})
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
|
|
|
expectNoPodUpdate(t, ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedSnapshotAndUpdates(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationSnapshotAndUpdates)
|
|
|
|
|
|
|
|
// see an set
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
// container updates are separated as UPDATE
|
2015-04-03 22:51:50 +00:00
|
|
|
pod := *podUpdate.Pods[0]
|
2015-01-26 17:52:50 +00:00
|
|
|
pod.Spec.Containers = []api.Container{{Name: "bar", Image: "test", ImagePullPolicy: api.PullIfNotPresent}}
|
2015-10-09 17:24:31 +00:00
|
|
|
channel <- CreatePodUpdate(kubetypes.ADD, TestSource, &pod)
|
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, &pod))
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedSnapshot(t *testing.T) {
|
|
|
|
channel, ch, config := createPodConfigTester(PodConfigNotificationSnapshot)
|
|
|
|
|
|
|
|
// see an set
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
config.Sync()
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, kubetypes.AllSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
// container updates are separated as UPDATE
|
2015-04-03 22:51:50 +00:00
|
|
|
pod := *podUpdate.Pods[0]
|
2015-01-26 17:52:50 +00:00
|
|
|
pod.Spec.Containers = []api.Container{{Name: "bar", Image: "test", ImagePullPolicy: api.PullIfNotPresent}}
|
2015-10-09 17:24:31 +00:00
|
|
|
channel <- CreatePodUpdate(kubetypes.ADD, TestSource, &pod)
|
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.SET, TestSource, &pod))
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedUpdatedRemoved(t *testing.T) {
|
|
|
|
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// should register an add
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
// should ignore ADDs that are identical
|
|
|
|
expectNoPodUpdate(t, ch)
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
// an kubetypes.ADD should be converted to kubetypes.UPDATE
|
2015-09-12 00:18:29 +00:00
|
|
|
pod := CreateValidPod("foo", "new")
|
2015-01-26 17:52:50 +00:00
|
|
|
pod.Spec.Containers = []api.Container{{Name: "bar", Image: "test", ImagePullPolicy: api.PullIfNotPresent}}
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.ADD, TestSource, pod)
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.REMOVE, TestSource, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "new"}})
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.REMOVE, TestSource, pod))
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPodAddedUpdatedSet(t *testing.T) {
|
|
|
|
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
// should register an add
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"), CreateValidPod("foo2", "new"), CreateValidPod("foo3", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"), CreateValidPod("foo2", "new"), CreateValidPod("foo3", "new")))
|
2014-07-15 14:52:39 +00:00
|
|
|
|
|
|
|
// should ignore ADDs that are identical
|
|
|
|
expectNoPodUpdate(t, ch)
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
// should be converted to an kubetypes.ADD, kubetypes.REMOVE, and kubetypes.UPDATE
|
2015-09-12 00:18:29 +00:00
|
|
|
pod := CreateValidPod("foo2", "new")
|
2015-01-26 17:52:50 +00:00
|
|
|
pod.Spec.Containers = []api.Container{{Name: "bar", Image: "test", ImagePullPolicy: api.PullIfNotPresent}}
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource, pod, CreateValidPod("foo3", "new"), CreateValidPod("foo4", "new"))
|
2014-07-15 14:52:39 +00:00
|
|
|
channel <- podUpdate
|
|
|
|
expectPodUpdate(t, ch,
|
2015-10-09 17:24:31 +00:00
|
|
|
CreatePodUpdate(kubetypes.REMOVE, TestSource, CreateValidPod("foo", "new")),
|
|
|
|
CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo4", "new")),
|
|
|
|
CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2014-07-15 14:52:39 +00:00
|
|
|
}
|
2015-08-28 22:34:22 +00:00
|
|
|
|
2015-10-14 14:35:25 +00:00
|
|
|
func TestInitialEmptySet(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
mode PodConfigNotificationMode
|
|
|
|
op kubetypes.PodOperation
|
|
|
|
}{
|
|
|
|
{PodConfigNotificationIncremental, kubetypes.ADD},
|
|
|
|
{PodConfigNotificationSnapshot, kubetypes.SET},
|
|
|
|
{PodConfigNotificationSnapshotAndUpdates, kubetypes.SET},
|
|
|
|
} {
|
|
|
|
channel, ch, _ := createPodConfigTester(test.mode)
|
|
|
|
|
|
|
|
// should register an empty PodUpdate operation
|
|
|
|
podUpdate := CreatePodUpdate(kubetypes.SET, TestSource)
|
|
|
|
channel <- podUpdate
|
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(test.op, TestSource))
|
|
|
|
|
|
|
|
// should ignore following empty sets
|
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource)
|
|
|
|
channel <- podUpdate
|
|
|
|
podUpdate = CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo", "new"))
|
|
|
|
channel <- podUpdate
|
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(test.op, TestSource, CreateValidPod("foo", "new")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 22:34:22 +00:00
|
|
|
func TestPodUpdateAnnotations(t *testing.T) {
|
|
|
|
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
2015-09-12 00:18:29 +00:00
|
|
|
pod := CreateValidPod("foo2", "new")
|
2015-08-28 22:34:22 +00:00
|
|
|
pod.Annotations = make(map[string]string, 0)
|
|
|
|
pod.Annotations["kubernetes.io/blah"] = "blah"
|
|
|
|
|
|
|
|
clone, err := conversion.NewCloner().DeepCopy(pod)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%v", err)
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo1", "new"), clone.(*api.Pod), CreateValidPod("foo3", "new"))
|
2015-08-28 22:34:22 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, CreateValidPod("foo1", "new"), pod, CreateValidPod("foo3", "new")))
|
2015-08-28 22:34:22 +00:00
|
|
|
|
|
|
|
pod.Annotations["kubenetes.io/blah"] = "superblah"
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo1", "new"), pod, CreateValidPod("foo3", "new"))
|
2015-08-28 22:34:22 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2015-08-28 22:34:22 +00:00
|
|
|
|
|
|
|
pod.Annotations["kubernetes.io/otherblah"] = "doh"
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo1", "new"), pod, CreateValidPod("foo3", "new"))
|
2015-08-28 22:34:22 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2015-08-28 22:34:22 +00:00
|
|
|
|
|
|
|
delete(pod.Annotations, "kubernetes.io/blah")
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource, CreateValidPod("foo1", "new"), pod, CreateValidPod("foo3", "new"))
|
2015-08-28 22:34:22 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2015-08-28 22:34:22 +00:00
|
|
|
}
|
2015-09-25 13:29:00 +00:00
|
|
|
|
|
|
|
func TestPodUpdateLables(t *testing.T) {
|
|
|
|
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
|
|
|
|
|
|
|
|
pod := CreateValidPod("foo2", "new")
|
|
|
|
pod.Labels = make(map[string]string, 0)
|
|
|
|
pod.Labels["key"] = "value"
|
|
|
|
|
|
|
|
clone, err := conversion.NewCloner().DeepCopy(pod)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%v", err)
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate := CreatePodUpdate(kubetypes.SET, TestSource, clone.(*api.Pod))
|
2015-09-25 13:29:00 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.ADD, TestSource, pod))
|
2015-09-25 13:29:00 +00:00
|
|
|
|
|
|
|
pod.Labels["key"] = "newValue"
|
2015-10-09 17:24:31 +00:00
|
|
|
podUpdate = CreatePodUpdate(kubetypes.SET, TestSource, pod)
|
2015-09-25 13:29:00 +00:00
|
|
|
channel <- podUpdate
|
2015-10-09 17:24:31 +00:00
|
|
|
expectPodUpdate(t, ch, CreatePodUpdate(kubetypes.UPDATE, TestSource, pod))
|
2015-09-25 13:29:00 +00:00
|
|
|
|
|
|
|
}
|