Skip to content

Commit ffdfa4c

Browse files
committed
Display current step in the canary deployment
Signed-off-by: João Pereira <[email protected]>
1 parent 5c12502 commit ffdfa4c

File tree

9 files changed

+105
-28
lines changed

9 files changed

+105
-28
lines changed

actor/v7action/deployment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (actor Actor) GetLatestActiveDeploymentForApp(appGUID string) (resources.De
2929
return resources.Deployment{}, Warnings(warnings), actionerror.ActiveDeploymentNotFoundError{}
3030
}
3131

32-
return resources.Deployment(ccDeployments[0]), Warnings(warnings), nil
32+
return ccDeployments[0], Warnings(warnings), nil
3333
}
3434

3535
func (actor Actor) CancelDeployment(deploymentGUID string) (Warnings, error) {

api/cloudcontroller/ccv3/application_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ var _ = Describe("Application", func() {
217217
})
218218

219219
When("lifecycle type buildpack is provided", func() {
220-
221220
When("other buildpacks are provided", func() {
222221
BeforeEach(func() {
223222
appBytes = []byte(`{"lifecycle":{"data":{"buildpacks":["some-buildpack"]},"type":"buildpack"}}`)

api/cloudcontroller/ccv3/deployment_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,13 @@ var _ = Describe("Deployment", func() {
339339
"strategy": "canary",
340340
"status": {
341341
"value": "FINALIZED",
342-
"reason": "SUPERSEDED"
342+
"reason": "SUPERSEDED",
343+
"canary": {
344+
"steps": {
345+
"current": 4,
346+
"total": 5
347+
}
348+
}
343349
},
344350
"droplet": {
345351
"guid": "some-droplet-guid"
@@ -374,6 +380,8 @@ var _ = Describe("Deployment", func() {
374380
Expect(deployment.StatusValue).To(Equal(constant.DeploymentStatusValueFinalized))
375381
Expect(deployment.StatusReason).To(Equal(constant.DeploymentStatusReasonSuperseded))
376382
Expect(deployment.Strategy).To(Equal(constant.DeploymentStrategyCanary))
383+
Expect(deployment.CanaryStatus.Steps.CurrentStep).To(Equal(4))
384+
Expect(deployment.CanaryStatus.Steps.TotalSteps).To(Equal(5))
377385
})
378386
})
379387

command/v7/shared/app_summary_displayer.go

+7
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,17 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
158158
if maxInFlight > 0 {
159159
maxInFlightRow = append(maxInFlightRow, display.UI.TranslateText("max-in-flight:"), strconv.Itoa(maxInFlight))
160160
}
161+
var canaryStepsRow []string
162+
if summary.Deployment.CanaryStatus.Steps.TotalSteps > 0 {
163+
stepStatus := summary.Deployment.CanaryStatus.Steps
164+
canaryStepsRow = []string{display.UI.TranslateText("canary-steps:"), fmt.Sprintf("%d/%d", stepStatus.CurrentStep, stepStatus.TotalSteps)}
165+
166+
}
161167

162168
keyValueTable := [][]string{
163169
{display.UI.TranslateText("strategy:"), strings.ToLower(string(summary.Deployment.Strategy))},
164170
maxInFlightRow,
171+
canaryStepsRow,
165172
}
166173

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

command/v7/shared/app_summary_displayer_test.go

+49-15
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,15 @@ var _ = Describe("app summary displayer", func() {
887887
BeforeEach(func() {
888888
summary = v7action.DetailedApplicationSummary{
889889
Deployment: resources.Deployment{
890-
Strategy: constant.DeploymentStrategyCanary,
891-
StatusValue: constant.DeploymentStatusValueActive,
892-
StatusReason: constant.DeploymentStatusReasonDeploying,
890+
Strategy: constant.DeploymentStrategyCanary,
891+
StatusValue: constant.DeploymentStatusValueActive,
892+
StatusReason: constant.DeploymentStatusReasonDeploying,
893+
CanaryStatus: resources.CanaryStatus{
894+
Steps: resources.CanaryStepStatus{
895+
CurrentStep: 2,
896+
TotalSteps: 5,
897+
},
898+
},
893899
LastStatusChange: LastStatusChangeTimeString,
894900
Options: resources.DeploymentOpts{
895901
MaxInFlight: 2,
@@ -907,15 +913,25 @@ var _ = Describe("app summary displayer", func() {
907913
It("displays max-in-flight value", func() {
908914
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
909915
})
916+
917+
It("displays the step the deployment is currently in", func() {
918+
Expect(testUI.Out).To(Say(`canary-steps: 2/5`))
919+
})
910920
})
911921

912922
When("max-in-flight value is default", func() {
913923
BeforeEach(func() {
914924
summary = v7action.DetailedApplicationSummary{
915925
Deployment: resources.Deployment{
916-
Strategy: constant.DeploymentStrategyCanary,
917-
StatusValue: constant.DeploymentStatusValueActive,
918-
StatusReason: constant.DeploymentStatusReasonDeploying,
926+
Strategy: constant.DeploymentStrategyCanary,
927+
StatusValue: constant.DeploymentStatusValueActive,
928+
StatusReason: constant.DeploymentStatusReasonDeploying,
929+
CanaryStatus: resources.CanaryStatus{
930+
Steps: resources.CanaryStepStatus{
931+
CurrentStep: 2,
932+
TotalSteps: 5,
933+
},
934+
},
919935
LastStatusChange: LastStatusChangeTimeString,
920936
Options: resources.DeploymentOpts{
921937
MaxInFlight: maxInFlightDefaultValue,
@@ -943,9 +959,15 @@ var _ = Describe("app summary displayer", func() {
943959
},
944960
},
945961
Deployment: resources.Deployment{
946-
Strategy: constant.DeploymentStrategyCanary,
947-
StatusValue: constant.DeploymentStatusValueActive,
948-
StatusReason: constant.DeploymentStatusReasonPaused,
962+
Strategy: constant.DeploymentStrategyCanary,
963+
StatusValue: constant.DeploymentStatusValueActive,
964+
StatusReason: constant.DeploymentStatusReasonPaused,
965+
CanaryStatus: resources.CanaryStatus{
966+
Steps: resources.CanaryStepStatus{
967+
CurrentStep: 2,
968+
TotalSteps: 5,
969+
},
970+
},
949971
LastStatusChange: LastStatusChangeTimeString,
950972
Options: resources.DeploymentOpts{
951973
MaxInFlight: 2,
@@ -974,9 +996,15 @@ var _ = Describe("app summary displayer", func() {
974996
},
975997
},
976998
Deployment: resources.Deployment{
977-
Strategy: constant.DeploymentStrategyCanary,
978-
StatusValue: constant.DeploymentStatusValueActive,
979-
StatusReason: constant.DeploymentStatusReasonPaused,
999+
Strategy: constant.DeploymentStrategyCanary,
1000+
StatusValue: constant.DeploymentStatusValueActive,
1001+
StatusReason: constant.DeploymentStatusReasonPaused,
1002+
CanaryStatus: resources.CanaryStatus{
1003+
Steps: resources.CanaryStepStatus{
1004+
CurrentStep: 2,
1005+
TotalSteps: 5,
1006+
},
1007+
},
9801008
LastStatusChange: LastStatusChangeTimeString,
9811009
Options: resources.DeploymentOpts{
9821010
MaxInFlight: maxInFlightDefaultValue,
@@ -999,9 +1027,15 @@ var _ = Describe("app summary displayer", func() {
9991027
BeforeEach(func() {
10001028
summary = v7action.DetailedApplicationSummary{
10011029
Deployment: resources.Deployment{
1002-
Strategy: constant.DeploymentStrategyCanary,
1003-
StatusValue: constant.DeploymentStatusValueActive,
1004-
StatusReason: constant.DeploymentStatusReasonCanceling,
1030+
Strategy: constant.DeploymentStrategyCanary,
1031+
StatusValue: constant.DeploymentStatusValueActive,
1032+
StatusReason: constant.DeploymentStatusReasonCanceling,
1033+
CanaryStatus: resources.CanaryStatus{
1034+
Steps: resources.CanaryStepStatus{
1035+
CurrentStep: 2,
1036+
TotalSteps: 5,
1037+
},
1038+
},
10051039
LastStatusChange: LastStatusChangeTimeString,
10061040
Options: resources.DeploymentOpts{
10071041
MaxInFlight: 2,

integration/v7/isolated/app_command_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ applications:
285285
session1 := helpers.CF("app", appName)
286286
Eventually(session1).Should(Say("Active deployment with status PAUSED"))
287287
Eventually(session1).Should(Say("strategy: canary"))
288+
Expect(session1).To(Say("canary-steps: 0/1"))
288289
Eventually(session1).Should(Exit(0))
289290
})
290291
})

integration/v7/isolated/continue_deployment_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,29 @@ var _ = Describe("Continue Deployment", func() {
8989

9090
Context("when the continue is successful", func() {
9191
When("There is a canary deployment", func() {
92-
It("succeeds", func() {
93-
helpers.WithHelloWorldApp(func(appDir string) {
94-
helpers.CF("push", appName, "-p", appDir, "--strategy=canary").Wait()
92+
When("instance steps are provided", func() {
93+
It("displays the number of steps", func() {
94+
helpers.WithHelloWorldApp(func(appDir string) {
95+
helpers.CF("push", appName, "-p", appDir, "--strategy=canary", "--instance-steps 10,20,30,70", "-i 5").Wait()
96+
})
97+
98+
session := helpers.CF("continue-deployment", appName)
99+
Eventually(session).Should(Say("canary-steps: 1/4"))
100+
Eventually(session).Should(Exit(0))
95101
})
102+
})
103+
104+
When("instance steps are NOT provided", func() {
105+
It("succeeds", func() {
106+
helpers.WithHelloWorldApp(func(appDir string) {
107+
helpers.CF("push", appName, "-p", appDir, "--strategy=canary").Wait()
108+
})
96109

97-
session := helpers.CF("continue-deployment", appName)
98-
Eventually(session).Should(Say(fmt.Sprintf("Continuing deployment for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
99-
Eventually(session).Should(Say(fmt.Sprintf(`TIP: Run 'cf app %s' to view app status.`, appName)))
100-
Eventually(session).Should(Exit(0))
110+
session := helpers.CF("continue-deployment", appName)
111+
Eventually(session).Should(Say(fmt.Sprintf("Continuing deployment for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
112+
Eventually(session).Should(Say(fmt.Sprintf(`TIP: Run 'cf app %s' to view app status.`, appName)))
113+
Eventually(session).Should(Exit(0))
114+
})
101115
})
102116
})
103117
})

integration/v7/push/canary_push_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = Describe("push with --strategy canary", func() {
3434
It("pushes the app and creates a new deployment and notes the max-in-flight value", func() {
3535
helpers.WithHelloWorldApp(func(appDir string) {
3636
session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
37-
PushCommandName, appName, "--strategy", "canary",
37+
PushCommandName, appName, "--strategy", "canary", "--instance-steps=10,60",
3838
)
3939

4040
Eventually(session).Should(Exit(0))
@@ -55,6 +55,7 @@ var _ = Describe("push with --strategy canary", func() {
5555
Expect(session).To(Say("Active deployment with status PAUSED"))
5656
Expect(session).To(Say("strategy: canary"))
5757
Expect(session).To(Say("max-in-flight: 1"))
58+
Expect(session).To(Say("canary-steps: 1/2"))
5859
Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName))
5960
Expect(session).To(Exit(0))
6061
})
@@ -86,6 +87,7 @@ var _ = Describe("push with --strategy canary", func() {
8687
Expect(session).To(Say("Active deployment with status PAUSED"))
8788
Expect(session).To(Say("strategy: canary"))
8889
Expect(session).To(Say("max-in-flight: 2"))
90+
Expect(session).To(Say("canary-steps: 0/1"))
8991
Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName))
9092
Expect(session).To(Exit(0))
9193
})

resources/deployment_resource.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Deployment struct {
1212
State constant.DeploymentState
1313
StatusValue constant.DeploymentStatusValue
1414
StatusReason constant.DeploymentStatusReason
15+
CanaryStatus CanaryStatus
1516
LastStatusChange string
1617
Options DeploymentOpts
1718
RevisionGUID string
@@ -78,6 +79,15 @@ func (d Deployment) MarshalJSON() ([]byte, error) {
7879
return json.Marshal(ccDeployment)
7980
}
8081

82+
type CanaryStepStatus struct {
83+
CurrentStep int `json:"current"`
84+
TotalSteps int `json:"total"`
85+
}
86+
87+
type CanaryStatus struct {
88+
Steps CanaryStepStatus `json:"steps"`
89+
}
90+
8191
// UnmarshalJSON helps unmarshal a Cloud Controller Deployment response.
8292
func (d *Deployment) UnmarshalJSON(data []byte) error {
8393
var ccDeployment struct {
@@ -89,8 +99,9 @@ func (d *Deployment) UnmarshalJSON(data []byte) error {
8999
Details struct {
90100
LastStatusChange string `json:"last_status_change"`
91101
}
92-
Value constant.DeploymentStatusValue `json:"value"`
93-
Reason constant.DeploymentStatusReason `json:"reason"`
102+
Value constant.DeploymentStatusValue `json:"value"`
103+
Reason constant.DeploymentStatusReason `json:"reason"`
104+
CanaryStatus CanaryStatus `json:"canary,omitempty"`
94105
} `json:"status"`
95106
Droplet Droplet `json:"droplet,omitempty"`
96107
NewProcesses []Process `json:"new_processes,omitempty"`
@@ -109,6 +120,7 @@ func (d *Deployment) UnmarshalJSON(data []byte) error {
109120
d.State = ccDeployment.State
110121
d.StatusValue = ccDeployment.Status.Value
111122
d.StatusReason = ccDeployment.Status.Reason
123+
d.CanaryStatus = ccDeployment.Status.CanaryStatus
112124
d.LastStatusChange = ccDeployment.Status.Details.LastStatusChange
113125
d.DropletGUID = ccDeployment.Droplet.GUID
114126
d.NewProcesses = ccDeployment.NewProcesses

0 commit comments

Comments
 (0)