From 99b331cf6747c7797df79300460873e8f77f29b0 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 26 Jun 2019 14:24:20 +0200 Subject: [PATCH] Support Cluster config with path to docker config Fix #2330 Signed-off-by: David Gageot --- pkg/skaffold/schema/defaults/defaults.go | 5 ++- pkg/skaffold/schema/defaults/defaults_test.go | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/pkg/skaffold/schema/defaults/defaults.go b/pkg/skaffold/schema/defaults/defaults.go index 8db401aac9b..580b26253e1 100644 --- a/pkg/skaffold/schema/defaults/defaults.go +++ b/pkg/skaffold/schema/defaults/defaults.go @@ -29,7 +29,6 @@ import ( // Set makes sure default values are set on a SkaffoldConfig. func Set(c *latest.SkaffoldConfig) error { - defaultToLocalBuild(c) defaultToKubectlDeploy(c) setDefaultTagger(c) @@ -207,8 +206,6 @@ func setDefaultClusterDockerConfigSecret(cluster *latest.ClusterDetails) error { return nil } - cluster.DockerConfig.SecretName = valueOrDefault(cluster.DockerConfig.SecretName, constants.DefaultKanikoDockerConfigSecretName) - if cluster.DockerConfig.Path != "" { absPath, err := homedir.Expand(cluster.DockerConfig.Path) if err != nil { @@ -219,6 +216,8 @@ func setDefaultClusterDockerConfigSecret(cluster *latest.ClusterDetails) error { return nil } + cluster.DockerConfig.SecretName = valueOrDefault(cluster.DockerConfig.SecretName, constants.DefaultKanikoDockerConfigSecretName) + return nil } diff --git a/pkg/skaffold/schema/defaults/defaults_test.go b/pkg/skaffold/schema/defaults/defaults_test.go index 07d37af8e6b..42cd07e7411 100644 --- a/pkg/skaffold/schema/defaults/defaults_test.go +++ b/pkg/skaffold/schema/defaults/defaults_test.go @@ -61,7 +61,7 @@ func TestSetDefaults(t *testing.T) { } func TestSetDefaultsOnCluster(t *testing.T) { - testutil.Run(t, "", func(t *testutil.T) { + testutil.Run(t, "no docker config", func(t *testutil.T) { t.SetupFakeKubernetesContext(api.Config{ CurrentContext: "cluster1", Contexts: map[string]*api.Context{ @@ -69,25 +69,49 @@ func TestSetDefaultsOnCluster(t *testing.T) { }, }) + // no docker config cfg := &latest.SkaffoldConfig{ Pipeline: latest.Pipeline{ Build: latest.BuildConfig{ - Artifacts: []*latest.Artifact{ - {ImageName: "image"}, - }, BuildType: latest.BuildType{ Cluster: &latest.ClusterDetails{}, }, }, }, } - err := Set(cfg) t.CheckNoError(err) t.CheckDeepEqual("ns", cfg.Build.Cluster.Namespace) t.CheckDeepEqual(constants.DefaultKanikoTimeout, cfg.Build.Cluster.Timeout) t.CheckDeepEqual(constants.DefaultKanikoSecretName, cfg.Build.Cluster.PullSecretName) + + // default docker config + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{} + err = Set(cfg) + + t.CheckNoError(err) + t.CheckDeepEqual(constants.DefaultKanikoDockerConfigSecretName, cfg.Build.Cluster.DockerConfig.SecretName) + + // docker config with path + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{ + Path: "/path", + } + err = Set(cfg) + + t.CheckNoError(err) + t.CheckDeepEqual("", cfg.Build.Cluster.DockerConfig.SecretName) + t.CheckDeepEqual("/path", cfg.Build.Cluster.DockerConfig.Path) + + // docker config with secret name + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{ + SecretName: "secret", + } + err = Set(cfg) + + t.CheckNoError(err) + t.CheckDeepEqual("secret", cfg.Build.Cluster.DockerConfig.SecretName) + t.CheckDeepEqual("", cfg.Build.Cluster.DockerConfig.Path) }) }