Config Context
ConfigOption
func ConfigOption(optionName string) string
Returns the value of the config option as a string.
For information about the config screen and associated options, see Config in the Custom Resources section.
'{{repl ConfigOption "hostname" }}'
ConfigOption
returns the base64 encoded value of the file
config option.
'{{repl ConfigOption "ssl_key"}}'
To use files in a Secret, use ConfigOption
:
apiVersion: v1
kind: Secret
metadata:
name: tls-secret
type: kubernetes.io/tls
data:
tls.crt: '{{repl ConfigOption "tls_certificate_file" }}'
tls.key: '{{repl ConfigOption "tls_private_key_file" }}'
For more information about using TLS certificates, see Using TLS Certificates.
ConfigOptionData
func ConfigOptionData(optionName string) string
ConfigOptionData
returns the base64 decoded value of a file
config option.
'{{repl ConfigOptionData "ssl_key"}}'
To use files in a ConfigMap, use ConfigOptionData
:
apiVersion: v1
kind: ConfigMap
metadata:
name: tls-config
data:
tls.crt: |
repl{{- ConfigOptionData "tls_certificate_file" | nindent 4 }}
tls.key: |
repl{{- ConfigOptionData "tls_private_key_file" | nindent 4 }}
ConfigOptionFilename
func ConfigOptionFilename(optionName string) string
ConfigOptionFilename
returns the filename associated with a file
config option.
It will return an empty string if used erroneously with other types.
'{{repl ConfigOptionFilename "pom_file"}}'
As an example, if you have the following Config Spec defined:
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: my-application
spec:
groups:
- name: java_settings
title: Java Settings
description: Configures the Java Server build parameters
items:
- name: pom_file
type: file
required: true
You can use ConfigOptionFilename
in a Pod Spec to mount a file like so:
apiVersion: v1
kind: Pod
metadata:
name: configmap-demo-pod
spec:
containers:
- name: some-java-app
image: busybox
command: ["bash"]
args:
- "-C"
- "cat /config/{{repl ConfigOptionFilename pom_file}}"
volumeMounts:
- name: config
mountPath: "/config"
readOnly: true
volumes:
- name: config
configMap:
name: demo-configmap
items:
- key: data_key_one
path: repl{{ ConfigOptionFilename pom_file }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-configmap
data:
data_key_one: repl{{ ConfigOptionData pom_file }}
ConfigOptionEquals
func ConfigOptionEquals(optionName string, expectedValue string) bool
Returns true if the configuration option value is equal to the supplied value.
'{{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.
'{{repl ConfigOptionNotEquals "http_enabled" "1" }}'
LocalRegistryAddress
func LocalRegistryAddress() string
Returns the local registry host or host/namespace that's configured. This will always return everything before the image name and tag.
LocalRegistryHost
func LocalRegistryHost() string
Returns the host of the local registry that the user configured. Alternatively, for air gap installations with Replicated Embedded Cluster or Replicated kURL, LocalRegistryHost returns the host of the built-in registry.
Includes the port if one is specified.
LocalRegistryNamespace
func LocalRegistryNamespace() string
Returns the namespace of the local registry that the user configured. Alternatively, for air gap installations with Embedded Cluster or kURL, LocalRegistryNamespace returns the namespace of the built-in registry.
LocalImageName
func LocalImageName(remoteImageName string) string
Given a remoteImageName
, rewrite the remoteImageName
so that it can be pulled to local hosts.
A common use case for the LocalImageName
function is to ensure that a Kubernetes Operator can determine the names of container images on Pods created at runtime. For more information, see Referencing Images in the Packaging a Kubernetes Operator Application section.
LocalImageName
rewrites the remoteImageName
in one of the following ways, depending on if a private registry is configured and if the image must be proxied:
-
If there is a private registry configured in the customer's environment, such as in air gapped environments, rewrite
remoteImageName
to reference the private registry locally. For example, rewriteelasticsearch:7.6.0
asregistry.somebigbank.com/my-app/elasticsearch:7.6.0
. -
If there is no private registry configured in the customer's environment, but the image must be proxied, rewrite
remoteImageName
so that the image can be pulled through the proxy registry. For example, rewrite"quay.io/orgname/private-image:v1.2.3"
asproxy.replicated.com/proxy/app-name/quay.io/orgname/private-image:v1.2.3
. -
If there is no private registry configured in the customer's environment and the image does not need to be proxied, return
remoteImageName
without changes.
For more information about the Replicated proxy registry, see About the Proxy Registry.
LocalRegistryImagePullSecret
func LocalRegistryImagePullSecret() string
Returns the base64 encoded local registry image pull secret value. This is often needed when an operator is deploying images to a namespace that is not managed by Replicated KOTS. Image pull secrets must be present in the namespace of the pod.
apiVersion: v1
kind: Secret
metadata:
name: my-image-pull-secret
namespace: my-namespace
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: '{{repl LocalRegistryImagePullSecret }}'
---
apiVersion: v1
kind: Pod
metadata:
name: dynamic-pod
namespace: my-namespace
spec:
containers:
- image: '{{repl LocalImageName "registry.replicated.com/my-app/my-image:abcdef" }}'
name: my-container
imagePullSecrets:
- name: my-image-pull-secret
ImagePullSecretName
func ImagePullSecretName() string
Returns the name of the image pull secret that can be added to pod specs that use private images. The secret will be automatically created in all application namespaces. It will contain authentication information for any private registry used with the application.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
imagePullSecrets:
- name: repl{{ ImagePullSecretName }}
HasLocalRegistry
func HasLocalRegistry() bool
Returns true if the environment is configured to rewrite images to a local registry. HasLocalRegistry is always true for air gap installations. HasLocalRegistry is true in online installations if the user pushed images to a local registry.