Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeSelector change does not trigger reconcile #186

Merged
merged 4 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func forThisNodePredicate(cl client.Client) predicate.Funcs {
return nodeSelectorMatchesThisNode(cl, deleteEvent.Object)
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
return nodeSelectorMatchesThisNode(cl, updateEvent.ObjectOld) &&
nodeSelectorMatchesThisNode(cl, updateEvent.ObjectNew)
return nodeSelectorMatchesThisNode(cl, updateEvent.ObjectNew)
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return nodeSelectorMatchesThisNode(cl, genericEvent.Object)
Expand Down
61 changes: 61 additions & 0 deletions test/e2e/node_selector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package e2e

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

nmstatev1alpha1 "github.com/nmstate/kubernetes-nmstate/pkg/apis/nmstate/v1alpha1"
)

var _ = Describe("NodeSelector", func() {
br1Up := nmstatev1alpha1.State(`interfaces:
- name: br1
type: linux-bridge
state: up
bridge:
options:
stp:
enabled: false
port:
- name: eth1
`)
br1Absent := nmstatev1alpha1.State(`interfaces:
- name: br1
type: linux-bridge
state: absent
`)
nonexistentNodeSelector := map[string]string{"nonexistentKey": "nonexistentValue"}

Context("when policy is set with node selector not matching any nodes", func() {
BeforeEach(func() {
setDesiredStateWithPolicyAndNodeSelector("br1", br1Up, nonexistentNodeSelector)
})

AfterEach(func() {
setDesiredStateWithPolicy("br1", br1Absent)
for _, node := range nodes {
interfacesNameForNode(node).ShouldNot(ContainElement("br1"))
}

deletePolicy("br1")
})

It("should not update any nodes", func() {
for _, node := range nodes {
interfacesNameForNode(node).ShouldNot(ContainElement("br1"))
}
})

Context("and we remove the node selector", func() {
BeforeEach(func() {
setDesiredStateWithPolicyAndNodeSelector("br1", br1Up, map[string]string{})
})

It("should update all nodes", func() {
for _, node := range nodes {
interfacesNameForNode(node).Should(ContainElement("br1"))
}
})
})
})
})
7 changes: 6 additions & 1 deletion test/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ func waitForDaemonSet(t *testing.T, kubeclient kubernetes.Interface, namespace,
return nil
}

func setDesiredStateWithPolicy(name string, desiredState nmstatev1alpha1.State) {
func setDesiredStateWithPolicyAndNodeSelector(name string, desiredState nmstatev1alpha1.State, nodeSelector map[string]string) {
policy := nmstatev1alpha1.NodeNetworkConfigurationPolicy{}
policy.Name = name
key := types.NamespacedName{Name: name}
Eventually(func() error {
err := framework.Global.Client.Get(context.TODO(), key, &policy)
policy.Spec.DesiredState = desiredState
policy.Spec.NodeSelector = nodeSelector
if err != nil {
if apierrors.IsNotFound(err) {
return framework.Global.Client.Create(context.TODO(), &policy, &framework.CleanupOptions{})
Expand All @@ -158,6 +159,10 @@ func setDesiredStateWithPolicy(name string, desiredState nmstatev1alpha1.State)
}, ReadTimeout, ReadInterval).ShouldNot(HaveOccurred())
}

func setDesiredStateWithPolicy(name string, desiredState nmstatev1alpha1.State) {
setDesiredStateWithPolicyAndNodeSelector(name, desiredState, map[string]string{})
}

func updateDesiredStateAtNode(node string, desiredState nmstatev1alpha1.State) {
key := types.NamespacedName{Name: node}
state := nmstatev1alpha1.NodeNetworkState{}
Expand Down