diff --git a/canary-checker/docs/scripting/gotemplate.md b/canary-checker/docs/scripting/gotemplate.mdx similarity index 99% rename from canary-checker/docs/scripting/gotemplate.md rename to canary-checker/docs/scripting/gotemplate.mdx index 7d25e20e..98b4603d 100644 --- a/canary-checker/docs/scripting/gotemplate.md +++ b/canary-checker/docs/scripting/gotemplate.mdx @@ -1,9 +1,10 @@ -# Go Templates +import GoTemplate from '@site/docs/partials/_gotemplate.md' - +# 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 @@ -18,20 +19,10 @@ spec: template: '$1 = €{{.json.rates.EUR}}, £{{.json.rates.GBP}}, ₪{{.json.rates.ILS}}' ``` -## Escaping +

-In case you might need to pass in a template variable without templating it, then you can put the template inside a string. -Example: + -``` -{{ .secret }} -``` - -To send `{{ .secret }}` as it is do this - -``` -{{`{{ .secret }}`}} -``` ## base64 diff --git a/canary-checker/docs/windows.md b/canary-checker/docs/windows.md index 1a3ba761..cb7f9a5e 100644 --- a/canary-checker/docs/windows.md +++ b/canary-checker/docs/windows.md @@ -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 @@ -56,8 +56,7 @@ 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 @@ -65,4 +64,4 @@ The powershell install script is able to download all requirements , if the wind 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 diff --git a/mission-control/docs/partials/_gotemplate.md b/mission-control/docs/partials/_gotemplate.md new file mode 100644 index 00000000..d2379e63 --- /dev/null +++ b/mission-control/docs/partials/_gotemplate.md @@ -0,0 +1,64 @@ +

+ +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 +``` + +
+ +
+ +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) + +
+ +
+ +If you are using a YAML multiline string use `|` and not `>` which will strip newlines + +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 +``` +
+ + +
+ +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 +``` +
diff --git a/mission-control/docs/playbooks/Actions/exec.mdx b/mission-control/docs/playbooks/Actions/exec.mdx index 7c7522c0..24885970 100644 --- a/mission-control/docs/playbooks/Actions/exec.mdx +++ b/mission-control/docs/playbooks/Actions/exec.mdx @@ -2,7 +2,7 @@ title: Exec --- import Templating from "../../reference/playbooks/context.mdx" - +import GoTemplate from '@site/docs/partials/_gotemplate.md' # Exec Action @@ -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 -``` + ### Connections