Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #150 from ironcladlou/backport-scheduling-fix
[release-4.2] Bug 1780213: Don't start DNS on NotReady nodes
  • Loading branch information
openshift-merge-robot committed Dec 12, 2019
2 parents b751e75 + 6be3d01 commit 221cae0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
5 changes: 3 additions & 2 deletions assets/dns/daemonset.yaml
Expand Up @@ -137,5 +137,6 @@ spec:
path: /etc/hosts
type: File
tolerations:
# tolerate all taints so that DNS is always present on all nodes
- operator: Exists
# DNS needs to run everywhere.
- key: "node-role.kubernetes.io/master"
operator: Exists
8 changes: 4 additions & 4 deletions pkg/manifests/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions pkg/operator/controller/controller_dns_daemonset.go
Expand Up @@ -194,8 +194,40 @@ func daemonsetConfigChanged(current, expected *appsv1.DaemonSet) (bool, *appsv1.
changed = true
}

if !cmp.Equal(current.Spec.Template.Spec.Tolerations, expected.Spec.Template.Spec.Tolerations, cmpopts.EquateEmpty(), cmpopts.SortSlices(cmpTolerations)) {
updated.Spec.Template.Spec.Tolerations = expected.Spec.Template.Spec.Tolerations
changed = true
}

if !changed {
return false, nil
}
return true, updated
}

// cmpTolerations compares two Tolerations values and returns a Boolean
// indicating whether they are equal.
func cmpTolerations(a, b corev1.Toleration) bool {
if a.Key != b.Key {
return false
}
if a.Value != b.Value {
return false
}
if a.Operator != b.Operator {
return false
}
if a.Effect != b.Effect {
return false
}
if a.Effect == corev1.TaintEffectNoExecute {
if (a.TolerationSeconds == nil) != (b.TolerationSeconds == nil) {
return false
}
// Field is ignored unless effect is NoExecute.
if a.TolerationSeconds != nil && *a.TolerationSeconds != *b.TolerationSeconds {
return false
}
}
return true
}
14 changes: 14 additions & 0 deletions pkg/operator/controller/controller_dns_daemonset_test.go
Expand Up @@ -64,6 +64,13 @@ func TestDesiredDNSDaemonset(t *testing.T) {
}
}

var toleration = corev1.Toleration{
Key: "foo",
Value: "bar",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoExecute,
}

func TestDaemonsetConfigChanged(t *testing.T) {
testCases := []struct {
description string
Expand All @@ -90,6 +97,13 @@ func TestDaemonsetConfigChanged(t *testing.T) {
},
expect: true,
},
{
description: "if .spec.template.spec.tolerations changes",
mutate: func(daemonset *appsv1.DaemonSet) {
daemonset.Spec.Template.Spec.Tolerations = []corev1.Toleration{toleration}
},
expect: true,
},
{
description: "if the dns-node-resolver container image is changed",
mutate: func(daemonset *appsv1.DaemonSet) {
Expand Down

0 comments on commit 221cae0

Please sign in to comment.