Skip to content

Commit

Permalink
Merge global and context-specific array settings in Skaffold config
Browse files Browse the repository at this point in the history
Close #2554

Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
  • Loading branch information
corneliusweig committed Aug 13, 2019
1 parent c7ef098 commit 28427cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/content/en/docs/concepts/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ There are several levels of granularity to allow insecure communication with som
1. Per user via Skaffold's global config
```bash
skaffold config set insecure-registries insecure1.io
skaffold config set insecure-registries insecure2.io
skaffold config set insecure-registries insecure1.io # for the current kube-context
skaffold config set --global insecure-registries insecure2.io # for any kube-context
```
Note that multiple set commands _add_ to the existing list of insecure registries.
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func getConfigForKubeContextWithGlobalDefaults(cfg *GlobalConfig, kubeContext st
if cfg.Global != nil {
// if values are unset for the current context, retrieve
// the global config and use its values as a fallback.
if err := mergo.Merge(&mergedConfig, cfg.Global); err != nil {
if err := mergo.Merge(&mergedConfig, cfg.Global, mergo.WithAppendSlice); err != nil {
return nil, errors.Wrapf(err, "merging context-specific and global config")
}
}
Expand Down
36 changes: 25 additions & 11 deletions pkg/skaffold/config/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
DefaultRepo: "my-private-registry",
}
sampleConfig2 := &ContextConfig{
Kubecontext: "another_context",
InsecureRegistries: []string{"good.io", "better.io"},
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
Kubecontext: "another_context",
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
}

tests := []struct {
Expand Down Expand Up @@ -177,21 +176,36 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
},
},
expectedConfig: &ContextConfig{
Kubecontext: someKubeContext,
InsecureRegistries: []string{"good.io", "better.io"},
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
Kubecontext: someKubeContext,
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
},
},
{
name: "config for unknown kubecontext with merged values",
kubecontext: someKubeContext,
cfg: &GlobalConfig{Global: sampleConfig2},
expectedConfig: &ContextConfig{
Kubecontext: someKubeContext,
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
},
},
{
name: "merge global and context-specific insecure-registries",
kubecontext: someKubeContext,
cfg: &GlobalConfig{
Global: &ContextConfig{
InsecureRegistries: []string{"good.io", "better.io"},
},
ContextConfigs: []*ContextConfig{{
Kubecontext: someKubeContext,
InsecureRegistries: []string{"bad.io", "worse.io"},
}},
},
expectedConfig: &ContextConfig{
Kubecontext: someKubeContext,
InsecureRegistries: []string{"good.io", "better.io"},
LocalCluster: util.BoolPtr(false),
DefaultRepo: "my-public-registry",
InsecureRegistries: []string{"bad.io", "worse.io", "good.io", "better.io"},
},
},
}
Expand Down

0 comments on commit 28427cf

Please sign in to comment.