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

fix(jsonnet): Restore tk.env #482

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pkg/tanka/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func (i *InlineLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environme
}

func inlineEval(path string, opts JsonnetOpts) (manifest.List, error) {
// Can't provide env as extVar, as we need to evaluate Jsonnet first to know it
opts.ExtCode.Set(environmentExtCode, `error "Using tk.env and std.extVar('tanka.dev/environment') is only supported for static environments. Directly access this data using standard Jsonnet instead."`)

raw, err := EvalJsonnet(path, opts)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions pkg/tanka/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/pkg/errors"
)

// environmentExtCode is the extCode ID `tk.env` uses underneath
// TODO: remove "import tk" and replace it with tanka-util
const environmentExtCode = spec.APIGroup + "/environment"

// Load loads the Environment at `path`. It automatically detects whether to
// load inline or statically
func Load(path string, opts Opts) (*LoadResult, error) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/tanka/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func (s StaticLoader) Load(path string, opts LoaderOpts) (*v1alpha1.Environment,
return nil, err
}

envCode, err := specToExtCode(*config)
if err != nil {
return nil, err
}
opts.ExtCode.Set(environmentExtCode, envCode)
sh0rez marked this conversation as resolved.
Show resolved Hide resolved

data, err := EvalJsonnet(path, opts.JsonnetOpts)
if err != nil {
return nil, err
Expand Down Expand Up @@ -48,6 +54,16 @@ func (s StaticLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environmen
return []*v1alpha1.Environment{env}, nil
}

func specToExtCode(spec v1alpha1.Environment) (string, error) {
spec.Data = nil
data, err := json.Marshal(spec)
if err != nil {
return "", err
}

return string(data), nil
}

// parseStaticSpec parses the `spec.json` of the environment and returns a
// *kubernetes.Kubernetes from it
func parseStaticSpec(path string) (*v1alpha1.Environment, error) {
Expand Down