Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create-env bug where an empty slice of disks from the state file results in null being passed to the CPI ask the disks argument #670

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
17 changes: 17 additions & 0 deletions cmd/create_env_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd_test

import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -1144,6 +1145,22 @@ var _ = Describe("CreateEnvCmd", func() {
err = command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())
})

It("constructs and empty array of disks using make, due to odd behavior in golang where empty var []string marshals as null", func() {
err := fs.WriteFileString(deploymentStatePath, `
{
"disks": null
}`)
Expect(err).ToNot(HaveOccurred())

expectDeploy.Do(func(_, _, _, _, _, _ interface{}, diskCIDs []string, _ interface{}) {
jsonMarshalOfDisks, err := json.Marshal(diskCIDs)
Expect(err).ToNot(HaveOccurred())
Expect(string(jsonMarshalOfDisks)).To(Equal("[]"))
})
err = command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())
})
})
})
})
2 changes: 1 addition & 1 deletion cmd/deployment_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (c *DeploymentPreparer) stemcellApiVersion(stemcell bistemcell.ExtractedSte

// These disk CIDs get passed all the way to the create_vm cpi call
func (c *DeploymentPreparer) extractDiskCIDsFromState(deploymentState biconfig.DeploymentState) []string {
var diskCIDs []string
diskCIDs := make([]string, 0)
for _, disk := range deploymentState.Disks {
diskCIDs = append(diskCIDs, disk.CID)
}
Expand Down