Skip to content

Commit 041e5b5

Browse files
committed
addressed comments
1 parent 7d604c3 commit 041e5b5

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

pkg/controller/daemon/daemon_controller.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,11 @@ func (dsc *DaemonSetsController) addNode(obj interface{}) {
623623
}
624624
node := obj.(*v1.Node)
625625
for _, ds := range dsList {
626-
shouldSchedule, _, err := dsc.nodeShouldRunDaemonPod(node, ds)
626+
shouldRun, _, err := dsc.nodeShouldRunDaemonPod(node, ds)
627627
if err != nil {
628628
continue
629629
}
630-
if shouldSchedule {
630+
if shouldRun {
631631
dsc.enqueueDaemonSet(ds)
632632
}
633633
}
@@ -685,15 +685,15 @@ func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
685685
}
686686
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
687687
for _, ds := range dsList {
688-
oldShouldSchedule, oldShouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(oldNode, ds)
688+
oldShouldRun, oldShouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(oldNode, ds)
689689
if err != nil {
690690
continue
691691
}
692-
currentShouldSchedule, currentShouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(curNode, ds)
692+
currentShouldRun, currentShouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(curNode, ds)
693693
if err != nil {
694694
continue
695695
}
696-
if (oldShouldSchedule != currentShouldSchedule) || (oldShouldContinueRunning != currentShouldContinueRunning) {
696+
if (oldShouldRun != currentShouldRun) || (oldShouldContinueRunning != currentShouldContinueRunning) {
697697
dsc.enqueueDaemonSet(ds)
698698
}
699699
}
@@ -789,15 +789,15 @@ func (dsc *DaemonSetsController) podsShouldBeOnNode(
789789
ds *apps.DaemonSet,
790790
) (nodesNeedingDaemonPods, podsToDelete []string, err error) {
791791

792-
shouldSchedule, shouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(node, ds)
792+
shouldRun, shouldContinueRunning, err := dsc.nodeShouldRunDaemonPod(node, ds)
793793
if err != nil {
794794
return
795795
}
796796

797797
daemonPods, exists := nodeToDaemonPods[node.Name]
798798

799799
switch {
800-
case shouldSchedule && !exists:
800+
case shouldRun && !exists:
801801
// If daemon pod is supposed to be running on node, but isn't, create daemon pod.
802802
nodesNeedingDaemonPods = append(nodesNeedingDaemonPods, node.Name)
803803
case shouldContinueRunning:
@@ -1054,14 +1054,14 @@ func (dsc *DaemonSetsController) updateDaemonSetStatus(ds *apps.DaemonSet, nodeL
10541054

10551055
var desiredNumberScheduled, currentNumberScheduled, numberMisscheduled, numberReady, updatedNumberScheduled, numberAvailable int
10561056
for _, node := range nodeList {
1057-
wantToRun, _, err := dsc.nodeShouldRunDaemonPod(node, ds)
1057+
shouldRun, _, err := dsc.nodeShouldRunDaemonPod(node, ds)
10581058
if err != nil {
10591059
return err
10601060
}
10611061

10621062
scheduled := len(nodeToDaemonPods[node.Name]) > 0
10631063

1064-
if wantToRun {
1064+
if shouldRun {
10651065
desiredNumberScheduled++
10661066
if scheduled {
10671067
currentNumberScheduled++
@@ -1195,8 +1195,8 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
11951195

11961196
// nodeShouldRunDaemonPod checks a set of preconditions against a (node,daemonset) and returns a
11971197
// summary. Returned booleans are:
1198-
// * shouldSchedule:
1199-
// Returns true when a daemonset should be scheduled to a node if a daemonset pod is not already
1198+
// * shouldRun:
1199+
// Returns true when a daemonset should run on the node if a daemonset pod is not already
12001200
// running on that node.
12011201
// * shouldContinueRunning:
12021202
// Returns true when a daemonset should continue running on a node if a daemonset pod is already
@@ -1217,24 +1217,24 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *apps.
12171217
return false, false, err
12181218
}
12191219

1220-
fitsNodeName, fitsNodeAffinity, fitsTaints := PodFitsNode(pod, node, taints)
1220+
fitsNodeName, fitsNodeAffinity, fitsTaints := Predicates(pod, node, taints)
12211221
if !fitsNodeName || !fitsNodeAffinity {
12221222
return false, false, nil
12231223
}
12241224

12251225
if !fitsTaints {
1226-
fitsNoExecuteTaint := v1helper.TolerationsTolerateTaintsWithFilter(pod.Spec.Tolerations, taints, func(t *v1.Taint) bool {
1226+
// Scheduled daemon pods should continue running if they tolerate NoExecute taint.
1227+
shouldContinueRunning := v1helper.TolerationsTolerateTaintsWithFilter(pod.Spec.Tolerations, taints, func(t *v1.Taint) bool {
12271228
return t.Effect == v1.TaintEffectNoExecute
12281229
})
1229-
1230-
return false, fitsNoExecuteTaint, nil
1230+
return false, shouldContinueRunning, nil
12311231
}
12321232

12331233
return true, true, nil
12341234
}
12351235

1236-
// PodFitsNode Checks if a DaemonSet's pod can be scheduled on a node.
1237-
func PodFitsNode(pod *v1.Pod, node *v1.Node, taints []v1.Taint) (fitsNodeName, fitsNodeAffinity, fitsTaints bool) {
1236+
// Predicates checks if a DaemonSet's pod can run on a node.
1237+
func Predicates(pod *v1.Pod, node *v1.Node, taints []v1.Taint) (fitsNodeName, fitsNodeAffinity, fitsTaints bool) {
12381238
fitsNodeName = len(pod.Spec.NodeName) == 0 || pod.Spec.NodeName == node.Name
12391239
fitsNodeAffinity = pluginhelper.PodMatchesNodeSelectorAndAffinityTerms(pod, node)
12401240
fitsTaints = v1helper.TolerationsTolerateTaintsWithFilter(pod.Spec.Tolerations, taints, func(t *v1.Taint) bool {

pkg/controller/daemon/daemon_controller_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,17 +1539,16 @@ func setDaemonSetCritical(ds *apps.DaemonSet) {
15391539
}
15401540

15411541
func TestNodeShouldRunDaemonPod(t *testing.T) {
1542-
var shouldCreate, shouldContinueRunning bool
1543-
shouldCreate = true
1544-
shouldContinueRunning = true
1542+
shouldRun := true
1543+
shouldContinueRunning := true
15451544
cases := []struct {
1546-
predicateName string
1547-
podsOnNode []*v1.Pod
1548-
nodeCondition []v1.NodeCondition
1549-
nodeUnschedulable bool
1550-
ds *apps.DaemonSet
1551-
wantToRun, shouldCreate, shouldContinueRunning bool
1552-
err error
1545+
predicateName string
1546+
podsOnNode []*v1.Pod
1547+
nodeCondition []v1.NodeCondition
1548+
nodeUnschedulable bool
1549+
ds *apps.DaemonSet
1550+
shouldRun, shouldContinueRunning bool
1551+
err error
15531552
}{
15541553
{
15551554
predicateName: "ShouldRunDaemonPod",
@@ -1564,7 +1563,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
15641563
},
15651564
},
15661565
},
1567-
shouldCreate: true,
1566+
shouldRun: true,
15681567
shouldContinueRunning: true,
15691568
},
15701569
{
@@ -1580,7 +1579,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
15801579
},
15811580
},
15821581
},
1583-
shouldCreate: shouldCreate,
1582+
shouldRun: shouldRun,
15841583
shouldContinueRunning: true,
15851584
},
15861585
{
@@ -1596,7 +1595,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
15961595
},
15971596
},
15981597
},
1599-
shouldCreate: false,
1598+
shouldRun: false,
16001599
shouldContinueRunning: false,
16011600
},
16021601
{
@@ -1629,7 +1628,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
16291628
},
16301629
},
16311630
},
1632-
shouldCreate: shouldCreate,
1631+
shouldRun: shouldRun,
16331632
shouldContinueRunning: shouldContinueRunning,
16341633
},
16351634
{
@@ -1657,7 +1656,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
16571656
},
16581657
},
16591658
},
1660-
shouldCreate: shouldCreate, // This is because we don't care about the resource constraints any more and let default scheduler handle it.
1659+
shouldRun: shouldRun, // This is because we don't care about the resource constraints any more and let default scheduler handle it.
16611660
shouldContinueRunning: true,
16621661
},
16631662
{
@@ -1685,7 +1684,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
16851684
},
16861685
},
16871686
},
1688-
shouldCreate: true,
1687+
shouldRun: true,
16891688
shouldContinueRunning: true,
16901689
},
16911690
{
@@ -1703,7 +1702,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
17031702
},
17041703
},
17051704
},
1706-
shouldCreate: false,
1705+
shouldRun: false,
17071706
shouldContinueRunning: false,
17081707
},
17091708
{
@@ -1721,7 +1720,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
17211720
},
17221721
},
17231722
},
1724-
shouldCreate: true,
1723+
shouldRun: true,
17251724
shouldContinueRunning: true,
17261725
},
17271726
{
@@ -1755,7 +1754,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
17551754
},
17561755
},
17571756
},
1758-
shouldCreate: false,
1757+
shouldRun: false,
17591758
shouldContinueRunning: false,
17601759
},
17611760
{
@@ -1789,7 +1788,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
17891788
},
17901789
},
17911790
},
1792-
shouldCreate: true,
1791+
shouldRun: true,
17931792
shouldContinueRunning: true,
17941793
},
17951794
{
@@ -1806,7 +1805,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
18061805
},
18071806
},
18081807
nodeUnschedulable: true,
1809-
shouldCreate: true,
1808+
shouldRun: true,
18101809
shouldContinueRunning: true,
18111810
},
18121811
}
@@ -1830,8 +1829,8 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
18301829
c.ds.Spec.UpdateStrategy = *strategy
18311830
shouldRun, shouldContinueRunning, err := manager.nodeShouldRunDaemonPod(node, c.ds)
18321831

