mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Added events back to Node Controller
It reverts @davidopp temp fix #6443. Fixes #6199.
This commit is contained in:
parent
b12d75d0ee
commit
c1dd881f48
@ -26,8 +26,10 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
@ -56,6 +58,7 @@ type NodeController struct {
|
|||||||
nodes []string
|
nodes []string
|
||||||
kubeClient client.Interface
|
kubeClient client.Interface
|
||||||
kubeletClient client.KubeletClient
|
kubeletClient client.KubeletClient
|
||||||
|
recorder record.EventRecorder
|
||||||
registerRetryCount int
|
registerRetryCount int
|
||||||
podEvictionTimeout time.Duration
|
podEvictionTimeout time.Duration
|
||||||
deletingPodsRateLimiter util.RateLimiter
|
deletingPodsRateLimiter util.RateLimiter
|
||||||
@ -104,6 +107,14 @@ func NewNodeController(
|
|||||||
nodeMonitorGracePeriod time.Duration,
|
nodeMonitorGracePeriod time.Duration,
|
||||||
nodeStartupGracePeriod time.Duration,
|
nodeStartupGracePeriod time.Duration,
|
||||||
nodeMonitorPeriod time.Duration) *NodeController {
|
nodeMonitorPeriod time.Duration) *NodeController {
|
||||||
|
eventBroadcaster := record.NewBroadcaster()
|
||||||
|
recorder := eventBroadcaster.NewRecorder(api.EventSource{Component: "controllermanager"})
|
||||||
|
if kubeClient != nil {
|
||||||
|
glog.Infof("Sending events to api server.")
|
||||||
|
eventBroadcaster.StartRecordingToSink(kubeClient.Events(""))
|
||||||
|
} else {
|
||||||
|
glog.Infof("No api server defined - no events will be sent to API server.")
|
||||||
|
}
|
||||||
return &NodeController{
|
return &NodeController{
|
||||||
cloud: cloud,
|
cloud: cloud,
|
||||||
matchRE: matchRE,
|
matchRE: matchRE,
|
||||||
@ -111,6 +122,7 @@ func NewNodeController(
|
|||||||
staticResources: staticResources,
|
staticResources: staticResources,
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
kubeletClient: kubeletClient,
|
kubeletClient: kubeletClient,
|
||||||
|
recorder: recorder,
|
||||||
registerRetryCount: registerRetryCount,
|
registerRetryCount: registerRetryCount,
|
||||||
podEvictionTimeout: podEvictionTimeout,
|
podEvictionTimeout: podEvictionTimeout,
|
||||||
deletingPodsRateLimiter: deletingPodsRateLimiter,
|
deletingPodsRateLimiter: deletingPodsRateLimiter,
|
||||||
@ -298,6 +310,19 @@ func (nc *NodeController) PopulateAddresses(nodes *api.NodeList) (*api.NodeList,
|
|||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nc *NodeController) recordNodeEvent(node *api.Node, event string) {
|
||||||
|
ref := &api.ObjectReference{
|
||||||
|
Kind: "Node",
|
||||||
|
Name: node.Name,
|
||||||
|
UID: types.UID(node.Name),
|
||||||
|
Namespace: "",
|
||||||
|
}
|
||||||
|
glog.V(2).Infof("Recording %s event message for node %s", event, node.Name)
|
||||||
|
// TODO: This requires a transaction, either both node status is updated
|
||||||
|
// and event is recorded or neither should happen, see issue #6055.
|
||||||
|
nc.recorder.Eventf(ref, event, "Node %s is now %s", node.Name, event)
|
||||||
|
}
|
||||||
|
|
||||||
// For a given node checks its conditions and tries to update it. Returns grace period to which given node
|
// For a given node checks its conditions and tries to update it. Returns grace period to which given node
|
||||||
// is entitled, state of current and last observed Ready Condition, and an error if it ocured.
|
// is entitled, state of current and last observed Ready Condition, and an error if it ocured.
|
||||||
func (nc *NodeController) tryUpdateNodeStatus(node *api.Node) (time.Duration, api.NodeCondition, *api.NodeCondition, error) {
|
func (nc *NodeController) tryUpdateNodeStatus(node *api.Node) (time.Duration, api.NodeCondition, *api.NodeCondition, error) {
|
||||||
@ -481,6 +506,17 @@ func (nc *NodeController) MonitorNodeStatus() error {
|
|||||||
nc.deletePods(node.Name)
|
nc.deletePods(node.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report node events.
|
||||||
|
if readyCondition.Status == api.ConditionTrue && lastReadyCondition.Status != api.ConditionTrue {
|
||||||
|
nc.recordNodeEvent(node, "ready")
|
||||||
|
}
|
||||||
|
if readyCondition.Status == api.ConditionFalse && lastReadyCondition.Status != api.ConditionFalse {
|
||||||
|
nc.recordNodeEvent(node, "not_ready")
|
||||||
|
}
|
||||||
|
if readyCondition.Status == api.ConditionUnknown && lastReadyCondition.Status != api.ConditionUnknown {
|
||||||
|
nc.recordNodeEvent(node, "unknown")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user