Skip to content

Commit

Permalink
Merge pull request #3072 from tejal29/add_deploy_healthcheck_events
Browse files Browse the repository at this point in the history
add event api integration for deploy health check
  • Loading branch information
tejal29 authored Oct 18, 2019
2 parents 28eca83 + 0cc0cdc commit ec51375
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/skaffold/deploy/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/resource"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
pkgkubernetes "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
)
Expand All @@ -58,6 +59,7 @@ type counter struct {

func StatusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx *runcontext.RunContext, out io.Writer) error {
client, err := pkgkubernetes.Client()
event.StatusCheckEventStarted()
if err != nil {
return errors.Wrap(err, "getting Kubernetes client")
}
Expand Down Expand Up @@ -136,9 +138,12 @@ func pollResourceStatus(ctx context.Context, runCtx *runcontext.RunContext, r Re

func getSkaffoldDeployStatus(c *counter) error {
if c.failed == 0 {
event.StatusCheckEventSucceeded()
return nil
}
return fmt.Errorf("%d/%d deployment(s) failed", c.failed, c.total)
err := fmt.Errorf("%d/%d deployment(s) failed", c.failed, c.total)
event.StatusCheckEventFailed(err)
return err
}

func getDeadline(d int) time.Duration {
Expand All @@ -151,12 +156,14 @@ func getDeadline(d int) time.Duration {
func printStatusCheckSummary(out io.Writer, r Resource, pending int, total int) {
status := fmt.Sprintf("%s %s", tabHeader, r)
if err := r.Status().Error(); err != nil {
event.ResourceStatusCheckEventFailed(r.String(), err)
status = fmt.Sprintf("%s failed.%s Error: %s.",
status,
trimNewLine(getPendingMessage(pending, total)),
trimNewLine(err.Error()),
)
} else {
event.ResourceStatusCheckEventSucceeded(r.String())
status = fmt.Sprintf("%s is ready.%s", status, getPendingMessage(pending, total))
}
color.Default.Fprintln(out, status)
Expand Down Expand Up @@ -188,6 +195,7 @@ func printStatus(resources []Resource, out io.Writer) bool {
}
allResourcesCheckComplete = false
if str := r.ReportSinceLastUpdated(); str != "" {
event.ResourceStatusCheckEventUpdated(r.String(), str)
color.Default.Fprintln(out, tabHeader, trimNewLine(str))
}
}
Expand Down

0 comments on commit ec51375

Please sign in to comment.