Skip to content

Commit ad57e74

Browse files
authored
Merge pull request kubernetes#77481 from danielqsj/fu
remove redundant else block
2 parents 8a668f5 + 6fc04b6 commit ad57e74

File tree

1 file changed

+42
-50
lines changed

1 file changed

+42
-50
lines changed

test/e2e/framework/util.go

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -882,13 +882,12 @@ func WaitForPersistentVolumePhase(phase v1.PersistentVolumePhase, c clientset.In
882882
if err != nil {
883883
Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
884884
continue
885-
} else {
886-
if pv.Status.Phase == phase {
887-
Logf("PersistentVolume %s found and phase=%s (%v)", pvName, phase, time.Since(start))
888-
return nil
889-
}
890-
Logf("PersistentVolume %s found but phase is %s instead of %s.", pvName, pv.Status.Phase, phase)
891885
}
886+
if pv.Status.Phase == phase {
887+
Logf("PersistentVolume %s found and phase=%s (%v)", pvName, phase, time.Since(start))
888+
return nil
889+
}
890+
Logf("PersistentVolume %s found but phase is %s instead of %s.", pvName, pv.Status.Phase, phase)
892891
}
893892
return fmt.Errorf("PersistentVolume %s not in phase %s within %v", pvName, phase, timeout)
894893
}
@@ -901,13 +900,12 @@ func WaitForStatefulSetReplicasReady(statefulSetName, ns string, c clientset.Int
901900
if err != nil {
902901
Logf("Get StatefulSet %s failed, ignoring for %v: %v", statefulSetName, Poll, err)
903902
continue
904-
} else {
905-
if sts.Status.ReadyReplicas == *sts.Spec.Replicas {
906-
Logf("All %d replicas of StatefulSet %s are ready. (%v)", sts.Status.ReadyReplicas, statefulSetName, time.Since(start))
907-
return nil
908-
}
909-
Logf("StatefulSet %s found but there are %d ready replicas and %d total replicas.", statefulSetName, sts.Status.ReadyReplicas, *sts.Spec.Replicas)
910903
}
904+
if sts.Status.ReadyReplicas == *sts.Spec.Replicas {
905+
Logf("All %d replicas of StatefulSet %s are ready. (%v)", sts.Status.ReadyReplicas, statefulSetName, time.Since(start))
906+
return nil
907+
}
908+
Logf("StatefulSet %s found but there are %d ready replicas and %d total replicas.", statefulSetName, sts.Status.ReadyReplicas, *sts.Spec.Replicas)
911909
}
912910
return fmt.Errorf("StatefulSet %s still has unready pods within %v", statefulSetName, timeout)
913911
}
@@ -920,13 +918,12 @@ func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll,
920918
if err == nil {
921919
Logf("PersistentVolume %s found and phase=%s (%v)", pvName, pv.Status.Phase, time.Since(start))
922920
continue
923-
} else {
924-
if apierrs.IsNotFound(err) {
925-
Logf("PersistentVolume %s was removed", pvName)
926-
return nil
927-
}
928-
Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
929921
}
922+
if apierrs.IsNotFound(err) {
923+
Logf("PersistentVolume %s was removed", pvName)
924+
return nil
925+
}
926+
Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
930927
}
931928
return fmt.Errorf("PersistentVolume %s still exists within %v", pvName, timeout)
932929
}
@@ -950,16 +947,15 @@ func WaitForPersistentVolumeClaimsPhase(phase v1.PersistentVolumeClaimPhase, c c
950947
if err != nil {
951948
Logf("Failed to get claim %q, retrying in %v. Error: %v", pvcName, Poll, err)
952949
continue
953-
} else {
954-
if pvc.Status.Phase == phase {
955-
Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
956-
if matchAny {
957-
return nil
958-
}
959-
} else {
960-
Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase)
961-
phaseFoundInAllClaims = false
950+
}
951+
if pvc.Status.Phase == phase {
952+
Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
953+
if matchAny {
954+
return nil
962955
}
956+
} else {
957+
Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase)
958+
phaseFoundInAllClaims = false
963959
}
964960
}
965961
if phaseFoundInAllClaims {
@@ -3513,41 +3509,37 @@ func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionT
35133509
if wantTrue {
35143510
if (cond.Status == v1.ConditionTrue) && !hasNodeControllerTaints {
35153511
return true
3516-
} else {
3517-
msg := ""
3518-
if !hasNodeControllerTaints {
3519-
msg = fmt.Sprintf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
3520-
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
3521-
} else {
3522-
msg = fmt.Sprintf("Condition %s of node %s is %v, but Node is tainted by NodeController with %v. Failure",
3523-
conditionType, node.Name, cond.Status == v1.ConditionTrue, taints)
3524-
}
3525-
if !silent {
3526-
Logf(msg)
3527-
}
3528-
return false
35293512
}
3530-
} else {
3531-
// TODO: check if the Node is tainted once we enable NC notReady/unreachable taints by default
3532-
if cond.Status != v1.ConditionTrue {
3533-
return true
3513+
msg := ""
3514+
if !hasNodeControllerTaints {
3515+
msg = fmt.Sprintf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
3516+
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
35343517
}
3518+
msg = fmt.Sprintf("Condition %s of node %s is %v, but Node is tainted by NodeController with %v. Failure",
3519+
conditionType, node.Name, cond.Status == v1.ConditionTrue, taints)
35353520
if !silent {
3536-
Logf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
3537-
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
3521+
Logf(msg)
35383522
}
35393523
return false
35403524
}
3541-
}
3542-
if (wantTrue && (cond.Status == v1.ConditionTrue)) || (!wantTrue && (cond.Status != v1.ConditionTrue)) {
3543-
return true
3544-
} else {
3525+
// TODO: check if the Node is tainted once we enable NC notReady/unreachable taints by default
3526+
if cond.Status != v1.ConditionTrue {
3527+
return true
3528+
}
35453529
if !silent {
35463530
Logf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
35473531
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
35483532
}
35493533
return false
35503534
}
3535+
if (wantTrue && (cond.Status == v1.ConditionTrue)) || (!wantTrue && (cond.Status != v1.ConditionTrue)) {
3536+
return true
3537+
}
3538+
if !silent {
3539+
Logf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
3540+
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
3541+
}
3542+
return false
35513543
}
35523544

35533545
}

0 commit comments

Comments
 (0)