@@ -595,13 +595,14 @@ func (nc *Controller) doNoExecuteTaintingPass() {
595
595
// Because we want to mimic NodeStatus.Condition["Ready"] we make "unreachable" and "not ready" taints mutually exclusive.
596
596
taintToAdd := v1.Taint {}
597
597
oppositeTaint := v1.Taint {}
598
- if condition .Status == v1 .ConditionFalse {
598
+ switch condition .Status {
599
+ case v1 .ConditionFalse :
599
600
taintToAdd = * NotReadyTaintTemplate
600
601
oppositeTaint = * UnreachableTaintTemplate
601
- } else if condition . Status == v1 .ConditionUnknown {
602
+ case v1 .ConditionUnknown :
602
603
taintToAdd = * UnreachableTaintTemplate
603
604
oppositeTaint = * NotReadyTaintTemplate
604
- } else {
605
+ default :
605
606
// It seems that the Node is ready again, so there's no need to taint it.
606
607
klog .V (4 ).Infof ("Node %v was in a taint queue, but it's ready now. Ignoring taint request." , value .Value )
607
608
return true , 0
@@ -720,7 +721,8 @@ func (nc *Controller) monitorNodeHealth() error {
720
721
decisionTimestamp := nc .now ()
721
722
if currentReadyCondition != nil {
722
723
// Check eviction timeout against decisionTimestamp
723
- if observedReadyCondition .Status == v1 .ConditionFalse {
724
+ switch observedReadyCondition .Status {
725
+ case v1 .ConditionFalse :
724
726
if nc .useTaintBasedEvictions {
725
727
// We want to update the taint straight away if Node is already tainted with the UnreachableTaint
726
728
if taintutils .TaintExists (node .Spec .Taints , UnreachableTaintTemplate ) {
@@ -746,8 +748,7 @@ func (nc *Controller) monitorNodeHealth() error {
746
748
}
747
749
}
748
750
}
749
- }
750
- if observedReadyCondition .Status == v1 .ConditionUnknown {
751
+ case v1 .ConditionUnknown :
751
752
if nc .useTaintBasedEvictions {
752
753
// We want to update the taint straight away if Node is already tainted with the UnreachableTaint
753
754
if taintutils .TaintExists (node .Spec .Taints , NotReadyTaintTemplate ) {
@@ -773,8 +774,7 @@ func (nc *Controller) monitorNodeHealth() error {
773
774
}
774
775
}
775
776
}
776
- }
777
- if observedReadyCondition .Status == v1 .ConditionTrue {
777
+ case v1 .ConditionTrue :
778
778
if nc .useTaintBasedEvictions {
779
779
removed , err := nc .markNodeAsReachable (node )
780
780
if err != nil {
@@ -807,7 +807,6 @@ func (nc *Controller) monitorNodeHealth() error {
807
807
// tryUpdateNodeHealth checks a given node's conditions and tries to update it. Returns grace period to
808
808
// which given node is entitled, state of current and last observed Ready Condition, and an error if it occurred.
809
809
func (nc * Controller ) tryUpdateNodeHealth (node * v1.Node ) (time.Duration , v1.NodeCondition , * v1.NodeCondition , error ) {
810
- var err error
811
810
var gracePeriod time.Duration
812
811
var observedReadyCondition v1.NodeCondition
813
812
_ , currentReadyCondition := nodeutil .GetNodeCondition (& node .Status , v1 .NodeReady )
@@ -836,7 +835,6 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
836
835
observedReadyCondition = * currentReadyCondition
837
836
gracePeriod = nc .nodeMonitorGracePeriod
838
837
}
839
-
840
838
savedNodeHealth , found := nc .nodeHealthMap [node .Name ]
841
839
// There are following cases to check:
842
840
// - both saved and new status have no Ready Condition set - we leave everything as it is,
@@ -858,35 +856,35 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
858
856
_ , savedCondition = nodeutil .GetNodeCondition (savedNodeHealth .status , v1 .NodeReady )
859
857
savedLease = savedNodeHealth .lease
860
858
}
861
- _ , observedCondition := nodeutil . GetNodeCondition ( & node . Status , v1 . NodeReady )
859
+
862
860
if ! found {
863
861
klog .Warningf ("Missing timestamp for Node %s. Assuming now as a timestamp." , node .Name )
864
862
savedNodeHealth = & nodeHealthData {
865
863
status : & node .Status ,
866
864
probeTimestamp : nc .now (),
867
865
readyTransitionTimestamp : nc .now (),
868
866
}
869
- } else if savedCondition == nil && observedCondition != nil {
867
+ } else if savedCondition == nil && currentReadyCondition != nil {
870
868
klog .V (1 ).Infof ("Creating timestamp entry for newly observed Node %s" , node .Name )
871
869
savedNodeHealth = & nodeHealthData {
872
870
status : & node .Status ,
873
871
probeTimestamp : nc .now (),
874
872
readyTransitionTimestamp : nc .now (),
875
873
}
876
- } else if savedCondition != nil && observedCondition == nil {
874
+ } else if savedCondition != nil && currentReadyCondition == nil {
877
875
klog .Errorf ("ReadyCondition was removed from Status of Node %s" , node .Name )
878
876
// TODO: figure out what to do in this case. For now we do the same thing as above.
879
877
savedNodeHealth = & nodeHealthData {
880
878
status : & node .Status ,
881
879
probeTimestamp : nc .now (),
882
880
readyTransitionTimestamp : nc .now (),
883
881
}
884
- } else if savedCondition != nil && observedCondition != nil && savedCondition .LastHeartbeatTime != observedCondition .LastHeartbeatTime {
882
+ } else if savedCondition != nil && currentReadyCondition != nil && savedCondition .LastHeartbeatTime != currentReadyCondition .LastHeartbeatTime {
885
883
var transitionTime metav1.Time
886
884
// If ReadyCondition changed since the last time we checked, we update the transition timestamp to "now",
887
885
// otherwise we leave it as it is.
888
- if savedCondition .LastTransitionTime != observedCondition .LastTransitionTime {
889
- klog .V (3 ).Infof ("ReadyCondition for Node %s transitioned from %v to %v" , node .Name , savedCondition , observedCondition )
886
+ if savedCondition .LastTransitionTime != currentReadyCondition .LastTransitionTime {
887
+ klog .V (3 ).Infof ("ReadyCondition for Node %s transitioned from %v to %v" , node .Name , savedCondition , currentReadyCondition )
890
888
transitionTime = nc .now ()
891
889
} else {
892
890
transitionTime = savedNodeHealth .readyTransitionTimestamp
@@ -919,31 +917,9 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
919
917
if nc .now ().After (savedNodeHealth .probeTimestamp .Add (gracePeriod )) {
920
918
// NodeReady condition or lease was last set longer ago than gracePeriod, so
921
919
// update it to Unknown (regardless of its current value) in the master.
922
- if currentReadyCondition == nil {
923
- klog .V (2 ).Infof ("node %v is never updated by kubelet" , node .Name )
924
- node .Status .Conditions = append (node .Status .Conditions , v1.NodeCondition {
925
- Type : v1 .NodeReady ,
926
- Status : v1 .ConditionUnknown ,
927
- Reason : "NodeStatusNeverUpdated" ,
928
- Message : fmt .Sprintf ("Kubelet never posted node status." ),
929
- LastHeartbeatTime : node .CreationTimestamp ,
930
- LastTransitionTime : nc .now (),
931
- })
932
- } else {
933
- klog .V (4 ).Infof ("node %v hasn't been updated for %+v. Last ready condition is: %+v" ,
934
- node .Name , nc .now ().Time .Sub (savedNodeHealth .probeTimestamp .Time ), observedReadyCondition )
935
- if observedReadyCondition .Status != v1 .ConditionUnknown {
936
- currentReadyCondition .Status = v1 .ConditionUnknown
937
- currentReadyCondition .Reason = "NodeStatusUnknown"
938
- currentReadyCondition .Message = "Kubelet stopped posting node status."
939
- // LastProbeTime is the last time we heard from kubelet.
940
- currentReadyCondition .LastHeartbeatTime = observedReadyCondition .LastHeartbeatTime
941
- currentReadyCondition .LastTransitionTime = nc .now ()
942
- }
943
- }
944
920
945
- // remaining node conditions should also be set to Unknown
946
- remainingNodeConditionTypes := [] v1.NodeConditionType {
921
+ nodeConditionTypes := []v1. NodeConditionType {
922
+ v1 .NodeReady ,
947
923
v1 .NodeMemoryPressure ,
948
924
v1 .NodeDiskPressure ,
949
925
v1 .NodePIDPressure ,
@@ -952,7 +928,7 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
952
928
}
953
929
954
930
nowTimestamp := nc .now ()
955
- for _ , nodeConditionType := range remainingNodeConditionTypes {
931
+ for _ , nodeConditionType := range nodeConditionTypes {
956
932
_ , currentCondition := nodeutil .GetNodeCondition (& node .Status , nodeConditionType )
957
933
if currentCondition == nil {
958
934
klog .V (2 ).Infof ("Condition %v of node %v was never updated by kubelet" , nodeConditionType , node .Name )
@@ -975,10 +951,11 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
975
951
}
976
952
}
977
953
}
954
+ // We need to update currentReadyCondition due to its value potentially changed.
955
+ _ , currentReadyCondition = nodeutil .GetNodeCondition (& node .Status , v1 .NodeReady )
978
956
979
- _ , currentCondition := nodeutil .GetNodeCondition (& node .Status , v1 .NodeReady )
980
- if ! apiequality .Semantic .DeepEqual (currentCondition , & observedReadyCondition ) {
981
- if _ , err = nc .kubeClient .CoreV1 ().Nodes ().UpdateStatus (node ); err != nil {
957
+ if ! apiequality .Semantic .DeepEqual (currentReadyCondition , & observedReadyCondition ) {
958
+ if _ , err := nc .kubeClient .CoreV1 ().Nodes ().UpdateStatus (node ); err != nil {
982
959
klog .Errorf ("Error updating node %s: %v" , node .Name , err )
983
960
return gracePeriod , observedReadyCondition , currentReadyCondition , err
984
961
}
@@ -992,7 +969,7 @@ func (nc *Controller) tryUpdateNodeHealth(node *v1.Node) (time.Duration, v1.Node
992
969
}
993
970
}
994
971
995
- return gracePeriod , observedReadyCondition , currentReadyCondition , err
972
+ return gracePeriod , observedReadyCondition , currentReadyCondition , nil
996
973
}
997
974
998
975
func (nc * Controller ) handleDisruption (zoneToNodeConditions map [string ][]* v1.NodeCondition , nodes []* v1.Node ) {
0 commit comments