Skip to content

Commit 18d4277

Browse files
joaopapereiraSamze
andauthored
[main] Discover canary steps status (#3393)
* Fix error message for push command Signed-off-by: João Pereira <joao.pereira@broadcom.com> * Display current step in the canary deployment Signed-off-by: João Pereira <joao.pereira@broadcom.com> * Fix canary steps tests * Fix continue test instance-step command * Fix integration test for canary --------- Signed-off-by: João Pereira <joao.pereira@broadcom.com> Co-authored-by: Sam Gunaratne <385176+Samze@users.noreply.github.com> Co-authored-by: Sam Gunaratne <sgunaratne@vmware.com>
1 parent c424a04 commit 18d4277

File tree

11 files changed

+109
-30
lines changed

11 files changed

+109
-30
lines changed

actor/v7action/deployment.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 9 additions & 1 deletion
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/push_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func (cmd PushCommand) ValidateFlags() error {
573573
case cmd.Strategy.Name != constant.DeploymentStrategyDefault && cmd.MaxInFlight != nil && *cmd.MaxInFlight < 1:
574574
return translatableerror.IncorrectUsageError{Message: "--max-in-flight must be greater than or equal to 1"}
575575
case len(cmd.InstanceSteps) > 0 && cmd.Strategy.Name != constant.DeploymentStrategyCanary:
576-
return translatableerror.ArgumentCombinationError{Args: []string{"--instance-steps", "--strategy=canary"}}
576+
return translatableerror.ArgumentCombinationError{Args: []string{"--instance-steps", "--strategy=rolling or --strategy not provided"}}
577577
case len(cmd.InstanceSteps) > 0 && !cmd.validateInstanceSteps():
578578
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
579579
}

command/v7/push_command_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ var _ = Describe("push Command", func() {
14381438
},
14391439
translatableerror.ArgumentCombinationError{
14401440
Args: []string{
1441-
"--instance-steps", "--strategy=canary",
1441+
"--instance-steps", "--strategy=rolling or --strategy not provided",
14421442
}}),
14431443
)
14441444
})

command/v7/shared/app_summary_displayer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,17 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
168168
if maxInFlight > 0 {
169169
maxInFlightRow = append(maxInFlightRow, display.UI.TranslateText("max-in-flight:"), strconv.Itoa(maxInFlight))
170170
}
171+
var canaryStepsRow []string
172+
if summary.Deployment.CanaryStatus.Steps.TotalSteps > 0 {
173+
stepStatus := summary.Deployment.CanaryStatus.Steps
174+
canaryStepsRow = []string{display.UI.TranslateText("canary-steps:"), fmt.Sprintf("%d/%d", stepStatus.CurrentStep, stepStatus.TotalSteps)}
175+
176+
}
171177

172178
keyValueTable := [][]string{
173179
{display.UI.TranslateText("strategy:"), strings.ToLower(string(summary.Deployment.Strategy))},
174180
maxInFlightRow,
181+
canaryStepsRow,
175182
}
176183

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

