Structured Logging migration: modify volume and container part logs of kubelet.

Signed-off-by: JunYang <yang.jun22@zte.com.cn>
This commit is contained in:
JunYang
2021-02-08 01:36:31 +08:00
committed by JUN YANG
parent ed6b9addbf
commit 01a4e4face
12 changed files with 111 additions and 172 deletions

View File

@@ -82,6 +82,6 @@ func (cgc *realContainerGC) GarbageCollect() error {
}
func (cgc *realContainerGC) DeleteAllUnusedContainers() error {
klog.Infof("attempting to delete unused containers")
klog.InfoS("Attempting to delete unused containers")
return cgc.runtime.GarbageCollect(cgc.policy, cgc.sourcesReadyProvider.AllReady(), true)
}

View File

@@ -31,7 +31,6 @@ import (
"k8s.io/client-go/tools/record"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/kubelet/util/format"
hashutil "k8s.io/kubernetes/pkg/util/hash"
"k8s.io/kubernetes/third_party/forked/golang/expansion"
utilsnet "k8s.io/utils/net"
@@ -82,13 +81,13 @@ func ShouldContainerBeRestarted(container *v1.Container, pod *v1.Pod, podStatus
}
// Check RestartPolicy for dead container
if pod.Spec.RestartPolicy == v1.RestartPolicyNever {
klog.V(4).Infof("Already ran container %q of pod %q, do nothing", container.Name, format.Pod(pod))
klog.V(4).InfoS("Already ran container, do nothing", "pod", klog.KObj(pod), "containerName", container.Name)
return false
}
if pod.Spec.RestartPolicy == v1.RestartPolicyOnFailure {
// Check the exit code.
if status.ExitCode == 0 {
klog.V(4).Infof("Already successfully ran container %q of pod %q, do nothing", container.Name, format.Pod(pod))
klog.V(4).InfoS("Already successfully ran container, do nothing", "pod", klog.KObj(pod), "containerName", container.Name)
return false
}
}
@@ -341,7 +340,7 @@ func MakePortMappings(container *v1.Container) (ports []PortMapping) {
// Protect against a port name being used more than once in a container.
if _, ok := names[name]; ok {
klog.Warningf("Port name conflicted, %q is defined more than once", name)
klog.InfoS("Port name conflicted, it is defined more than once", "portName", name)
continue
}
ports = append(ports, pm)

View File

@@ -204,7 +204,7 @@ func BuildContainerID(typ, ID string) ContainerID {
func ParseContainerID(containerID string) ContainerID {
var id ContainerID
if err := id.ParseString(containerID); err != nil {
klog.Error(err)
klog.ErrorS(err, "Parsing containerID failed")
}
return id
}