@@ -936,7 +936,7 @@ func (dsc *DaemonSetsController) podsShouldBeOnNode(
936
936
// After figuring out which nodes should run a Pod of ds but not yet running one and
937
937
// which nodes should not run a Pod of ds but currently running one, it calls function
938
938
// syncNodes with a list of pods to remove and a list of nodes to run a Pod of ds.
939
- func (dsc * DaemonSetsController ) manage (ds * apps.DaemonSet , hash string ) error {
939
+ func (dsc * DaemonSetsController ) manage (ds * apps.DaemonSet , nodeList [] * v1. Node , hash string ) error {
940
940
// Find out the pods which are created for the nodes by DaemonSet.
941
941
nodeToDaemonPods , err := dsc .getNodesToDaemonPods (ds )
942
942
if err != nil {
@@ -945,10 +945,6 @@ func (dsc *DaemonSetsController) manage(ds *apps.DaemonSet, hash string) error {
945
945
946
946
// For each node, if the node is running the daemon pod but isn't supposed to, kill the daemon
947
947
// pod. If the node is supposed to run the daemon pod, but isn't, create the daemon pod on the node.
948
- nodeList , err := dsc .nodeLister .List (labels .Everything ())
949
- if err != nil {
950
- return fmt .Errorf ("couldn't get list of nodes when syncing daemon set %#v: %v" , ds , err )
951
- }
952
948
var nodesNeedingDaemonPods , podsToDelete []string
953
949
var failedPodsObserved int
954
950
for _ , node := range nodeList {
@@ -1149,18 +1145,13 @@ func storeDaemonSetStatus(dsClient unversionedapps.DaemonSetInterface, ds *apps.
1149
1145
return updateErr
1150
1146
}
1151
1147
1152
- func (dsc * DaemonSetsController ) updateDaemonSetStatus (ds * apps.DaemonSet , hash string , updateObservedGen bool ) error {
1148
+ func (dsc * DaemonSetsController ) updateDaemonSetStatus (ds * apps.DaemonSet , nodeList [] * v1. Node , hash string , updateObservedGen bool ) error {
1153
1149
klog .V (4 ).Infof ("Updating daemon set status" )
1154
1150
nodeToDaemonPods , err := dsc .getNodesToDaemonPods (ds )
1155
1151
if err != nil {
1156
1152
return fmt .Errorf ("couldn't get node to daemon pod mapping for daemon set %q: %v" , ds .Name , err )
1157
1153
}
1158
1154
1159
- nodeList , err := dsc .nodeLister .List (labels .Everything ())
1160
- if err != nil {
1161
- return fmt .Errorf ("couldn't get list of nodes when updating daemon set %#v: %v" , ds , err )
1162
- }
1163
-
1164
1155
var desiredNumberScheduled , currentNumberScheduled , numberMisscheduled , numberReady , updatedNumberScheduled , numberAvailable int
1165
1156
for _ , node := range nodeList {
1166
1157
wantToRun , _ , _ , err := dsc .nodeShouldRunDaemonPod (node , ds )
@@ -1230,6 +1221,11 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
1230
1221
return fmt .Errorf ("unable to retrieve ds %v from store: %v" , key , err )
1231
1222
}
1232
1223
1224
+ nodeList , err := dsc .nodeLister .List (labels .Everything ())
1225
+ if err != nil {
1226
+ return fmt .Errorf ("couldn't get list of nodes when syncing daemon set %#v: %v" , ds , err )
1227
+ }
1228
+
1233
1229
everything := metav1.LabelSelector {}
1234
1230
if reflect .DeepEqual (ds .Spec .Selector , & everything ) {
1235
1231
dsc .eventRecorder .Eventf (ds , v1 .EventTypeWarning , SelectingAllReason , "This daemon set is selecting all pods. A non-empty selector is required." )
@@ -1265,10 +1261,10 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
1265
1261
1266
1262
if ! dsc .expectations .SatisfiedExpectations (dsKey ) {
1267
1263
// Only update status. Don't raise observedGeneration since controller didn't process object of that generation.
1268
- return dsc .updateDaemonSetStatus (ds , hash , false )
1264
+ return dsc .updateDaemonSetStatus (ds , nodeList , hash , false )
1269
1265
}
1270
1266
1271
- err = dsc .manage (ds , hash )
1267
+ err = dsc .manage (ds , nodeList , hash )
1272
1268
if err != nil {
1273
1269
return err
1274
1270
}
@@ -1278,7 +1274,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
1278
1274
switch ds .Spec .UpdateStrategy .Type {
1279
1275
case apps .OnDeleteDaemonSetStrategyType :
1280
1276
case apps .RollingUpdateDaemonSetStrategyType :
1281
- err = dsc .rollingUpdate (ds , hash )
1277
+ err = dsc .rollingUpdate (ds , nodeList , hash )
1282
1278
}
1283
1279
if err != nil {
1284
1280
return err
@@ -1290,7 +1286,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
1290
1286
return fmt .Errorf ("failed to clean up revisions of DaemonSet: %v" , err )
1291
1287
}
1292
1288
1293
- return dsc .updateDaemonSetStatus (ds , hash , true )
1289
+ return dsc .updateDaemonSetStatus (ds , nodeList , hash , true )
1294
1290
}
1295
1291
1296
1292
func (dsc * DaemonSetsController ) simulate (newPod * v1.Pod , node * v1.Node , ds * apps.DaemonSet ) ([]predicates.PredicateFailureReason , * schedulernodeinfo.NodeInfo , error ) {
0 commit comments