mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #108485 from BigDarkClown/master
Make daemon.NodeShouldRunDaemonPod function public
This commit is contained in:
commit
02b1ec5b0b
@ -641,7 +641,7 @@ func (dsc *DaemonSetsController) addNode(obj interface{}) {
|
|||||||
}
|
}
|
||||||
node := obj.(*v1.Node)
|
node := obj.(*v1.Node)
|
||||||
for _, ds := range dsList {
|
for _, ds := range dsList {
|
||||||
if shouldRun, _ := dsc.nodeShouldRunDaemonPod(node, ds); shouldRun {
|
if shouldRun, _ := NodeShouldRunDaemonPod(node, ds); shouldRun {
|
||||||
dsc.enqueueDaemonSet(ds)
|
dsc.enqueueDaemonSet(ds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -699,8 +699,8 @@ func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
|
|||||||
}
|
}
|
||||||
// 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).
|
// 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).
|
||||||
for _, ds := range dsList {
|
for _, ds := range dsList {
|
||||||
oldShouldRun, oldShouldContinueRunning := dsc.nodeShouldRunDaemonPod(oldNode, ds)
|
oldShouldRun, oldShouldContinueRunning := NodeShouldRunDaemonPod(oldNode, ds)
|
||||||
currentShouldRun, currentShouldContinueRunning := dsc.nodeShouldRunDaemonPod(curNode, ds)
|
currentShouldRun, currentShouldContinueRunning := NodeShouldRunDaemonPod(curNode, ds)
|
||||||
if (oldShouldRun != currentShouldRun) || (oldShouldContinueRunning != currentShouldContinueRunning) {
|
if (oldShouldRun != currentShouldRun) || (oldShouldContinueRunning != currentShouldContinueRunning) {
|
||||||
dsc.enqueueDaemonSet(ds)
|
dsc.enqueueDaemonSet(ds)
|
||||||
}
|
}
|
||||||
@ -798,7 +798,7 @@ func (dsc *DaemonSetsController) podsShouldBeOnNode(
|
|||||||
hash string,
|
hash string,
|
||||||
) (nodesNeedingDaemonPods, podsToDelete []string) {
|
) (nodesNeedingDaemonPods, podsToDelete []string) {
|
||||||
|
|
||||||
shouldRun, shouldContinueRunning := dsc.nodeShouldRunDaemonPod(node, ds)
|
shouldRun, shouldContinueRunning := NodeShouldRunDaemonPod(node, ds)
|
||||||
daemonPods, exists := nodeToDaemonPods[node.Name]
|
daemonPods, exists := nodeToDaemonPods[node.Name]
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@ -1118,7 +1118,7 @@ func (dsc *DaemonSetsController) updateDaemonSetStatus(ctx context.Context, ds *
|
|||||||
var desiredNumberScheduled, currentNumberScheduled, numberMisscheduled, numberReady, updatedNumberScheduled, numberAvailable int
|
var desiredNumberScheduled, currentNumberScheduled, numberMisscheduled, numberReady, updatedNumberScheduled, numberAvailable int
|
||||||
now := dsc.failedPodsBackoff.Clock.Now()
|
now := dsc.failedPodsBackoff.Clock.Now()
|
||||||
for _, node := range nodeList {
|
for _, node := range nodeList {
|
||||||
shouldRun, _ := dsc.nodeShouldRunDaemonPod(node, ds)
|
shouldRun, _ := NodeShouldRunDaemonPod(node, ds)
|
||||||
scheduled := len(nodeToDaemonPods[node.Name]) > 0
|
scheduled := len(nodeToDaemonPods[node.Name]) > 0
|
||||||
|
|
||||||
if shouldRun {
|
if shouldRun {
|
||||||
@ -1254,7 +1254,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(ctx context.Context, key string)
|
|||||||
return dsc.updateDaemonSetStatus(ctx, ds, nodeList, hash, true)
|
return dsc.updateDaemonSetStatus(ctx, ds, nodeList, hash, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nodeShouldRunDaemonPod checks a set of preconditions against a (node,daemonset) and returns a
|
// NodeShouldRunDaemonPod checks a set of preconditions against a (node,daemonset) and returns a
|
||||||
// summary. Returned booleans are:
|
// summary. Returned booleans are:
|
||||||
// * shouldRun:
|
// * shouldRun:
|
||||||
// Returns true when a daemonset should run on the node if a daemonset pod is not already
|
// Returns true when a daemonset should run on the node if a daemonset pod is not already
|
||||||
@ -1262,7 +1262,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(ctx context.Context, key string)
|
|||||||
// * shouldContinueRunning:
|
// * shouldContinueRunning:
|
||||||
// Returns true when a daemonset should continue running on a node if a daemonset pod is already
|
// Returns true when a daemonset should continue running on a node if a daemonset pod is already
|
||||||
// running on that node.
|
// running on that node.
|
||||||
func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *apps.DaemonSet) (bool, bool) {
|
func NodeShouldRunDaemonPod(node *v1.Node, ds *apps.DaemonSet) (bool, bool) {
|
||||||
pod := NewPod(ds, node.Name)
|
pod := NewPod(ds, node.Name)
|
||||||
|
|
||||||
// If the daemon set specifies a node name, check that it matches with node.Name.
|
// If the daemon set specifies a node name, check that it matches with node.Name.
|
||||||
@ -1271,7 +1271,7 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *apps.
|
|||||||
}
|
}
|
||||||
|
|
||||||
taints := node.Spec.Taints
|
taints := node.Spec.Taints
|
||||||
fitsNodeName, fitsNodeAffinity, fitsTaints := Predicates(pod, node, taints)
|
fitsNodeName, fitsNodeAffinity, fitsTaints := predicates(pod, node, taints)
|
||||||
if !fitsNodeName || !fitsNodeAffinity {
|
if !fitsNodeName || !fitsNodeAffinity {
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
@ -1287,8 +1287,8 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *apps.
|
|||||||
return true, true
|
return true, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predicates checks if a DaemonSet's pod can run on a node.
|
// predicates checks if a DaemonSet's pod can run on a node.
|
||||||
func Predicates(pod *v1.Pod, node *v1.Node, taints []v1.Taint) (fitsNodeName, fitsNodeAffinity, fitsTaints bool) {
|
func predicates(pod *v1.Pod, node *v1.Node, taints []v1.Taint) (fitsNodeName, fitsNodeAffinity, fitsTaints bool) {
|
||||||
fitsNodeName = len(pod.Spec.NodeName) == 0 || pod.Spec.NodeName == node.Name
|
fitsNodeName = len(pod.Spec.NodeName) == 0 || pod.Spec.NodeName == node.Name
|
||||||
// Ignore parsing errors for backwards compatibility.
|
// Ignore parsing errors for backwards compatibility.
|
||||||
fitsNodeAffinity, _ = nodeaffinity.GetRequiredNodeAffinity(pod).Match(node)
|
fitsNodeAffinity, _ = nodeaffinity.GetRequiredNodeAffinity(pod).Match(node)
|
||||||
|
@ -2397,7 +2397,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
|
|||||||
manager.podNodeIndex.Add(p)
|
manager.podNodeIndex.Add(p)
|
||||||
}
|
}
|
||||||
c.ds.Spec.UpdateStrategy = *strategy
|
c.ds.Spec.UpdateStrategy = *strategy
|
||||||
shouldRun, shouldContinueRunning := manager.nodeShouldRunDaemonPod(node, c.ds)
|
shouldRun, shouldContinueRunning := NodeShouldRunDaemonPod(node, c.ds)
|
||||||
|
|
||||||
if shouldRun != c.shouldRun {
|
if shouldRun != c.shouldRun {
|
||||||
t.Errorf("[%v] strategy: %v, predicateName: %v expected shouldRun: %v, got: %v", i, c.ds.Spec.UpdateStrategy.Type, c.predicateName, c.shouldRun, shouldRun)
|
t.Errorf("[%v] strategy: %v, predicateName: %v expected shouldRun: %v, got: %v", i, c.ds.Spec.UpdateStrategy.Type, c.predicateName, c.shouldRun, shouldRun)
|
||||||
|
@ -528,7 +528,7 @@ func (dsc *DaemonSetsController) updatedDesiredNodeCounts(ds *apps.DaemonSet, no
|
|||||||
var desiredNumberScheduled int
|
var desiredNumberScheduled int
|
||||||
for i := range nodeList {
|
for i := range nodeList {
|
||||||
node := nodeList[i]
|
node := nodeList[i]
|
||||||
wantToRun, _ := dsc.nodeShouldRunDaemonPod(node, ds)
|
wantToRun, _ := NodeShouldRunDaemonPod(node, ds)
|
||||||
if !wantToRun {
|
if !wantToRun {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,8 @@ func SchedulableNodes(c clientset.Interface, ds *appsv1.DaemonSet) []string {
|
|||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
nodeNames := make([]string, 0)
|
nodeNames := make([]string, 0)
|
||||||
for _, node := range nodeList.Items {
|
for _, node := range nodeList.Items {
|
||||||
if !canScheduleOnNode(node, ds) {
|
shouldRun, _ := daemon.NodeShouldRunDaemonPod(&node, ds)
|
||||||
|
if !shouldRun {
|
||||||
framework.Logf("DaemonSet pods can't tolerate node %s with taints %+v, skip checking this node", node.Name, node.Spec.Taints)
|
framework.Logf("DaemonSet pods can't tolerate node %s with taints %+v, skip checking this node", node.Name, node.Spec.Taints)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -93,13 +94,6 @@ func SchedulableNodes(c clientset.Interface, ds *appsv1.DaemonSet) []string {
|
|||||||
return nodeNames
|
return nodeNames
|
||||||
}
|
}
|
||||||
|
|
||||||
// canScheduleOnNode checks if a given DaemonSet can schedule pods on the given node
|
|
||||||
func canScheduleOnNode(node v1.Node, ds *appsv1.DaemonSet) bool {
|
|
||||||
newPod := daemon.NewPod(ds, node.Name)
|
|
||||||
fitsNodeName, fitsNodeAffinity, fitsTaints := daemon.Predicates(newPod, &node, node.Spec.Taints)
|
|
||||||
return fitsNodeName && fitsNodeAffinity && fitsTaints
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckDaemonPodOnNodes(f *framework.Framework, ds *appsv1.DaemonSet, nodeNames []string) func() (bool, error) {
|
func CheckDaemonPodOnNodes(f *framework.Framework, ds *appsv1.DaemonSet, nodeNames []string) func() (bool, error) {
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
return checkDaemonPodStateOnNodes(f.ClientSet, ds, f.Namespace.Name, nodeNames, func(pod *v1.Pod) bool {
|
return checkDaemonPodStateOnNodes(f.ClientSet, ds, f.Namespace.Name, nodeNames, func(pod *v1.Pod) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user