Skip to content

Commit

Permalink
Test update propagation
Browse files Browse the repository at this point in the history
Test the upgrade path through controllers.
  • Loading branch information
bpineau committed Apr 26, 2018
1 parent fe136d3 commit 1720692
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func New(client cache.ListerWatcher,
excluded []string,
) *Controller {

selector := metav1.ListOptions{LabelSelector: filter}
selector := metav1.ListOptions{LabelSelector: filter, ResourceVersion: "0"}
lw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return client.List(selector)
Expand Down
41 changes: 40 additions & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,39 @@ var (
"metadata": map[string]interface{}{
"name": "Bar3",
"namespace": "ns3",
"resourceVersion": 1,
"resourceVersion": "1",
"uid": "00000000-0000-0000-0000-000000000042",
"selfLink": "shouldnotbethere",
},
"status": "shouldnotbethere",
},
}

obj4 = &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Foo2",
"metadata": map[string]interface{}{
"name": "Bar4",
"namespace": "ns4",
"resourceVersion": "2",
"foo": "canary-bar4",
"uid": "00000000-0000-0000-0000-000000000042",
"selfLink": "shouldnotbethere",
},
"status": "shouldnotbethere",
},
}

obj5 = &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Foo2",
"metadata": map[string]interface{}{
"name": "Bar4",
"namespace": "ns4",
"ResourceVersion": "4",
"foo": "canary-bar5",
"uid": "00000000-0000-0000-0000-000000000042",
"selfLink": "shouldnotbethere",
},
Expand Down Expand Up @@ -95,6 +127,8 @@ func TestController(t *testing.T) {

client.Add(obj2)
client.Add(obj3)
client.Add(obj4)
client.Modify(obj5)

ctrl.Start()
// wait until queue is drained
Expand Down Expand Up @@ -123,6 +157,11 @@ func TestController(t *testing.T) {
if strings.Compare(ev.Key, "ns3/Bar3") == 0 {
t.Error("execludedobject filter failed")
}

// ensure updates propagate
if strings.Contains(string(ev.Object), "canary-bar4") {
t.Error("update didn't propagate")
}
}

if !gotFoo2 {
Expand Down

0 comments on commit 1720692

Please sign in to comment.