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

Support stemcell name property #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions bosh/bosh_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type Stemcell struct {
Alias string `yaml:"alias"`
OS string `yaml:"os"`
Version string `yaml:"version"`
Name string `yaml:"name,omitempty"`
}

type InstanceGroup struct {
Expand Down
37 changes: 28 additions & 9 deletions bosh/bosh_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package bosh_test

import (
"errors"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -245,7 +245,7 @@ var _ = Describe("(de)serialising BOSH manifests", func() {
It("serialises bosh manifests", func() {
cwd, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())
manifestBytes, err := ioutil.ReadFile(filepath.Join(cwd, "fixtures", "manifest.yml"))
manifestBytes, err := os.ReadFile(filepath.Join(cwd, "fixtures", "manifest.yml"))
Expect(err).NotTo(HaveOccurred())

serialisedManifest, err := yaml.Marshal(sampleManifest)
Expand All @@ -256,7 +256,7 @@ var _ = Describe("(de)serialising BOSH manifests", func() {
It("deserialises bosh manifest features into struct", func() {
cwd, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())
manifestBytes, err := ioutil.ReadFile(filepath.Join(cwd, "fixtures", "manifest.yml"))
manifestBytes, err := os.ReadFile(filepath.Join(cwd, "fixtures", "manifest.yml"))
Expect(err).NotTo(HaveOccurred())

manifest := bosh.BoshManifest{}
Expand Down Expand Up @@ -379,13 +379,10 @@ var _ = Describe("(de)serialising BOSH manifests", func() {
tmpl, err := template.ParseFiles(filepath.Join(cwd, "fixtures", "manifest_template.yml"))
Expect(err).NotTo(HaveOccurred())

type params struct {
MaxInFlight bosh.MaxInFlightValue
}
p := params{maxInFlight}

output := gbytes.NewBuffer()
err = tmpl.Execute(output, p)
err = tmpl.Execute(output, map[string]any{
"MaxInFlight": maxInFlight,
})
Expect(err).NotTo(HaveOccurred())

var manifest bosh.BoshManifest
Expand All @@ -405,4 +402,26 @@ var _ = Describe("(de)serialising BOSH manifests", func() {
Entry("a bool", true, errors.New("MaxInFlight must be either an integer or a percentage. Got true")),
Entry("a non percentage string", "some instances", errors.New("MaxInFlight must be either an integer or a percentage. Got some instances")),
)

When("a stemcell name has been configured", func() {
It("correctly handles a manifest including a stemcell name property", func() {
tmpl, err := template.ParseFiles(filepath.Join("fixtures", "manifest_template.yml"))
Expect(err).NotTo(HaveOccurred())

params := map[string]any{
"MaxInFlight": 1,
"StemcellName": "ubuntu-fancy-name-with-fips",
}

output := gbytes.NewBuffer()
err = tmpl.Execute(io.MultiWriter(GinkgoWriter, output), params)
Expect(err).NotTo(HaveOccurred())

var manifest bosh.BoshManifest
err = yaml.Unmarshal(output.Contents(), &manifest)
Expect(err).NotTo(HaveOccurred())

Expect(manifest.Stemcells[0].Name).To(Equal("ubuntu-fancy-name-with-fips"))
})
})
})
4 changes: 2 additions & 2 deletions bosh/bosh_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package bosh_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"testing"
)

func TestBosh(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions bosh/fixtures/manifest_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ stemcells:
- alias: greatest
os: Windows
version: "3.1"
{{ if ne (index . "StemcellName") "" -}}
name: {{.StemcellName}}
{{- end }}

instance_groups:
- name: jerb
Expand Down
2 changes: 1 addition & 1 deletion bosh/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (j Job) AddConsumesLink(name, fromJob string) Job {
return j.addConsumesLink(name, ConsumesLink{From: fromJob})
}

func (j Job) AddCrossDeploymentConsumesLink(name, fromJob string, deployment string) Job {
func (j Job) AddCrossDeploymentConsumesLink(name, fromJob, deployment string) Job {
return j.addConsumesLink(name, ConsumesLink{From: fromJob, Deployment: deployment})
}

Expand Down
17 changes: 11 additions & 6 deletions integration_tests/command_line_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ var (

expectedRequestParams = map[string]interface{}{"key": "foo", "bar": "baz"}

expectedResultantBoshManifest = bosh.BoshManifest{Name: "deployment-name",
expectedResultantBoshManifest = bosh.BoshManifest{
Name: "deployment-name",
Releases: []bosh.Release{
{
Name: "a-release",
Expand Down Expand Up @@ -110,7 +111,8 @@ var (

expectedPlan = expectedPreviousPlan

expectedPreviousManifest = bosh.BoshManifest{Name: "another-deployment-name",
expectedPreviousManifest = bosh.BoshManifest{
Name: "another-deployment-name",
Releases: []bosh.Release{
{
Name: "a-release",
Expand All @@ -124,7 +126,8 @@ var (
OS: "Windows",
Version: "3.1",
},
}}
},
}

expectedBindingID = "bindingId"

Expand All @@ -138,7 +141,6 @@ var (
)

var _ = Describe("Command line handler", func() {

BeforeEach(func() {
doNotImplementInterfaces = false
stdout = new(bytes.Buffer)
Expand All @@ -163,7 +165,8 @@ var _ = Describe("Command line handler", func() {
Describe("generate-manifest subcommand", func() {
Describe("with positional arguments", func() {
It("succeeds without optional parameters", func() {
exitCode = startPassingCommandAndGetExitCode([]string{"generate-manifest",
exitCode = startPassingCommandAndGetExitCode([]string{
"generate-manifest",
toJson(expectedServiceDeployment),
toJson(expectedCurrentPlan),
toJson(expectedRequestParams),
Expand Down Expand Up @@ -201,7 +204,8 @@ var _ = Describe("Command line handler", func() {
})

It("exits 1 and logs when a generic error occurs", func() {
exitCode = startFailingCommandAndGetExitCode([]string{"generate-manifest",
exitCode = startFailingCommandAndGetExitCode([]string{
"generate-manifest",
toJson(expectedServiceDeployment),
toJson(expectedCurrentPlan),
toJson(expectedRequestParams),
Expand Down Expand Up @@ -763,6 +767,7 @@ func toYaml(obj interface{}) string {
Expect(err).NotTo(HaveOccurred())
return string(str)
}

func toJson(obj interface{}) string {
str, err := json.Marshal(obj)
Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/testharness/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func main() {
type manifestGenerator struct{}

func (m *manifestGenerator) GenerateManifest(params serviceadapter.GenerateManifestParams) (serviceadapter.GenerateManifestOutput, error) {

if os.Getenv(testvariables.OperationFailsKey) == OperationShouldFail {
fmt.Fprintf(os.Stderr, "not valid")
return serviceadapter.GenerateManifestOutput{}, errors.New("some message to the user")
}

manifest := bosh.BoshManifest{Name: "deployment-name",
manifest := bosh.BoshManifest{
Name: "deployment-name",
Releases: []bosh.Release{
{
Name: "a-release",
Expand Down
4 changes: 1 addition & 3 deletions serviceadapter/command_line_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"sort"

"strings"

"path/filepath"
)

// CommandLineHandler contains all of the implementers required for the service adapter interface
Expand Down
12 changes: 5 additions & 7 deletions serviceadapter/command_line_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
package serviceadapter_test

import (
"bytes"
"errors"
"io"
"io/ioutil"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"

"bytes"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"github.com/pivotal-cf/on-demand-services-sdk/serviceadapter"
"github.com/pivotal-cf/on-demand-services-sdk/serviceadapter/fakes"
Expand Down Expand Up @@ -188,7 +186,6 @@ var _ = Describe("CommandLineHandler", func() {
err := handler.Handle([]string{commandName, "generate-manifest"}, outputBuffer, errorBuffer, bytes.NewBufferString(""))

Expect(err).To(BeACLIError(serviceadapter.NotImplementedExitCode, "generate-manifest not implemented"))

})

It("returns a missing args error when arguments are missing", func() {
Expand Down Expand Up @@ -427,7 +424,8 @@ var _ = Describe("CommandLineHandler", func() {

It("returns a missing args error when request JSON is missing", func() {
err := handler.Handle([]string{
commandName, "delete-binding", previousManifestYAML}, outputBuffer, errorBuffer, bytes.NewBufferString(""))
commandName, "delete-binding", previousManifestYAML,
}, outputBuffer, errorBuffer, bytes.NewBufferString(""))

Expect(err).To(BeACLIError(1, "Missing arguments for delete-binding. Usage:"))
})
Expand Down Expand Up @@ -486,7 +484,7 @@ var _ = Describe("CommandLineHandler", func() {

Expect(fakeSchemaGenerator.GeneratePlanSchemaArgsForCall(0).Plan).To(Equal(plan))

contents, err := ioutil.ReadAll(outputBuffer)
contents, err := io.ReadAll(outputBuffer)
Expect(err).NotTo(HaveOccurred())
Expect(contents).To(MatchJSON(toJson(expectedPlanSchema)))
})
Expand Down Expand Up @@ -528,7 +526,7 @@ var _ = Describe("CommandLineHandler", func() {

Expect(fakeSchemaGenerator.GeneratePlanSchemaArgsForCall(0).Plan).To(Equal(plan))

contents, err := ioutil.ReadAll(outputBuffer)
contents, err := io.ReadAll(outputBuffer)
Expect(err).NotTo(HaveOccurred())
Expect(contents).To(MatchJSON(toJson(expectedPlanSchema)))
})
Expand Down
8 changes: 4 additions & 4 deletions serviceadapter/create_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
)

type CreateBindingAction struct {
Expand Down Expand Up @@ -45,7 +45,7 @@ func (a *CreateBindingAction) ParseArgs(reader io.Reader, args []string) (InputP
return inputParams, nil
}

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return inputParams, CLIHandlerError{ErrorExitCode, fmt.Sprintf("error reading input params JSON, error: %s", err)}
}
Expand Down
8 changes: 4 additions & 4 deletions serviceadapter/dashboard_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
)

type DashboardUrlAction struct {
Expand Down Expand Up @@ -43,7 +43,7 @@ func (d *DashboardUrlAction) ParseArgs(reader io.Reader, args []string) (InputPa
return inputParams, nil
}

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return inputParams, CLIHandlerError{ErrorExitCode, fmt.Sprintf("error reading input params JSON, error: %s", err)}
}
Expand Down
8 changes: 4 additions & 4 deletions serviceadapter/delete_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
)

type DeleteBindingAction struct {
Expand Down Expand Up @@ -44,7 +44,7 @@ func (d *DeleteBindingAction) ParseArgs(reader io.Reader, args []string) (InputP
return inputParams, nil
}

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return inputParams, CLIHandlerError{ErrorExitCode, fmt.Sprintf("error reading input params JSON, error: %s", err)}
}
Expand Down
13 changes: 9 additions & 4 deletions serviceadapter/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ type PlanSchema struct {
ServiceBinding ServiceBindingSchema `json:"service_binding"`
}

type ManifestSecrets map[string]string
type DNSAddresses map[string]string
type (
ManifestSecrets map[string]string
DNSAddresses map[string]string
)

type DashboardUrl struct {
DashboardUrl string `json:"dashboard_url"`
Expand Down Expand Up @@ -165,8 +167,10 @@ type InputParams struct {
TextOutput bool `json:"-"`
}

type ODBManagedSecrets map[string]interface{}
type BOSHConfigs map[string]string
type (
ODBManagedSecrets map[string]interface{}
BOSHConfigs map[string]string
)

type GenerateManifestOutput struct {
Manifest bosh.BoshManifest `json:"manifest"`
Expand Down Expand Up @@ -285,6 +289,7 @@ func (r ServiceReleases) Validate() error {
}

type Stemcell struct {
Name string `json:"stemcell_name,omitempty"`
OS string `json:"stemcell_os" validate:"required"`
Version string `json:"stemcell_version" validate:"required"`
}
Expand Down
8 changes: 4 additions & 4 deletions serviceadapter/generate_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/pivotal-cf/on-demand-services-sdk/bosh"
)

type GenerateManifestAction struct {
Expand Down Expand Up @@ -46,7 +46,7 @@ func (g *GenerateManifestAction) ParseArgs(reader io.Reader, args []string) (Inp
return inputParams, nil
}

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return inputParams, CLIHandlerError{ErrorExitCode, fmt.Sprintf("error reading input params JSON, error: %s", err)}
}
Expand Down
Loading
Loading