Skip to content

Commit

Permalink
Always show max-in-flight value for active deployments [v8] (#3119)
Browse files Browse the repository at this point in the history
* Always show max-in-flight value for active deployments
- show deployment strategy value on its own line
* Make an active rolling deployment test more robust
  • Loading branch information
weresch committed Aug 19, 2024
1 parent 5dba014 commit 1d04f1e
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 107 deletions.
2 changes: 0 additions & 2 deletions api/cloudcontroller/ccv3/constant/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ const (
DeploymentStatusValueActive DeploymentStatusValue = "ACTIVE"
DeploymentStatusValueFinalized DeploymentStatusValue = "FINALIZED"
)

const DeploymentMaxInFlightDefaultValue int = 1
25 changes: 15 additions & 10 deletions command/v7/shared/app_summary_displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shared

import (
"fmt"
"strconv"
"strings"
"time"

Expand All @@ -13,8 +14,6 @@ import (
"code.cloudfoundry.org/cli/types"
"code.cloudfoundry.org/cli/util/ui"
log "github.com/sirupsen/logrus"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type AppSummaryDisplayer struct {
Expand Down Expand Up @@ -58,7 +57,7 @@ func (display AppSummaryDisplayer) AppDisplay(summary v7action.DetailedApplicati
}
}

display.UI.DisplayKeyValueTable("", keyValueTable, 3)
display.UI.DisplayKeyValueTable("", keyValueTable, ui.DefaultTableSpacePadding)

if summary.LifecycleType == constant.AppLifecycleTypeBuildpack {
display.displayBuildpackTable(summary.CurrentDroplet.Buildpacks)
Expand Down Expand Up @@ -153,7 +152,7 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
startCommandRow,
}

display.UI.DisplayKeyValueTable("", keyValueTable, 3)
display.UI.DisplayKeyValueTable("", keyValueTable, ui.DefaultTableSpacePadding)

if len(process.InstanceDetails) == 0 {
display.UI.DisplayText("There are no running instances of this process.")
Expand All @@ -166,11 +165,19 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
display.UI.DisplayNewline()
display.UI.DisplayText(display.getDeploymentStatusText(summary))

var maxInFlightRow []string
var maxInFlight = summary.Deployment.Options.MaxInFlight
if maxInFlight > 0 && maxInFlight != constant.DeploymentMaxInFlightDefaultValue {
display.UI.DisplayText(fmt.Sprintf("max-in-flight: %d", maxInFlight))
if maxInFlight > 0 {
maxInFlightRow = append(maxInFlightRow, display.UI.TranslateText("max-in-flight:"), strconv.Itoa(maxInFlight))
}

keyValueTable := [][]string{
{display.UI.TranslateText("strategy:"), strings.ToLower(string(summary.Deployment.Strategy))},
maxInFlightRow,
}

display.UI.DisplayKeyValueTable("", keyValueTable, ui.DefaultTableSpacePadding)

if summary.Deployment.Strategy == constant.DeploymentStrategyCanary && summary.Deployment.StatusReason == constant.DeploymentStatusReasonPaused {
display.UI.DisplayNewline()
display.UI.DisplayText(fmt.Sprintf("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", summary.Application.Name, summary.Application.Name))
Expand All @@ -181,13 +188,11 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
func (display AppSummaryDisplayer) getDeploymentStatusText(summary v7action.DetailedApplicationSummary) string {
var lastStatusChangeTime = display.getLastStatusChangeTime(summary)
if lastStatusChangeTime != "" {
return fmt.Sprintf("%s deployment currently %s (since %s)",
cases.Title(language.English, cases.NoLower).String(string(summary.Deployment.Strategy)),
return fmt.Sprintf("Active deployment with status %s (since %s)",
summary.Deployment.StatusReason,
lastStatusChangeTime)
} else {
return fmt.Sprintf("%s deployment currently %s.",
cases.Title(language.English, cases.NoLower).String(string(summary.Deployment.Strategy)),
return fmt.Sprintf("Active deployment with status %s.",
summary.Deployment.StatusReason)
}
}
Expand Down
93 changes: 40 additions & 53 deletions command/v7/shared/app_summary_displayer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package shared_test

import (
"fmt"
"time"

"code.cloudfoundry.org/cli/actor/v7action"
Expand All @@ -14,8 +13,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var _ = Describe("app summary displayer", func() {
Expand Down Expand Up @@ -679,11 +676,12 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: rolling`))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -703,11 +701,9 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: rolling`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
})
})

Expand All @@ -724,11 +720,9 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: rolling`))
Expect(testUI.Out).ToNot(Say(`max-in-flight`))
})
})

Expand All @@ -748,12 +742,13 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING`))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING`))
Expect(testUI.Out).NotTo(Say(`\(since`))
Expect(testUI.Out).To(Say(`strategy: rolling`))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -773,12 +768,10 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING`))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING`))
Expect(testUI.Out).NotTo(Say(`\(since`))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
Expect(testUI.Out).To(Say(`strategy: rolling`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
})
})
})
Expand All @@ -800,11 +793,12 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: rolling`))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -824,11 +818,9 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Rolling deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
Expect(testUI.Out).To(Say(`Active deployment with status CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: rolling`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
})
})
})
Expand All @@ -852,12 +844,13 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -877,12 +870,10 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status DEPLOYING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
})
})
})
Expand All @@ -909,12 +900,13 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently PAUSED \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status PAUSED \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).To(Say("Please run `cf continue-deployment foobar` to promote the canary deployment, or `cf cancel-deployment foobar` to rollback to the previous version."))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -939,13 +931,11 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently PAUSED \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status PAUSED \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
Expect(testUI.Out).To(Say("Please run `cf continue-deployment foobar` to promote the canary deployment, or `cf cancel-deployment foobar` to rollback to the previous version."))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
})
})
})

