Skip to content

Commit 12ad8c9

Browse files
authored
configurable container capabilities (zalando#1336)
* configurable container capabilities * revert change on TestTLS * fix e2e test * minor fix
1 parent d488ae1 commit 12ad8c9

File tree

16 files changed

+155
-32
lines changed

16 files changed

+155
-32
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ spec:
130130
kubernetes:
131131
type: object
132132
properties:
133+
additional_pod_capabilities:
134+
type: array
135+
items:
136+
type: string
133137
cluster_domain:
134138
type: string
135139
default: "cluster.local"

charts/postgres-operator/values-crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ configUsers:
5959
super_username: postgres
6060

6161
configKubernetes:
62+
# list of additional capabilities for postgres container
63+
# additional_pod_capabilities:
64+
# - "SYS_NICE"
65+
6266
# default DNS domain of K8s cluster where operator is running
6367
cluster_domain: cluster.local
6468
# additional labels assigned to the cluster objects

charts/postgres-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ configUsers:
6161
super_username: postgres
6262

6363
configKubernetes:
64+
# list of additional capabilities for postgres container
65+
# additional_pod_capabilities: "SYS_NICE"
66+
6467
# default DNS domain of K8s cluster where operator is running
6568
cluster_domain: cluster.local
6669
# additional labels assigned to the cluster objects

docs/reference/operator_parameters.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ configuration they are grouped under the `kubernetes` key.
351351
used for AWS volume resizing and not required if you don't need that
352352
capability. The default is `false`.
353353

354+
* **additional_pod_capabilities**
355+
list of additional capabilities to be added to the postgres container's
356+
SecurityContext (e.g. SYS_NICE etc.). Please, make sure first that the
357+
PodSecruityPolicy allows the capabilities listed here. Otherwise, the
358+
container will not start. The default is empty.
359+
354360
* **master_pod_move_timeout**
355361
The period of time to wait for the success of migration of master pods from
356362
an unschedulable node. The migration includes Patroni switchovers to

e2e/tests/k8s_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ def count_running_pods(self, labels='application=spilo,cluster-name=acid-minimal
182182
pods = self.api.core_v1.list_namespaced_pod(namespace, label_selector=labels).items
183183
return len(list(filter(lambda x: x.status.phase == 'Running', pods)))
184184

185+
def count_pods_with_container_capabilities(self, capabilities, labels, namespace='default'):
186+
pods = self.api.core_v1.list_namespaced_pod(namespace, label_selector=labels).items
187+
return len(list(filter(lambda x: x.spec.containers[0].security_context.capabilities.add == capabilities, pods)))
188+
185189
def wait_for_pod_failover(self, failover_targets, labels, namespace='default'):
186190
pod_phase = 'Failing over'
187191
new_pod_node = ''
@@ -433,6 +437,10 @@ def count_running_pods(self, labels='application=spilo,cluster-name=acid-minimal
433437
pods = self.api.core_v1.list_namespaced_pod(namespace, label_selector=labels).items
434438
return len(list(filter(lambda x: x.status.phase == 'Running', pods)))
435439

440+
def count_pods_with_container_capabilities(self, capabilities, labels, namespace='default'):
441+
pods = self.api.core_v1.list_namespaced_pod(namespace, label_selector=labels).items
442+
return len(list(filter(lambda x: x.spec.containers[0].security_context.capabilities.add == capabilities, pods)))
443+
436444
def wait_for_pod_failover(self, failover_targets, labels, namespace='default'):
437445
pod_phase = 'Failing over'
438446
new_pod_node = ''

e2e/tests/test_e2e.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ def setUpClass(cls):
155155
print('Operator log: {}'.format(k8s.get_operator_log()))
156156
raise
157157

158+
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
159+
def test_additional_pod_capabilities(self):
160+
'''
161+
Extend postgres container capabilities
162+
'''
163+
cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster'
164+
capabilities = ["SYS_NICE","CHOWN"]
165+
patch_capabilities = {
166+
"data": {
167+
"additional_pod_capabilities": ','.join(capabilities),
168+
},
169+
}
170+
self.k8s.update_config(patch_capabilities)
171+
self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"},
172+
"Operator does not get in sync")
173+
174+
self.eventuallyEqual(lambda: self.k8s.count_pods_with_container_capabilities(capabilities, cluster_label),
175+
2, "Container capabilities not updated")
176+
158177
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
159178
def test_overwrite_pooler_deployment(self):
160179
self.k8s.create_with_kubectl("manifests/minimal-fake-pooler-deployment.yaml")

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ kind: ConfigMap
33
metadata:
44
name: postgres-operator
55
data:
6+
# additional_pod_capabilities: "SYS_NICE"
67
# additional_secret_mount: "some-secret-name"
78
# additional_secret_mount_path: "/some/dir"
89
api_port: "8080"

manifests/operatorconfiguration.crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ spec:
126126
kubernetes:
127127
type: object
128128
properties:
129+
additional_pod_capabilities:
130+
type: array
131+
items:
132+
type: string
129133
cluster_domain:
130134
type: string
131135
default: "cluster.local"

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ configuration:
2626
replication_username: standby
2727
super_username: postgres
2828
kubernetes:
29+
# additional_pod_capabilities:
30+
# - "SYS_NICE"
2931
cluster_domain: cluster.local
3032
cluster_labels:
3133
application: spilo

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,14 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
968968
"kubernetes": {
969969
Type: "object",
970970
Properties: map[string]apiextv1.JSONSchemaProps{
971+
"additional_pod_capabilities": {
972+
Type: "array",
973+
Items: &apiextv1.JSONSchemaPropsOrArray{
974+
Schema: &apiextv1.JSONSchemaProps{
975+
Type: "string",
976+
},
977+
},
978+
},
971979
"cluster_domain": {
972980
Type: "string",
973981
},

0 commit comments

Comments
 (0)