Skip to content

Commit

Permalink
Merge branch 'cappyzawa-feature/max-in-flight'
Browse files Browse the repository at this point in the history
  • Loading branch information
drich10 committed May 16, 2019
2 parents 42699c4 + 93190b5 commit 7573cc4
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 47 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 25 additions & 15 deletions bosh/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
"strconv"
"time"

"github.com/cloudfoundry/bosh-deployment-resource/concourse"
Expand All @@ -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 {
Expand Down Expand Up @@ -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: convertMaxInFlight(deployParams.MaxInFlight),
Recreate: deployParams.Recreate,
SkipDrain: skipDrains,
VarFlags: boshcmd.VarFlags{
VarKVs: varKVsFromVars(deployParams.Vars),
VarsFiles: boshVarsFiles,
Expand Down Expand Up @@ -384,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)
Expand Down
32 changes: 26 additions & 6 deletions bosh/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"io"
"io/ioutil"
"strconv"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -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())

Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
27 changes: 14 additions & 13 deletions concourse/out_params.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions out/out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions out/out_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down

0 comments on commit 7573cc4

Please sign in to comment.