[state] - Fix issue where spec[].Namespace were ignored
This commit is contained in:
parent
c990d19cb0
commit
76dcc6b182
|
|
@ -117,7 +117,9 @@ func renderTemplateString(s string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *HelmState) applyDefaultsTo(spec ReleaseSpec) ReleaseSpec {
|
func (state *HelmState) applyDefaultsTo(spec ReleaseSpec) ReleaseSpec {
|
||||||
spec.Namespace = state.Namespace
|
if state.Namespace != "" {
|
||||||
|
spec.Namespace = state.Namespace
|
||||||
|
}
|
||||||
return spec
|
return spec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,7 +157,6 @@ func (state *HelmState) SyncReleases(helm helmexec.Interface, additonalValues []
|
||||||
if workerLimit < 1 {
|
if workerLimit < 1 {
|
||||||
workerLimit = len(state.Releases)
|
workerLimit = len(state.Releases)
|
||||||
}
|
}
|
||||||
|
|
||||||
for w := 1; w <= workerLimit; w++ {
|
for w := 1; w <= workerLimit; w++ {
|
||||||
go func() {
|
go func() {
|
||||||
for release := range jobQueue {
|
for release := range jobQueue {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -8,6 +9,7 @@ func TestReadFromYaml(t *testing.T) {
|
||||||
yamlFile := "example/path/to/yaml/file"
|
yamlFile := "example/path/to/yaml/file"
|
||||||
yamlContent := []byte(`releases:
|
yamlContent := []byte(`releases:
|
||||||
- name: myrelease
|
- name: myrelease
|
||||||
|
namespace: mynamespace
|
||||||
chart: mychart
|
chart: mychart
|
||||||
`)
|
`)
|
||||||
state, err := readFromYaml(yamlContent, yamlFile)
|
state, err := readFromYaml(yamlContent, yamlFile)
|
||||||
|
|
@ -18,6 +20,9 @@ func TestReadFromYaml(t *testing.T) {
|
||||||
if state.Releases[0].Name != "myrelease" {
|
if state.Releases[0].Name != "myrelease" {
|
||||||
t.Errorf("unexpected release name: expected=myrelease actual=%s", state.Releases[0].Name)
|
t.Errorf("unexpected release name: expected=myrelease actual=%s", state.Releases[0].Name)
|
||||||
}
|
}
|
||||||
|
if state.Releases[0].Namespace != "mynamespace" {
|
||||||
|
t.Errorf("unexpected chart namespace: expected=mynamespace actual=%s", state.Releases[0].Chart)
|
||||||
|
}
|
||||||
if state.Releases[0].Chart != "mychart" {
|
if state.Releases[0].Chart != "mychart" {
|
||||||
t.Errorf("unexpected chart name: expected=mychart actual=%s", state.Releases[0].Chart)
|
t.Errorf("unexpected chart name: expected=mychart actual=%s", state.Releases[0].Chart)
|
||||||
}
|
}
|
||||||
|
|
@ -56,3 +61,93 @@ releases:
|
||||||
t.Error("expected error")
|
t.Error("expected error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHelmState_applyDefaultsTo(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
BaseChartPath string
|
||||||
|
Context string
|
||||||
|
DeprecatedReleases []ReleaseSpec
|
||||||
|
Namespace string
|
||||||
|
Repositories []RepositorySpec
|
||||||
|
Releases []ReleaseSpec
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
spec ReleaseSpec
|
||||||
|
}
|
||||||
|
specWithNamespace := ReleaseSpec{
|
||||||
|
Chart: "test/chart",
|
||||||
|
Version: "0.1",
|
||||||
|
Verify: false,
|
||||||
|
Name: "test-charts",
|
||||||
|
Namespace: "test-namespace",
|
||||||
|
Values: nil,
|
||||||
|
SetValues: nil,
|
||||||
|
EnvValues: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
specWithoutNamespace := specWithNamespace
|
||||||
|
specWithoutNamespace.Namespace = ""
|
||||||
|
specWithNamespaceFromFields := specWithNamespace
|
||||||
|
specWithNamespaceFromFields.Namespace = "test-namespace-field"
|
||||||
|
|
||||||
|
fieldsWithNamespace := fields{
|
||||||
|
BaseChartPath: ".",
|
||||||
|
Context: "test_context",
|
||||||
|
DeprecatedReleases: nil,
|
||||||
|
Namespace: specWithNamespaceFromFields.Namespace,
|
||||||
|
Repositories: nil,
|
||||||
|
Releases: []ReleaseSpec{
|
||||||
|
specWithNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsWithoutNamespace := fieldsWithNamespace
|
||||||
|
fieldsWithoutNamespace.Namespace = ""
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
want ReleaseSpec
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Has a namespace from spec",
|
||||||
|
fields: fieldsWithoutNamespace,
|
||||||
|
args: args{
|
||||||
|
spec: specWithNamespace,
|
||||||
|
},
|
||||||
|
want: specWithNamespace,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Has a namespace from flags",
|
||||||
|
fields: fieldsWithoutNamespace,
|
||||||
|
args: args{
|
||||||
|
spec: specWithNamespace,
|
||||||
|
},
|
||||||
|
want: specWithNamespace,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Has a namespace from flags and from spec",
|
||||||
|
fields: fieldsWithNamespace,
|
||||||
|
args: args{
|
||||||
|
spec: specWithNamespace,
|
||||||
|
},
|
||||||
|
want: specWithNamespaceFromFields,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
state := &HelmState{
|
||||||
|
BaseChartPath: tt.fields.BaseChartPath,
|
||||||
|
Context: tt.fields.Context,
|
||||||
|
DeprecatedReleases: tt.fields.DeprecatedReleases,
|
||||||
|
Namespace: tt.fields.Namespace,
|
||||||
|
Repositories: tt.fields.Repositories,
|
||||||
|
Releases: tt.fields.Releases,
|
||||||
|
}
|
||||||
|
if got := state.applyDefaultsTo(tt.args.spec); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("HelmState.applyDefaultsTo() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue