Skip to content

Commit f726926

Browse files
drich10claude
andcommitted
Merge origin/main — resolve conflict between BOSH link types and validateVariables
Both branches added code after the progress() function: the PR branch added boshLinkConsumer/jobSpecOverlay types; main added validateVariables (from #664). Include both blocks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 parents 7c638ad + 8dc0354 commit f726926

5 files changed

Lines changed: 105 additions & 33 deletions

File tree

internal/carvel/baker.go

Lines changed: 19 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 {
@@ -263,6 +270,18 @@ type jobSpecOverlay struct {
263270
Consumes []boshLinkConsumer `yaml:"consumes"`
264271
}
265272

273+
func validateVariables(vars []proofing.Variable) error {
274+
var errs []error
275+
for i, v := range vars {
276+
if v.Name == "" {
277+
errs = append(errs, fmt.Errorf("variables[%d]: missing required field 'name'", i))
278+
} else if v.Type == "" {
279+
errs = append(errs, fmt.Errorf("variables[%d] (%q): missing required field 'type'", i, v.Name))
280+
}
281+
}
282+
return errors.Join(errs...)
283+
}
284+
266285
func (b *baker) generateBoshReleaseDir() error {
267286
dirName := path.Join(b.source, ".boshrelease")
268287
err := os.RemoveAll(dirName)

internal/carvel/baker_test.go

Lines changed: 45 additions & 2 deletions
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

@@ -245,7 +246,11 @@ consumes:
245246
Expect(outMeta.Serial).To(BeFalse())
246247
Expect(outMeta.PropertyBlueprints).To(HaveLen(2))
247248
Expect(outMeta.FormTypes).To(HaveLen(1))
248-
Expect(outMeta.Variables).To(BeEmpty())
249+
Expect(outMeta.Variables).To(HaveLen(1))
250+
Expect(outMeta.Variables[0].Name).To(Equal("sample-tile-ca"))
251+
Expect(outMeta.Variables[0].Type).To(Equal("certificate"))
252+
Expect(outMeta.Variables[0].Options).To(HaveKeyWithValue("common_name", "Sample Tile CA"))
253+
Expect(outMeta.Variables[0].Options).To(HaveKeyWithValue("is_ca", true))
249254
Expect(outMeta.Releases).To(HaveLen(1))
250255
Expect(outMeta.Releases[0]).To(ContainSubstring("k8s-tile-test"))
251256
Expect(outMeta.InstanceGroups).To(HaveLen(0))
@@ -373,7 +378,7 @@ consumes:
373378
`$( property "admin_password" )`,
374379
},
375380
FormTypes: []string{`$( form "db_props" )`},
376-
Variables: []string{},
381+
Variables: []proofing.Variable{},
377382
PackageInstalls: []string{`$( package "test-install" )`},
378383
}
379384
yamlData, err := yaml.Marshal(&m)
@@ -667,4 +672,42 @@ consumes:
667672
Expect(nonEmpty).To(Equal(5))
668673
})
669674
})
675+
676+
Context("validateVariables", func() {
677+
It("passes for an empty list", func() {
678+
err := validateVariables([]proofing.Variable{})
679+
Expect(err).NotTo(HaveOccurred())
680+
})
681+
682+
It("passes for a valid certificate variable", func() {
683+
err := validateVariables([]proofing.Variable{
684+
{
685+
Name: "/cf/diego-instance-identity-root-ca-2-6",
686+
Type: "certificate",
687+
Options: map[string]any{
688+
"common_name": "Diego Instance Identity Root CA",
689+
"is_ca": true,
690+
"duration": 1095,
691+
},
692+
},
693+
})
694+
Expect(err).NotTo(HaveOccurred())
695+
})
696+
697+
It("errors when name is empty", func() {
698+
err := validateVariables([]proofing.Variable{
699+
{Name: "", Type: "certificate"},
700+
})
701+
Expect(err).To(HaveOccurred())
702+
Expect(err.Error()).To(ContainSubstring("missing required field 'name'"))
703+
})
704+
705+
It("errors when type is empty", func() {
706+
err := validateVariables([]proofing.Variable{
707+
{Name: "my-var", Type: ""},
708+
})
709+
Expect(err).To(HaveOccurred())
710+
Expect(err.Error()).To(ContainSubstring("missing required field 'type'"))
711+
})
712+
})
670713
})

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 {

internal/carvel/testdata/sample-tile/base.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ property_blueprints:
1111
- $( property "admin_password" )
1212
form_types:
1313
- $( form "db_props" )
14-
variables: []
14+
variables:
15+
- name: sample-tile-ca
16+
type: certificate
17+
options:
18+
common_name: Sample Tile CA
19+
is_ca: true
20+
duration: 730
1521
package_installs:
1622
- $( package "test-install" )
1723
compatible_kubernetes_distributions:

0 commit comments

Comments
 (0)