mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #110747 from harshanarayana/cleanup/GIT-110737/logging-improvements
structured-logging: replace KObjs with KObjSlice for logging
This commit is contained in:
commit
98742f9d77
@ -231,10 +231,8 @@ func (rsc *ReplicaSetController) getReplicaSetsWithSameController(rs *apps.Repli
|
|||||||
relatedRSs = append(relatedRSs, obj.(*apps.ReplicaSet))
|
relatedRSs = append(relatedRSs, obj.(*apps.ReplicaSet))
|
||||||
}
|
}
|
||||||
|
|
||||||
// The if check is used to avoid the overhead for the KObjs call, see
|
|
||||||
// https://github.com/kubernetes/kubernetes/issues/106945.
|
|
||||||
if klogV := klog.V(2); klogV.Enabled() {
|
if klogV := klog.V(2); klogV.Enabled() {
|
||||||
klogV.InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", klog.KObjs(relatedRSs))
|
klogV.InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", klog.KObjSlice(relatedRSs))
|
||||||
}
|
}
|
||||||
|
|
||||||
return relatedRSs
|
return relatedRSs
|
||||||
@ -802,7 +800,7 @@ func (rsc *ReplicaSetController) getIndirectlyRelatedPods(rs *apps.ReplicaSet) (
|
|||||||
relatedPods = append(relatedPods, pod)
|
relatedPods = append(relatedPods, pod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(4).InfoS("Found related pods", "kind", rsc.Kind, "object", klog.KObj(rs), "pods", klog.KObjs(relatedPods))
|
klog.V(4).InfoS("Found related pods", "kind", rsc.Kind, "object", klog.KObj(rs), "pods", klog.KObjSlice(relatedPods))
|
||||||
return relatedPods, nil
|
return relatedPods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,5 +417,5 @@ func (rc *reconciler) reportMultiAttachError(volumeToAttach cache.VolumeToAttach
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log all pods for system admin
|
// Log all pods for system admin
|
||||||
klog.InfoS("Multi-Attach error: volume is already used by pods", "pods", klog.KObjs(pods), "attachedTo", otherNodesStr, "volume", volumeToAttach)
|
klog.InfoS("Multi-Attach error: volume is already used by pods", "pods", klog.KObjSlice(pods), "attachedTo", otherNodesStr, "volume", volumeToAttach)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
@ -257,16 +257,16 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
|
|||||||
switch update.Op {
|
switch update.Op {
|
||||||
case kubetypes.ADD, kubetypes.UPDATE, kubetypes.DELETE:
|
case kubetypes.ADD, kubetypes.UPDATE, kubetypes.DELETE:
|
||||||
if update.Op == kubetypes.ADD {
|
if update.Op == kubetypes.ADD {
|
||||||
klog.V(4).InfoS("Adding new pods from source", "source", source, "pods", klog.KObjs(update.Pods))
|
klog.V(4).InfoS("Adding new pods from source", "source", source, "pods", klog.KObjSlice(update.Pods))
|
||||||
} else if update.Op == kubetypes.DELETE {
|
} else if update.Op == kubetypes.DELETE {
|
||||||
klog.V(4).InfoS("Gracefully deleting pods from source", "source", source, "pods", klog.KObjs(update.Pods))
|
klog.V(4).InfoS("Gracefully deleting pods from source", "source", source, "pods", klog.KObjSlice(update.Pods))
|
||||||
} else {
|
} else {
|
||||||
klog.V(4).InfoS("Updating pods from source", "source", source, "pods", klog.KObjs(update.Pods))
|
klog.V(4).InfoS("Updating pods from source", "source", source, "pods", klog.KObjSlice(update.Pods))
|
||||||
}
|
}
|
||||||
updatePodsFunc(update.Pods, pods, pods)
|
updatePodsFunc(update.Pods, pods, pods)
|
||||||
|
|
||||||
case kubetypes.REMOVE:
|
case kubetypes.REMOVE:
|
||||||
klog.V(4).InfoS("Removing pods from source", "source", source, "pods", klog.KObjs(update.Pods))
|
klog.V(4).InfoS("Removing pods from source", "source", source, "pods", klog.KObjSlice(update.Pods))
|
||||||
for _, value := range update.Pods {
|
for _, value := range update.Pods {
|
||||||
if existing, found := pods[value.UID]; found {
|
if existing, found := pods[value.UID]; found {
|
||||||
// this is a delete
|
// this is a delete
|
||||||
|
@ -197,7 +197,7 @@ func (m *managerImpl) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePod
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
if evictedPods := m.synchronize(diskInfoProvider, podFunc); evictedPods != nil {
|
if evictedPods := m.synchronize(diskInfoProvider, podFunc); evictedPods != nil {
|
||||||
klog.InfoS("Eviction manager: pods evicted, waiting for pod to be cleaned up", "pods", klog.KObjs(evictedPods))
|
klog.InfoS("Eviction manager: pods evicted, waiting for pod to be cleaned up", "pods", klog.KObjSlice(evictedPods))
|
||||||
m.waitForPodsCleanup(podCleanedUpFunc, evictedPods)
|
m.waitForPodsCleanup(podCleanedUpFunc, evictedPods)
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(monitoringInterval)
|
time.Sleep(monitoringInterval)
|
||||||
@ -366,7 +366,7 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
|
|||||||
// rank the running pods for eviction for the specified resource
|
// rank the running pods for eviction for the specified resource
|
||||||
rank(activePods, statsFunc)
|
rank(activePods, statsFunc)
|
||||||
|
|
||||||
klog.InfoS("Eviction manager: pods ranked for eviction", "pods", klog.KObjs(activePods))
|
klog.InfoS("Eviction manager: pods ranked for eviction", "pods", klog.KObjSlice(activePods))
|
||||||
|
|
||||||
//record age of metrics for met thresholds that we are using for evictions.
|
//record age of metrics for met thresholds that we are using for evictions.
|
||||||
for _, t := range thresholds {
|
for _, t := range thresholds {
|
||||||
@ -401,7 +401,7 @@ func (m *managerImpl) waitForPodsCleanup(podCleanedUpFunc PodCleanedUpFunc, pods
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeout.C():
|
case <-timeout.C():
|
||||||
klog.InfoS("Eviction manager: timed out waiting for pods to be cleaned up", "pods", klog.KObjs(pods))
|
klog.InfoS("Eviction manager: timed out waiting for pods to be cleaned up", "pods", klog.KObjSlice(pods))
|
||||||
return
|
return
|
||||||
case <-ticker.C():
|
case <-ticker.C():
|
||||||
for i, pod := range pods {
|
for i, pod := range pods {
|
||||||
@ -409,7 +409,7 @@ func (m *managerImpl) waitForPodsCleanup(podCleanedUpFunc PodCleanedUpFunc, pods
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if i == len(pods)-1 {
|
if i == len(pods)-1 {
|
||||||
klog.InfoS("Eviction manager: pods successfully cleaned up", "pods", klog.KObjs(pods))
|
klog.InfoS("Eviction manager: pods successfully cleaned up", "pods", klog.KObjSlice(pods))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2103,23 +2103,23 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
|
|||||||
|
|
||||||
switch u.Op {
|
switch u.Op {
|
||||||
case kubetypes.ADD:
|
case kubetypes.ADD:
|
||||||
klog.V(2).InfoS("SyncLoop ADD", "source", u.Source, "pods", klog.KObjs(u.Pods))
|
klog.V(2).InfoS("SyncLoop ADD", "source", u.Source, "pods", klog.KObjSlice(u.Pods))
|
||||||
// After restarting, kubelet will get all existing pods through
|
// After restarting, kubelet will get all existing pods through
|
||||||
// ADD as if they are new pods. These pods will then go through the
|
// ADD as if they are new pods. These pods will then go through the
|
||||||
// admission process and *may* be rejected. This can be resolved
|
// admission process and *may* be rejected. This can be resolved
|
||||||
// once we have checkpointing.
|
// once we have checkpointing.
|
||||||
handler.HandlePodAdditions(u.Pods)
|
handler.HandlePodAdditions(u.Pods)
|
||||||
case kubetypes.UPDATE:
|
case kubetypes.UPDATE:
|
||||||
klog.V(2).InfoS("SyncLoop UPDATE", "source", u.Source, "pods", klog.KObjs(u.Pods))
|
klog.V(2).InfoS("SyncLoop UPDATE", "source", u.Source, "pods", klog.KObjSlice(u.Pods))
|
||||||
handler.HandlePodUpdates(u.Pods)
|
handler.HandlePodUpdates(u.Pods)
|
||||||
case kubetypes.REMOVE:
|
case kubetypes.REMOVE:
|
||||||
klog.V(2).InfoS("SyncLoop REMOVE", "source", u.Source, "pods", klog.KObjs(u.Pods))
|
klog.V(2).InfoS("SyncLoop REMOVE", "source", u.Source, "pods", klog.KObjSlice(u.Pods))
|
||||||
handler.HandlePodRemoves(u.Pods)
|
handler.HandlePodRemoves(u.Pods)
|
||||||
case kubetypes.RECONCILE:
|
case kubetypes.RECONCILE:
|
||||||
klog.V(4).InfoS("SyncLoop RECONCILE", "source", u.Source, "pods", klog.KObjs(u.Pods))
|
klog.V(4).InfoS("SyncLoop RECONCILE", "source", u.Source, "pods", klog.KObjSlice(u.Pods))
|
||||||
handler.HandlePodReconcile(u.Pods)
|
handler.HandlePodReconcile(u.Pods)
|
||||||
case kubetypes.DELETE:
|
case kubetypes.DELETE:
|
||||||
klog.V(2).InfoS("SyncLoop DELETE", "source", u.Source, "pods", klog.KObjs(u.Pods))
|
klog.V(2).InfoS("SyncLoop DELETE", "source", u.Source, "pods", klog.KObjSlice(u.Pods))
|
||||||
// DELETE is treated as a UPDATE because of graceful deletion.
|
// DELETE is treated as a UPDATE because of graceful deletion.
|
||||||
handler.HandlePodUpdates(u.Pods)
|
handler.HandlePodUpdates(u.Pods)
|
||||||
case kubetypes.SET:
|
case kubetypes.SET:
|
||||||
@ -2154,7 +2154,7 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
|
|||||||
if len(podsToSync) == 0 {
|
if len(podsToSync) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
klog.V(4).InfoS("SyncLoop (SYNC) pods", "total", len(podsToSync), "pods", klog.KObjs(podsToSync))
|
klog.V(4).InfoS("SyncLoop (SYNC) pods", "total", len(podsToSync), "pods", klog.KObjSlice(podsToSync))
|
||||||
handler.HandlePodSyncs(podsToSync)
|
handler.HandlePodSyncs(podsToSync)
|
||||||
case update := <-kl.livenessManager.Updates():
|
case update := <-kl.livenessManager.Updates():
|
||||||
if update.Result == proberesults.Failure {
|
if update.Result == proberesults.Failure {
|
||||||
|
@ -153,10 +153,10 @@ func TestKlogIntegration(t *testing.T) {
|
|||||||
format: `{"ts":%f,"caller":"json/klog_test.go:%d","msg":"some","v":0,"pod":{"name":"pod-1","namespace":"kube-system"}}`,
|
format: `{"ts":%f,"caller":"json/klog_test.go:%d","msg":"some","v":0,"pod":{"name":"pod-1","namespace":"kube-system"}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "KObjs",
|
name: "KObjSlice",
|
||||||
fun: func() {
|
fun: func() {
|
||||||
klog.InfoS("several", "pods",
|
klog.InfoS("several", "pods",
|
||||||
klog.KObjs([]interface{}{
|
klog.KObjSlice([]interface{}{
|
||||||
&kmeta{Name: "pod-1", Namespace: "kube-system"},
|
&kmeta{Name: "pod-1", Namespace: "kube-system"},
|
||||||
&kmeta{Name: "pod-2", Namespace: "kube-system"},
|
&kmeta{Name: "pod-2", Namespace: "kube-system"},
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user