Merge pull request #88374 from tanjunchen/remove-TODO-simplify-code

test/e2e/framework/node/:remove TODO and and make some functions private
This commit is contained in:
Kubernetes Prow Robot 2020-02-21 18:32:13 -08:00 committed by GitHub
commit 8ac7a5bdc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 15 deletions

View File

@ -67,7 +67,6 @@ func FirstAddress(nodelist *v1.NodeList, addrType v1.NodeAddressType) string {
return "" return ""
} }
// TODO: better to change to a easy read name
func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue, silent bool) bool { func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue, silent bool) bool {
// Check the node readiness condition (logging all). // Check the node readiness condition (logging all).
for _, cond := range node.Status.Conditions { for _, cond := range node.Status.Conditions {
@ -138,8 +137,8 @@ func IsConditionSetAsExpectedSilent(node *v1.Node, conditionType v1.NodeConditio
return isNodeConditionSetAsExpected(node, conditionType, wantTrue, true) return isNodeConditionSetAsExpected(node, conditionType, wantTrue, true)
} }
// IsConditionUnset returns true if conditions of the given node do not have a match to the given conditionType, otherwise false. // isConditionUnset returns true if conditions of the given node do not have a match to the given conditionType, otherwise false.
func IsConditionUnset(node *v1.Node, conditionType v1.NodeConditionType) bool { func isConditionUnset(node *v1.Node, conditionType v1.NodeConditionType) bool {
for _, cond := range node.Status.Conditions { for _, cond := range node.Status.Conditions {
if cond.Type == conditionType { if cond.Type == conditionType {
return false return false
@ -207,11 +206,9 @@ func GetExternalIP(node *v1.Node) (string, error) {
func GetInternalIP(node *v1.Node) (string, error) { func GetInternalIP(node *v1.Node) (string, error) {
host := "" host := ""
for _, address := range node.Status.Addresses { for _, address := range node.Status.Addresses {
if address.Type == v1.NodeInternalIP { if address.Type == v1.NodeInternalIP && address.Address != "" {
if address.Address != "" { host = net.JoinHostPort(address.Address, sshPort)
host = net.JoinHostPort(address.Address, sshPort) break
break
}
} }
} }
if host == "" { if host == "" {
@ -278,7 +275,7 @@ func GetReadySchedulableNodes(c clientset.Interface) (nodes *v1.NodeList, err er
return nil, fmt.Errorf("listing schedulable nodes error: %s", err) return nil, fmt.Errorf("listing schedulable nodes error: %s", err)
} }
Filter(nodes, func(node v1.Node) bool { Filter(nodes, func(node v1.Node) bool {
return IsNodeSchedulable(&node) && IsNodeUntainted(&node) return IsNodeSchedulable(&node) && isNodeUntainted(&node)
}) })
if len(nodes.Items) == 0 { if len(nodes.Items) == 0 {
return nil, fmt.Errorf("there are currently no ready, schedulable nodes in the cluster") return nil, fmt.Errorf("there are currently no ready, schedulable nodes in the cluster")
@ -343,16 +340,16 @@ func GetMasterAndWorkerNodes(c clientset.Interface) (sets.String, *v1.NodeList,
for _, n := range all.Items { for _, n := range all.Items {
if system.DeprecatedMightBeMasterNode(n.Name) { if system.DeprecatedMightBeMasterNode(n.Name) {
masters.Insert(n.Name) masters.Insert(n.Name)
} else if IsNodeSchedulable(&n) && IsNodeUntainted(&n) { } else if IsNodeSchedulable(&n) && isNodeUntainted(&n) {
nodes.Items = append(nodes.Items, n) nodes.Items = append(nodes.Items, n)
} }
} }
return masters, nodes, nil return masters, nodes, nil
} }
// IsNodeUntainted tests whether a fake pod can be scheduled on "node", given its current taints. // isNodeUntainted tests whether a fake pod can be scheduled on "node", given its current taints.
// TODO: need to discuss wether to return bool and error type // TODO: need to discuss wether to return bool and error type
func IsNodeUntainted(node *v1.Node) bool { func isNodeUntainted(node *v1.Node) bool {
return isNodeUntaintedWithNonblocking(node, "") return isNodeUntaintedWithNonblocking(node, "")
} }
@ -427,7 +424,7 @@ func IsNodeSchedulable(node *v1.Node) bool {
// 2) doesn't have NetworkUnavailable condition set to true // 2) doesn't have NetworkUnavailable condition set to true
func IsNodeReady(node *v1.Node) bool { func IsNodeReady(node *v1.Node) bool {
nodeReady := IsConditionSetAsExpected(node, v1.NodeReady, true) nodeReady := IsConditionSetAsExpected(node, v1.NodeReady, true)
networkReady := IsConditionUnset(node, v1.NodeNetworkUnavailable) || networkReady := isConditionUnset(node, v1.NodeNetworkUnavailable) ||
IsConditionSetAsExpectedSilent(node, v1.NodeNetworkUnavailable, false) IsConditionSetAsExpectedSilent(node, v1.NodeNetworkUnavailable, false)
return nodeReady && networkReady return nodeReady && networkReady
} }

View File

@ -164,7 +164,7 @@ func CheckReady(c clientset.Interface, size int, timeout time.Duration) ([]v1.No
// Filter out not-ready nodes. // Filter out not-ready nodes.
Filter(nodes, func(node v1.Node) bool { Filter(nodes, func(node v1.Node) bool {
nodeReady := IsConditionSetAsExpected(&node, v1.NodeReady, true) nodeReady := IsConditionSetAsExpected(&node, v1.NodeReady, true)
networkReady := IsConditionUnset(&node, v1.NodeNetworkUnavailable) || IsConditionSetAsExpected(&node, v1.NodeNetworkUnavailable, false) networkReady := isConditionUnset(&node, v1.NodeNetworkUnavailable) || IsConditionSetAsExpected(&node, v1.NodeNetworkUnavailable, false)
return nodeReady && networkReady return nodeReady && networkReady
}) })
numReady := len(nodes.Items) numReady := len(nodes.Items)
@ -274,7 +274,7 @@ func readyForTests(node *v1.Node, nonblockingTaints string) bool {
return false return false
} }
} else { } else {
if !IsNodeSchedulable(node) || !IsNodeUntainted(node) { if !IsNodeSchedulable(node) || !isNodeUntainted(node) {
return false return false
} }
} }