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

feat(jsonnet): expose Environment at runtime #163

Merged
merged 3 commits into from
Jan 13, 2020
Merged

Conversation

sh0rez
Copy link
Member

@sh0rez sh0rez commented Jan 13, 2020

This change allows to use the parsed spec.json contents at runtime:

local tk = import "tk";

{
  env: tk.env,
}

It also introduces a Tanka native API extension (import "tk"), which serves as
a wrapper for all std.extVar and std.nativeFunc we use, so that we can make
breaking changes to those internals, without affecting the public API.

⚠️ There is a bug at the moment, that the metadata.name of the Environment is the CLI argument and not the actual name. This is fixed in #131 but not merged yet

Fixes #161

This change allows to use the parsed `spec.json` contents at runtime:

```jsonnet
local tk = import "tk";

{
  env: tk.env,
}
```

It also introduces a Tanka native API extension (`import "tk"`), which serves as
a wrapper for all `std.extVar` and `std.nativeFunc` we use, so that we can make
breaking changes to those internals, without affecting the public API.
@sh0rez sh0rez added kind/feature Something new should be added component/jsonnet Everything regarding the jsonnet language labels Jan 13, 2020
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good @sh0rez, just a few small comments / questions. The new Eval function looks like it should be functionally equivalent although I'm a bit nervous about it. Is there existing code coverage there?

cmd/tk/jsonnet.go Outdated Show resolved Hide resolved
pkg/jsonnet/eval.go Show resolved Hide resolved
pkg/jsonnet/eval.go Show resolved Hide resolved
}
}

// Import implements the functionality offered by the ExtendedImporter
func (i *ExtendedImporter) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error) {
// check if an interceptor handles this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand this better? Is the idea that you can only have one interceptor and one postprocessor for a given import at a time? I'd like to see some stronger godocs around these interceptors and processors since the ordering is important (i.e., if two interceptors operate on yaml, only the first will ever be used).

pkg/jsonnet/tk.libsonnet.go Outdated Show resolved Hide resolved
pkg/jsonnet/importer.go Outdated Show resolved Hide resolved
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sh0rez sh0rez merged commit e2fe3d8 into master Jan 13, 2020
@sh0rez sh0rez deleted the jsonnet-metadata branch January 13, 2020 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/jsonnet Everything regarding the jsonnet language kind/feature Something new should be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to Tanka metadata
2 participants