Skip to content

Commit

Permalink
Add TestCoreDNSDaemonSetReconciliation
Browse files Browse the repository at this point in the history
Add an end-to-end test that verifies that the operator reconciles changes
to the dns-default daemonset.  This new test adds a node selector to the
daemonset and verifies that the operator reverts the change.

The operator already has unit tests to verify that the daemonset update
logic handles changes to image pullspecs and other important fields.
Together, the new end-to-end test and the existing unit tests should
provide sufficient test coverage for reconciliation of daemonsets.

* test/e2e/operator_test.go (TestCoreDNSDaemonSetReconciliation): New
test.  Verify that the operator reconciles the dns-default daemonset.
  • Loading branch information
Miciah committed Mar 9, 2021
1 parent f090cc1 commit 08015c7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,66 @@ func TestDefaultDNSSteadyConditions(t *testing.T) {
}
}

// TestCoreDNSDaemonSetReconciliation verifies that the operator reconciles the
// dns-default daemonset. The test modifies the daemonset and verifies that the
// operator reverts the change.
func TestCoreDNSDaemonSetReconciliation(t *testing.T) {
cl, err := getClient()
if err != nil {
t.Fatal(err)
}

defaultDNS := &operatorv1.DNS{}
err = wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) {
if err := cl.Get(context.TODO(), types.NamespacedName{Name: operatorcontroller.DefaultDNSController}, defaultDNS); err != nil {
t.Logf("failed to get dns %q: %v", operatorcontroller.DefaultDNSController, err)
return false, nil
}
return true, nil
})
if err != nil {
t.Fatalf("failed to get dns %q: %v", operatorcontroller.DefaultDNSController, err)
}

newNodeSelector := "foo"
namespacedName := operatorcontroller.DNSDaemonSetName(defaultDNS)
err = wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) {
dnsDaemonSet := &appsv1.DaemonSet{}
if err := cl.Get(context.TODO(), namespacedName, dnsDaemonSet); err != nil {
t.Logf("failed to get daemonset %s: %v", namespacedName, err)
return false, nil
}
dnsDaemonSet.Spec.Template.Spec.NodeSelector[newNodeSelector] = ""
if err := cl.Update(context.TODO(), dnsDaemonSet); err != nil {
t.Logf("failed to update daemonset %s: %v", namespacedName, err)
return false, nil
}
return true, nil
})
if err != nil {
t.Errorf("failed to update daemonset %s: %v", namespacedName, err)
}

err = wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) {
dnsDaemonSet := &appsv1.DaemonSet{}
if err := cl.Get(context.TODO(), namespacedName, dnsDaemonSet); err != nil {
t.Logf("failed to get daemonset %s: %v", namespacedName, err)
return false, nil
}
for k := range dnsDaemonSet.Spec.Template.Spec.NodeSelector {
if k == newNodeSelector {
t.Logf("found %q node selector on daemonset %s: %v", newNodeSelector, namespacedName, err)
return false, nil
}
}
t.Logf("observed absence of %q node selector on daemonset %s: %v", newNodeSelector, namespacedName, err)
return true, nil
})
if err != nil {
t.Errorf("failed to observe reversion of update to daemonset %s: %v", namespacedName, err)
}
}

func TestDNSForwarding(t *testing.T) {
cl, err := getClient()
if err != nil {
Expand Down

0 comments on commit 08015c7

Please sign in to comment.