1833-
if shouldRun != c.shouldCreate {
1834-
t.Errorf("[%v] strategy: %v, predicateName: %v expected shouldRun: %v, got: %v", i, c.ds.Spec.UpdateStrategy.Type, c.predicateName, c.shouldCreate, shouldRun)
1832+
if shouldRun != c.shouldRun {
1833+
t.Errorf("[%v] strategy: %v, predicateName: %v expected shouldRun: %v, got: %v", i, c.ds.Spec.UpdateStrategy.Type, c.predicateName, c.shouldRun, shouldRun)
18351834
}
18361835
if shouldContinueRunning != c.shouldContinueRunning {
18371836
t.Errorf("[%v] strategy: %v, predicateName: %v expected shouldContinueRunning: %v, got: %v", i, c.ds.Spec.UpdateStrategy.Type, c.predicateName, c.shouldContinueRunning, shouldContinueRunning)

test/e2e/apps/daemon_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func canScheduleOnNode(node v1.Node, ds *appsv1.DaemonSet) bool {
693693
framework.Failf("Can't test DaemonSet predicates for node %s: %v", node.Name, err)
694694
return false
695695
}
696-
fitsNodeName, fitsNodeAffinity, fitsTaints := daemon.PodFitsNode(newPod, &node, taints)
696+
fitsNodeName, fitsNodeAffinity, fitsTaints := daemon.Predicates(newPod, &node, taints)
697697
return fitsNodeName && fitsNodeAffinity && fitsTaints
698698
}
699699

0 commit comments

Comments
 (0)