Template Functions

The dynamic configuration management functionality available throughout the Replicated YAML.

Template functions are marked by the double curly bracket + “repl” escape sequence. They allow for user input to be dynamically inserted into application configuration values. The sequence should be {{repl, not {{ repl.

Go Templates

Replicated uses Go’s template engine to execute the following functions. In addition to the functions listed here, all of the Go template runtime is available. Please note that Go template functions must still be escaped with “repl” escape sequence as demonstrated below.

{{repl if pipeline}} T1 {{repl else}} T0 {{repl end}}

Replicated Template Function

ConfigOption

func ConfigOption(optionName string) string

Returns the value of the config option as a string.

properties:
  app_url: http://{{repl ConfigOption "hostname" }}

ConfigOptionData

(only supports type: file)

func ConfigOptionData(fileName string) string

Returns the contents of the file uploaded for a configuration option as a string.

kind: Secret
metadata:
  name: www-tls
data:
  cert: '{{repl ConfigOptionData "ssl_cert" | Base64Encode }}'

ConfigOptionEquals

func ConfigOptionEquals(optionName string, expectedValue string) bool

Returns true if the configuration option value is equal to the supplied value.

ports:
   - private_port: "80"
     public_port: "80"
     port_type: tcp
     when: '{{repl ConfigOptionEquals "http_enabled" "1" }}'

ConfigOptionNotEquals

func ConfigOptionNotEquals(optionName string, expectedValue string) bool

Returns true if the configuration option value is not equal to the supplied value.

ports:
   - private_port: "443"
     public_port: "443"
     port_type: tcp
     when: '{{repl ConfigOptionNotEquals "http_enabled" "1" }}'

LicenseFieldValue

func LicenseFieldValue(customLicenseFieldName string) string

Returns the value for the Custom License Field as a string.

env:
- name: MAX_USERS
  value: '{{repl LicenseFieldValue "maximum_users" }}'

LicenseProperty

func LicenseProperty(propertyName string) string

Returns a property from the License as a string. Valid propertyNames are “assignee”, “channel.name”, “expiration.date”, “expiration.policy”, and “license.id”.

env:
- name: LICENSE_ID
  value: '{{repl LicenseFieldValue "license.id" }}'

AppID

func AppID() string

Returns the app id.

env:
- name: APP_ID
  value: '{{repl AppID }}'

AppVersion

func AppVersion() int

Returns the app version sequence.

env:
- name: APP_VERSION
  value: '{{repl AppVersion }}'

AppVersionFirst

func AppVersionFirst() int

Returns the version sequence of the first version installed.

env:
- name: APP_VERSION_FIRST
  value: '{{repl AppVersionFirst }}'

AppVersionCurrent

func AppVersionCurrent() int

Returns the current app version sequence.

env:
- name: APP_VERSION_CURRENT
  value: '{{repl AppVersionCurrent }}'

RunOffline

func RunOffline() bool

Returns whether or not we are running in airgap mode. This is available in the Kubernetes and Swarm implementations, but will always return false.

env:
- name: IS_AIRGAP
  value: '{{repl RunOffline }}'

AppSetting

func AppSetting(key string) string

Returns a setting from the current app release.

Possible Options: version.label release.notes release.date install.date release.channel

env:
- name: VERSION
  value: '{{repl AppSetting "version.label"}}'
- name: RELEASE_NOTES
  value: '{{repl AppSetting "release.notes"}}'
- name: INSTALL_DATE
  value: '{{repl AppSetting "install.date"}}'
- name: RELEASE_DATE
  value: '{{repl AppSetting "release.date"}}'
- name: RELEASE_CHANNEL
  value: '{{repl AppSetting "release.channel"}}'

ConsoleSetting

func ConsoleSetting(consoleSettingName string) string

Returns customer defined console settings for the TLS data or proxy settings. Values are returned as a string.

Option Returned Value
tls.key.name TLS key filename
tls.key.data TLS key contents
tls.cert.name TLS cert filename
tls.cert.data TLS cert contents
tls.hostname Hostname used to secure Replicated TLS traffic
tls.source Source of the TLS cert, either “self-signed”, “key-cert” or “server-path”
http.proxy Proxy http address (e.g. http://10.128.0.4:3128)
http.proxy.enabled Proxy is enabled when value is 1, not enabled when it is 0
config:
- name: console_info
  title: Console Info
  items:
  - name: key_filename
    type: text
    readonly: true
    value: '{{repl ConsoleSetting "tls.key.name"}}'

ConsoleSettingEquals

func ConsoleSettingEquals(name string, value string) bool

Returns a bool indicating if the value is the currently applied value for ConsoleSetting with name.

ConsoleSettingNotEquals

func ConsoleSettingNotEquals(name string, value string) bool

Returns a bool indicating if the value is not the currently applied value for ConsoleSetting with name.

LDAPCopyAuthFrom

func LdapCopyAuthFrom(keyName string) interface{}

Possible Options:

Key Type
Hostname string
Port string
SearchUsername string
SearchPassword string
BaseDN string
UserSearchDNFirst string
UserSearchDNAll string
RestrictedGroupCNFirst []string
RestrictedGroupCNAll []string
FieldUsername string
LoginUsername string
AdvancedSearchBool boolean
UserQuery string
RestrictedGroupQuery string
env:
- name: LDAP_HOSTNAME
  value: '{{repl LdapCopyAuthFrom "Hostname"}}'

Now

func Now() string

Returns the current timestamp as an RFC3339 formatted string.

env:
- name: START_TIME
  value: '{{repl Now }}'

NowFmt

func NowFmt(format string) string

Returns the current timestamp as a formatted string. See Golang’s time formatting guidelines [here](https://golang.org/pkg/time/#pkg-constants.

env:
- name: START_DATE
  value: '{{repl Now "20060102" }}'

TrimSpace

func TrimSpace(s string) string

Trim returns a string with all leading and trailing spaces removed.

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | Trim }}

Trim

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).

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | Trim " " "." }}

Split

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.

env:
- name: BROKEN_APART_A_B_C
  value: '{{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.

env:
- name: GITHUB_HOSTNAME
  value: '{{repl index (Split (index (Split (ConfigOption "github_url") "/") 2) ":") 0}}'

ToLower

func ToLower(stringToAlter string) string

Returns the string, in lowercase.

env:
- name: COMPANY_NAME
  value: '{{repl ConfigOption "company_name" | ToLower }}'

ToUpper

func ToUpper(stringToAlter string) string

Returns the string, in uppercase.

env:
- name: COMPANY_NAME
  value: '{{repl ConfigOption "company_name" | ToUpper }}'

HumanSize

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.

env:
- name: MIN_SIZE_HUMAN
  value: '{{repl ConfigOption "min_size_bytes" | HumanSize }}

UrlEncode

func UrlEncode(stringToEncode string) string

Returns the string, url encoded.

env:
- name: SMTP_CONNECTION_URL
  value: '{{repl ConfigOption "smtp_email" | UrlEncode }}:{{repl ConfigOption "smtp_password" | UrlEncode }}@smtp.example.com:587'

Base64Encode

func Base64Encode(stringToEncode string) string

Returns a Base64 encoded string.

env:
- name: NAME_64_VALUE
  value: '{{repl ConfigOption "name" | Base64Encode }}'

Base64Decode

func Base64Decode(stringToDecode string) string

Returns decoded string from a Base64 stored value.

env:
- name: NAME_PLAIN_TEXT
  value: '{{repl ConfigOption "base_64_encoded_name" | Base64Decode }}'

ParseBool

func ParseBool(str string) bool

ParseBool returns the boolean value represented by the string.

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | ParseBool }}'

