Skip to content

Commit 5da0da5

Browse files
drich10cursoragent
andcommitted
feat(carvel): support structured BOSH variable declarations in base.yml
Changes Variables []string to []proofing.Variable in both Metadata structs. Adds validateVariables() to baker.go to catch missing name/type at bake time. Covers with 4 Ginkgo specs. TNZ-112157 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 20910ea commit 5da0da5

4 files changed

Lines changed: 94 additions & 31 deletions

File tree

internal/carvel/baker.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/pivotal-cf/kiln/internal/carvel/models"
1919
"github.com/pivotal-cf/kiln/pkg/cargo"
20+
"github.com/pivotal-cf/kiln/pkg/proofing"
2021

2122
"github.com/hashicorp/go-version"
2223
"gopkg.in/yaml.v3"
@@ -89,6 +90,9 @@ func (b *baker) Bake(source string) error {
8990
if err != nil {
9091
return err
9192
}
93+
if err := validateVariables(b.metadata.Variables); err != nil {
94+
return err
95+
}
9296

9397
ver, err := b.GetVersion()
9498
if err != nil {
@@ -137,6 +141,9 @@ func (b *baker) BakeFromLockfile(source string, releaseLock cargo.BOSHReleaseTar
137141
if err != nil {
138142
return err
139143
}
144+
if err := validateVariables(b.metadata.Variables); err != nil {
145+
return err
146+
}
140147

141148
ver, err := b.GetVersion()
142149
if err != nil {
@@ -248,6 +255,19 @@ func (b *baker) progress(message string) {
248255
_, _ = fmt.Fprintln(b.progressWriter, message)
249256
}
250257

258+
// validateVariables checks that each variable declaration has the required name and type fields.
259+
func validateVariables(vars []proofing.Variable) error {
260+
for i, v := range vars {
261+
if v.Name == "" {
262+
return fmt.Errorf("variables[%d]: missing required field 'name'", i)
263+
}
264+
if v.Type == "" {
265+
return fmt.Errorf("variables[%d] (%q): missing required field 'type'", i, v.Name)
266+
}
267+
}
268+
return nil
269+
}
270+
251271
func (b *baker) generateBoshReleaseDir() error {
252272
dirName := path.Join(b.source, ".boshrelease")
253273
err := os.RemoveAll(dirName)

internal/carvel/baker_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
. "github.com/onsi/gomega"
1515
"github.com/pivotal-cf/kiln/internal/carvel/models"
1616
"github.com/pivotal-cf/kiln/pkg/cargo"
17+
"github.com/pivotal-cf/kiln/pkg/proofing"
1718
"gopkg.in/yaml.v3"
1819
)
1920

@@ -297,7 +298,7 @@ var _ = Describe("Carvel Baker", func() {
297298
`$( property "admin_password" )`,
298299
},
299300
FormTypes: []string{`$( form "db_props" )`},
300-
Variables: []string{},
301+
Variables: []proofing.Variable{},
301302
PackageInstalls: []string{`$( package "test-install" )`},
302303
}
303304
yamlData, err := yaml.Marshal(&m)
@@ -591,4 +592,42 @@ var _ = Describe("Carvel Baker", func() {
591592
Expect(nonEmpty).To(Equal(5))
592593
})
593594
})
595+
596+
Context("validateVariables", func() {
597+
It("passes for an empty list", func() {
598+
err := validateVariables([]proofing.Variable{})
599+
Expect(err).NotTo(HaveOccurred())
600+
})
601+
602+
It("passes for a valid certificate variable", func() {
603+
err := validateVariables([]proofing.Variable{
604+
{
605+
Name: "/cf/diego-instance-identity-root-ca-2-6",
606+
Type: "certificate",
607+
Options: map[string]any{
608+
"common_name": "Diego Instance Identity Root CA",
609+
"is_ca": true,
610+
"duration": 1095,
611+
},
612+
},
613+
})
614+
Expect(err).NotTo(HaveOccurred())
615+
})
616+
617+
It("errors when name is empty", func() {
618+
err := validateVariables([]proofing.Variable{
619+
{Name: "", Type: "certificate"},
620+
})
621+
Expect(err).To(HaveOccurred())
622+
Expect(err.Error()).To(ContainSubstring("missing required field 'name'"))
623+
})
624+
625+
It("errors when type is empty", func() {
626+
err := validateVariables([]proofing.Variable{
627+
{Name: "my-var", Type: ""},
628+
})
629+
Expect(err).To(HaveOccurred())
630+
Expect(err.Error()).To(ContainSubstring("missing required field 'type'"))
631+
})
632+
})
594633
})

