mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
port setNodeOODCondition to Setter abstraction
This commit is contained in:
parent
15b03b8c0c
commit
c33f321acd
@ -892,39 +892,6 @@ func (kl *Kubelet) setNodeDiskPressureCondition(node *v1.Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set OODCondition for the node.
|
|
||||||
func (kl *Kubelet) setNodeOODCondition(node *v1.Node) {
|
|
||||||
currentTime := metav1.NewTime(kl.clock.Now())
|
|
||||||
var nodeOODCondition *v1.NodeCondition
|
|
||||||
|
|
||||||
// Check if NodeOutOfDisk condition already exists and if it does, just pick it up for update.
|
|
||||||
for i := range node.Status.Conditions {
|
|
||||||
if node.Status.Conditions[i].Type == v1.NodeOutOfDisk {
|
|
||||||
nodeOODCondition = &node.Status.Conditions[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newOODCondition := nodeOODCondition == nil
|
|
||||||
if newOODCondition {
|
|
||||||
nodeOODCondition = &v1.NodeCondition{}
|
|
||||||
}
|
|
||||||
if nodeOODCondition.Status != v1.ConditionFalse {
|
|
||||||
nodeOODCondition.Type = v1.NodeOutOfDisk
|
|
||||||
nodeOODCondition.Status = v1.ConditionFalse
|
|
||||||
nodeOODCondition.Reason = "KubeletHasSufficientDisk"
|
|
||||||
nodeOODCondition.Message = "kubelet has sufficient disk space available"
|
|
||||||
nodeOODCondition.LastTransitionTime = currentTime
|
|
||||||
kl.recordNodeStatusEvent(v1.EventTypeNormal, "NodeHasSufficientDisk")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the heartbeat time irrespective of all the conditions.
|
|
||||||
nodeOODCondition.LastHeartbeatTime = currentTime
|
|
||||||
|
|
||||||
if newOODCondition {
|
|
||||||
node.Status.Conditions = append(node.Status.Conditions, *nodeOODCondition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// record if node schedulable change.
|
// record if node schedulable change.
|
||||||
func (kl *Kubelet) recordNodeSchedulableEvent(node *v1.Node) {
|
func (kl *Kubelet) recordNodeSchedulableEvent(node *v1.Node) {
|
||||||
kl.lastNodeUnschedulableLock.Lock()
|
kl.lastNodeUnschedulableLock.Lock()
|
||||||
@ -990,7 +957,7 @@ func (kl *Kubelet) defaultNodeStatusFuncs() []func(*v1.Node) error {
|
|||||||
return []func(*v1.Node) error{
|
return []func(*v1.Node) error{
|
||||||
nodestatus.NodeAddress(kl.nodeIP, kl.nodeIPValidator, kl.hostname, kl.externalCloudProvider, kl.cloud, nodeAddressesFunc),
|
nodestatus.NodeAddress(kl.nodeIP, kl.nodeIPValidator, kl.hostname, kl.externalCloudProvider, kl.cloud, nodeAddressesFunc),
|
||||||
withoutError(kl.setNodeStatusInfo),
|
withoutError(kl.setNodeStatusInfo),
|
||||||
withoutError(kl.setNodeOODCondition),
|
nodestatus.OutOfDiskCondition(kl.clock.Now, kl.recordNodeStatusEvent),
|
||||||
withoutError(kl.setNodeMemoryPressureCondition),
|
withoutError(kl.setNodeMemoryPressureCondition),
|
||||||
withoutError(kl.setNodeDiskPressureCondition),
|
withoutError(kl.setNodeDiskPressureCondition),
|
||||||
withoutError(kl.setNodePIDPressureCondition),
|
withoutError(kl.setNodePIDPressureCondition),
|
||||||
|
@ -9,6 +9,7 @@ go_library(
|
|||||||
"//pkg/cloudprovider:go_default_library",
|
"//pkg/cloudprovider:go_default_library",
|
||||||
"//pkg/kubelet/apis:go_default_library",
|
"//pkg/kubelet/apis:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -19,8 +19,10 @@ package nodestatus
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
||||||
@ -139,3 +141,42 @@ func NodeAddress(nodeIP net.IP, // typically Kubelet.nodeIP
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutOfDiskCondition returns a Setter that updates the v1.NodeOutOfDisk condition on the node.
|
||||||
|
// TODO(#65658): remove this condition
|
||||||
|
func OutOfDiskCondition(nowFunc func() time.Time, // typically Kubelet.clock.Now
|
||||||
|
recordEventFunc func(eventType, event string), // typically Kubelet.recordNodeStatusEvent
|
||||||
|
) Setter {
|
||||||
|
return func(node *v1.Node) error {
|
||||||
|
currentTime := metav1.NewTime(nowFunc())
|
||||||
|
var nodeOODCondition *v1.NodeCondition
|
||||||
|
|
||||||
|
// Check if NodeOutOfDisk condition already exists and if it does, just pick it up for update.
|
||||||
|
for i := range node.Status.Conditions {
|
||||||
|
if node.Status.Conditions[i].Type == v1.NodeOutOfDisk {
|
||||||
|
nodeOODCondition = &node.Status.Conditions[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newOODCondition := nodeOODCondition == nil
|
||||||
|
if newOODCondition {
|
||||||
|
nodeOODCondition = &v1.NodeCondition{}
|
||||||
|
}
|
||||||
|
if nodeOODCondition.Status != v1.ConditionFalse {
|
||||||
|
nodeOODCondition.Type = v1.NodeOutOfDisk
|
||||||
|
nodeOODCondition.Status = v1.ConditionFalse
|
||||||
|
nodeOODCondition.Reason = "KubeletHasSufficientDisk"
|
||||||
|
nodeOODCondition.Message = "kubelet has sufficient disk space available"
|
||||||
|
nodeOODCondition.LastTransitionTime = currentTime
|
||||||
|
recordEventFunc(v1.EventTypeNormal, "NodeHasSufficientDisk")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the heartbeat time irrespective of all the conditions.
|
||||||
|
nodeOODCondition.LastHeartbeatTime = currentTime
|
||||||
|
|
||||||
|
if newOODCondition {
|
||||||
|
node.Status.Conditions = append(node.Status.Conditions, *nodeOODCondition)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user