From 367284916c0242ee7a2fb1e17c18e4df6ef4115d Mon Sep 17 00:00:00 2001 From: David Gageot Date: Sat, 19 May 2018 21:39:50 +0200 Subject: [PATCH] Strict YAML parsing. Fail on unknown fields Signed-off-by: David Gageot --- pkg/skaffold/config/config_test.go | 18 +++++++++--------- pkg/skaffold/schema/v1alpha1/config.go | 2 +- pkg/skaffold/schema/v1alpha2/config.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/skaffold/config/config_test.go b/pkg/skaffold/config/config_test.go index 58a66c662fa..df5877301a9 100644 --- a/pkg/skaffold/config/config_test.go +++ b/pkg/skaffold/config/config_test.go @@ -38,7 +38,7 @@ build: artifacts: - imageName: example deploy: - name: example + kubectl: {} ` completeConfig = ` apiVersion: skaffold/v1alpha2 @@ -58,7 +58,7 @@ build: googleCloudBuild: projectId: ID deploy: - name: example + kubectl: {} ` badConfig = "bad config" ) @@ -88,7 +88,7 @@ func TestParseConfig(t *testing.T) { withTagPolicy(v1alpha2.TagPolicy{GitTagger: &v1alpha2.GitTagger{}}), withDockerArtifact("example", ".", "Dockerfile"), ), - withDeploy(), + withKubectlDeploy(), ), }, { @@ -100,7 +100,7 @@ func TestParseConfig(t *testing.T) { withDockerArtifact("image1", "./examples/app1", "Dockerfile.dev"), withBazelArtifact("image2", "./examples/app2", "//:example.tar"), ), - withDeploy(), + withKubectlDeploy(), ), }, { @@ -146,13 +146,13 @@ func withGCBBuild(id string, ops ...func(*v1alpha2.BuildConfig)) func(*SkaffoldC } } -func withDeploy(ops ...func(*v1alpha2.DeployConfig)) func(*SkaffoldConfig) { +func withKubectlDeploy() func(*SkaffoldConfig) { return func(cfg *SkaffoldConfig) { - d := v1alpha2.DeployConfig{} - for _, op := range ops { - op(&d) + cfg.Deploy = v1alpha2.DeployConfig{ + DeployType: v1alpha2.DeployType{ + KubectlDeploy: &v1alpha2.KubectlDeploy{}, + }, } - cfg.Deploy = d } } diff --git a/pkg/skaffold/schema/v1alpha1/config.go b/pkg/skaffold/schema/v1alpha1/config.go index 6cb76441673..bc1d2e2d61a 100644 --- a/pkg/skaffold/schema/v1alpha1/config.go +++ b/pkg/skaffold/schema/v1alpha1/config.go @@ -135,7 +135,7 @@ func (config *SkaffoldConfig) Parse(contents []byte, useDefault bool) error { *config = SkaffoldConfig{} } - return yaml.Unmarshal(contents, config) + return yaml.UnmarshalStrict(contents, config) } func (config *SkaffoldConfig) getDefaultForMode(dev bool) *SkaffoldConfig { diff --git a/pkg/skaffold/schema/v1alpha2/config.go b/pkg/skaffold/schema/v1alpha2/config.go index 14432a43d14..5c8b43bdfa5 100644 --- a/pkg/skaffold/schema/v1alpha2/config.go +++ b/pkg/skaffold/schema/v1alpha2/config.go @@ -159,7 +159,7 @@ type BazelArtifact struct { // Parse reads a SkaffoldConfig from yaml. func (c *SkaffoldConfig) Parse(contents []byte, useDefaults bool) error { - if err := yaml.Unmarshal(contents, c); err != nil { + if err := yaml.UnmarshalStrict(contents, c); err != nil { return err }