internal/carvel/models/metadata.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package models
22

3+
import "github.com/pivotal-cf/kiln/pkg/proofing"
4+
35
type Metadata struct {
4-
Name string `yaml:"name"`
5-
ProductVersion string `yaml:"product_version"`
6-
IconImage string `yaml:"icon_image"`
7-
Label string `yaml:"label"`
8-
MetadataVersion string `yaml:"metadata_version"`
9-
MinimumVersionForUpgrade string `yaml:"minimum_version_for_upgrade"`
10-
Rank int `yaml:"rank"`
11-
Serial bool `yaml:"serial"`
12-
PropertyBlueprints []string `yaml:"property_blueprints"`
13-
FormTypes []string `yaml:"form_types"`
14-
Variables []string `yaml:"variables"`
15-
PackageInstalls []string `yaml:"package_installs"`
16-
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions,omitempty"`
6+
Name string `yaml:"name"`
7+
ProductVersion string `yaml:"product_version"`
8+
IconImage string `yaml:"icon_image"`
9+
Label string `yaml:"label"`
10+
MetadataVersion string `yaml:"metadata_version"`
11+
MinimumVersionForUpgrade string `yaml:"minimum_version_for_upgrade"`
12+
Rank int `yaml:"rank"`
13+
Serial bool `yaml:"serial"`
14+
PropertyBlueprints []string `yaml:"property_blueprints"`
15+
FormTypes []string `yaml:"form_types"`
16+
Variables []proofing.Variable `yaml:"variables"`
17+
PackageInstalls []string `yaml:"package_installs"`
18+
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions,omitempty"`
1719
}

internal/carvel/models/metadata_out.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package models
22

3+
import "github.com/pivotal-cf/kiln/pkg/proofing"
4+
35
type MetadataOut struct {
4-
Name string `yaml:"name"`
5-
ProductVersion string `yaml:"product_version"`
6-
IconImage string `yaml:"icon_image"`
7-
Label string `yaml:"label"`
8-
MetadataVersion string `yaml:"metadata_version"`
9-
MinimumVersionForUpgrade string `yaml:"minimum_version_for_upgrade"`
10-
Rank int `yaml:"rank"`
11-
Serial bool `yaml:"serial"`
12-
PropertyBlueprints []string `yaml:"property_blueprints"`
13-
FormTypes []string `yaml:"form_types"`
14-
Variables []string `yaml:"variables"`
15-
InstanceGroups []string `yaml:"job_types"`
16-
StemcellCriteria StemcellCriteria `yaml:"stemcell_criteria"`
17-
Releases []string `yaml:"releases"`
18-
RuntimeConfigs []string `yaml:"runtime_configs"`
19-
RequiresKubernetes bool `yaml:"requires_kubernetes"`
20-
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions"`
6+
Name string `yaml:"name"`
7+
ProductVersion string `yaml:"product_version"`
8+
IconImage string `yaml:"icon_image"`
9+
Label string `yaml:"label"`
10+
MetadataVersion string `yaml:"metadata_version"`
11+
MinimumVersionForUpgrade string `yaml:"minimum_version_for_upgrade"`
12+
Rank int `yaml:"rank"`
13+
Serial bool `yaml:"serial"`
14+
PropertyBlueprints []string `yaml:"property_blueprints"`
15+
FormTypes []string `yaml:"form_types"`
16+
Variables []proofing.Variable `yaml:"variables"`
17+
InstanceGroups []string `yaml:"job_types"`
18+
StemcellCriteria StemcellCriteria `yaml:"stemcell_criteria"`
19+
Releases []string `yaml:"releases"`
20+
RuntimeConfigs []string `yaml:"runtime_configs"`
21+
RequiresKubernetes bool `yaml:"requires_kubernetes"`
22+
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions"`
2123
}
2224

2325
type StemcellCriteria struct {

0 commit comments

Comments
 (0)