ParseFloat

func ParseFloat(str string) float64

ParseFloat returns the float value represented by the string.

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | ParseFloat }}'

ParseInt

func ParseInt(str string, args ...int) int64

ParseInt returns the integer value represented by the string with optional base (default 10).

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | ParseInt }}'

ParseUint

func ParseUint(str string, args ...int) uint64

ParseUint returns the unsigned integer value represented by the string with optional base (default 10).

env:
- name: VALUE
  value: '{{repl ConfigOption "str_value" | ParseUint }}'

Add

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.

env:
- name: MAX_USERS_PLUS_ONE
  value: '{{repl Add (LicenseFieldValue "maximum_users") 1}}'

Sub

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.

env:
- name: MAX_USERS_MINUS_ONE
  value: '{{repl Sub (LicenseFieldValue "maximum_users") 1}}'

Mult

func Mult(x interface{}, y interface{}) interface{}

Multiplies 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.

env:
- name: DOUBLE_NUM_ADDRESSES
  value: '{{repl Mult (NodePrivateIPAddressAll "DB" "redis" | len) 2}}'

Div

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.

env:
- name: HALF_MAX_USERS
  value: '{{repl Div (LicenseFieldValue "maximum_users") 2.0}}'

Namespace

func Namespace() string

Namespace returns the value of the namespace the vendor application is installed in.

ServiceAddress

ServiceAddress(name string, port int32) string

ServiceAddress returns the address of the ingress.

properties:
  app_url: '{{repl ServiceAddress "frontend" 80 }}'

IngressAddress

IngressAddress(name string, port int32) string

IngressAddress returns the address of the ingress.

properties:
  app_url: '{{repl IngressAddress "frontend" 80 }}'

PremkitAPIAddress

PremkitAPIAddress() string

PremkitAPIAddress returns the address of the Premkit service in the cluster.

StatsdAddress

StatsdAddress() string

StatsdAddress returns the address of the Statsd service in the cluster.

Notes

When referencing another container in a template object, you must make sure the referenced container is started first. Please see the Events and Orchestration section for more information on orchestrating container startup.