mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #8430 from vmarmol/logging
Don't run OOM watcher is cAdvisor is not available.
This commit is contained in:
commit
c5f7ee6f96
@ -675,22 +675,19 @@ func (kl *Kubelet) Run(updates <-chan PodUpdate) {
|
|||||||
glog.Errorf("Failed to start ContainerManager, system may not be properly isolated: %v", err)
|
glog.Errorf("Failed to start ContainerManager, system may not be properly isolated: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = kl.oomWatcher.Start(kl.nodeRef)
|
||||||
|
if err != nil {
|
||||||
|
kl.recorder.Eventf(kl.nodeRef, "kubeletSetupFailed", "Failed to start OOM watcher %v", err)
|
||||||
|
glog.Errorf("Failed to start OOM watching: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
go util.Until(kl.updateRuntimeUp, 5*time.Second, util.NeverStop)
|
go util.Until(kl.updateRuntimeUp, 5*time.Second, util.NeverStop)
|
||||||
go kl.syncNodeStatus()
|
go kl.syncNodeStatus()
|
||||||
// Run the system oom watcher forever.
|
// Run the system oom watcher forever.
|
||||||
go util.Until(kl.runOOMWatcher, time.Second, util.NeverStop)
|
|
||||||
kl.statusManager.Start()
|
kl.statusManager.Start()
|
||||||
kl.syncLoop(updates, kl)
|
kl.syncLoop(updates, kl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watches for system OOMs.
|
|
||||||
func (kl *Kubelet) runOOMWatcher() {
|
|
||||||
glog.V(5).Infof("Starting to record system OOMs")
|
|
||||||
if err := kl.oomWatcher.RecordSysOOMs(kl.nodeRef); err != nil {
|
|
||||||
glog.Errorf("failed to record system OOMs - %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// syncNodeStatus periodically synchronizes node status to master.
|
// syncNodeStatus periodically synchronizes node status to master.
|
||||||
func (kl *Kubelet) syncNodeStatus() {
|
func (kl *Kubelet) syncNodeStatus() {
|
||||||
if kl.kubeClient == nil {
|
if kl.kubeClient == nil {
|
||||||
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||||||
package kubelet
|
package kubelet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
|
||||||
@ -29,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type OOMWatcher interface {
|
type OOMWatcher interface {
|
||||||
RecordSysOOMs(ref *api.ObjectReference) error
|
Start(ref *api.ObjectReference) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type realOOMWatcher struct {
|
type realOOMWatcher struct {
|
||||||
@ -47,7 +45,7 @@ func NewOOMWatcher(cadvisor cadvisor.Interface, recorder record.EventRecorder) O
|
|||||||
const systemOOMEvent = "SystemOOM"
|
const systemOOMEvent = "SystemOOM"
|
||||||
|
|
||||||
// Watches cadvisor for system oom's and records an event for every system oom encountered.
|
// Watches cadvisor for system oom's and records an event for every system oom encountered.
|
||||||
func (ow *realOOMWatcher) RecordSysOOMs(ref *api.ObjectReference) error {
|
func (ow *realOOMWatcher) Start(ref *api.ObjectReference) error {
|
||||||
request := events.Request{
|
request := events.Request{
|
||||||
EventType: map[cadvisorApi.EventType]bool{
|
EventType: map[cadvisorApi.EventType]bool{
|
||||||
cadvisorApi.EventOom: true,
|
cadvisorApi.EventOom: true,
|
||||||
@ -59,9 +57,15 @@ func (ow *realOOMWatcher) RecordSysOOMs(ref *api.ObjectReference) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for event := range eventChannel.GetChannel() {
|
|
||||||
glog.V(2).Infof("got sys oom event from cadvisor: %v", event)
|
go func() {
|
||||||
ow.recorder.PastEventf(ref, util.Time{event.Timestamp}, systemOOMEvent, "System OOM encountered")
|
defer util.HandleCrash()
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to watch cadvisor for sys oom events")
|
for event := range eventChannel.GetChannel() {
|
||||||
|
glog.V(2).Infof("Got sys oom event from cadvisor: %v", event)
|
||||||
|
ow.recorder.PastEventf(ref, util.Time{event.Timestamp}, systemOOMEvent, "System OOM encountered")
|
||||||
|
}
|
||||||
|
glog.Errorf("Unexpectedly stopped receiving OOM notifications from cAdvisor")
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,11 @@ func TestBasic(t *testing.T) {
|
|||||||
mockCadvisor := &cadvisor.Fake{}
|
mockCadvisor := &cadvisor.Fake{}
|
||||||
node := &api.ObjectReference{}
|
node := &api.ObjectReference{}
|
||||||
oomWatcher := NewOOMWatcher(mockCadvisor, fakeRecorder)
|
oomWatcher := NewOOMWatcher(mockCadvisor, fakeRecorder)
|
||||||
go func() {
|
err := oomWatcher.Start(node)
|
||||||
oomWatcher.RecordSysOOMs(node)
|
if err != nil {
|
||||||
}()
|
t.Errorf("Should not have failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Improve this test once cadvisor exports events.EventChannel as an interface
|
// TODO: Improve this test once cadvisor exports events.EventChannel as an interface
|
||||||
// and thereby allow using a mock version of cadvisor.
|
// and thereby allow using a mock version of cadvisor.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user