Skip to content

Commit

Permalink
馃尡 [e2e] add debug output for deployment failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Aug 7, 2020
1 parent 6b6c8e0 commit 9455243
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test/framework/alltypes_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package framework

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -172,3 +173,12 @@ func CreateRelatedResources(ctx context.Context, input CreateRelatedResourcesInp
}, intervals...).Should(Succeed())
}
}

// PrettyPrint returns a formatted JSON version of the object given.
func PrettyPrint(v interface{}) string {
b, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err.Error()
}
return string(b)
}
18 changes: 16 additions & 2 deletions test/framework/deployment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo"
Expand All @@ -49,8 +50,8 @@ type WaitForDeploymentsAvailableInput struct {
// This can be used to check if Cluster API controllers installed in the management cluster are working.
func WaitForDeploymentsAvailable(ctx context.Context, input WaitForDeploymentsAvailableInput, intervals ...interface{}) {
By(fmt.Sprintf("waiting for deployment %s/%s to be available", input.Deployment.GetNamespace(), input.Deployment.GetName()))
deployment := &appsv1.Deployment{}
Eventually(func() bool {
deployment := &appsv1.Deployment{}
key := client.ObjectKey{
Namespace: input.Deployment.GetNamespace(),
Name: input.Deployment.GetName(),
Expand All @@ -65,7 +66,20 @@ func WaitForDeploymentsAvailable(ctx context.Context, input WaitForDeploymentsAv
}
return false

}, intervals...).Should(BeTrue(), "Deployment %s/%s failed to get status.Available = True condition", input.Deployment.GetNamespace(), input.Deployment.GetName())
}, intervals...).Should(BeTrue(), func() string { return DescribeFailedDeployment(input, deployment) })
}

// DescribeFailedDeployment returns detailed output to help debug a deployment failure in e2e.
func DescribeFailedDeployment(input WaitForDeploymentsAvailableInput, deployment *appsv1.Deployment) string {
b := strings.Builder{}
b.WriteString(fmt.Sprintf("Deployment %s/%s failed to get status.Available = True condition",
input.Deployment.GetNamespace(), input.Deployment.GetName()))
if deployment == nil {
b.WriteString("\nDeployment: nil\n")
} else {
b.WriteString(fmt.Sprintf("\nDeployment:\n%s\n", PrettyPrint(deployment)))
}
return b.String()
}

// WatchDeploymentLogsInput is the input for WatchDeploymentLogs.
Expand Down

0 comments on commit 9455243

Please sign in to comment.