Skip to content

Commit

Permalink
chore: doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Aug 30, 2024
1 parent 79a8e36 commit 08b7a4f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Go Templates
import GoTemplate from '@site/docs/partials/_gotemplate.md'

<!-- // cspell:ignore conv, strconv,Ints -->
# Go Templates

`template` expressions use the [Go Text Template](https://pkg.go.dev/text/template) library with some additional functions provided by the [gomplate](https://docs.gomplate.ca/) library.
In this example we get the current exchange rate:

In this example we print out the exchange rates returned by an HTTP API Call

```yaml title="display-with-gotemplate.yaml"
apiVersion: canaries.flanksource.com/v1
Expand All @@ -18,20 +19,10 @@ spec:
template: '$1 = €{{.json.rates.EUR}}, £{{.json.rates.GBP}}, ₪{{.json.rates.ILS}}'
```
## Escaping
<p/>
In case you might need to pass in a template variable without templating it, then you can put the template inside a string.
Example:
<GoTemplate/>
```
{{ .secret }}
```

To send `{{ .secret }}` as it is do this

```
{{`{{ .secret }}`}}
```
## base64
Expand Down
7 changes: 3 additions & 4 deletions canary-checker/docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In order to run Canary Checker on windows please ensure the following
2. You must be able to execute the powershell install script as a local administrator
3. Canary Checker uses an embedded Postgress DB which requires [Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.38.33130](https://www.microsoft.com/en-us/Download/confirmation.aspx?id=52685)

4. Canary checker uses port 8080 (can be changed) for the HTTP API and port 6432 for the embedded posgres sql server , ensure these ports are free
4. Canary checker uses port 8080 (can be changed) for the HTTP API and port 6432 for the embedded postgresql server , ensure these ports are free

## 2. Downloading required files

Expand Down Expand Up @@ -56,13 +56,12 @@ To test our canary config without installing it, use the below
```

## 4. Install Canary Checker as a service

The powershell install script is able to download all requirements , if the windows machine does not have internet accesss you will need to manually download the [prerequisites](/##-1.-check-prerequisites) and place them in the script folder.
The powershell install script is able to download all requirements , if the windows machine does not have internet access you will need to manually download the [prerequisites](/##-1.-check-prerequisites) and place them in the script folder.

```
.\install-service.ps1 -configfile .\canary-checker.yaml -operation install
```

Note: Add `-httpPort 8081` to change http port (default is 8080)

Note: You can use the `-operation uninstall` to remove the service Or `-operation reinstall` to overwrite an exiting install
Note: You can use the ```-operation uninstall``` to remove the service Or ```-operation reinstall``` to overwrite an exiting install
64 changes: 64 additions & 0 deletions mission-control/docs/partials/_gotemplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Details summary="Switching scripting language">

Use a shebang (`#!`) line to choose a different shell (`python`, `bash` and `pwsh` are included in the base image)

```yaml
exec:
script: |
//highlight-next-line
#! pwsh
Get-Items | ConvertTo-JSON
```
</Details>
<Details summary="Escaping templates in Helm Charts">
If you need to pass a template through a Helm Chart and prevent Helm from templating you need to escape it:
```
{{`{{ .secret }}`}}
```

Alternatively [change the templating delimiters](#changing-templating-delimiters)

</Details>

<Details summary="Multiline handling with YAML">

If you are using a YAML multiline string use `|` and not `>` which will strip newlines

Check failure on line 29 in mission-control/docs/partials/_gotemplate.md

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/partials/_gotemplate.md#L29

[Flanksource.Spelling] Is 'multiline' spelled correctly? Is it missing code formatting?
Raw output
{"message": "[Flanksource.Spelling] Is 'multiline' spelled correctly? Is it missing code formatting?", "location": {"path": "mission-control/docs/partials/_gotemplate.md", "range": {"start": {"line": 29, "column": 25}}}, "severity": "ERROR"}

Check failure on line 29 in mission-control/docs/partials/_gotemplate.md

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/partials/_gotemplate.md#L29

[Vale.Spelling] Did you really mean 'multiline'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'multiline'?", "location": {"path": "mission-control/docs/partials/_gotemplate.md", "range": {"start": {"line": 29, "column": 25}}}, "severity": "ERROR"}

Check warning on line 29 in mission-control/docs/partials/_gotemplate.md

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/partials/_gotemplate.md#L29

[Flanksource.FutureTense] Use present tense verbs, not future tense verbs like 'will'. Say '(event) happens' instead of '(event) will happen'.
Raw output
{"message": "[Flanksource.FutureTense] Use present tense verbs, not future tense verbs like 'will'. Say '(event) happens' instead of '(event) will happen'.", "location": {"path": "mission-control/docs/partials/_gotemplate.md", "range": {"start": {"line": 29, "column": 68}}}, "severity": "WARNING"}

Instead of:
```yaml
exec:
//highlight-next-line
script: >
#! pwsh
Get-Items | ConvertTo-JSON
```
Do this:
```yaml
exec:
//highlight-next-line
script: |
#! pwsh
Get-Items | ConvertTo-JSON
```
</Details>
<Details summary="Changing templating delimiters">
The template delimiters can be changed from the defaults of `$()` and `{{}}` with `gotemplate` comments

```yaml
exec:
script: |
#! pwsh
//highlight-next-line
# gotemplate: left-delim=$[[ right-delim=]]
$message = "$[[.config.name]]"
Write-Host "{{ $message }}"
Write-Host @{ Number = 1; Shape = "Square"; Color = "Blue"} | ConvertTo-JSON
```
</Details>
51 changes: 3 additions & 48 deletions mission-control/docs/playbooks/Actions/exec.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Exec
---
import Templating from "../../reference/playbooks/context.mdx"

import GoTemplate from '@site/docs/partials/_gotemplate.md'

# <Icon name="console"/> Exec Action

Expand All @@ -23,61 +23,16 @@ Exec action allows you to executes a command or a script file on the target host
{field: 'connections', scheme: '[Connections](#connections)', description: 'Connections used by the action'}
]}/>


:::note Powershell
Shebang lines are supported to choose a different shell (`python`, `bash` and `pwsh` are included in the base image)
```yaml
exec:
script: |
#! pwsh
Get-Items | ConvertTo-JSON
```
:::
::: note Multiline
If you are using YAML multiline string use `|` and not `>` which will strip newlines


Instead of:
```
exec:
script: >
//highlight-nextline
#! pwsh
Get-Items | ConvertTo-JSON
```

Do this:
```
exec:
//highlight-nextline
script: |
#! pwsh
Get-Items | ConvertTo-JSON
```
:::


## Templating

Scripts are templatable with [Go Templates](/reference/script/gotemplate)
Scripts are templatable with [Go Templates](/reference/scripting/gotemplate)

```yaml
exec:
script: kubectl rollout release deployment -n $(.config.tags.namespace) $(.conf
```
The template delimiters can be changed from the defaults of `$()` and `{{}}` with `gotemplate` comments

```yaml
exec:
script: |
#! pwsh
# gotemplate: left-delim=$[[ right-delim=]]
$message = "$[[.config.name]]"
Write-Host "{{ $message }}"
Write-Host @{ Number = 1; Shape = "Square"; Color = "Blue"} | ConvertTo-JSON
```
<GoTemplate/>
### Connections
Expand Down

0 comments on commit 08b7a4f

Please sign in to comment.