Skip to content

Commit

Permalink
Add more debug info when the CI build fails
Browse files Browse the repository at this point in the history
Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs committed Feb 17, 2022
1 parent f529bd1 commit e0756ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions controllers/installation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (r *InstallationReconciler) Reconcile(ctx context.Context, req ctrl.Request
err := r.Get(ctx, req.NamespacedName, inst)
if err != nil {
if apierrors.IsNotFound(err) {
log.V(Log4Debug).Info("Reconciliation complete: Installation CRD is deleted.")
log.V(Log5Trace).Info("Reconciliation skipped: Installation CRD or one of its owned resources was deleted.")
return ctrl.Result{}, nil
}
return ctrl.Result{Requeue: false}, err
return ctrl.Result{}, err
}

log = log.WithValues("resourceVersion", inst.ResourceVersion, "generation", inst.Generation, "observedGeneration", inst.Status.ObservedGeneration)
Expand Down
27 changes: 26 additions & 1 deletion tests/integration/installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (

porterv1 "get.porter.sh/operator/api/v1"
"get.porter.sh/operator/controllers"
"github.com/carolynvs/magex/shx"
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"github.com/tidwall/pretty"
batchv1 "k8s.io/api/batch/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -80,7 +82,7 @@ var _ = Describe("Installation Lifecycle", func() {
func waitForPorter(ctx context.Context, inst *porterv1.Installation, msg string) error {
Log("%s: %s/%s", msg, inst.Namespace, inst.Name)
key := client.ObjectKey{Namespace: inst.Namespace, Name: inst.Name}
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
ctx, cancel := context.WithTimeout(ctx, 120*time.Second)
defer cancel()
for {
select {
Expand All @@ -100,10 +102,14 @@ func waitForPorter(ctx context.Context, inst *porterv1.Installation, msg string)
// Check if the latest change has been processed
if inst.Generation == inst.Status.ObservedGeneration {
if apimeta.IsStatusConditionTrue(inst.Status.Conditions, string(porterv1.ConditionComplete)) {
// Grab some extra info to help with debugging
debugFailedInstallation(ctx, inst)
return nil
}

if apimeta.IsStatusConditionTrue(inst.Status.Conditions, string(porterv1.ConditionFailed)) {
// Grab some extra info to help with debugging
debugFailedInstallation(ctx, inst)
return errors.New("porter did not run successfully")
}
}
Expand All @@ -114,6 +120,25 @@ func waitForPorter(ctx context.Context, inst *porterv1.Installation, msg string)
}
}

func debugFailedInstallation(ctx context.Context, inst *porterv1.Installation) {
actionKey := client.ObjectKey{Name: inst.Status.Action.Name, Namespace: inst.Namespace}
action := &porterv1.AgentAction{}
if err := k8sClient.Get(ctx, actionKey, action); err != nil {
Log(errors.Wrap(err, "could not retrieve the Installation's AgentAction to troubleshoot").Error())
return
}

jobKey := client.ObjectKey{Name: action.Status.Job.Name, Namespace: action.Namespace}
job := &batchv1.Job{}
if err := k8sClient.Get(ctx, jobKey, job); err != nil {
Log(errors.Wrap(err, "could not retrieve the Installation's Job to troubleshoot").Error())
return
}

shx.Command("kubectl", "logs", "-n="+job.Namespace, "job/"+job.Name).
Env("KUBECONFIG=" + "../../kind.config").RunV()
}

func waitForInstallationDeleted(ctx context.Context, inst *porterv1.Installation) error {
Log("Waiting for installation to finish deleting: %s/%s", inst.Namespace, inst.Name)
key := client.ObjectKey{Namespace: inst.Namespace, Name: inst.Name}
Expand Down

0 comments on commit e0756ad

Please sign in to comment.