Skip to content

Commit

Permalink
Improve deploy --cancel output
Browse files Browse the repository at this point in the history
Make the deploy --cancel output more accurate and informative.
  • Loading branch information
ironcladlou committed Sep 14, 2015
1 parent 1e58d08 commit 21fb856
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/cmd/cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"io"
"strconv"
"strings"
"time"

"github.com/docker/docker/pkg/units"
"github.com/spf13/cobra"

kapi "k8s.io/kubernetes/pkg/api"
Expand Down Expand Up @@ -284,14 +286,17 @@ func (o *DeployOptions) cancel(config *deployapi.DeploymentConfig, out io.Writer
return err
}
if len(deployments.Items) == 0 {
fmt.Fprintln(out, "no deployments found to cancel")
fmt.Fprintf(out, "there have been no deployments for %s/%s\n", config.Namespace, config.Name)
return nil
}
failedCancellations := []string{}
anyCancelled := false
var latest *kapi.ReplicationController
for _, deployment := range deployments.Items {
status := deployutil.DeploymentStatusFor(&deployment)

if deployment.Name == deployutil.LatestDeploymentNameForConfig(config) {
latest = &deployment
}
switch status {
case deployapi.DeploymentStatusNew,
deployapi.DeploymentStatusPending,
Expand All @@ -317,7 +322,18 @@ func (o *DeployOptions) cancel(config *deployapi.DeploymentConfig, out io.Writer
return fmt.Errorf("couldn't cancel deployment %s", strings.Join(failedCancellations, ", "))
}
if !anyCancelled {
fmt.Fprintln(out, "no active deployments to cancel")
if latest == nil {
// TODO: this could mean that a new deployment is forthcoming but hasn't
// yet been created; might not be worth trying to express in this
// context.
fmt.Fprintf(out, "no deployments are in progress\n")
} else {
timeAt := strings.ToLower(units.HumanDuration(time.Now().Sub(latest.CreationTimestamp.Time)))
fmt.Fprintf(out, "no deployments are in progress (latest deployment #%d %s %s ago)\n",
deployutil.DeploymentVersionFor(latest),
strings.ToLower(string(deployutil.DeploymentStatusFor(latest))),
timeAt)
}
}
return nil
}
Expand Down

0 comments on commit 21fb856

Please sign in to comment.