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

Error when apiVersion is not set in a patch when creating cluster #8270

Closed
frezbo opened this issue Feb 6, 2024 · 0 comments · Fixed by #8285
Closed

Error when apiVersion is not set in a patch when creating cluster #8270

frezbo opened this issue Feb 6, 2024 · 0 comments · Fixed by #8285
Assignees

Comments

@frezbo
Copy link
Member

frezbo commented Feb 6, 2024

Bug Report

Gets an unable to decode keys error when a patch has apiVersion missing, or apiversion is mistyped

For example, this patch below triggers the error:

---
apiversion: v1alpha1
kind: ExtensionServicesConfig
config:
    - name: nut-client
      configFiles:
        - content: MONITOR ${upsmonHost} 1 remote pass foo
          mountPath: /usr/local/etc/nut/upsmon.conf

note that apiversion is misttyped

Description

A hacky patch is attached here, which doesn't seem to be correct

diff --git hack/release.toml hack/release.toml
index ef3b501e8..a7bd28339 100644
--- hack/release.toml
+++ hack/release.toml
@@ -6,7 +6,7 @@ github_repo = "siderolabs/talos"
 match_deps = "^github.com/((talos-systems|siderolabs)/[a-zA-Z0-9-]+)$"
 
 # previous release
-previous = "v1.6.3"
+previous = "v1.6.0"
 
 pre_release = true
 
diff --git pkg/machinery/config/configloader/internal/decoder/decoder.go pkg/machinery/config/configloader/internal/decoder/decoder.go
index 3e2a89e6c..70d67d206 100644
--- pkg/machinery/config/configloader/internal/decoder/decoder.go
+++ pkg/machinery/config/configloader/internal/decoder/decoder.go
@@ -16,12 +16,8 @@ import (
 	"github.com/siderolabs/talos/pkg/machinery/config/internal/registry"
 )
 
-var (
-	// ErrMissingKind indicates that the manifest is missing a kind.
-	ErrMissingKind = errors.New("missing kind")
-	// ErrMissingVersion indicates that the manifest is missing a version.
-	ErrMissingVersion = errors.New("missing apiVersion key")
-)
+// ErrMissingKind indicates that the manifest is missing a kind.
+var ErrMissingKind = errors.New("missing kind")
 
 const (
 	// ManifestAPIVersionKey is the string indicating a manifest's version.
@@ -128,8 +124,6 @@ func decode(manifest *yaml.Node) (target config.Document, err error) {
 	}
 
 	switch {
-	case version == "":
-		err = ErrMissingVersion
 	case version == "v1alpha1" && kind == "":
 		target, err = registry.New("v1alpha1", "")
 	case kind == "":
diff --git pkg/machinery/config/configpatcher/apply_test.go pkg/machinery/config/configpatcher/apply_test.go
index db8d578e1..2875970c3 100644
--- pkg/machinery/config/configpatcher/apply_test.go
+++ pkg/machinery/config/configpatcher/apply_test.go
@@ -98,13 +98,6 @@ func TestApplyMultiDocFail(t *testing.T) {
 	}
 }
 
-func TestValidateAPIVersion(t *testing.T) {
-	_, err := configpatcher.LoadPatches([]string{
-		"@testdata/multidoc/wrong-apiversion.yaml",
-	})
-	assert.EqualError(t, err, "missing apiVersion key")
-}
-
 func TestApplyMultiDoc(t *testing.T) {
 	patches, err := configpatcher.LoadPatches([]string{
 		"@testdata/multidoc/strategic1.yaml",
diff --git pkg/machinery/config/configpatcher/testdata/multidoc/wrong-apiversion.yaml pkg/machinery/config/configpatcher/testdata/multidoc/wrong-apiversion.yaml
deleted file mode 100644
index f7a8eefe1..000000000
--- pkg/machinery/config/configpatcher/testdata/multidoc/wrong-apiversion.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-apiversion: v1alpha1
-kind: SideroLinkConfig
-apiUrl: https://siderolink.api/join?jointoken=secret&user=alice
@smira smira self-assigned this Feb 8, 2024
smira added a commit to smira/talos that referenced this issue Feb 8, 2024
Fixes siderolabs#8270

The base bug was that the registry will return `nil` `ConfigDocument` if
the version is not registered for a kind, which would result into weird
config decoding errors.

Add more unit-tests, while at it, also add more fuzzing samples.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants