From cc2b2cda18ce5a98c9e591f5acbc747e84ede5db Mon Sep 17 00:00:00 2001 From: 00255991 Date: Wed, 3 Nov 2021 15:11:11 +0800 Subject: [PATCH] Migrate statefulset pkg files to structured logging --- .../statefulset/stateful_set_control.go | 87 ++++++------------- 1 file changed, 27 insertions(+), 60 deletions(-) diff --git a/pkg/controller/statefulset/stateful_set_control.go b/pkg/controller/statefulset/stateful_set_control.go index 7f653d13c20..2967c2c5200 100644 --- a/pkg/controller/statefulset/stateful_set_control.go +++ b/pkg/controller/statefulset/stateful_set_control.go @@ -110,19 +110,15 @@ func (ssc *defaultStatefulSetControl) performUpdate( if err != nil { return currentRevision, updateRevision, currentStatus, err } - klog.V(4).Infof("StatefulSet %s/%s pod status replicas=%d ready=%d current=%d updated=%d", - set.Namespace, - set.Name, - currentStatus.Replicas, - currentStatus.ReadyReplicas, - currentStatus.CurrentReplicas, - currentStatus.UpdatedReplicas) + klog.V(4).InfoS("StatefulSet pod status", "statefulSet", klog.KObj(set), + "replicas", currentStatus.Replicas, + "readyReplicas", currentStatus.ReadyReplicas, + "currentReplicas", currentStatus.CurrentReplicas, + "updatedReplicas", currentStatus.UpdatedReplicas) - klog.V(4).Infof("StatefulSet %s/%s revisions current=%s update=%s", - set.Namespace, - set.Name, - currentStatus.CurrentRevision, - currentStatus.UpdateRevision) + klog.V(4).InfoS("StatefulSet revisions", "statefulSet", klog.KObj(set), + "currentRevision", currentStatus.CurrentRevision, + "updateRevision", currentStatus.UpdateRevision) return currentRevision, updateRevision, currentStatus, nil } @@ -375,11 +371,7 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( } if unhealthy > 0 { - klog.V(4).Infof("StatefulSet %s/%s has %d unhealthy Pods starting with %s", - set.Namespace, - set.Name, - unhealthy, - firstUnhealthyPod.Name) + klog.V(4).InfoS("StatefulSet has unhealthy Pods", "statefulSet", klog.KObj(set), "unhealthyReplicas", unhealthy, "pod", klog.KObj(firstUnhealthyPod)) } // If the StatefulSet is being deleted, don't do anything other than updating @@ -439,22 +431,16 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( // If we find a Pod that is currently terminating, we must wait until graceful deletion // completes before we continue to make progress. if isTerminating(replicas[i]) && monotonic { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to Terminate", - set.Namespace, - set.Name, - replicas[i].Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to Terminate", + "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i])) return &status, nil } // If we have a Pod that has been created but is not running and ready we can not make progress. // We must ensure that all for each Pod, when we create it, all of its predecessors, with respect to its // ordinal, are Running and Ready. if !isRunningAndReady(replicas[i]) && monotonic { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to be Running and Ready", - set.Namespace, - set.Name, - replicas[i].Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to be Running and Ready", + "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i])) return &status, nil } // If we have a Pod that has been created but is not available we can not make progress. @@ -463,11 +449,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( // TODO: Since available is superset of Ready, once we have this featuregate enabled by default, we can remove the // isRunningAndReady block as only Available pods should be brought down. if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetMinReadySeconds) && !isRunningAndAvailable(replicas[i], set.Spec.MinReadySeconds) && monotonic { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to be Available", - set.Namespace, - set.Name, - replicas[i].Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to be Available", + "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i])) return &status, nil } // Enforce the StatefulSet invariants @@ -489,11 +472,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( for target := len(condemned) - 1; target >= 0; target-- { // wait for terminating pods to expire if isTerminating(condemned[target]) { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to Terminate prior to scale down", - set.Namespace, - set.Name, - condemned[target].Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to Terminate prior to scale down", + "statefulSet", klog.KObj(set), "pod", klog.KObj(condemned[target])) // block if we are in monotonic mode if monotonic { return &status, nil @@ -502,28 +482,20 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( } // if we are in monotonic mode and the condemned target is not the first unhealthy Pod block if !isRunningAndReady(condemned[target]) && monotonic && condemned[target] != firstUnhealthyPod { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to be Running and Ready prior to scale down", - set.Namespace, - set.Name, - firstUnhealthyPod.Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to be Running and Ready prior to scale down", + "statefulSet", klog.KObj(set), "pod", klog.KObj(firstUnhealthyPod)) return &status, nil } // if we are in monotonic mode and the condemned target is not the first unhealthy Pod, block. // TODO: Since available is superset of Ready, once we have this featuregate enabled by default, we can remove the // isRunningAndReady block as only Available pods should be brought down. if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetMinReadySeconds) && !isRunningAndAvailable(condemned[target], set.Spec.MinReadySeconds) && monotonic && condemned[target] != firstUnhealthyPod { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to be Available prior to scale down", - set.Namespace, - set.Name, - firstUnhealthyPod.Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to be Available prior to scale down", + "statefulSet", klog.KObj(set), "pod", klog.KObj(firstUnhealthyPod)) return &status, nil } - klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for scale down", - set.Namespace, - set.Name, - condemned[target].Name) + klog.V(2).InfoS("Pod of StatefulSet is terminating for scale down", + "statefulSet", klog.KObj(set), "pod", klog.KObj(condemned[target])) if err := ssc.podControl.DeleteStatefulPod(set, condemned[target]); err != nil { return &status, err @@ -554,10 +526,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( // delete the Pod if it is not already terminating and does not match the update revision. if getPodRevision(replicas[target]) != updateRevision.Name && !isTerminating(replicas[target]) { - klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for update", - set.Namespace, - set.Name, - replicas[target].Name) + klog.V(2).InfoS("Pod of StatefulSet is terminating for update", + "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[target])) err := ssc.podControl.DeleteStatefulPod(set, replicas[target]) status.CurrentReplicas-- return &status, err @@ -565,11 +535,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( // wait for unhealthy Pods on update if !isHealthy(replicas[target]) { - klog.V(4).Infof( - "StatefulSet %s/%s is waiting for Pod %s to update", - set.Namespace, - set.Name, - replicas[target].Name) + klog.V(4).InfoS("StatefulSet is waiting for Pod to update", + "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[target])) return &status, nil }