Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/create_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func (c *CreateEnvCmd) Run(stage boshui.Stage, opts CreateEnvOpts) error {
depPreparer := c.envProvider(opts.Args.Manifest.Path, opts.StatePath, opts.VarFlags.AsVariables(), opts.OpsFlags.AsOp()) //nolint:staticcheck

return depPreparer.PrepareDeployment(stage, DeploymentOptions{
Recreate: opts.Recreate,
RecreatePersistentDisks: opts.RecreatePersistentDisks,
FixStemcell: opts.FixStemcell,
SkipDrain: opts.SkipDrain,
Recreate: opts.Recreate,
RecreatePersistentDisks: opts.RecreatePersistentDisks,
FixStemcell: opts.FixStemcell,
SkipDrain: opts.SkipDrain,
SkipDeleteUnusedStemcells: opts.SkipDeleteUnusedStemcells,
})
}
11 changes: 11 additions & 0 deletions cmd/create_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,17 @@ var _ = Describe("CreateEnvCmd", func() {
Expect(mockStemcellManager.DeleteUnusedCallCount()).To(Equal(1))
})

Context("when SkipDeleteUnusedStemcells is specified", func() {
It("does not delete unused stemcells", func() {
defaultCreateEnvOpts.SkipDeleteUnusedStemcells = true

err := command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())

Expect(mockStemcellManager.DeleteUnusedCallCount()).To(Equal(0))
})
})

Context("when SkipDrain is specified", func() {
BeforeEach(func() {
expectedSkipDrain = true
Expand Down
17 changes: 13 additions & 4 deletions cmd/deployment_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ type DeploymentPreparer struct {

// DeploymentOptions carries the per-run switches for PrepareDeployment.
type DeploymentOptions struct {
Recreate bool
RecreatePersistentDisks bool
FixStemcell bool
SkipDrain bool
Recreate bool
RecreatePersistentDisks bool
FixStemcell bool
SkipDrain bool
SkipDeleteUnusedStemcells bool
}

func (c *DeploymentPreparer) PrepareDeployment(stage biui.Stage, opts DeploymentOptions) (err error) {
recreate := opts.Recreate
recreatePersistentDisks := opts.RecreatePersistentDisks
fix := opts.FixStemcell
skipDrain := opts.SkipDrain
skipDeleteUnusedStemcells := opts.SkipDeleteUnusedStemcells

c.ui.BeginLinef("Deployment state: '%s'\n", c.deploymentStateService.Path())

Expand Down Expand Up @@ -233,6 +235,7 @@ func (c *DeploymentPreparer) PrepareDeployment(stage biui.Stage, opts Deployment
manifestSHA,
skipDrain,
fix,
skipDeleteUnusedStemcells,
stage,
cloud,
)
Expand Down Expand Up @@ -264,6 +267,7 @@ func (c *DeploymentPreparer) deploy(
manifestSHA string,
skipDrain bool,
fix bool,
skipDeleteUnusedStemcells bool,
stage biui.Stage,
cloud bicloud.Cloud,
) (err error) {
Expand Down Expand Up @@ -322,6 +326,11 @@ func (c *DeploymentPreparer) deploy(

// TODO: cleanup unused disks here?

if skipDeleteUnusedStemcells {
c.ui.BeginLinef("Skipping deletion of unused stemcells\n")
return nil
}

err = stemcellManager.DeleteUnused(stage)
if err != nil {
return err
Expand Down
13 changes: 7 additions & 6 deletions cmd/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ type CreateEnvOpts struct {
Args CreateEnvArgs `positional-args:"true" required:"true"`
VarFlags
OpsFlags
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
Recreate bool `long:"recreate" description:"Recreate VM in deployment"`
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate persistent disks in the deployment"`
FixStemcell bool `long:"fix-stemcell" description:"Forces re-upload of the stemcell; any existing stemcell image is orphaned and the VM is recreated"`
PackageDir string `long:"package-dir" value-name:"DIR" description:"Package cache location override"`
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
Recreate bool `long:"recreate" description:"Recreate VM in deployment"`
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate persistent disks in the deployment"`
FixStemcell bool `long:"fix-stemcell" description:"Forces re-upload of the stemcell; any existing stemcell image is orphaned and the VM is recreated"`
SkipDeleteUnusedStemcells bool `long:"skip-delete-unused-stemcells" description:"Keep stemcells that are no longer current; use when another deployment reuses the same stemcell image"`
PackageDir string `long:"package-dir" value-name:"DIR" description:"Package cache location override"`
cmd
}

Expand Down
Loading