From e8d9c75949b502fd57611ca74a4d42b1ca38b661 Mon Sep 17 00:00:00 2001 From: Georg Kunz Date: Mon, 30 Oct 2017 17:41:32 +0100 Subject: [PATCH] Allow custom Postgres pod environment variables --- README.md | 32 ++++++++++++++++++++++++++++++++ pkg/cluster/k8sres.go | 8 ++++++++ pkg/util/config/config.go | 1 + 3 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 3ba1ae0cb..bf4f6efd7 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,38 @@ spec: Please be aware that the taint and toleration only ensures that no other pod gets scheduled to a PostgreSQL node but not that PostgreSQL pods are placed on such a node. This can be achieved by setting a node affinity rule in the ConfigMap. +#### Custom Pod Environment Variables + +It is possible to configure a config map which is used by the Postgres pods as an additional provider for environment variables. + +One use case is to customize the Spilo image and configure it with environment variables. The config map with the additional settings is configured in the operator's main config map: + +**postgres-operator ConfigMap** + +``` +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-operator +data: + # referencing config map with custom settings + pod_environment_configmap: postgres-pod-config + ... +``` + +**referenced ConfigMap `postgres-pod-config`** + +``` +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-pod-config + namespace: default +data: + MY_CUSTOM_VAR: value +``` + +This ConfigMap is then added as a source of environment variables to the Postgres StatefulSet/pods. # Setup development environment diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 2170bea16..582911734 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -362,6 +362,13 @@ func (c *Cluster) generatePodTemplate(resourceRequirements *v1.ResourceRequireme if cloneDescription.ClusterName != "" { envVars = append(envVars, c.generateCloneEnvironment(cloneDescription)...) } + + envFromSource := []v1.EnvFromSource{} + if c.OpConfig.PodEnvironmentConfigMap != "" { + configMapRef := v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: c.OpConfig.PodEnvironmentConfigMap}} + envFromSource = append(envFromSource, v1.EnvFromSource{ConfigMapRef: &configMapRef}) + } + privilegedMode := true containerImage := c.OpConfig.DockerImage if dockerImage != nil && *dockerImage != "" { @@ -393,6 +400,7 @@ func (c *Cluster) generatePodTemplate(resourceRequirements *v1.ResourceRequireme }, }, Env: envVars, + EnvFrom: envFromSource, SecurityContext: &v1.SecurityContext{ Privileged: &privilegedMode, }, diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 8a737b218..772503ab5 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -30,6 +30,7 @@ type Resources struct { DefaultMemoryRequest string `name:"default_memory_request" default:"100Mi"` DefaultCPULimit string `name:"default_cpu_limit" default:"3"` DefaultMemoryLimit string `name:"default_memory_limit" default:"1Gi"` + PodEnvironmentConfigMap string `name:"pod_environment_configmap" default:""` NodeEOLLabel map[string]string `name:"node_eol_label" default:"lifecycle-status:pending-decommission"` NodeReadinessLabel map[string]string `name:"node_readiness_label" default:"lifecycle-status:ready"` }