Skip to content

Commit

Permalink
Merge pull request kubernetes#979 from mm4tt/node_condition_logging
Browse files Browse the repository at this point in the history
Simplify logging in the isNodeConditionSetAsExpected
  • Loading branch information
k8s-ci-robot authored Jan 14, 2020
2 parents b000148 + 3fc93a3 commit 9117226
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions clusterloader2/pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func IsNodeSchedulableAndUntainted(node *corev1.Node) bool {
// 2) it's Ready condition is set to true
// 3) doesn't have NetworkUnavailable condition set to true
func isNodeSchedulable(node *corev1.Node) bool {
nodeReady := isNodeConditionSetAsExpected(node, corev1.NodeReady, true, false)
nodeReady := isNodeConditionSetAsExpected(node, corev1.NodeReady, true)
networkReady := isNodeConditionUnset(node, corev1.NodeNetworkUnavailable) ||
isNodeConditionSetAsExpected(node, corev1.NodeNetworkUnavailable, false, true)
isNodeConditionSetAsExpected(node, corev1.NodeNetworkUnavailable, false)
return !node.Spec.Unschedulable && nodeReady && networkReady
}

Expand All @@ -96,24 +96,20 @@ func isNodeUntainted(node *corev1.Node) bool {
return true
}

func isNodeConditionSetAsExpected(node *corev1.Node, conditionType corev1.NodeConditionType, wantTrue, silent bool) bool {
func isNodeConditionSetAsExpected(node *corev1.Node, conditionType corev1.NodeConditionType, wantTrue bool) bool {
// Check the node readiness condition (logging all).
for _, cond := range node.Status.Conditions {
// Ensure that the condition type and the status matches as desired.
if cond.Type == conditionType {
if wantTrue == (cond.Status == corev1.ConditionTrue) {
return true
}
if !silent {
klog.Infof("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == corev1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
}
klog.V(4).Infof("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == corev1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
return false
}
}
if !silent {
klog.Infof("Couldn't find condition %v on node %v", conditionType, node.Name)
}
klog.V(4).Infof("Couldn't find condition %v on node %v", conditionType, node.Name)
return false
}

Expand Down

0 comments on commit 9117226

Please sign in to comment.