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

Support Cluster config with a path #2342

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions integration/testdata/regressions/docker-config-path/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Test for #2330
apiVersion: skaffold/v1beta11
kind: Config
build:
artifacts:
- image: image
kaniko: {}
cluster:
dockerConfig:
path: C:\Users\prashant\.docker\config.json
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
54 changes: 31 additions & 23 deletions pkg/skaffold/schema/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ import (
"path/filepath"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/testutil"
)

const (
samplesRoot = "../../../docs/content/en/samples"
examplesRoot = "../../../examples"
samplesRoot = "../../../docs/content/en/samples"
)

var (
ignoredSamples = []string{"structureTest.yaml", "build.sh"}
)

// Test that every example can be parsed and produces a valid
// Skaffold configuration.
func TestParseExamples(t *testing.T) {
parseConfigFiles(t, "../../../examples")
parseConfigFiles(t, "../../../integration/testdata/regressions")
}

// Samples are skaffold.yaml fragments that are used
// in the documentation.
func TestParseSamples(t *testing.T) {
Expand All @@ -52,37 +60,39 @@ func TestParseSamples(t *testing.T) {

for _, path := range paths {
name := filepath.Base(path)
if util.StrSliceContains(ignoredSamples, name) {
continue
}

testutil.Run(t, name, func(t *testutil.T) {
for _, is := range ignoredSamples {
if name == is {
t.Skip()
}
}

buf, err := ioutil.ReadFile(path)
t.CheckNoError(err)

configFile := t.TempFile("skaffold.yaml", addHeader(buf))
cfg, err := ParseConfig(configFile, true)
t.CheckNoError(err)

err = validation.Process(cfg.(*latest.SkaffoldConfig))
t.CheckNoError(err)
checkSkaffoldConfig(t, addHeader(buf))
})
}
}

// TestParseExamples complete skaffold.yaml that user can use
// with the latest release of Skaffold.
func TestParseExamples(t *testing.T) {
paths, err := findExamples(examplesRoot)
func checkSkaffoldConfig(t *testutil.T, yaml []byte) {
configFile := t.TempFile("skaffold.yaml", yaml)
cfg, err := ParseConfig(configFile, true)
t.CheckNoError(err)

err = defaults.Set(cfg.(*latest.SkaffoldConfig))
t.CheckNoError(err)

err = validation.Process(cfg.(*latest.SkaffoldConfig))
t.CheckNoError(err)
}

func parseConfigFiles(t *testing.T, root string) {
paths, err := findExamples(root)
if err != nil {
t.Fatalf("unable to list examples in %q", examplesRoot)
t.Fatalf("unable to list skaffold configuration files in %q", root)
}

if len(paths) == 0 {
t.Fatalf("did not find examples in %q", examplesRoot)
t.Fatalf("did not find skaffold configuration files in %q", root)
}

for _, path := range paths {
Expand All @@ -92,9 +102,7 @@ func TestParseExamples(t *testing.T) {
buf, err := ioutil.ReadFile(path)
t.CheckNoError(err)

configFile := t.TempFile("skaffold.yaml", buf)
_, err = ParseConfig(configFile, true)
t.CheckNoError(err)
checkSkaffoldConfig(t, buf)
})
}
}
Expand Down