Skip to content

Commit 068e313

Browse files
committed
Migrate to slog in ready.go
1 parent 36b1dce commit 068e313

File tree

1 file changed

+73
-20
lines changed

1 file changed

+73
-20
lines changed

pkg/kube/ready.go

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kube // import "helm.sh/helm/v4/pkg/kube"
1919
import (
2020
"context"
2121
"fmt"
22+
"log/slog"
2223

2324
appsv1 "k8s.io/api/apps/v1"
2425
batchv1 "k8s.io/api/batch/v1"
@@ -225,18 +226,19 @@ func (c *ReadyChecker) isPodReady(pod *corev1.Pod) bool {
225226
return true
226227
}
227228
}
228-
c.log("Pod is not ready: %s/%s", pod.GetNamespace(), pod.GetName())
229+
// c.log("Pod is not ready: %s/%s", pod.GetNamespace(), pod.GetName())
230+
slog.Info("Pod is not ready", "namespace", pod.GetNamespace(), "name", pod.GetName())
229231
return false
230232
}
231233

232234
func (c *ReadyChecker) jobReady(job *batchv1.Job) (bool, error) {
233235
if job.Status.Failed > *job.Spec.BackoffLimit {
234-
c.log("Job is failed: %s/%s", job.GetNamespace(), job.GetName())
236+
slog.Info("Job failed", "namespace", job.GetNamespace(), "name", job.GetName())
235237
// If a job is failed, it can't recover, so throw an error
236238
return false, fmt.Errorf("job is failed: %s/%s", job.GetNamespace(), job.GetName())
237239
}
238240
if job.Spec.Completions != nil && job.Status.Succeeded < *job.Spec.Completions {
239-
c.log("Job is not completed: %s/%s", job.GetNamespace(), job.GetName())
241+
slog.Info("Job is not completed", "namespace", job.GetNamespace(), "name", job.GetName())
240242
return false, nil
241243
}
242244
return true, nil
@@ -250,20 +252,20 @@ func (c *ReadyChecker) serviceReady(s *corev1.Service) bool {
250252

251253
// Ensure that the service cluster IP is not empty
252254
if s.Spec.ClusterIP == "" {
253-
c.log("Service does not have cluster IP address: %s/%s", s.GetNamespace(), s.GetName())
255+
slog.Info("Service does not have cluster IP address", "namespace", s.GetNamespace(), "name", s.GetName())
254256
return false
255257
}
256258

257259
// This checks if the service has a LoadBalancer and that balancer has an Ingress defined
258260
if s.Spec.Type == corev1.ServiceTypeLoadBalancer {
259261
// do not wait when at least 1 external IP is set
260262
if len(s.Spec.ExternalIPs) > 0 {
261-
c.log("Service %s/%s has external IP addresses (%v), marking as ready", s.GetNamespace(), s.GetName(), s.Spec.ExternalIPs)
263+
slog.Info("Service has external IP addresses, marking as ready", "namespace", s.GetNamespace(), "name", s.GetName(), "externalIPs", s.Spec.ExternalIPs)
262264
return true
263265
}
264266

265267
if s.Status.LoadBalancer.Ingress == nil {
266-
c.log("Service does not have load balancer ingress IP address: %s/%s", s.GetNamespace(), s.GetName())
268+
slog.Info("Service does not have load balancer ingress IP address", "namespace", s.GetNamespace(), "name", s.GetName())
267269
return false
268270
}
269271
}
@@ -273,7 +275,7 @@ func (c *ReadyChecker) serviceReady(s *corev1.Service) bool {
273275

274276
func (c *ReadyChecker) volumeReady(v *corev1.PersistentVolumeClaim) bool {
275277
if v.Status.Phase != corev1.ClaimBound {
276-
c.log("PersistentVolumeClaim is not bound: %s/%s", v.GetNamespace(), v.GetName())
278+
slog.Info("PersistentVolumeClaim is not bound", "namespace", v.GetNamespace(), "name", v.GetName())
277279
return false
278280
}
279281
return true
@@ -286,13 +288,21 @@ func (c *ReadyChecker) deploymentReady(rs *appsv1.ReplicaSet, dep *appsv1.Deploy
286288
}
287289
// Verify the generation observed by the deployment controller matches the spec generation
288290
if dep.Status.ObservedGeneration != dep.ObjectMeta.Generation {
289-
c.log("Deployment is not ready: %s/%s. observedGeneration (%d) does not match spec generation (%d).", dep.Namespace, dep.Name, dep.Status.ObservedGeneration, dep.ObjectMeta.Generation)
291+
slog.Info("Deployment is not ready: observedGeneration does not match spec generation",
292+
"namespace", dep.Namespace,
293+
"name", dep.Name,
294+
"observedGeneration", dep.Status.ObservedGeneration,
295+
"specGeneration", dep.ObjectMeta.Generation)
290296
return false
291297
}
292298

293299
expectedReady := *dep.Spec.Replicas - deploymentutil.MaxUnavailable(*dep)
294300
if !(rs.Status.ReadyReplicas >= expectedReady) {
295-
c.log("Deployment is not ready: %s/%s. %d out of %d expected pods are ready", dep.Namespace, dep.Name, rs.Status.ReadyReplicas, expectedReady)
301+
slog.Info("Deployment is not ready: not enough pods ready",
302+
"namespace", dep.Namespace,
303+
"name", dep.Name,
304+
"readyReplicas", rs.Status.ReadyReplicas,
305+
"expectedReplicas", expectedReady)
296306
return false
297307
}
298308
return true
@@ -301,7 +311,11 @@ func (c *ReadyChecker) deploymentReady(rs *appsv1.ReplicaSet, dep *appsv1.Deploy
301311
func (c *ReadyChecker) daemonSetReady(ds *appsv1.DaemonSet) bool {
302312
// Verify the generation observed by the daemonSet controller matches the spec generation
303313
if ds.Status.ObservedGeneration != ds.ObjectMeta.Generation {
304-
c.log("DaemonSet is not ready: %s/%s. observedGeneration (%d) does not match spec generation (%d).", ds.Namespace, ds.Name, ds.Status.ObservedGeneration, ds.ObjectMeta.Generation)
314+
slog.Info("DaemonSet is not ready: observedGeneration does not match spec generation",
315+
"namespace", ds.Namespace,
316+
"name", ds.Name,
317+
"observedGeneration", ds.Status.ObservedGeneration,
318+
"specGeneration", ds.ObjectMeta.Generation)
305319
return false
306320
}
307321

@@ -312,7 +326,11 @@ func (c *ReadyChecker) daemonSetReady(ds *appsv1.DaemonSet) bool {
312326

313327
// Make sure all the updated pods have been scheduled
314328
if ds.Status.UpdatedNumberScheduled != ds.Status.DesiredNumberScheduled {
315-
c.log("DaemonSet is not ready: %s/%s. %d out of %d expected pods have been scheduled", ds.Namespace, ds.Name, ds.Status.UpdatedNumberScheduled, ds.Status.DesiredNumberScheduled)
329+
slog.Info("DaemonSet is not ready: not enough pods scheduled",
330+
"namespace", ds.Namespace,
331+
"name", ds.Name,
332+
"updatedScheduled", ds.Status.UpdatedNumberScheduled,
333+
"desiredScheduled", ds.Status.DesiredNumberScheduled)
316334
return false
317335
}
318336
maxUnavailable, err := intstr.GetScaledValueFromIntOrPercent(ds.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable, int(ds.Status.DesiredNumberScheduled), true)
@@ -325,7 +343,11 @@ func (c *ReadyChecker) daemonSetReady(ds *appsv1.DaemonSet) bool {
325343

326344
expectedReady := int(ds.Status.DesiredNumberScheduled) - maxUnavailable
327345
if !(int(ds.Status.NumberReady) >= expectedReady) {
328-
c.log("DaemonSet is not ready: %s/%s. %d out of %d expected pods are ready", ds.Namespace, ds.Name, ds.Status.NumberReady, expectedReady)
346+
slog.Info("DaemonSet is not ready: not enough pods ready",
347+
"namespace", ds.Namespace,
348+
"name", ds.Name,
349+
"readyPods", ds.Status.NumberReady,
350+
"expectedPods", expectedReady)
329351
return false
330352
}
331353
return true
@@ -377,13 +399,20 @@ func (c *ReadyChecker) crdReady(crd apiextv1.CustomResourceDefinition) bool {
377399
func (c *ReadyChecker) statefulSetReady(sts *appsv1.StatefulSet) bool {
378400
// Verify the generation observed by the statefulSet controller matches the spec generation
379401
if sts.Status.ObservedGeneration != sts.ObjectMeta.Generation {
380-
c.log("StatefulSet is not ready: %s/%s. observedGeneration (%d) does not match spec generation (%d).", sts.Namespace, sts.Name, sts.Status.ObservedGeneration, sts.ObjectMeta.Generation)
402+
slog.Info("StatefulSet is not ready: observedGeneration does not match spec generation",
403+
"namespace", sts.Namespace,
404+
"name", sts.Name,
405+
"observedGeneration", sts.Status.ObservedGeneration,
406+
"specGeneration", sts.ObjectMeta.Generation)
381407
return false
382408
}
383409

384410
// If the update strategy is not a rolling update, there will be nothing to wait for
385411
if sts.Spec.UpdateStrategy.Type != appsv1.RollingUpdateStatefulSetStrategyType {
386-
c.log("StatefulSet skipped ready check: %s/%s. updateStrategy is %v", sts.Namespace, sts.Name, sts.Spec.UpdateStrategy.Type)
412+
slog.Info("StatefulSet skipped ready check",
413+
"namespace", sts.Namespace,
414+
"name", sts.Name,
415+
"updateStrategy", sts.Spec.UpdateStrategy.Type)
387416
return true
388417
}
389418

@@ -409,30 +438,50 @@ func (c *ReadyChecker) statefulSetReady(sts *appsv1.StatefulSet) bool {
409438

410439
// Make sure all the updated pods have been scheduled
411440
if int(sts.Status.UpdatedReplicas) < expectedReplicas {
412-
c.log("StatefulSet is not ready: %s/%s. %d out of %d expected pods have been scheduled", sts.Namespace, sts.Name, sts.Status.UpdatedReplicas, expectedReplicas)
441+
slog.Info("StatefulSet is not ready: not enough pods scheduled",
442+
"namespace", sts.Namespace,
443+
"name", sts.Name,
444+
"updatedReplicas", sts.Status.UpdatedReplicas,
445+
"expectedReplicas", expectedReplicas)
413446
return false
414447
}
415448

416449
if int(sts.Status.ReadyReplicas) != replicas {
417-
c.log("StatefulSet is not ready: %s/%s. %d out of %d expected pods are ready", sts.Namespace, sts.Name, sts.Status.ReadyReplicas, replicas)
450+
slog.Info("StatefulSet is not ready: not enough pods ready",
451+
"namespace", sts.Namespace,
452+
"name", sts.Name,
453+
"readyReplicas", sts.Status.ReadyReplicas,
454+
"expectedReplicas", replicas)
418455
return false
419456
}
420457
// This check only makes sense when all partitions are being upgraded otherwise during a
421458
// partitioned rolling upgrade, this condition will never evaluate to true, leading to
422459
// error.
423460
if partition == 0 && sts.Status.CurrentRevision != sts.Status.UpdateRevision {
424-
c.log("StatefulSet is not ready: %s/%s. currentRevision %s does not yet match updateRevision %s", sts.Namespace, sts.Name, sts.Status.CurrentRevision, sts.Status.UpdateRevision)
461+
slog.Info("StatefulSet is not ready: currentRevision does not match updateRevision",
462+
"namespace", sts.Namespace,
463+
"name", sts.Name,
464+
"currentRevision", sts.Status.CurrentRevision,
465+
"updateRevision", sts.Status.UpdateRevision)
425466
return false
426467
}
427468

428-
c.log("StatefulSet is ready: %s/%s. %d out of %d expected pods are ready", sts.Namespace, sts.Name, sts.Status.ReadyReplicas, replicas)
469+
slog.Info("StatefulSet is ready",
470+
"namespace", sts.Namespace,
471+
"name", sts.Name,
472+
"readyReplicas", sts.Status.ReadyReplicas,
473+
"expectedReplicas", replicas)
429474
return true
430475
}
431476

432477
func (c *ReadyChecker) replicationControllerReady(rc *corev1.ReplicationController) bool {
433478
// Verify the generation observed by the replicationController controller matches the spec generation
434479
if rc.Status.ObservedGeneration != rc.ObjectMeta.Generation {
435-
c.log("ReplicationController is not ready: %s/%s. observedGeneration (%d) does not match spec generation (%d).", rc.Namespace, rc.Name, rc.Status.ObservedGeneration, rc.ObjectMeta.Generation)
480+
slog.Info("ReplicationController is not ready: observedGeneration does not match spec generation",
481+
"namespace", rc.Namespace,
482+
"name", rc.Name,
483+
"observedGeneration", rc.Status.ObservedGeneration,
484+
"specGeneration", rc.ObjectMeta.Generation)
436485
return false
437486
}
438487
return true
@@ -441,7 +490,11 @@ func (c *ReadyChecker) replicationControllerReady(rc *corev1.ReplicationControll
441490
func (c *ReadyChecker) replicaSetReady(rs *appsv1.ReplicaSet) bool {
442491
// Verify the generation observed by the replicaSet controller matches the spec generation
443492
if rs.Status.ObservedGeneration != rs.ObjectMeta.Generation {
444-
c.log("ReplicaSet is not ready: %s/%s. observedGeneration (%d) does not match spec generation (%d).", rs.Namespace, rs.Name, rs.Status.ObservedGeneration, rs.ObjectMeta.Generation)
493+
slog.Info("ReplicaSet is not ready: observedGeneration does not match spec generation",
494+
"namespace", rs.Namespace,
495+
"name", rs.Name,
496+
"observedGeneration", rs.Status.ObservedGeneration,
497+
"specGeneration", rs.ObjectMeta.Generation)
445498
return false
446499
}
447500
return true

0 commit comments

Comments
 (0)