Many of the utility functions provided come from Sprig, a third-party library of Go template functions. The Sprig documentation can be found here.
func Namespace() string
Namespace returns the Kubernetes namespace that the KOTS application belongs to.
'{{repl Namespace}}'
func KubeSeal(certData string, namespace string, name string, value string) string
func HumanSize(size interface{}) string
HumanSize returns a human-readable approximation of a size in bytes capped at 4 valid numbers (eg. “2.746 MB”, “796 KB”). The size must be a integer or floating point number.
'{{repl ConfigOption "min_size_bytes" | HumanSize }}'
func Now() string
Returns the current timestamp as an RFC3339 formatted string.
'{{repl Now }}'
func NowFmt(format string) string
Returns the current timestamp as a formatted string. See Go’s time formatting guidelines here.
'{{repl Now "20060102" }}'
func ToLower(stringToAlter string) string
Returns the string, in lowercase.
'{{repl ConfigOption "company_name" | ToLower }}'
func ToUpper(stringToAlter string) string
Returns the string, in uppercase.
'{{repl ConfigOption "company_name" | ToUpper }}'
func TrimSpace(s string) string
Trim returns a string with all leading and trailing spaces removed.
'{{repl ConfigOption "str_value" | TrimSpace }}'
func Trim(s string, args ...string) string
Trim returns a string with all leading and trailing string contained in the optional args removed (default space).
'{{repl ConfigOption "str_value" | Trim " " "." }}'
func UrlEncode(stringToEncode string) string
Returns the string, url encoded.
Equivalent to the QueryEscape
function within the golang net/url
library.
'{{repl ConfigOption "smtp_email" | UrlEncode }}:{{repl ConfigOption "smtp_password" | UrlEncode }}@smtp.example.com:587'
func UrlPathEscape(stringToEncode string) string
Returns the string, url path encoded.
Equivalent to the PathEscape
function within the golang net/url
library.
'{{repl ConfigOption "smtp_email" | UrlPathEscape }}:{{repl ConfigOption "smtp_password" | UrlPathEscape }}@smtp.example.com:587'
func Base64Encode(stringToEncode string) string
Returns a Base64 encoded string.
'{{repl ConfigOption "name" | Base64Encode }}'
func Base64Decode(stringToDecode string) string
Returns decoded string from a Base64 stored value.
'{{repl ConfigOption "base_64_encoded_name" | Base64Decode }}'
func Split(s string, sep string) []string
Split slices s into all substrings separated by sep and returns an array of the substrings between those separators.
'{{repl Split "A,B,C" "," }}'
Combining Split
and index
:
Assuming the github_url
param is set to https://github.mycorp.internal:3131
, the following would set
GITHUB_HOSTNAME
to github.mycorp.internal
.
'{{repl index (Split (index (Split (ConfigOption "github_url") "/") 2) ":") 0}}'
func RandomString(length uint64, providedCharset ...string) string
Returns a random string with the desired length and charset.
Provided charsets must be Perl formatted and match individual characters.
If no charset is provided, [_A-Za-z0-9]
will be used.
'{{repl RandomString 64}}'
Or for a total of 64 a
s and b
s:
'{{repl RandomString 64 "[ab]" }}'
Each time that this function is called, the behavior changes based on the hidden and readonly properties.
RandomString
value that is persistent between Config changes, use it in conjunction with hidden
property set to true
. The value
is not shown in HTML, hence it cannot be modified.RandomString
value that is ephemeral between Config changes, use it in conjunction with readonly
property set to true
. The value
is shown in HTML but the it cannot be modified.hidden
and readonly
are not set or set to false
, the value
is persistent between Config changes but it can also be modified in HTML.hidden
and readonly
are set to true
, the value
is not shown in HTML but it is ephemeral between Config changes and not modifiable.func Add(x interface{}, y interface{}) interface{}
Adds x and y.
If at least one of the operands is a floating point number, the result will be a floating point number.
If both operands are integers, the result will be an integer.
'{{repl Add (ConfigOption "maximum_users") 1}}'
func Sub(x interface{}, y interface{}) interface{}
Subtracts y from x.
If at least one of the operands is a floating point number, the result will be a floating point number.
If both operands are integers, the result will be an integer.
'{{repl Sub (ConfigOption "maximum_users") 1}}'
func Mult(x interface{}, y interface{}) interface{}
Multiplies x and y.
Both operands must be either an integer or a floating point number.
If at least one of the operands is a floating point number, the result will be a floating point number.
If both operands are integers, the result will be an integer.
'{{repl Mult (NodePrivateIPAddressAll "DB" "redis" | len) 2}}'
If a template function returns a string, the value must be converted to an integer or a floating point number first:
'{{repl Mult (ConfigOption "session_cookie_age" | ParseInt) 86400}}'
func Div(x interface{}, y interface{}) interface{}
Divides x by y.
If at least one of the operands is a floating point number, the result will be a floating point number.
If both operands are integers, the result will be an integer and will be rounded down.
'{{repl Div (ConfigOption "maximum_users") 2.0}}'
func ParseBool(str string) bool
ParseBool returns the boolean value represented by the string.
'{{repl ConfigOption "str_value" | ParseBool }}'
func ParseFloat(str string) float64
ParseFloat returns the float value represented by the string.
'{{repl ConfigOption "str_value" | ParseFloat }}'
func ParseInt(str string, args ...int) int64
ParseInt returns the integer value represented by the string with optional base (default 10).
'{{repl ConfigOption "str_value" | ParseInt }}'
func ParseUint(str string, args ...int) uint64
ParseUint returns the unsigned integer value represented by the string with optional base (default 10).
'{{repl ConfigOption "str_value" | ParseUint }}'
Deprecation Notice
This function has been superseded in KOTS 1.26.0 by Sprig’s crypto functions. Refer to this example for more information.
func TLSCert(certName string, cn string, ips []interface{}, alternateDNS []interface{}, daysValid int) string
TLSCert generates and returns a self-signed certificate identified by certName
.
The first parameter can be used in the TLSKey
function to retrieve the matching key.
TLSCert takes the following parameters
repl{{ TLSCert "my_custom_cert" "foo.com" (list "10.0.0.1" "10.0.0.2") (list "bar.com" "bat.com") 365 }}
Deprecation Notice
This function has been superseded in KOTS 1.26.0 by Sprig’s crypto functions. Refer to this example for more information.
func TLSKey(certName string, cn string, ips []interface{}, alternateDNS []interface{}, daysValid int) string
TLSKey returns the key that matches the certificate identified by certName
.
The rest of the arguments are the same as in TLSCert
and, if specified, must have the same values.
If they are omitted and the certificate with this name does not exist, the function will return an empty string.
repl{{ TLSKey "my_custom_cert" "foo.com" (list "10.0.0.1" "10.0.0.2") (list "bar.com" "bat.com") 365 }}
Deprecation Notice
This function has been superseded in KOTS 1.26.0 by Sprig’s crypto functions. Refer to this example for more information.
func TLSCACert(caName string, daysValid int) string
TLSCACert generates and returns a CA certificate that can be used as a CA to sign other certificates.
TLSCACert takes the following parameters
repl{{ TLSCACert "foo.com" 365 }}
Deprecation Notice
This function has been superseded in KOTS 1.26.0 by Sprig’s crypto functions. Refer to this example for more information.
func TLSCertFromCA(caName string, certName string, cn string, ips []interface{}, alternateDNS []interface{}, daysValid int) string
TLSCertFromCA generates and returns a certificate signed by the CA identified by caName
.
The rest of the arguments are the same as in TLSCert
.
repl{{ TLSCertFromCA "foo.com" "my_custom_cert" "bar.com" (list "10.0.0.1" "10.0.0.2") (list "bar.com" "bat.com") 365 }}
Deprecation Notice
This function has been superseded in KOTS 1.26.0 by Sprig’s crypto functions. Refer to this example for more information.
func TLSKeyFromCA(caName string, certName string, cn string, ips []interface{}, alternateDNS []interface{}, daysValid int) string
TLSKeyFromCA generates and returns a key that matches the certificate returned by TLSCertFromCA
.
The arguments are the same as in TLSCertFromCA
and their values must match.
repl{{ TLSKeyFromCA "foo.com" "my_custom_cert" "bar.com" (list "10.0.0.1" "10.0.0.2") (list "bar.com" "bat.com") 365 }}
func IsKurl() bool
IsKurl returns true if running within a kurl-based installation.
repl{{ IsKurl }}
func Distribution() string
Distribution returns the kubernetes distribution detected, such as kurl
, openShift
or eks
.
repl{{ Distribution }}
func NodeCount() int
NodeCount returns the number of nodes detected within the kubernetes cluster.
repl{{ NodeCount }}
func HTTPProxy() string
HTTPProxy returns the address of the proxy that the Admin Console is configured to use.
repl{{ HTTPProxy }}
func NoProxy() string
NoProxy returns the comma-separated list of no-proxy addresses that the Admin Console is configured to use.
repl{{ NoProxy }}
func KotsVersion() string
KotsVersion returns the current KOTS tag/version the Admin Console is using.
repl{{ KotsVersion }}
KotsVersion
can be compared to semvers like follows:
repl{{KotsVersion | semverCompare ">= 1.19"}}
The above template function will return true
if KotsVersion
is greater than 1.19
.
For more complex comparisons, please refer to sprig Semantic Version Functions