mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-27 10:19:35 +00:00
migrate pkg/kubelet/nodeshutdown to contextual logging
This commit is contained in:
@@ -213,6 +213,7 @@ linters:
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/sysctl/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/apis/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/kubeletconfig/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/nodeshutdown/.*
|
||||
|
||||
# As long as contextual logging is alpha or beta, all WithName, WithValues,
|
||||
# NewContext calls have to go through klog. Once it is GA, we can lift
|
||||
|
||||
@@ -227,6 +227,7 @@ linters:
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/sysctl/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/apis/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/kubeletconfig/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/nodeshutdown/.*
|
||||
|
||||
# As long as contextual logging is alpha or beta, all WithName, WithValues,
|
||||
# NewContext calls have to go through klog. Once it is GA, we can lift
|
||||
|
||||
@@ -59,6 +59,7 @@ contextual k8s.io/kubernetes/pkg/kubelet/status/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/sysctl/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/apis/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/kubeletconfig/.*
|
||||
contextual k8s.io/kubernetes/pkg/kubelet/nodeshutdown/.*
|
||||
|
||||
# As long as contextual logging is alpha or beta, all WithName, WithValues,
|
||||
# NewContext calls have to go through klog. Once it is GA, we can lift
|
||||
|
||||
@@ -51,7 +51,7 @@ type dbusInhibiter interface {
|
||||
InhibitShutdown() (systemd.InhibitLock, error)
|
||||
ReleaseInhibitLock(lock systemd.InhibitLock) error
|
||||
ReloadLogindConf() error
|
||||
MonitorShutdown() (<-chan bool, error)
|
||||
MonitorShutdown(klog.Logger) (<-chan bool, error)
|
||||
OverrideInhibitDelay(inhibitDelayMax time.Duration) error
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (m *managerImpl) start() (chan struct{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
events, err := m.dbusCon.MonitorShutdown()
|
||||
events, err := m.dbusCon.MonitorShutdown(m.logger)
|
||||
if err != nil {
|
||||
releaseErr := m.dbusCon.ReleaseInhibitLock(m.inhibitLock)
|
||||
if releaseErr != nil {
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/tools/record"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
_ "k8s.io/klog/v2/ktesting/init" // activate ktesting command line flags
|
||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||
@@ -81,7 +82,7 @@ func (f *fakeDbus) ReloadLogindConf() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeDbus) MonitorShutdown() (<-chan bool, error) {
|
||||
func (f *fakeDbus) MonitorShutdown(_ klog.Logger) (<-chan bool, error) {
|
||||
return f.shutdownChan, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ func (bus *DBusCon) ReloadLogindConf() error {
|
||||
|
||||
// MonitorShutdown detects the node shutdown by watching for "PrepareForShutdown" logind events.
|
||||
// see https://www.freedesktop.org/wiki/Software/systemd/inhibit/ for more details.
|
||||
func (bus *DBusCon) MonitorShutdown() (<-chan bool, error) {
|
||||
func (bus *DBusCon) MonitorShutdown(logger klog.Logger) (<-chan bool, error) {
|
||||
err := bus.SystemBus.AddMatchSignal(dbus.WithMatchInterface(logindInterface), dbus.WithMatchMember("PrepareForShutdown"), dbus.WithMatchObjectPath("/org/freedesktop/login1"))
|
||||
|
||||
if err != nil {
|
||||
@@ -155,12 +155,12 @@ func (bus *DBusCon) MonitorShutdown() (<-chan bool, error) {
|
||||
return
|
||||
}
|
||||
if event == nil || len(event.Body) == 0 {
|
||||
klog.ErrorS(nil, "Failed obtaining shutdown event, PrepareForShutdown event was empty")
|
||||
logger.Error(nil, "Failed obtaining shutdown event, PrepareForShutdown event was empty")
|
||||
continue
|
||||
}
|
||||
shutdownActive, ok := event.Body[0].(bool)
|
||||
if !ok {
|
||||
klog.ErrorS(nil, "Failed obtaining shutdown event, PrepareForShutdown event was not bool type as expected")
|
||||
logger.Error(nil, "Failed obtaining shutdown event, PrepareForShutdown event was not bool type as expected")
|
||||
continue
|
||||
}
|
||||
shutdownChan <- shutdownActive
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
)
|
||||
|
||||
type fakeDBusObject struct {
|
||||
@@ -145,6 +146,7 @@ func TestReloadLogindConf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMonitorShutdown(t *testing.T) {
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
var tests = []struct {
|
||||
desc string
|
||||
shutdownActive bool
|
||||
@@ -167,7 +169,7 @@ func TestMonitorShutdown(t *testing.T) {
|
||||
SystemBus: fakeSystemBus,
|
||||
}
|
||||
|
||||
outChan, err := bus.MonitorShutdown()
|
||||
outChan, err := bus.MonitorShutdown(logger)
|
||||
assert.NoError(t, err)
|
||||
|
||||
done := make(chan bool)
|
||||
|
||||
Reference in New Issue
Block a user