Skip to content

Commit 4dd152f

Browse files
Samzejoaopapereira
andauthored
Discover canary steps status (#3393) (#3461)
* Fix error message for push command * Display current step in the canary deployment * Fix canary steps tests * Fix continue test instance-step command * Fix integration test for canary --------- Signed-off-by: João Pereira <[email protected]> Co-authored-by: João Pereira <[email protected]>
1 parent 0e8398e commit 4dd152f

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
@@ -579,7 +579,7 @@ func (cmd PushCommand) ValidateFlags() error {
579579
case cmd.Strategy.Name != constant.DeploymentStrategyDefault && cmd.MaxInFlight != nil && *cmd.MaxInFlight < 1:
580580
return translatableerror.IncorrectUsageError{Message: "--max-in-flight must be greater than or equal to 1"}
581581
case len(cmd.InstanceSteps) > 0 && cmd.Strategy.Name != constant.DeploymentStrategyCanary:
582-
return translatableerror.ArgumentCombinationError{Args: []string{"--instance-steps", "--strategy=canary"}}
582+
return translatableerror.ArgumentCombinationError{Args: []string{"--instance-steps", "--strategy=rolling or --strategy not provided"}}
583583
case len(cmd.InstanceSteps) > 0 && !cmd.validateInstanceSteps():
584584
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
585585
}

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
@@ -161,10 +161,17 @@ func (display AppSummaryDisplayer) displayProcessTable(summary v7action.Detailed
161161
if maxInFlight > 0 {
162162
maxInFlightRow = append(maxInFlightRow, display.UI.TranslateText("max-in-flight:"), strconv.Itoa(maxInFlight))
163163
}
164+
var canaryStepsRow []string
165+
if summary.Deployment.CanaryStatus.Steps.TotalSteps > 0 {
166+
stepStatus := summary.Deployment.CanaryStatus.Steps
167+
canaryStepsRow = []string{display.UI.TranslateText("canary-steps:"), fmt.Sprintf("%d/%d", stepStatus.CurrentStep, stepStatus.TotalSteps)}
168+
169+
}
164170

165171
keyValueTable := [][]string{
166172
{display.UI.TranslateText("strategy:"), strings.ToLower(string(summary.Deployment.Strategy))},
167173
maxInFlightRow,
174+
canaryStepsRow,
168175
}
169176

170177
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
@@ -848,9 +848,15 @@ var _ = Describe("app summary displayer", func() {
848848
BeforeEach(func() {
849849
summary = v7action.DetailedApplicationSummary{
850850
Deployment: resources.Deployment{
851-
Strategy: constant.DeploymentStrategyCanary,
852-
StatusValue: constant.DeploymentStatusValueActive,
853-
StatusReason: constant.DeploymentStatusReasonDeploying,
851+
Strategy: constant.DeploymentStrategyCanary,
852+
StatusValue: constant.DeploymentStatusValueActive,
853+
StatusReason: constant.DeploymentStatusReasonDeploying,
854+
CanaryStatus: resources.CanaryStatus{
855+
Steps: resources.CanaryStepStatus{
856+
CurrentStep: 2,
857+
TotalSteps: 5,
858+
},
859+
},
854860
LastStatusChange: LastStatusChangeTimeString,
855861
Options: resources.DeploymentOpts{
856862
MaxInFlight: 2,
@@ -868,15 +874,25 @@ var _ = Describe("app summary displayer", func() {
868874
It("displays max-in-flight value", func() {
869875
Expect(testUI.Out).To(Say(`max-in-flight: 2`))
870876
})
877+
878+
It("displays the step the deployment is currently in", func() {
879+
Expect(testUI.Out).To(Say(`canary-steps: 2/5`))
880+
})
871881
})
872882

873883
When("max-in-flight value is default", func() {
874884
BeforeEach(func() {
875885
summary = v7action.DetailedApplicationSummary{
876886
Deployment: resources.Deployment{
877-
Strategy: constant.DeploymentStrategyCanary,
878-
StatusValue: constant.DeploymentStatusValueActive,
879-
StatusReason: constant.DeploymentStatusReasonDeploying,
887+
Strategy: constant.DeploymentStrategyCanary,
888+
StatusValue: constant.DeploymentStatusValueActive,
889+
StatusReason: constant.DeploymentStatusReasonDeploying,
890+
CanaryStatus: resources.CanaryStatus{
891+
Steps: resources.CanaryStepStatus{
892+
CurrentStep: 2,
893+
TotalSteps: 5,
894+
},
895+
},
880896
LastStatusChange: LastStatusChangeTimeString,
881897
Options: resources.DeploymentOpts{
882898
MaxInFlight: maxInFlightDefaultValue,
@@ -904,9 +920,15 @@ var _ = Describe("app summary displayer", func() {
904920
},
905921
},
906922
Deployment: resources.Deployment{
907-
Strategy: constant.DeploymentStrategyCanary,
908-
StatusValue: constant.DeploymentStatusValueActive,
909-
StatusReason: constant.DeploymentStatusReasonPaused,
923+
Strategy: constant.DeploymentStrategyCanary,
924+
StatusValue: constant.DeploymentStatusValueActive,
925+
StatusReason: constant.DeploymentStatusReasonPaused,
926+
CanaryStatus: resources.CanaryStatus{
927+
Steps: resources.CanaryStepStatus{
928+
CurrentStep: 2,
929+
TotalSteps: 5,
930+
},
931+
},
910932
LastStatusChange: LastStatusChangeTimeString,
911933
Options: resources.DeploymentOpts{
912934
MaxInFlight: 2,
@@ -935,9 +957,15 @@ var _ = Describe("app summary displayer", func() {
935957
},
936958
},
937959
Deployment: resources.Deployment{
938-
Strategy: constant.DeploymentStrategyCanary,
939-
StatusValue: constant.DeploymentStatusValueActive,
940-
StatusReason: constant.DeploymentStatusReasonPaused,
960+
Strategy: constant.DeploymentStrategyCanary,
961+
StatusValue: constant.DeploymentStatusValueActive,
962+
StatusReason: constant.DeploymentStatusReasonPaused,
963+
CanaryStatus: resources.CanaryStatus{
964+
Steps: resources.CanaryStepStatus{
965+
CurrentStep: 2,
966+
TotalSteps: 5,
967+
},
968+
},
941969
LastStatusChange: LastStatusChangeTimeString,
942970
Options: resources.DeploymentOpts{
943971
MaxInFlight: maxInFlightDefaultValue,
@@ -960,9 +988,15 @@ var _ = Describe("app summary displayer", func() {
960988
BeforeEach(func() {
961989
summary = v7action.DetailedApplicationSummary{
962990
Deployment: resources.Deployment{
963-
Strategy: constant.DeploymentStrategyCanary,
964-
StatusValue: constant.DeploymentStatusValueActive,
965-
StatusReason: constant.DeploymentStatusReasonCanceling,
991+
Strategy: constant.DeploymentStrategyCanary,
992+
StatusValue: constant.DeploymentStatusValueActive,
993+
StatusReason: constant.DeploymentStatusReasonCanceling,
994+
CanaryStatus: resources.CanaryStatus{
995+
Steps: resources.CanaryStepStatus{
996+
CurrentStep: 2,
997+
TotalSteps: 5,
998+
},
999+
},
9661000
LastStatusChange: LastStatusChangeTimeString,
9671001
Options: resources.DeploymentOpts{
9681002
MaxInFlight: 2,

integration/v7/isolated/app_command_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ applications:
286286
session1 := helpers.CF("app", appName)
287287
Eventually(session1).Should(Say("Active deployment with status PAUSED"))
288288
Eventually(session1).Should(Say("strategy: canary"))
289+
Expect(session1).To(Say("canary-steps: 1/1"))
289290
Eventually(session1).Should(Exit(0))
290291
})
291292
})

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)