Skip to content

Commit

Permalink
Canary rollback command changes (#3089)
Browse files Browse the repository at this point in the history
  • Loading branch information
gururajsh authored Aug 8, 2024
1 parent 081fd8d commit edf2552
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
15 changes: 10 additions & 5 deletions command/v7/rollback_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
type RollbackCommand struct {
BaseCommand

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

LogCacheClient sharedaction.LogCacheClient
Stager shared.AppStager
Expand Down Expand Up @@ -112,6 +113,10 @@ func (cmd RollbackCommand) Execute(args []string) error {
AppAction: constant.ApplicationRollingBack,
}

if cmd.Strategy.Name != "" {
opts.Strategy = cmd.Strategy.Name
}

startAppErr := cmd.Stager.StartApp(app, cmd.Config.TargetedSpace(), cmd.Config.TargetedOrganization(), revision.GUID, opts)
if startAppErr != nil {
return startAppErr
Expand Down
21 changes: 21 additions & 0 deletions command/v7/rollback_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var _ = Describe("rollback Command", func() {
Expect(application.GUID).To(Equal("123"))
Expect(revisionGUID).To(Equal("some-1-guid"))
Expect(opts.AppAction).To(Equal(constant.ApplicationRollingBack))
Expect(opts.Strategy).To(Equal(constant.DeploymentStrategyRolling))

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))
Expect(testUI.Out).To(Say("Are you sure you want to continue?"))
Expand All @@ -232,6 +233,25 @@ var _ = Describe("rollback Command", func() {
})
})

When("the strategy flag is passed", func() {
BeforeEach(func() {
cmd.Strategy.Name = constant.DeploymentStrategyCanary

_, err := input.Write([]byte("y\n"))
Expect(err).NotTo(HaveOccurred())
})
It("uses the specified strategy to rollback", func() {
Expect(fakeAppStager.StartAppCallCount()).To(Equal(1), "GetStartApp call count")

application, _, _, revisionGUID, opts := fakeAppStager.StartAppArgsForCall(0)
Expect(executeErr).NotTo(HaveOccurred())
Expect(application.GUID).To(Equal("123"))
Expect(revisionGUID).To(Equal("some-1-guid"))
Expect(opts.AppAction).To(Equal(constant.ApplicationRollingBack))
Expect(opts.Strategy).To(Equal(constant.DeploymentStrategyCanary))
})
})

When("user says no to prompt", func() {
BeforeEach(func() {
_, err := input.Write([]byte("n\n"))
Expand Down Expand Up @@ -265,4 +285,5 @@ var _ = Describe("rollback Command", func() {
})
})
})

})
21 changes: 19 additions & 2 deletions integration/v7/isolated/rollback_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ var _ = Describe("rollback command", func() {
Expect(session).To(Say("USAGE:"))
Expect(session).To(Say(`cf rollback APP_NAME \[--version VERSION\]`))
Expect(session).To(Say("OPTIONS:"))
Expect(session).To(Say("-f Force rollback without confirmation"))
Expect(session).To(Say("--version Roll back to the specified revision"))
Expect(session).To(Say("-f Force rollback without confirmation"))
Expect(session).To(Say("--strategy Deployment strategy can be canary or rolling. When not specified, it defaults to rolling."))
Expect(session).To(Say("--version Roll back to the specified revision"))
Expect(session).To(Say("SEE ALSO:"))
Expect(session).To(Say("revisions"))
})
Expand Down Expand Up @@ -148,6 +149,22 @@ applications:

Expect(session).To(Say(`3\(deployed\)\s+New droplet deployed.`))
})

When("the strategy flag is provided", func() {
BeforeEach(func() {
_, err := buffer.Write([]byte("y\n"))
Expect(err).ToNot(HaveOccurred())
})

It("uses the given strategy to rollback", func() {
session := helpers.CFWithStdin(buffer, "rollback", appName, "--version", "1", "--strategy", "canary")
Eventually(session).Should(Exit(0))

Expect(session).To(HaveRollbackPrompt())
Expect(session).To(HaveRollbackOutput(appName, orgName, spaceName, userName))
Expect(session).To(Say("OK"))
})
})
})

When("the user enters n", func() {
Expand Down

0 comments on commit edf2552

Please sign in to comment.