Skip to content

fix(cli): Environment name at env creation (#397) #404

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

Merged
merged 1 commit into from
Oct 12, 2020
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
7 changes: 6 additions & 1 deletion cmd/tk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/labels"

"github.com/grafana/tanka/pkg/jsonnet/jpath"
"github.com/grafana/tanka/pkg/kubernetes/client"
"github.com/grafana/tanka/pkg/spec/v1alpha1"
"github.com/grafana/tanka/pkg/term"
Expand Down Expand Up @@ -156,8 +157,12 @@ func addEnv(dir string, cfg *v1alpha1.Config) error {
}
}

rootDir, err := jpath.FindRoot(path)
if err != nil {
return err
}
// the other properties are already set by v1alpha1.New() and pflag.Parse()
cfg.Metadata.Name = filepath.Base(path)
cfg.Metadata.Name, _ = filepath.Rel(rootDir, path)

// write spec.json
if err := writeJSON(cfg, filepath.Join(path, "spec.json")); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/jsonnet/jpath/jpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Resolve(workdir string) (path []string, base, root string, err error) {
return nil, "", "", err
}

root, err = findRoot(workdir)
root, err = FindRoot(workdir)
if err != nil {
return nil, "", "", err
}
Expand All @@ -60,10 +60,10 @@ func Resolve(workdir string) (path []string, base, root string, err error) {
}, base, root, nil
}

// findRoot searches for a rootDir by the following criteria:
// FindRoot searches for a rootDir by the following criteria:
// - tkrc.yaml is considered first, for a jb-independent way of marking the root
// - if it is not present (default), jsonnetfile.json is used.
func findRoot(start string) (dir string, err error) {
func FindRoot(start string) (dir string, err error) {
// root path based on os
stop := "/"
if runtime.GOOS == "windows" {
Expand Down