Skip to content

Commit 9709f1c

Browse files
committed
fix: pin the empty kind to installation
1 parent 2d84572 commit 9709f1c

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

api/v1alpha1/casting_kind.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ var (
2222
KindInfrastructure Kind = Kind{s: "Infrastructure"}
2323
)
2424

25-
// Kind discriminates between top-level casting resource types. Every casting
26-
// document states its own, so that one file can hold several.
25+
// Kind discriminates between top-level casting resource types.
26+
// An empty/missing kind unmarshals to KindInstallation for backwards compatibility
27+
// with casting files written before kind was introduced.
2728
type Kind struct {
2829
s string
2930
}
@@ -51,7 +52,8 @@ func (kind *Kind) UnmarshalJSON(text []byte) error {
5152

5253
func (kind *Kind) UnmarshalText(text []byte) error {
5354
if len(text) == 0 {
54-
return errors.New("kind is required")
55+
*kind = KindInstallation
56+
return nil
5557
}
5658

5759
for _, available := range Kinds() {

internal/config/yamlconfig/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ func (c *yamlConfig) castings(contents []byte, path string, read func(loader, []
172172
return nil, errors.Wrapf(err, errors.TypeInvalidInput, "invalid casting file %s: document %d", path, position)
173173
}
174174

175+
// Empty or missing kind defaults to KindInstallation so existing
176+
// castings without `kind` keep working.
175177
if probe.Kind == (v1alpha1.Kind{}) {
176-
return nil, errors.Newf(errors.TypeInvalidInput, "invalid casting file %s: document %d: kind is required", path, position)
178+
probe.Kind = v1alpha1.KindInstallation
177179
}
178180

179181
// A Kind appears at most once: two documents of a Kind would pour into

internal/config/yamlconfig/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ spec:
457457
expectedError: "Installation is declared twice",
458458
},
459459
{
460-
name: "MissingKind_Invalid",
460+
name: "MissingKind_DefaultsToInstallation",
461461
contents: `
462462
apiVersion: v1alpha1
463463
metadata:
@@ -467,7 +467,8 @@ spec:
467467
mode: docker
468468
flavor: compose
469469
`,
470-
expectedError: "kind is required",
470+
expectedKinds: []v1alpha1.Kind{v1alpha1.KindInstallation},
471+
pass: true,
471472
},
472473
{
473474
name: "UnknownKind_Invalid",

0 commit comments

Comments
 (0)