mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #99830 from krzysiekg/structured_logging_pkg_kubelet_prober
Migrate pkg/kubelet/prober to structured logging
This commit is contained in:
commit
76b29c4cbb
@ -30,7 +30,6 @@ import (
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||
)
|
||||
|
||||
// ProberResults stores the cumulative number of a probe by result as prometheus metrics.
|
||||
@ -162,8 +161,8 @@ func (m *manager) AddPod(pod *v1.Pod) {
|
||||
if c.StartupProbe != nil {
|
||||
key.probeType = startup
|
||||
if _, ok := m.workers[key]; ok {
|
||||
klog.Errorf("Startup probe already exists! %v - %v",
|
||||
format.Pod(pod), c.Name)
|
||||
klog.ErrorS(nil, "Startup probe already exists for container",
|
||||
"pod", klog.KObj(pod), "containerName", c.Name)
|
||||
return
|
||||
}
|
||||
w := newWorker(m, startup, pod, c)
|
||||
@ -174,8 +173,8 @@ func (m *manager) AddPod(pod *v1.Pod) {
|
||||
if c.ReadinessProbe != nil {
|
||||
key.probeType = readiness
|
||||
if _, ok := m.workers[key]; ok {
|
||||
klog.Errorf("Readiness probe already exists! %v - %v",
|
||||
format.Pod(pod), c.Name)
|
||||
klog.ErrorS(nil, "Readiness probe already exists for container",
|
||||
"pod", klog.KObj(pod), "containerName", c.Name)
|
||||
return
|
||||
}
|
||||
w := newWorker(m, readiness, pod, c)
|
||||
@ -186,8 +185,8 @@ func (m *manager) AddPod(pod *v1.Pod) {
|
||||
if c.LivenessProbe != nil {
|
||||
key.probeType = liveness
|
||||
if _, ok := m.workers[key]; ok {
|
||||
klog.Errorf("Liveness probe already exists! %v - %v",
|
||||
format.Pod(pod), c.Name)
|
||||
klog.ErrorS(nil, "Liveness probe already exists for container",
|
||||
"pod", klog.KObj(pod), "containerName", c.Name)
|
||||
return
|
||||
}
|
||||
w := newWorker(m, liveness, pod, c)
|
||||
|
@ -20,14 +20,13 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/klog/v2"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||
)
|
||||
|
||||
// worker handles the periodic probing of its assigned container. Each worker has a go-routine
|
||||
@ -185,22 +184,22 @@ func (w *worker) doProbe() (keepGoing bool) {
|
||||
status, ok := w.probeManager.statusManager.GetPodStatus(w.pod.UID)
|
||||
if !ok {
|
||||
// Either the pod has not been created yet, or it was already deleted.
|
||||
klog.V(3).Infof("No status for pod: %v", format.Pod(w.pod))
|
||||
klog.V(3).InfoS("No status for pod", "pod", klog.KObj(w.pod))
|
||||
return true
|
||||
}
|
||||
|
||||
// Worker should terminate if pod is terminated.
|
||||
if status.Phase == v1.PodFailed || status.Phase == v1.PodSucceeded {
|
||||
klog.V(3).Infof("Pod %v %v, exiting probe worker",
|
||||
format.Pod(w.pod), status.Phase)
|
||||
klog.V(3).InfoS("Pod is terminated, exiting probe worker",
|
||||
"pod", klog.KObj(w.pod), "phase", status.Phase)
|
||||
return false
|
||||
}
|
||||
|
||||
c, ok := podutil.GetContainerStatus(status.ContainerStatuses, w.container.Name)
|
||||
if !ok || len(c.ContainerID) == 0 {
|
||||
// Either the container has not been created yet, or it was deleted.
|
||||
klog.V(3).Infof("Probe target container not found: %v - %v",
|
||||
format.Pod(w.pod), w.container.Name)
|
||||
klog.V(3).InfoS("Probe target container not found",
|
||||
"pod", klog.KObj(w.pod), "containerName", w.container.Name)
|
||||
return true // Wait for more information.
|
||||
}
|
||||
|
||||
@ -220,8 +219,8 @@ func (w *worker) doProbe() (keepGoing bool) {
|
||||
}
|
||||
|
||||
if c.State.Running == nil {
|
||||
klog.V(3).Infof("Non-running container probed: %v - %v",
|
||||
format.Pod(w.pod), w.container.Name)
|
||||
klog.V(3).InfoS("Non-running container probed",
|
||||
"pod", klog.KObj(w.pod), "containerName", w.container.Name)
|
||||
if !w.containerID.IsEmpty() {
|
||||
w.resultsManager.Set(w.containerID, results.Failure, w.pod)
|
||||
}
|
||||
@ -232,11 +231,11 @@ func (w *worker) doProbe() (keepGoing bool) {
|
||||
|
||||
// Graceful shutdown of the pod.
|
||||
if w.pod.ObjectMeta.DeletionTimestamp != nil && (w.probeType == liveness || w.probeType == startup) {
|
||||
klog.V(3).Infof("Pod deletion requested, setting %v probe result to success: %v - %v",
|
||||
w.probeType.String(), format.Pod(w.pod), w.container.Name)
|
||||
klog.V(3).InfoS("Pod deletion requested, setting probe result to success",
|
||||
"probeType", w.probeType, "pod", klog.KObj(w.pod), "containerName", w.container.Name)
|
||||
if w.probeType == startup {
|
||||
klog.Warningf("Pod deletion requested before container has fully started: %v - %v",
|
||||
format.Pod(w.pod), w.container.Name)
|
||||
klog.InfoS("Pod deletion requested before container has fully started",
|
||||
"pod", klog.KObj(w.pod), "containerName", w.container.Name)
|
||||
}
|
||||
// Set a last result to ensure quiet shutdown.
|
||||
w.resultsManager.Set(w.containerID, results.Success, w.pod)
|
||||
|
Loading…
Reference in New Issue
Block a user