command/v7/shared/app_summary_displayer_test.go

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,15 @@ var _ = Describe("app summary displayer", func() {
896896
BeforeEach(func() {
897897
summary = v7action.DetailedApplicationSummary{
898898
Deployment: resources.Deployment{
899-
Strategy: constant.DeploymentStrategyCanary,
900-
StatusValue: constant.DeploymentStatusValueActive,
901-
StatusReason: constant.DeploymentStatusReasonDeploying,
899+
Strategy: constant.DeploymentStrategyCanary,
900+
StatusValue: constant.DeploymentStatusValueActive,
901+
StatusReason: constant.DeploymentStatusReasonDeploying,
902+
CanaryStatus: resources.CanaryStatus{
903+
Steps: resources.CanaryStepStatus{
904+
CurrentStep: 2,
905+
TotalSteps: 5,
906+
},
907+
},
902908
LastStatusChange: LastStatusChangeTimeString,
903909
Options: resources.DeploymentOpts{
904910
MaxInFlight: 2,
@@ -916,15 +922,25 @@ var _ = Describe("app summary displayer", func() {
916922
It("displays max-in-flight value", func() {
917923
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
918924
})
925+
926+
It("displays the step the deployment is currently in", func() {
927+
Expect(testUI.Out).To(Say(`canary-steps: 2/5`))
928+
})
919929
})
920930

921931
When("max-in-flight value is default", func() {
922932
BeforeEach(func() {
923933
summary = v7action.DetailedApplicationSummary{
924934
Deployment: resources.Deployment{
925-
Strategy: constant.DeploymentStrategyCanary,
926-
StatusValue: constant.DeploymentStatusValueActive,
927-
StatusReason: constant.DeploymentStatusReasonDeploying,
935+
Strategy: constant.DeploymentStrategyCanary,
936+
StatusValue: constant.DeploymentStatusValueActive,
937+
StatusReason: constant.DeploymentStatusReasonDeploying,
938+
CanaryStatus: resources.CanaryStatus{
939+
Steps: resources.CanaryStepStatus{
940+
CurrentStep: 2,
941+
TotalSteps: 5,
942+
},
943+
},
928944
LastStatusChange: LastStatusChangeTimeString,
929945
Options: resources.DeploymentOpts{
930946
MaxInFlight: maxInFlightDefaultValue,
@@ -952,9 +968,15 @@ var _ = Describe("app summary displayer", func() {
952968
},
953969
},
954970
Deployment: resources.Deployment{
955-
Strategy: constant.DeploymentStrategyCanary,
956-
StatusValue: constant.DeploymentStatusValueActive,
957-
StatusReason: constant.DeploymentStatusReasonPaused,
971+
Strategy: constant.DeploymentStrategyCanary,
972+
StatusValue: constant.DeploymentStatusValueActive,
973+
StatusReason: constant.DeploymentStatusReasonPaused,
974+
CanaryStatus: resources.CanaryStatus{
975+
Steps: resources.CanaryStepStatus{
976+
CurrentStep: 2,
977+
TotalSteps: 5,
978+
},
979+
},
958980
LastStatusChange: LastStatusChangeTimeString,
959981
Options: resources.DeploymentOpts{
960982
MaxInFlight: 2,
@@ -983,9 +1005,15 @@ var _ = Describe("app summary displayer", func() {
9831005
},
9841006
},
9851007
Deployment: resources.Deployment{
986-
Strategy: constant.DeploymentStrategyCanary,
987-
StatusValue: constant.DeploymentStatusValueActive,
988-
StatusReason: constant.DeploymentStatusReasonPaused,
1008+
Strategy: constant.DeploymentStrategyCanary,
1009+
StatusValue: constant.DeploymentStatusValueActive,
1010+
StatusReason: constant.DeploymentStatusReasonPaused,
1011+
CanaryStatus: resources.CanaryStatus{
1012+
Steps: resources.CanaryStepStatus{
1013+
CurrentStep: 2,
1014+
TotalSteps: 5,
1015+
},
1016+
},
9891017
LastStatusChange: LastStatusChangeTimeString,
9901018
Options: resources.DeploymentOpts{
9911019
MaxInFlight: maxInFlightDefaultValue,
@@ -1008,9 +1036,15 @@ var _ = Describe("app summary displayer", func() {
10081036
BeforeEach(func() {
10091037
summary = v7action.DetailedApplicationSummary{
10101038
Deployment: resources.Deployment{
1011-
Strategy: constant.DeploymentStrategyCanary,
1012-
StatusValue: constant.DeploymentStatusValueActive,
1013-
StatusReason: constant.DeploymentStatusReasonCanceling,
1039+
Strategy: constant.DeploymentStrategyCanary,
1040+
StatusValue: constant.DeploymentStatusValueActive,
1041+
StatusReason: constant.DeploymentStatusReasonCanceling,
1042+
CanaryStatus: resources.CanaryStatus{
1043+
Steps: resources.CanaryStepStatus{
1044+
CurrentStep: 2,
1045+
TotalSteps: 5,
1046+
},
1047+
},
10141048
LastStatusChange: LastStatusChangeTimeString,
10151049
Options: resources.DeploymentOpts{
10161050
MaxInFlight: 2,

integration/v7/isolated/app_command_test.go

Lines changed: 1 addition & 0 deletions
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: 1/1"))
288289
Eventually(session1).Should(Exit(0))
289290
})
290291
})

integration/v7/isolated/continue_deployment_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,31 @@ 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("app", appName)
99+
Eventually(session).Should(Say("canary-steps: 1/4"))
100+
session = helpers.CF("continue-deployment", appName)
101+
Eventually(session).Should(Say("canary-steps: 2/4"))
102+
Eventually(session).Should(Exit(0))
95103
})
104+
})
105+
106+
When("instance steps are NOT provided", func() {
107+
It("succeeds", func() {
108+
helpers.WithHelloWorldApp(func(appDir string) {
109+
helpers.CF("push", appName, "-p", appDir, "--strategy=canary").Wait()
110+
})
96111

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))
112+
session := helpers.CF("continue-deployment", appName)
113+
Eventually(session).Should(Say(fmt.Sprintf("Continuing deployment for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
114+
Eventually(session).Should(Say(fmt.Sprintf(`TIP: Run 'cf app %s' to view app status.`, appName)))
115+
Eventually(session).Should(Exit(0))
116+
})
101117
})
102118
})
103119
})

integration/v7/push/canary_push_test.go

Lines changed: 3 additions & 1 deletion
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: 1/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
})

0 commit comments

Comments
 (0)