From afac101ae24e10a5743508144a1313601cfc519b Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Wed, 3 Apr 2019 01:49:46 +0900 Subject: [PATCH 1/3] enable to use max in flight option --- bosh/director.go | 33 ++++++++++++++++++--------------- bosh/director_test.go | 32 ++++++++++++++++++++++++++------ concourse/out_params.go | 27 ++++++++++++++------------- out/out_command.go | 13 +++++++------ out/out_command_test.go | 23 +++++++++++++++++++++++ 5 files changed, 88 insertions(+), 40 deletions(-) diff --git a/bosh/director.go b/bosh/director.go index 2a2502987..804b344b1 100644 --- a/bosh/director.go +++ b/bosh/director.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "io/ioutil" + "strconv" "time" "github.com/cloudfoundry/bosh-deployment-resource/concourse" @@ -18,16 +19,17 @@ import ( ) type DeployParams struct { - Vars map[string]interface{} - VarFiles map[string]string - VarsFiles []string - OpsFiles []string - NoRedact bool - DryRun bool - Recreate bool - SkipDrain []string - Cleanup bool - VarsStore string + Vars map[string]interface{} + VarFiles map[string]string + VarsFiles []string + OpsFiles []string + NoRedact bool + DryRun bool + MaxInFlight int + Recreate bool + SkipDrain []string + Cleanup bool + VarsStore string } type InterpolateParams struct { @@ -96,11 +98,12 @@ func (d BoshDirector) Deploy(manifestBytes []byte, deployParams DeployParams) er } deployOpts := boshcmd.DeployOpts{ - Args: boshcmd.DeployArgs{Manifest: boshcmd.FileBytesArg{Bytes: manifestBytes}}, - NoRedact: deployParams.NoRedact, - DryRun: deployParams.DryRun, - Recreate: deployParams.Recreate, - SkipDrain: skipDrains, + Args: boshcmd.DeployArgs{Manifest: boshcmd.FileBytesArg{Bytes: manifestBytes}}, + NoRedact: deployParams.NoRedact, + DryRun: deployParams.DryRun, + MaxInFlight: strconv.Itoa(deployParams.MaxInFlight), + Recreate: deployParams.Recreate, + SkipDrain: skipDrains, VarFlags: boshcmd.VarFlags{ VarKVs: varKVsFromVars(deployParams.Vars), VarsFiles: boshVarsFiles, diff --git a/bosh/director_test.go b/bosh/director_test.go index 26271de75..a59553aa4 100644 --- a/bosh/director_test.go +++ b/bosh/director_test.go @@ -5,6 +5,7 @@ import ( "errors" "io" "io/ioutil" + "strconv" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -70,13 +71,15 @@ var _ = Describe("BoshDirector", func() { noRedact := true dryRun := false + maxInFlight := 5 err := director.Deploy(sillyBytes, bosh.DeployParams{ - NoRedact: noRedact, - DryRun: dryRun, - Vars: vars, - VarFiles: map[string]string{"key2": varFile.Name()}, - VarsFiles: []string{varsFile.Name()}, - OpsFiles: []string{opsFile.Name()}, + NoRedact: noRedact, + DryRun: dryRun, + MaxInFlight: maxInFlight, + Vars: vars, + VarFiles: map[string]string{"key2": varFile.Name()}, + VarsFiles: []string{varsFile.Name()}, + OpsFiles: []string{opsFile.Name()}, }) Expect(err).ToNot(HaveOccurred()) @@ -86,6 +89,7 @@ var _ = Describe("BoshDirector", func() { Expect(deployOpts.Args.Manifest.Bytes).To(Equal(sillyBytes)) Expect(deployOpts.NoRedact).To(Equal(noRedact)) Expect(deployOpts.DryRun).To(Equal(dryRun)) + Expect(deployOpts.MaxInFlight).To(Equal(strconv.Itoa(maxInFlight))) Expect(deployOpts.VarKVs).To(Equal(varKVs)) Expect(len(deployOpts.VarsFiles)).To(Equal(1)) Expect(deployOpts.VarsFiles[0].Vars).To(Equal(boshtpl.StaticVariables{ @@ -173,6 +177,22 @@ var _ = Describe("BoshDirector", func() { }) }) + Context("when max in flight is specified", func() { + It("use max-in-flight flags", func() { + maxInFlight := 5 + err := director.Deploy(sillyBytes, bosh.DeployParams{ + MaxInFlight: maxInFlight, + }) + Expect(err).ToNot(HaveOccurred()) + + Expect(commandRunner.ExecuteCallCount()).To(Equal(1)) + + deployOpts := commandRunner.ExecuteArgsForCall(0).(*boshcmd.DeployOpts) + Expect(deployOpts.Args.Manifest.Bytes).To(Equal(sillyBytes)) + Expect(deployOpts.MaxInFlight).To(Equal(strconv.Itoa(maxInFlight))) + }) + }) + Context("when skipdrain is specified", func() { It("uses skip-drain flag", func() { err := director.Deploy(sillyBytes, bosh.DeployParams{ diff --git a/concourse/out_params.go b/concourse/out_params.go index 26cbeff0e..d940b970d 100644 --- a/concourse/out_params.go +++ b/concourse/out_params.go @@ -1,19 +1,20 @@ package concourse type OutParams struct { - Manifest string `json:"manifest"` - NoRedact bool `json:"no_redact,omitempty"` - DryRun bool `json:"dry_run,omitempty"` - Recreate bool `json:"recreate,omitempty"` - SkipDrain []string `json:"skip_drain,omitempty"` - Cleanup bool `json:"cleanup,omitempty"` - Releases []string `json:"releases,omitempty"` - Stemcells []string `json:"stemcells,omitempty"` - Vars map[string]interface{} `json:"vars,omitempty"` - VarsFiles []string `json:"vars_files,omitempty"` - VarFiles map[string]string `json:"var_files,omitempty"` - OpsFiles []string `json:"ops_files,omitempty"` - Delete DeleteParams `json:"delete,omitempty"` + Manifest string `json:"manifest"` + NoRedact bool `json:"no_redact,omitempty"` + DryRun bool `json:"dry_run,omitempty"` + MaxInFlight int `json:"max_in_flight,omitempty"` + Recreate bool `json:"recreate,omitempty"` + SkipDrain []string `json:"skip_drain,omitempty"` + Cleanup bool `json:"cleanup,omitempty"` + Releases []string `json:"releases,omitempty"` + Stemcells []string `json:"stemcells,omitempty"` + Vars map[string]interface{} `json:"vars,omitempty"` + VarsFiles []string `json:"vars_files,omitempty"` + VarFiles map[string]string `json:"var_files,omitempty"` + OpsFiles []string `json:"ops_files,omitempty"` + Delete DeleteParams `json:"delete,omitempty"` } type DeleteParams struct { diff --git a/out/out_command.go b/out/out_command.go index 8e530503c..1c0241b4d 100644 --- a/out/out_command.go +++ b/out/out_command.go @@ -87,12 +87,13 @@ func (c OutCommand) deploy(outRequest concourse.OutRequest) (OutResponse, error) } deployParams := bosh.DeployParams{ - NoRedact: outRequest.Params.NoRedact, - DryRun: outRequest.Params.DryRun, - Recreate: outRequest.Params.Recreate, - SkipDrain: outRequest.Params.SkipDrain, - Cleanup: outRequest.Params.Cleanup, - VarFiles: c.prependResourcesDir(outRequest.Params.VarFiles), + NoRedact: outRequest.Params.NoRedact, + DryRun: outRequest.Params.DryRun, + MaxInFlight: outRequest.Params.MaxInFlight, + Recreate: outRequest.Params.Recreate, + SkipDrain: outRequest.Params.SkipDrain, + Cleanup: outRequest.Params.Cleanup, + VarFiles: c.prependResourcesDir(outRequest.Params.VarFiles), } var varsStoreFile *os.File diff --git a/out/out_command_test.go b/out/out_command_test.go index f253e1197..4e6c90578 100644 --- a/out/out_command_test.go +++ b/out/out_command_test.go @@ -136,6 +136,29 @@ var _ = Describe("OutCommand", func() { })) }) + It("deploys with max in flight", func() { + outRequest.Params.MaxInFlight = 5 + + _, err := outCommand.Run(outRequest) + Expect(err).ToNot(HaveOccurred()) + + _, actualInterpolateParams := director.InterpolateArgsForCall(0) + Expect(actualInterpolateParams.Vars).To(Equal( + map[string]interface{}{ + "foo": "bar", + }, + )) + + Expect(director.DeployCallCount()).To(Equal(1)) + actualManifestYaml, actualDeployParams := director.DeployArgsForCall(0) + Expect(actualManifestYaml).To(MatchYAML(manifestYaml)) + Expect(actualDeployParams).To(Equal(bosh.DeployParams{ + NoRedact: true, + MaxInFlight: 5, + VarFiles: map[string]string{}, + })) + }) + It("deploys with skip drain", func() { outRequest.Params.SkipDrain = []string{"all"} From bef4fbf9f4df337936606296fc070bc571519383 Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Wed, 3 Apr 2019 03:18:41 +0900 Subject: [PATCH 2/3] add description for max in flight option --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4d0d02dfb..90f3bc042 100644 --- a/README.md +++ b/README.md @@ -154,16 +154,18 @@ deployment manifest and then deploy. * `ops_files`: *Optional.* A collection of ops files to be applied over the deployment manifest. -* `cleanup`: *Optional* An boolean that specifies if a bosh cleanup should be +* `cleanup`: *Optional.* An boolean that specifies if a bosh cleanup should be run after deployment. Defaults to false. -* `no_redact`: *Optional* Removes redacted from Bosh output. Defaults to false. +* `no_redact`: *Optional.* Removes redacted from Bosh output. Defaults to false. -* `dry_run`: *Optional* Shows the deployment diff without running a deploy. Defaults to false. +* `dry_run`: *Optional.* Shows the deployment diff without running a deploy. Defaults to false. -* `recreate`: *Optional* Recreate all VMs in deployment. Defaults to false. +* `max_in_flight`: *Optional.* A number of max in flight option. -* `skip_drain`: *Optional* A collection of instance group names to skip running drain scripts for. Defaults to empty. +* `recreate`: *Optional.* Recreate all VMs in deployment. Defaults to false. + +* `skip_drain`: *Optional.* A collection of instance group names to skip running drain scripts for. Defaults to empty. * `source_file`: *Optional.* Path to a file containing a BOSH director address. This allows the target to be determined at runtime, e.g. by acquiring a BOSH @@ -173,9 +175,9 @@ deployment manifest and then deploy. If both `source_file` and `target` are specified, `source_file` takes precedence. -* `delete.enabled`: *Optional* Deletes the configured deployment instead of doing a deploy. +* `delete.enabled`: *Optional.* Deletes the configured deployment instead of doing a deploy. -* `delete.force`: *Optional* Defaults to `false`. Asks bosh to ignore errors when deleting the configured deployment. +* `delete.force`: *Optional.* Defaults to `false`. Asks bosh to ignore errors when deleting the configured deployment. ``` yaml From 93190b5d1aac69cb14ced66fc95e0624cd41f84e Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Wed, 3 Apr 2019 04:18:21 +0900 Subject: [PATCH 3/3] if max_in_flight is not set, it is converted to "" to avoid max in flight is 0 --- bosh/director.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bosh/director.go b/bosh/director.go index 804b344b1..4533b9161 100644 --- a/bosh/director.go +++ b/bosh/director.go @@ -101,7 +101,7 @@ func (d BoshDirector) Deploy(manifestBytes []byte, deployParams DeployParams) er Args: boshcmd.DeployArgs{Manifest: boshcmd.FileBytesArg{Bytes: manifestBytes}}, NoRedact: deployParams.NoRedact, DryRun: deployParams.DryRun, - MaxInFlight: strconv.Itoa(deployParams.MaxInFlight), + MaxInFlight: convertMaxInFlight(deployParams.MaxInFlight), Recreate: deployParams.Recreate, SkipDrain: skipDrains, VarFlags: boshcmd.VarFlags{ @@ -387,6 +387,13 @@ func parsedSkipDrains(drains []string) ([]boshdir.SkipDrain, error) { return parsedDrains, nil } +func convertMaxInFlight(maxInFlight int) string { + if maxInFlight == 0 { + return "" + } + return strconv.Itoa(maxInFlight) +} + func boshFileSystem() boshsys.FileSystem { nullLogger := boshlog.NewWriterLogger(boshlog.LevelInfo, ioutil.Discard) return boshsys.NewOsFileSystemWithStrictTempRoot(nullLogger)