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

[docs] Add documentation for nomad-pack template functions #494

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

angrycub
Copy link
Contributor

This PR starts chipping away at the Pack documentation tech debt by documenting the template helper functions that Pack provides to the template context.

Copy link
Member

@gulducat gulducat left a comment

Choose a reason for hiding this comment

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

couple lil things, but otherwise LGTM!

##### Example

```
[[ $cs := ( customSpew | withDisableCapacities true ) ]][[ $cs.Sdump . ]]
Copy link
Member

Choose a reason for hiding this comment

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

should be a toStringList example

Comment on lines +89 to +98
##### Example

```

```

##### Output

```
```
Copy link
Member

Choose a reason for hiding this comment

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

empty example/output for nomadRegions


#### `fileContents` <a id="fileContents"></a>

Imports the contents of a file on the local file system into the template at runtime.

Choose a reason for hiding this comment

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

Can it be clarified that the files are relative to the directory where nomad-pack is invoked? I'm pretty sure they aren't relative to the job as that isn't working for me (which is frustrating, because thats where I'd expect them to be).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fileContents function is part of the job meta-templating and is run while building the job spec itself. Should you want to import files while processing the jobspec , you should consider the HCL2 file function, which would work more like you expect; but requires that the file to include always travel with the job spec.

@josegonzalez
Copy link

I think this is also missing the functions defined [here]https://github.com/hashicorp/nomad-pack/blob/3c0178a561b360906c591718edb25ae25ae9d964/internal/pkg/variable/parser/template_context.go#L159( for variable retrieval.

##### Example

```
[[ $cs := ( customSpew | withMaxDepth true ) ]][[ $cs.Sdump . ]]

Choose a reason for hiding this comment

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

Max Depth should be an integer

[[ $cs := ( customSpew | withMaxDepth 5) ]][[ $cs.Sdump . ]]

##### Example

```
[[ $cs := ( customSpew | withDisableMethods true ) ]][[ $cs.Sdump . ]]

Choose a reason for hiding this comment

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

withDisableMethods sets s.DisableMethods to true. So only "true" is not allowed (want 1 got 2). So it should be:

    [[ $cs := ( customSpew | withDisableMethods ) ]][[ $cs.Sdump . ]]

Choose a reason for hiding this comment

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

Same with all the following, which use "true" as parameter

@josegonzalez
Copy link

Could this get merged and then improved at a later date?

@jrasell jrasell assigned jrasell and unassigned angrycub Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants