Skip to content

Commit ba9cf68

Browse files
authored
Change type of pod environment config map to NamespacedName (zalando#870)
* allow PodEnvironmentConfigMap in other namespaces * update codegen * update docs and comments
1 parent 9dfa433 commit ba9cf68

File tree

10 files changed

+73
-64
lines changed

10 files changed

+73
-64
lines changed

charts/postgres-operator/values-crd.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ configKubernetes:
7171
enable_pod_disruption_budget: true
7272
# enables sidecar containers to run alongside Spilo in the same pod
7373
enable_sidecars: true
74-
# name of the secret containing infrastructure roles names and passwords
74+
# namespaced name of the secret containing infrastructure roles names and passwords
7575
# infrastructure_roles_secret_name: postgresql-infrastructure-roles
7676

7777
# list of labels that can be inherited from the cluster manifest
@@ -86,15 +86,15 @@ configKubernetes:
8686
# node_readiness_label:
8787
# status: ready
8888

89-
# name of the secret containing the OAuth2 token to pass to the teams API
89+
# namespaced name of the secret containing the OAuth2 token to pass to the teams API
9090
# oauth_token_secret_name: postgresql-operator
9191

9292
# defines the template for PDB (Pod Disruption Budget) names
9393
pdb_name_format: "postgres-{cluster}-pdb"
9494
# override topology key for pod anti affinity
9595
pod_antiaffinity_topology_key: "kubernetes.io/hostname"
96-
# name of the ConfigMap with environment variables to populate on every pod
97-
# pod_environment_configmap: ""
96+
# namespaced name of the ConfigMap with environment variables to populate on every pod
97+
# pod_environment_configmap: "default/my-custom-config"
9898

9999
# specify the pod management policy of stateful sets of Postgres clusters
100100
pod_management_policy: "ordered_ready"

charts/postgres-operator/values.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ configKubernetes:
6767
enable_pod_disruption_budget: "true"
6868
# enables sidecar containers to run alongside Spilo in the same pod
6969
enable_sidecars: "true"
70-
# name of the secret containing infrastructure roles names and passwords
70+
# namespaced name of the secret containing infrastructure roles names and passwords
7171
# infrastructure_roles_secret_name: postgresql-infrastructure-roles
7272

7373
# list of labels that can be inherited from the cluster manifest
@@ -79,15 +79,15 @@ configKubernetes:
7979
# set of labels that a running and active node should possess to be considered ready
8080
# node_readiness_label: ""
8181

82-
# name of the secret containing the OAuth2 token to pass to the teams API
82+
# namespaced name of the secret containing the OAuth2 token to pass to the teams API
8383
# oauth_token_secret_name: postgresql-operator
8484

8585
# defines the template for PDB (Pod Disruption Budget) names
8686
pdb_name_format: "postgres-{cluster}-pdb"
8787
# override topology key for pod anti affinity
8888
pod_antiaffinity_topology_key: "kubernetes.io/hostname"
89-
# name of the ConfigMap with environment variables to populate on every pod
90-
# pod_environment_configmap: ""
89+
# namespaced name of the ConfigMap with environment variables to populate on every pod
90+
# pod_environment_configmap: "default/my-custom-config"
9191

9292
# specify the pod management policy of stateful sets of Postgres clusters
9393
pod_management_policy: "ordered_ready"

docs/administrator.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ spec:
321321
## Custom Pod Environment Variables
322322

323323
It is possible to configure a ConfigMap which is used by the Postgres pods as
324-
an additional provider for environment variables.
325-
326-
One use case is to customize the Spilo image and configure it with environment
327-
variables. The ConfigMap with the additional settings is configured in the
328-
operator's main ConfigMap:
324+
an additional provider for environment variables. One use case is to customize
325+
the Spilo image and configure it with environment variables. The ConfigMap with
326+
the additional settings is referenced in the operator's main configuration.
327+
A namespace can be specified along with the name. If left out, the configured
328+
default namespace of your K8s client will be used and if the ConfigMap is not
329+
found there, the Postgres cluster's namespace is taken when different:
329330

330331
**postgres-operator ConfigMap**
331332

@@ -336,7 +337,7 @@ metadata:
336337
name: postgres-operator
337338
data:
338339
# referencing config map with custom settings
339-
pod_environment_configmap: postgres-pod-config
340+
pod_environment_configmap: default/postgres-pod-config
340341
```
341342

342343
**OperatorConfiguration**
@@ -349,7 +350,7 @@ metadata:
349350
configuration:
350351
kubernetes:
351352
# referencing config map with custom settings
352-
pod_environment_configmap: postgres-pod-config
353+
pod_environment_configmap: default/postgres-pod-config
353354
```
354355

355356
**referenced ConfigMap `postgres-pod-config`**

docs/reference/operator_parameters.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,12 @@ configuration they are grouped under the `kubernetes` key.
221221
to the Postgres clusters after creation.
222222

223223
* **oauth_token_secret_name**
224-
a name of the secret containing the `OAuth2` token to pass to the teams API.
225-
The default is `postgresql-operator`.
224+
namespaced name of the secret containing the `OAuth2` token to pass to the
225+
teams API. The default is `postgresql-operator`.
226226

227227
* **infrastructure_roles_secret_name**
228-
name of the secret containing infrastructure roles names and passwords.
228+
namespaced name of the secret containing infrastructure roles names and
229+
passwords.
229230

230231
* **pod_role_label**
231232
name of the label assigned to the Postgres pods (and services/endpoints) by
@@ -262,11 +263,11 @@ configuration they are grouped under the `kubernetes` key.
262263
for details on taints and tolerations. The default is empty.
263264

264265
* **pod_environment_configmap**
265-
a name of the ConfigMap with environment variables to populate on every pod.
266-
Right now this ConfigMap is searched in the namespace of the Postgres cluster.
267-
All variables from that ConfigMap are injected to the pod's environment, on
268-
conflicts they are overridden by the environment variables generated by the
269-
operator. The default is empty.
266+
namespaced name of the ConfigMap with environment variables to populate on
267+
every pod. Right now this ConfigMap is searched in the namespace of the
268+
Postgres cluster. All variables from that ConfigMap are injected to the pod's
269+
environment, on conflicts they are overridden by the environment variables
270+
generated by the operator. The default is empty.
270271

271272
* **pod_priority_class_name**
272273
a name of the [priority class](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass)

manifests/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ data:
6969
pdb_name_format: "postgres-{cluster}-pdb"
7070
# pod_antiaffinity_topology_key: "kubernetes.io/hostname"
7171
pod_deletion_wait_timeout: 10m
72-
# pod_environment_configmap: ""
72+
# pod_environment_configmap: "default/my-custom-config"
7373
pod_label_wait_timeout: 10m
7474
pod_management_policy: "ordered_ready"
7575
pod_role_label: spilo-role

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ configuration:
4040
oauth_token_secret_name: postgresql-operator
4141
pdb_name_format: "postgres-{cluster}-pdb"
4242
pod_antiaffinity_topology_key: "kubernetes.io/hostname"
43-
# pod_environment_configmap: ""
43+
# pod_environment_configmap: "default/my-custom-config"
4444
pod_management_policy: "ordered_ready"
4545
# pod_priority_class_name: ""
4646
pod_role_label: spilo-role

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ type KubernetesMetaConfiguration struct {
6565
NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"`
6666
CustomPodAnnotations map[string]string `json:"custom_pod_annotations,omitempty"`
6767
// TODO: use a proper toleration structure?
68-
PodToleration map[string]string `json:"toleration,omitempty"`
69-
// TODO: use namespacedname
70-
PodEnvironmentConfigMap string `json:"pod_environment_configmap,omitempty"`
71-
PodPriorityClassName string `json:"pod_priority_class_name,omitempty"`
72-
MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"`
73-
EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"`
74-
PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"`
75-
PodManagementPolicy string `json:"pod_management_policy,omitempty"`
68+
PodToleration map[string]string `json:"toleration,omitempty"`
69+
PodEnvironmentConfigMap spec.NamespacedName `json:"pod_environment_configmap,omitempty"`
70+
PodPriorityClassName string `json:"pod_priority_class_name,omitempty"`
71+
MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"`
72+
EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"`
73+
PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"`
74+
PodManagementPolicy string `json:"pod_management_policy,omitempty"`
7675
}
7776

7877
// PostgresPodResourcesDefaults defines the spec of default resources

pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cluster/k8sres.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
2020
"github.com/zalando/postgres-operator/pkg/spec"
21+
pkgspec "github.com/zalando/postgres-operator/pkg/spec"
2122
"github.com/zalando/postgres-operator/pkg/util"
2223
"github.com/zalando/postgres-operator/pkg/util/config"
2324
"github.com/zalando/postgres-operator/pkg/util/constants"
@@ -485,9 +486,9 @@ func generateSidecarContainers(sidecars []acidv1.Sidecar,
485486

486487
// Check whether or not we're requested to mount an shm volume,
487488
// taking into account that PostgreSQL manifest has precedence.
488-
func mountShmVolumeNeeded(opConfig config.Config, pgSpec *acidv1.PostgresSpec) *bool {
489-
if pgSpec.ShmVolume != nil && *pgSpec.ShmVolume {
490-
return pgSpec.ShmVolume
489+
func mountShmVolumeNeeded(opConfig config.Config, spec *acidv1.PostgresSpec) *bool {
490+
if spec.ShmVolume != nil && *spec.ShmVolume {
491+
return spec.ShmVolume
491492
}
492493

493494
return opConfig.ShmVolume
@@ -911,11 +912,17 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
911912

912913
customPodEnvVarsList := make([]v1.EnvVar, 0)
913914

914-
if c.OpConfig.PodEnvironmentConfigMap != "" {
915+
if c.OpConfig.PodEnvironmentConfigMap != (pkgspec.NamespacedName{}) {
915916
var cm *v1.ConfigMap
916-
cm, err = c.KubeClient.ConfigMaps(c.Namespace).Get(c.OpConfig.PodEnvironmentConfigMap, metav1.GetOptions{})
917+
cm, err = c.KubeClient.ConfigMaps(c.OpConfig.PodEnvironmentConfigMap.Namespace).Get(c.OpConfig.PodEnvironmentConfigMap.Name, metav1.GetOptions{})
917918
if err != nil {
918-
return nil, fmt.Errorf("could not read PodEnvironmentConfigMap: %v", err)
919+
// if not found, try again using the cluster's namespace if it's different (old behavior)
920+
if k8sutil.ResourceNotFound(err) && c.Namespace != c.OpConfig.PodEnvironmentConfigMap.Namespace {
921+
cm, err = c.KubeClient.ConfigMaps(c.Namespace).Get(c.OpConfig.PodEnvironmentConfigMap.Name, metav1.GetOptions{})
922+
}
923+
if err != nil {
924+
return nil, fmt.Errorf("could not read PodEnvironmentConfigMap: %v", err)
925+
}
919926
}
920927
for k, v := range cm.Data {
921928
customPodEnvVarsList = append(customPodEnvVarsList, v1.EnvVar{Name: k, Value: v})

pkg/util/config/config.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ type CRD struct {
2222

2323
// Resources describes kubernetes resource specific configuration parameters
2424
type Resources struct {
25-
ResourceCheckInterval time.Duration `name:"resource_check_interval" default:"3s"`
26-
ResourceCheckTimeout time.Duration `name:"resource_check_timeout" default:"10m"`
27-
PodLabelWaitTimeout time.Duration `name:"pod_label_wait_timeout" default:"10m"`
28-
PodDeletionWaitTimeout time.Duration `name:"pod_deletion_wait_timeout" default:"10m"`
29-
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
30-
SpiloFSGroup *int64 `name:"spilo_fsgroup"`
31-
PodPriorityClassName string `name:"pod_priority_class_name"`
32-
ClusterDomain string `name:"cluster_domain" default:"cluster.local"`
33-
SpiloPrivileged bool `name:"spilo_privileged" default:"false"`
34-
ClusterLabels map[string]string `name:"cluster_labels" default:"application:spilo"`
35-
InheritedLabels []string `name:"inherited_labels" default:""`
36-
ClusterNameLabel string `name:"cluster_name_label" default:"cluster-name"`
37-
PodRoleLabel string `name:"pod_role_label" default:"spilo-role"`
38-
PodToleration map[string]string `name:"toleration" default:""`
39-
DefaultCPURequest string `name:"default_cpu_request" default:"100m"`
40-
DefaultMemoryRequest string `name:"default_memory_request" default:"100Mi"`
41-
DefaultCPULimit string `name:"default_cpu_limit" default:"1"`
42-
DefaultMemoryLimit string `name:"default_memory_limit" default:"500Mi"`
43-
MinCPULimit string `name:"min_cpu_limit" default:"250m"`
44-
MinMemoryLimit string `name:"min_memory_limit" default:"250Mi"`
45-
PodEnvironmentConfigMap string `name:"pod_environment_configmap" default:""`
46-
NodeReadinessLabel map[string]string `name:"node_readiness_label" default:""`
47-
MaxInstances int32 `name:"max_instances" default:"-1"`
48-
MinInstances int32 `name:"min_instances" default:"-1"`
49-
ShmVolume *bool `name:"enable_shm_volume" default:"true"`
25+
ResourceCheckInterval time.Duration `name:"resource_check_interval" default:"3s"`
26+
ResourceCheckTimeout time.Duration `name:"resource_check_timeout" default:"10m"`
27+
PodLabelWaitTimeout time.Duration `name:"pod_label_wait_timeout" default:"10m"`
28+
PodDeletionWaitTimeout time.Duration `name:"pod_deletion_wait_timeout" default:"10m"`
29+
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
30+
SpiloFSGroup *int64 `name:"spilo_fsgroup"`
31+
PodPriorityClassName string `name:"pod_priority_class_name"`
32+
ClusterDomain string `name:"cluster_domain" default:"cluster.local"`
33+
SpiloPrivileged bool `name:"spilo_privileged" default:"false"`
34+
ClusterLabels map[string]string `name:"cluster_labels" default:"application:spilo"`
35+
InheritedLabels []string `name:"inherited_labels" default:""`
36+
ClusterNameLabel string `name:"cluster_name_label" default:"cluster-name"`
37+
PodRoleLabel string `name:"pod_role_label" default:"spilo-role"`
38+
PodToleration map[string]string `name:"toleration" default:""`
39+
DefaultCPURequest string `name:"default_cpu_request" default:"100m"`
40+
DefaultMemoryRequest string `name:"default_memory_request" default:"100Mi"`
41+
DefaultCPULimit string `name:"default_cpu_limit" default:"1"`
42+
DefaultMemoryLimit string `name:"default_memory_limit" default:"500Mi"`
43+
MinCPULimit string `name:"min_cpu_limit" default:"250m"`
44+
MinMemoryLimit string `name:"min_memory_limit" default:"250Mi"`
45+
PodEnvironmentConfigMap spec.NamespacedName `name:"pod_environment_configmap"`
46+
NodeReadinessLabel map[string]string `name:"node_readiness_label" default:""`
47+
MaxInstances int32 `name:"max_instances" default:"-1"`
48+
MinInstances int32 `name:"min_instances" default:"-1"`
49+
ShmVolume *bool `name:"enable_shm_volume" default:"true"`
5050
}
5151

5252
// Auth describes authentication specific configuration parameters

0 commit comments

Comments
 (0)