Skip to content

Commit

Permalink
Merge pull request #625 from cloudfoundry/force-latest-variables-flag
Browse files Browse the repository at this point in the history
Add `--force-latest-variables` flag to `deploy` command
  • Loading branch information
selzoc authored Aug 15, 2023
2 parents 9cfebad + e57efc8 commit f506bb2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c DeployCmd) Run(opts DeployOpts) error {
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Diff: deploymentDiff,
ForceLatestVariables: opts.ForceLatestVariables,
}

return c.deployment.Update(bytes, updateOpts)
Expand Down
15 changes: 15 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ var _ = Describe("DeployCmd", func() {
}))
})

It("deploys manifest allowing to force latest variables", func() {
opts.ForceLatestVariables = true

err := act()
Expect(err).ToNot(HaveOccurred())

Expect(deployment.UpdateCallCount()).To(Equal(1))

bytes, updateOpts := deployment.UpdateArgsForCall(0)
Expect(bytes).To(Equal([]byte("name: dep\n")))
Expect(updateOpts).To(Equal(boshdir.UpdateOpts{
ForceLatestVariables: true,
}))
})

It("deploys templated manifest", func() {
opts.Args.Manifest = FileBytesArg{
Bytes: []byte("name: dep\nname1: ((name1))\nname2: ((name2))\n"),
Expand Down
3 changes: 2 additions & 1 deletion cmd/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ type DeployOpts struct {
Canaries string `long:"canaries" description:"Override manifest values for canaries"`
MaxInFlight string `long:"max-in-flight" description:"Override manifest values for max_in_flight"`

DryRun bool `long:"dry-run" description:"Renders job templates without altering deployment"`
DryRun bool `long:"dry-run" description:"Renders job templates without altering deployment"`
ForceLatestVariables bool `long:"force-latest-variables" description:"Retrieve the latest variable values from the config server regardless of their update strategy"`

cmd
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/opts/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,14 @@ var _ = Describe("Opts", func() {
})
})

Describe("ForceLatestVariables", func() {
It("contains desired values", func() {
Expect(getStructTagForName("ForceLatestVariables", opts)).To(Equal(
`long:"force-latest-variables" description:"Retrieve the latest variable values from the config server regardless of their update strategy"`,
))
})
})

Describe("FixReleases", func() {
It("contains desired values", func() {
Expect(getStructTagForName("FixReleases", opts)).To(Equal(
Expand Down
4 changes: 4 additions & 0 deletions director/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ func (c Client) UpdateDeployment(manifest []byte, opts UpdateOpts) error {
query.Add("dry_run", "true")
}

if opts.ForceLatestVariables {
query.Add("force_latest_variables", "true")
}

if len(opts.Diff.context) != 0 {
context := map[string]interface{}{}

Expand Down
23 changes: 23 additions & 0 deletions director/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,29 @@ var _ = Describe("Deployment", func() {
Expect(err).ToNot(HaveOccurred())
})

It("succeeds updating deployment with force latest variables flag", func() {
forceLatestVariables := true

ConfigureTaskResult(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/deployments", fmt.Sprintf("force_latest_variables=%t", forceLatestVariables)),
ghttp.VerifyBasicAuth("username", "password"),
ghttp.VerifyHeader(http.Header{
"Content-Type": []string{"text/yaml"},
}),
ghttp.VerifyBody([]byte("manifest")),
),
``,
server,
)

updateOpts := UpdateOpts{
ForceLatestVariables: forceLatestVariables,
}
err := deployment.Update([]byte("manifest"), updateOpts)
Expect(err).ToNot(HaveOccurred())
})

It("succeeds updating deployment with diff context values", func() {
context := map[string]interface{}{
"cloud_config_id": "2",
Expand Down
1 change: 1 addition & 0 deletions director/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ type UpdateOpts struct {
MaxInFlight string
DryRun bool
Diff DeploymentDiff
ForceLatestVariables bool
}

//counterfeiter:generate . ReleaseSeries
Expand Down

0 comments on commit f506bb2

Please sign in to comment.