Skip to content

Commit c46b898

Browse files
CYPH4Rsmira
authored andcommitted
fix: validate missing apiVersion in config document decoder
Add ErrMissingAPIVersion check in the config document decoder, parallel to the existing ErrMissingKind. Previously, a typo in the apiVersion key (e.g. 'apiVerstion') would result in a misleading 'not registered' error instead of clearly indicating the missing field. Signed-off-by: Dominik Pitz <pitzdominik@gmail.com> Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com> (cherry picked from commit a728bbd)
1 parent c47cad9 commit c46b898

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/machinery/config/configloader/internal/decoder/decoder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
// ErrMissingKind indicates that the manifest is missing a kind.
2222
var ErrMissingKind = errors.New("missing kind")
2323

24+
// ErrMissingAPIVersion indicates that the manifest is missing an apiVersion.
25+
var ErrMissingAPIVersion = errors.New("missing apiVersion")
26+
2427
const (
2528
// ManifestAPIVersionKey is the string indicating a manifest's version.
2629
ManifestAPIVersionKey = "apiVersion"
@@ -176,6 +179,8 @@ func decode(manifest *yaml.Node) (target config.Document, err error) {
176179
target, err = registry.New("v1alpha1", "")
177180
case kind == "":
178181
err = ErrMissingKind
182+
case version == "":
183+
err = ErrMissingAPIVersion
179184
default:
180185
target, err = registry.New(kind, version)
181186
}

pkg/machinery/config/configloader/internal/decoder/decoder_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,15 @@ config:
322322
- content: MONITOR ${upsmonHost} 1 remote pass foo
323323
mountPath: /usr/local/etc/nut/upsmon.conf
324324
`),
325-
expectedErr: "error decoding document /ExtensionServiceConfig/ (line 2): \"ExtensionServiceConfig\" \"\": not registered",
325+
expectedErr: "error decoding document /ExtensionServiceConfig/ (line 2): missing apiVersion",
326+
},
327+
{
328+
name: "missing apiVersion",
329+
source: []byte(`---
330+
kind: mock
331+
test: true
332+
`),
333+
expectedErr: "error decoding document /mock/ (line 2): missing apiVersion",
326334
},
327335
}
328336

0 commit comments

Comments
 (0)