Skip to content

Commit edf2552

Browse files
authored
Canary rollback command changes (#3089)
1 parent 081fd8d commit edf2552

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

command/v7/rollback_command.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
type RollbackCommand struct {
1515
BaseCommand
1616

17-
Force bool `short:"f" description:"Force rollback without confirmation"`
18-
RequiredArgs flag.AppName `positional-args:"yes"`
19-
Version flag.Revision `long:"version" required:"true" description:"Roll back to the specified revision"`
20-
relatedCommands interface{} `related_commands:"revisions"`
21-
usage interface{} `usage:"CF_NAME rollback APP_NAME [--version VERSION] [-f]"`
17+
Force bool `short:"f" description:"Force rollback without confirmation"`
18+
RequiredArgs flag.AppName `positional-args:"yes"`
19+
Strategy flag.DeploymentStrategy `long:"strategy" description:"Deployment strategy can be canary or rolling. When not specified, it defaults to rolling."`
20+
Version flag.Revision `long:"version" required:"true" description:"Roll back to the specified revision"`
21+
relatedCommands interface{} `related_commands:"revisions"`
22+
usage interface{} `usage:"CF_NAME rollback APP_NAME [--version VERSION] [-f]"`
2223

2324
LogCacheClient sharedaction.LogCacheClient
2425
Stager shared.AppStager
@@ -112,6 +113,10 @@ func (cmd RollbackCommand) Execute(args []string) error {
112113
AppAction: constant.ApplicationRollingBack,
113114
}
114115

116+
if cmd.Strategy.Name != "" {
117+
opts.Strategy = cmd.Strategy.Name
118+
}
119+
115120
startAppErr := cmd.Stager.StartApp(app, cmd.Config.TargetedSpace(), cmd.Config.TargetedOrganization(), revision.GUID, opts)
116121
if startAppErr != nil {
117122
return startAppErr

command/v7/rollback_command_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ var _ = Describe("rollback Command", func() {
219219
Expect(application.GUID).To(Equal("123"))
220220
Expect(revisionGUID).To(Equal("some-1-guid"))
221221
Expect(opts.AppAction).To(Equal(constant.ApplicationRollingBack))
222+
Expect(opts.Strategy).To(Equal(constant.DeploymentStrategyRolling))
222223

223224
Expect(testUI.Out).To(Say("Rolling '%s' back to revision '1' will create a new revision. The new revision will use the settings from revision '1'.", app))
224225
Expect(testUI.Out).To(Say("Are you sure you want to continue?"))
@@ -232,6 +233,25 @@ var _ = Describe("rollback Command", func() {
232233
})
233234
})
234235

236+
When("the strategy flag is passed", func() {
237+
BeforeEach(func() {
238+
cmd.Strategy.Name = constant.DeploymentStrategyCanary
239+
240+
_, err := input.Write([]byte("y\n"))
241+
Expect(err).NotTo(HaveOccurred())
242+
})
243+
It("uses the specified strategy to rollback", func() {
244+
Expect(fakeAppStager.StartAppCallCount()).To(Equal(1), "GetStartApp call count")
245+
246+
application, _, _, revisionGUID, opts := fakeAppStager.StartAppArgsForCall(0)
247+
Expect(executeErr).NotTo(HaveOccurred())
248+
Expect(application.GUID).To(Equal("123"))
249+
Expect(revisionGUID).To(Equal("some-1-guid"))
250+
Expect(opts.AppAction).To(Equal(constant.ApplicationRollingBack))
251+
Expect(opts.Strategy).To(Equal(constant.DeploymentStrategyCanary))
252+
})
253+
})
254+
235255
When("user says no to prompt", func() {
236256
BeforeEach(func() {
237257
_, err := input.Write([]byte("n\n"))
@@ -265,4 +285,5 @@ var _ = Describe("rollback Command", func() {
265285
})
266286
})
267287
})
288+
268289
})

integration/v7/isolated/rollback_command_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ var _ = Describe("rollback command", func() {
3434
Expect(session).To(Say("USAGE:"))
3535
Expect(session).To(Say(`cf rollback APP_NAME \[--version VERSION\]`))
3636
Expect(session).To(Say("OPTIONS:"))
37-
Expect(session).To(Say("-f Force rollback without confirmation"))
38-
Expect(session).To(Say("--version Roll back to the specified revision"))
37+
Expect(session).To(Say("-f Force rollback without confirmation"))
38+
Expect(session).To(Say("--strategy Deployment strategy can be canary or rolling. When not specified, it defaults to rolling."))
39+
Expect(session).To(Say("--version Roll back to the specified revision"))
3940
Expect(session).To(Say("SEE ALSO:"))
4041
Expect(session).To(Say("revisions"))
4142
})
@@ -148,6 +149,22 @@ applications:
148149

149150
Expect(session).To(Say(`3\(deployed\)\s+New droplet deployed.`))
150151
})
152+
153+
When("the strategy flag is provided", func() {
154+
BeforeEach(func() {
155+
_, err := buffer.Write([]byte("y\n"))
156+
Expect(err).ToNot(HaveOccurred())
157+
})
158+
159+
It("uses the given strategy to rollback", func() {
160+
session := helpers.CFWithStdin(buffer, "rollback", appName, "--version", "1", "--strategy", "canary")
161+
Eventually(session).Should(Exit(0))
162+
163+
Expect(session).To(HaveRollbackPrompt())
164+
Expect(session).To(HaveRollbackOutput(appName, orgName, spaceName, userName))
165+
Expect(session).To(Say("OK"))
166+
})
167+
})
151168
})
152169

153170
When("the user enters n", func() {

0 commit comments

Comments
 (0)