Expand All @@ -966,12 +956,13 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
})

It("displays max-in-flight value", func() {
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
})
})

Expand All @@ -991,13 +982,11 @@ var _ = Describe("app summary displayer", func() {
})

It("displays the message", func() {
Expect(testUI.Out).To(Say(`Canary deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`Active deployment with status CANCELING \(since %s\)`, dateTimeRegexPattern))
Expect(testUI.Out).To(Say(`strategy: canary`))
Expect(testUI.Out).To(Say(`max-in-flight: 1`))
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
})

It("does not display max-in-flight", func() {
Expect(testUI.Out).NotTo(Say(`max-in-flight`))
})
})
})
})
Expand All @@ -1015,9 +1004,7 @@ var _ = Describe("app summary displayer", func() {
})

It("does not display deployment info", func() {
Expect(testUI.Out).NotTo(Say(fmt.Sprintf("%s deployment currently %s",
cases.Title(language.English, cases.NoLower).String(string(summary.Deployment.Strategy)),
summary.Deployment.StatusReason)))
Expect(testUI.Out).NotTo(Say(`Active deployment with status`))
})

It("does not display max-in-flight", func() {
Expand Down
27 changes: 9 additions & 18 deletions integration/v7/isolated/app_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,26 +264,15 @@ applications:
When("the deployment strategy is rolling", func() {
When("the deployment is in progress", func() {
It("displays the message", func() {
session := helpers.CF("restart", appName, "--strategy", "rolling")

session1 := helpers.CF("app", appName)
Eventually(session1).Should(Say("Rolling deployment currently DEPLOYING"))
Eventually(session).Should(Exit(0))
Eventually(session1).Should(Exit(0))
})
})
When("the deployment is cancelled", func() {
It("displays the message", func() {
helpers.CF("restart", appName, "--strategy", "rolling")
Eventually(func() *Session {
return helpers.CF("cancel-deployment", appName).Wait()
}).Should(Exit(0))
restartSession := helpers.CF("restart", appName, "--strategy", "rolling")

Eventually(func(g Gomega) {
session := helpers.CF("app", appName).Wait()
g.Expect(session).Should(Say("Rolling deployment currently CANCELING"))
g.Expect(session).Should(Say("Active deployment with status DEPLOYING"))
g.Expect(session).Should(Say("strategy: rolling"))
g.Expect(session).Should(Exit(0))
}).Should(Succeed())
Eventually(restartSession).Should(Exit(0))
})
})
})
Expand All @@ -294,7 +283,8 @@ applications:
Eventually(helpers.CF("restart", appName, "--strategy", "canary")).Should(Exit(0))

session1 := helpers.CF("app", appName)
Eventually(session1).Should(Say("Canary deployment currently PAUSED"))
Eventually(session1).Should(Say("Active deployment with status PAUSED"))
Eventually(session1).Should(Say("strategy: canary"))
Eventually(session1).Should(Exit(0))
})
})
Expand All @@ -306,7 +296,8 @@ applications:

Eventually(func(g Gomega) {
session := helpers.CF("app", appName).Wait()
g.Expect(session).Should(Say("Canary deployment currently CANCELING"))
g.Expect(session).Should(Say("Active deployment with status CANCELING"))
g.Expect(session).Should(Say("strategy: canary"))
g.Expect(session).Should(Exit(0))
}).Should(Succeed())
})
Expand All @@ -324,7 +315,7 @@ applications:
It("does not display the message", func() {
session := helpers.CF("app", appName)
Eventually(session).Should(Exit(0))
Eventually(session).ShouldNot(Say(`\w+ deployment currently \w+`))
Eventually(session).ShouldNot(Say(`Active deployment with status \w+`))
})
})
})
Expand Down
10 changes: 6 additions & 4 deletions integration/v7/isolated/copy_source_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ var _ = Describe("copy-source command", func() {
Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username))
Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username))
Eventually(session).Should(Say("Waiting for app to deploy..."))
Eventually(session).Should(Say("Canary deployment currently PAUSED"))
Eventually(session).ShouldNot(Say("max-in-flight"))
Eventually(session).Should(Say("Active deployment with status PAUSED"))
Eventually(session).Should(Say("strategy: canary"))
Eventually(session).Should(Say("max-in-flight: 1"))
Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", targetAppName, targetAppName))
Eventually(session).Should(Exit(0))

Expand All @@ -408,8 +409,9 @@ var _ = Describe("copy-source command", func() {
Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username))
Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username))
Eventually(session).Should(Say("Waiting for app to deploy..."))
Eventually(session).Should(Say("Canary deployment currently PAUSED"))
Eventually(session).Should(Say("max-in-flight: 2"))
Eventually(session).Should(Say("Active deployment with status PAUSED"))
Eventually(session).Should(Say("strategy: canary"))
Eventually(session).Should(Say("max-in-flight: 2"))
Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", targetAppName, targetAppName))
Eventually(session).Should(Exit(0))

Expand Down
Loading

0 comments on commit 1d04f1e

Please sign in to comment.