Skip to content

Commit

Permalink
Print container status on reconcile timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Oct 26, 2023
1 parent efc206d commit bcc8bad
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -225,7 +226,7 @@ func reconcileNs(cfg config.Config) error {
if err != nil {
return err
}
if *d.Spec.Replicas == replicas {
if d.Status.ReadyReplicas == replicas {
return nil
}
deployment.Spec.Replicas = &replicas
Expand All @@ -243,9 +244,11 @@ func reconcileNs(cfg config.Config) error {

func waitForDeployment(ns, deployment string, maxWaitTimeout time.Duration) error {
var errMsg string
var dep *appsv1.Deployment
var err error
log.Infof("Waiting for replicas from deployment %s in ns %s to be ready", deployment, ns)
err := wait.PollUntilContextTimeout(context.TODO(), time.Second, maxWaitTimeout, true, func(ctx context.Context) (bool, error) {
dep, err := clientSet.AppsV1().Deployments(ns).Get(context.TODO(), deployment, metav1.GetOptions{})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, maxWaitTimeout, true, func(ctx context.Context) (bool, error) {
dep, err = clientSet.AppsV1().Deployments(ns).Get(context.TODO(), deployment, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand All @@ -259,6 +262,17 @@ func waitForDeployment(ns, deployment string, maxWaitTimeout time.Duration) erro
})
if err != nil && errMsg != "" {
log.Error(errMsg)
failedPods, _ := clientSet.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{
FieldSelector: "status.phase=Pending",
LabelSelector: labels.SelectorFromSet(dep.Spec.Selector.MatchLabels).String(),
})
for _, pod := range failedPods.Items {
for _, cs := range pod.Status.ContainerStatuses {
if cs.State.Waiting != nil {
log.Errorf("%v: %v", pod.Name, cs.State.Waiting.Message)
}
}
}
}
return err
}

0 comments on commit bcc8bad

Please sign in to comment.