mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Fixes for the No ref for container
in probes after kubelet restart
This commit is contained in:
parent
4e26c35064
commit
4cb28f64ea
@ -80,6 +80,20 @@ func newProber(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recordContainerEvent should be used by the prober for all container related events.
|
||||||
|
func (pb *prober) recordContainerEvent(pod *v1.Pod, container *v1.Container, containerID kubecontainer.ContainerID, eventType, reason, message string, args ...interface{}) {
|
||||||
|
var err error
|
||||||
|
ref, hasRef := pb.refManager.GetRef(containerID)
|
||||||
|
if !hasRef {
|
||||||
|
ref, err = kubecontainer.GenerateContainerRef(pod, container)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("Can't make a ref to pod %q, container %v: %v", format.Pod(pod), container.Name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pb.recorder.Eventf(ref, eventType, reason, message, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// probe probes the container.
|
// probe probes the container.
|
||||||
func (pb *prober) probe(probeType probeType, pod *v1.Pod, status v1.PodStatus, container v1.Container, containerID kubecontainer.ContainerID) (results.Result, error) {
|
func (pb *prober) probe(probeType probeType, pod *v1.Pod, status v1.PodStatus, container v1.Container, containerID kubecontainer.ContainerID) (results.Result, error) {
|
||||||
var probeSpec *v1.Probe
|
var probeSpec *v1.Probe
|
||||||
@ -103,27 +117,17 @@ func (pb *prober) probe(probeType probeType, pod *v1.Pod, status v1.PodStatus, c
|
|||||||
result, output, err := pb.runProbeWithRetries(probeType, probeSpec, pod, status, container, containerID, maxProbeRetries)
|
result, output, err := pb.runProbeWithRetries(probeType, probeSpec, pod, status, container, containerID, maxProbeRetries)
|
||||||
if err != nil || (result != probe.Success && result != probe.Warning) {
|
if err != nil || (result != probe.Success && result != probe.Warning) {
|
||||||
// Probe failed in one way or another.
|
// Probe failed in one way or another.
|
||||||
ref, hasRef := pb.refManager.GetRef(containerID)
|
|
||||||
if !hasRef {
|
|
||||||
klog.Warningf("No ref for container %q (%s)", containerID.String(), ctrName)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(1).Infof("%s probe for %q errored: %v", probeType, ctrName, err)
|
klog.V(1).Infof("%s probe for %q errored: %v", probeType, ctrName, err)
|
||||||
if hasRef {
|
pb.recordContainerEvent(pod, &container, containerID, v1.EventTypeWarning, events.ContainerUnhealthy, "%s probe errored: %v", probeType, err)
|
||||||
pb.recorder.Eventf(ref, v1.EventTypeWarning, events.ContainerUnhealthy, "%s probe errored: %v", probeType, err)
|
|
||||||
}
|
|
||||||
} else { // result != probe.Success
|
} else { // result != probe.Success
|
||||||
klog.V(1).Infof("%s probe for %q failed (%v): %s", probeType, ctrName, result, output)
|
klog.V(1).Infof("%s probe for %q failed (%v): %s", probeType, ctrName, result, output)
|
||||||
if hasRef {
|
pb.recordContainerEvent(pod, &container, containerID, v1.EventTypeWarning, events.ContainerUnhealthy, "%s probe failed: %v", probeType, output)
|
||||||
pb.recorder.Eventf(ref, v1.EventTypeWarning, events.ContainerUnhealthy, "%s probe failed: %s", probeType, output)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results.Failure, err
|
return results.Failure, err
|
||||||
}
|
}
|
||||||
if result == probe.Warning {
|
if result == probe.Warning {
|
||||||
if ref, hasRef := pb.refManager.GetRef(containerID); hasRef {
|
pb.recordContainerEvent(pod, &container, containerID, v1.EventTypeWarning, events.ContainerProbeWarning, "%s probe warning: %v", probeType, output)
|
||||||
pb.recorder.Eventf(ref, v1.EventTypeWarning, events.ContainerProbeWarning, "%s probe warning: %s", probeType, output)
|
|
||||||
}
|
|
||||||
klog.V(3).Infof("%s probe for %q succeeded with a warning: %s", probeType, ctrName, output)
|
klog.V(3).Infof("%s probe for %q succeeded with a warning: %s", probeType, ctrName, output)
|
||||||
} else {
|
} else {
|
||||||
klog.V(3).Infof("%s probe for %q succeeded", probeType, ctrName)
|
klog.V(3).Infof("%s probe for %q succeeded", probeType, ctrName)
|
||||||
|
Loading…
Reference in New Issue
Block a user