Skip to content

Commit

Permalink
tiltfile: fix a bug in helm(namespace=) semantics. Fixes #3701 (#3702)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Aug 14, 2020
1 parent 5ed892f commit 4824354
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/k8s/client.go
Expand Up @@ -42,6 +42,7 @@ type NodeID string
type ServiceName string
type KubeContext string

// NOTE(nick): This isn't right. DefaultNamespace is a function of your kubectl context.
const DefaultNamespace = Namespace("default")

var ForbiddenFieldsRe = regexp.MustCompile(`updates to .* are forbidden`)
Expand Down
8 changes: 8 additions & 0 deletions internal/k8s/entity.go
Expand Up @@ -221,6 +221,14 @@ func (e K8sEntity) Namespace() Namespace {
return Namespace(n)
}

func (e K8sEntity) NamespaceOrDefault(defaultVal string) string {
n := e.meta().GetNamespace()
if n == "" {
return defaultVal
}
return n
}

func (e K8sEntity) UID() types.UID {
return e.meta().GetUID()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tiltfile/files.go
Expand Up @@ -247,7 +247,7 @@ func (s *tiltfileState) helm(thread *starlark.Thread, fn *starlark.Builtin, args
}

for i, e := range parsed {
parsed[i] = e.WithNamespace(namespace)
parsed[i] = e.WithNamespace(e.NamespaceOrDefault(namespace))
}

yaml, err = k8s.SerializeSpecYAML(parsed)
Expand Down
30 changes: 30 additions & 0 deletions internal/tiltfile/helm_test.go
Expand Up @@ -9,6 +9,36 @@ import (
"github.com/tilt-dev/tilt/internal/tiltfile/testdata"
)

func TestHelmNamespace(t *testing.T) {
f := newFixture(t)
defer f.TearDown()

f.setupHelm()
f.file("helm/templates/public-config.yaml", `apiVersion: v1
kind: ConfigMap
metadata:
name: public-config
namespace: kube-public
data:
noData: "true"
`)

f.file("Tiltfile", `
yml = helm('./helm', name='rose-quartz', namespace='garnet')
k8s_yaml(yml)
`)

f.load()

m := f.assertNextManifestUnresourced(
"public-config",
"rose-quartz-helloworld-chart")
yaml := m.K8sTarget().YAML

assert.Contains(t, yaml, "name: rose-quartz-helloworld-chart\n namespace: garnet")
assert.Contains(t, yaml, "name: public-config\n namespace: kube-public")
}

func TestHelmSetArgs(t *testing.T) {
f := newFixture(t)
defer f.TearDown()
Expand Down

0 comments on commit 4824354

Please sign in to comment.