Skip to content

Commit

Permalink
Support Cluster config with path to docker config
Browse files Browse the repository at this point in the history
Fix GoogleContainerTools#2330

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jun 28, 2019
1 parent 0b5c6d7 commit 99b331c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/skaffold/schema/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -219,6 +216,8 @@ func setDefaultClusterDockerConfigSecret(cluster *latest.ClusterDetails) error {
return nil
}

cluster.DockerConfig.SecretName = valueOrDefault(cluster.DockerConfig.SecretName, constants.DefaultKanikoDockerConfigSecretName)

return nil
}

Expand Down
34 changes: 29 additions & 5 deletions pkg/skaffold/schema/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,57 @@ 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{
"cluster1": {Namespace: "ns"},
},
})

// 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)
})
}

Expand Down

0 comments on commit 99b331c

Please sign in to comment.