@@ -58,6 +58,57 @@ def setUpClass(cls):
5858 k8s .create_with_kubectl ("manifests/minimal-postgres-manifest.yaml" )
5959 k8s .wait_for_pod_start ('spilo-role=master' )
6060
61+ @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
62+ def test_min_resource_limits (self ):
63+ '''
64+ Lower resource limits below configured minimum and let operator fix it
65+ '''
66+ k8s = self .k8s
67+ cluster_label = 'version=acid-minimal-cluster'
68+ _ , failover_targets = k8s .get_pg_nodes (cluster_label )
69+
70+ # configure minimum boundaries for CPU and memory limits
71+ minCPULimit = '250m'
72+ minMemoryLimit = '250Mi'
73+ patch_min_resource_limits = {
74+ "data" : {
75+ "min_cpu_limit" : minCPULimit ,
76+ "min_memory_limit" : minMemoryLimit
77+ }
78+ }
79+ k8s .update_config (patch_min_resource_limits )
80+
81+ # lower resource limits below minimum
82+ pg_patch_resources = {
83+ "spec" : {
84+ "resources" : {
85+ "requests" : {
86+ "cpu" : "10m" ,
87+ "memory" : "50Mi"
88+ },
89+ "limits" : {
90+ "cpu" : "200m" ,
91+ "memory" : "200Mi"
92+ }
93+ }
94+ }
95+ }
96+ k8s .api .custom_objects_api .patch_namespaced_custom_object (
97+ "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-minimal-cluster" , pg_patch_resources )
98+ k8s .wait_for_master_failover (failover_targets )
99+
100+ pods = k8s .api .core_v1 .list_namespaced_pod (
101+ 'default' , label_selector = 'spilo-role=master,' + cluster_label ).items
102+ self .assert_master_is_unique ()
103+ masterPod = pods [0 ]
104+
105+ self .assertEqual (masterPod .spec .containers [0 ].resources .limits ['cpu' ], minCPULimit ,
106+ "Expected CPU limit {}, found {}"
107+ .format (minCPULimit , masterPod .spec .containers [0 ].resources .limits ['cpu' ]))
108+ self .assertEqual (masterPod .spec .containers [0 ].resources .limits ['memory' ], minMemoryLimit ,
109+ "Expected memory limit {}, found {}"
110+ .format (minMemoryLimit , masterPod .spec .containers [0 ].resources .limits ['memory' ]))
111+
61112 @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
62113 def test_multi_namespace_support (self ):
63114 '''
@@ -76,10 +127,9 @@ def test_multi_namespace_support(self):
76127
77128 @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
78129 def test_scaling (self ):
79- """
130+ '''
80131 Scale up from 2 to 3 and back to 2 pods by updating the Postgres manifest at runtime.
81- """
82-
132+ '''
83133 k8s = self .k8s
84134 labels = "version=acid-minimal-cluster"
85135
@@ -93,9 +143,9 @@ def test_scaling(self):
93143
94144 @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
95145 def test_taint_based_eviction (self ):
96- """
146+ '''
97147 Add taint "postgres=:NoExecute" to node with master. This must cause a failover.
98- """
148+ '''
99149 k8s = self .k8s
100150 cluster_label = 'version=acid-minimal-cluster'
101151
@@ -145,15 +195,15 @@ def test_taint_based_eviction(self):
145195
146196 @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
147197 def test_logical_backup_cron_job (self ):
148- """
198+ '''
149199 Ensure we can (a) create the cron job at user request for a specific PG cluster
150200 (b) update the cluster-wide image for the logical backup pod
151201 (c) delete the job at user request
152202
153203 Limitations:
154204 (a) Does not run the actual batch job because there is no S3 mock to upload backups to
155205 (b) Assumes 'acid-minimal-cluster' exists as defined in setUp
156- """
206+ '''
157207
158208 k8s = self .k8s
159209
@@ -208,10 +258,10 @@ def test_logical_backup_cron_job(self):
208258 "Expected 0 logical backup jobs, found {}" .format (len (jobs )))
209259
210260 def assert_master_is_unique (self , namespace = 'default' , version = "acid-minimal-cluster" ):
211- """
261+ '''
212262 Check that there is a single pod in the k8s cluster with the label "spilo-role=master"
213263 To be called manually after operations that affect pods
214- """
264+ '''
215265
216266 k8s = self .k8s
217267 labels = 'spilo-role=master,version=' + version
0 commit comments