Migrate statefulset pkg files to structured logging

This commit is contained in:
00255991 2021-11-03 15:11:11 +08:00
parent 2a821d787b
commit cc2b2cda18

View File

@ -110,19 +110,15 @@ func (ssc *defaultStatefulSetControl) performUpdate(
if err != nil { if err != nil {
return currentRevision, updateRevision, currentStatus, err return currentRevision, updateRevision, currentStatus, err
} }
klog.V(4).Infof("StatefulSet %s/%s pod status replicas=%d ready=%d current=%d updated=%d", klog.V(4).InfoS("StatefulSet pod status", "statefulSet", klog.KObj(set),
set.Namespace, "replicas", currentStatus.Replicas,
set.Name, "readyReplicas", currentStatus.ReadyReplicas,
currentStatus.Replicas, "currentReplicas", currentStatus.CurrentReplicas,
currentStatus.ReadyReplicas, "updatedReplicas", currentStatus.UpdatedReplicas)
currentStatus.CurrentReplicas,
currentStatus.UpdatedReplicas)
klog.V(4).Infof("StatefulSet %s/%s revisions current=%s update=%s", klog.V(4).InfoS("StatefulSet revisions", "statefulSet", klog.KObj(set),
set.Namespace, "currentRevision", currentStatus.CurrentRevision,
set.Name, "updateRevision", currentStatus.UpdateRevision)
currentStatus.CurrentRevision,
currentStatus.UpdateRevision)
return currentRevision, updateRevision, currentStatus, nil return currentRevision, updateRevision, currentStatus, nil
} }
@ -375,11 +371,7 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
} }
if unhealthy > 0 { if unhealthy > 0 {
klog.V(4).Infof("StatefulSet %s/%s has %d unhealthy Pods starting with %s", klog.V(4).InfoS("StatefulSet has unhealthy Pods", "statefulSet", klog.KObj(set), "unhealthyReplicas", unhealthy, "pod", klog.KObj(firstUnhealthyPod))
set.Namespace,
set.Name,
unhealthy,
firstUnhealthyPod.Name)
} }
// If the StatefulSet is being deleted, don't do anything other than updating // 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 // If we find a Pod that is currently terminating, we must wait until graceful deletion
// completes before we continue to make progress. // completes before we continue to make progress.
if isTerminating(replicas[i]) && monotonic { if isTerminating(replicas[i]) && monotonic {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to Terminate",
"StatefulSet %s/%s is waiting for Pod %s to Terminate", "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i]))
set.Namespace,
set.Name,
replicas[i].Name)
return &status, nil return &status, nil
} }
// If we have a Pod that has been created but is not running and ready we can not make progress. // 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 // 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. // ordinal, are Running and Ready.
if !isRunningAndReady(replicas[i]) && monotonic { if !isRunningAndReady(replicas[i]) && monotonic {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to be Running and Ready",
"StatefulSet %s/%s is waiting for Pod %s to be Running and Ready", "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i]))
set.Namespace,
set.Name,
replicas[i].Name)
return &status, nil return &status, nil
} }
// If we have a Pod that has been created but is not available we can not make progress. // 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 // 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. // isRunningAndReady block as only Available pods should be brought down.
if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetMinReadySeconds) && !isRunningAndAvailable(replicas[i], set.Spec.MinReadySeconds) && monotonic { if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetMinReadySeconds) && !isRunningAndAvailable(replicas[i], set.Spec.MinReadySeconds) && monotonic {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to be Available",
"StatefulSet %s/%s is waiting for Pod %s to be Available", "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i]))
set.Namespace,
set.Name,
replicas[i].Name)
return &status, nil return &status, nil
} }
// Enforce the StatefulSet invariants // Enforce the StatefulSet invariants
@ -489,11 +472,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
for target := len(condemned) - 1; target >= 0; target-- { for target := len(condemned) - 1; target >= 0; target-- {
// wait for terminating pods to expire // wait for terminating pods to expire
if isTerminating(condemned[target]) { if isTerminating(condemned[target]) {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to Terminate prior to scale down",
"StatefulSet %s/%s is waiting for Pod %s to Terminate prior to scale down", "statefulSet", klog.KObj(set), "pod", klog.KObj(condemned[target]))
set.Namespace,
set.Name,
condemned[target].Name)
// block if we are in monotonic mode // block if we are in monotonic mode
if monotonic { if monotonic {
return &status, nil 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 we are in monotonic mode and the condemned target is not the first unhealthy Pod block
if !isRunningAndReady(condemned[target]) && monotonic && condemned[target] != firstUnhealthyPod { if !isRunningAndReady(condemned[target]) && monotonic && condemned[target] != firstUnhealthyPod {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to be Running and Ready prior to scale down",
"StatefulSet %s/%s is waiting for Pod %s to be Running and Ready prior to scale down", "statefulSet", klog.KObj(set), "pod", klog.KObj(firstUnhealthyPod))
set.Namespace,
set.Name,
firstUnhealthyPod.Name)
return &status, nil return &status, nil
} }
// if we are in monotonic mode and the condemned target is not the first unhealthy Pod, block. // 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 // 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. // 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 { if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetMinReadySeconds) && !isRunningAndAvailable(condemned[target], set.Spec.MinReadySeconds) && monotonic && condemned[target] != firstUnhealthyPod {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to be Available prior to scale down",
"StatefulSet %s/%s is waiting for Pod %s to be Available prior to scale down", "statefulSet", klog.KObj(set), "pod", klog.KObj(firstUnhealthyPod))
set.Namespace,
set.Name,
firstUnhealthyPod.Name)
return &status, nil return &status, nil
} }
klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for scale down", klog.V(2).InfoS("Pod of StatefulSet is terminating for scale down",
set.Namespace, "statefulSet", klog.KObj(set), "pod", klog.KObj(condemned[target]))
set.Name,
condemned[target].Name)
if err := ssc.podControl.DeleteStatefulPod(set, condemned[target]); err != nil { if err := ssc.podControl.DeleteStatefulPod(set, condemned[target]); err != nil {
return &status, err 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. // 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]) { if getPodRevision(replicas[target]) != updateRevision.Name && !isTerminating(replicas[target]) {
klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for update", klog.V(2).InfoS("Pod of StatefulSet is terminating for update",
set.Namespace, "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[target]))
set.Name,
replicas[target].Name)
err := ssc.podControl.DeleteStatefulPod(set, replicas[target]) err := ssc.podControl.DeleteStatefulPod(set, replicas[target])
status.CurrentReplicas-- status.CurrentReplicas--
return &status, err return &status, err
@ -565,11 +535,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
// wait for unhealthy Pods on update // wait for unhealthy Pods on update
if !isHealthy(replicas[target]) { if !isHealthy(replicas[target]) {
klog.V(4).Infof( klog.V(4).InfoS("StatefulSet is waiting for Pod to update",
"StatefulSet %s/%s is waiting for Pod %s to update", "statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[target]))
set.Namespace,
set.Name,
replicas[target].Name)
return &status, nil return &status, nil
} }