Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f842529
Merge pull request #1 from zalando/master
sagor999 Oct 10, 2020
abc2cb4
Merge pull request #3 from zalando/master
sagor999 Nov 17, 2020
d412754
Merge pull request #4 from zalando/master
sagor999 Dec 6, 2020
abc48a6
Merge pull request #5 from zalando/master
sagor999 Dec 15, 2020
c7aadba
Adding nodeaffinity support alongside node_readiness_label
spohner May 13, 2020
4014442
Add nodeAffinity support to ConnectionPooler
adastleyatvi Jul 3, 2020
b6a83ca
Add tests for ConnectionPooler nodeAffinity
adastleyatvi Oct 10, 2020
9b53763
fix compareStatefulSet to take into account nodeAffinity
sagor999 Oct 11, 2020
b8751e8
add documentation for node affinity
sagor999 Oct 12, 2020
58c2142
add node affinity test
sagor999 Oct 12, 2020
300183f
fix print statement
sagor999 Oct 18, 2020
04be950
update codegen
sagor999 Oct 20, 2020
a3dea03
fix crd api for node affinity
sagor999 Nov 17, 2020
f032cd5
fix node affinity test
sagor999 Nov 17, 2020
fc9d5bf
fix e2e test for node affinity
sagor999 Nov 18, 2020
88743f8
replace hardcoded sleep with wait_for_pod_start in node affinity e2e
sagor999 Nov 18, 2020
a8c9b0e
remove extra affinity check, as it is already done
sagor999 Dec 6, 2020
8f05753
improve crd readability by moving Required field up
sagor999 Dec 6, 2020
03f91c3
improve node affinity e2e test
sagor999 Dec 6, 2020
867b294
add node affinity into various crds and add example into complete man…
sagor999 Dec 6, 2020
3bfa3af
fix missing type in crd
sagor999 Dec 6, 2020
8e8cd93
remove node affinity from connection pooler
sagor999 Dec 15, 2020
f5a871b
fix unit test for node affinity
sagor999 Dec 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve node affinity e2e test
  • Loading branch information
sagor999 committed Dec 15, 2020
commit 03f91c3a6eabf84046e653199d60da7286b9745f
32 changes: 23 additions & 9 deletions e2e/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,16 @@ def test_node_affinity(self):
k8s = self.k8s
cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster'

# verify we are in good state from potential previous tests
self.eventuallyEqual(lambda: k8s.count_running_pods(), 2, "No 2 pods running")
self.eventuallyEqual(lambda: len(k8s.get_patroni_running_members("acid-minimal-cluster-0")), 2, "Postgres status did not enter running")
self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")

# get nodes of master and replica(s)
current_master_node, current_replica_nodes = k8s.get_pg_nodes(cluster_label)
master_node, replica_nodes = k8s.get_pg_nodes(cluster_label)

self.assertNotEqual(master_node, [])
self.assertNotEqual(replica_nodes, [])

# label node with environment=postgres
node_label_body = {
Expand All @@ -951,8 +959,8 @@ def test_node_affinity(self):

try:
# patch current master node with the label
print('patching master node: {}'.format(current_master_node))
k8s.api.core_v1.patch_node(current_master_node, node_label_body)
print('patching master node: {}'.format(master_node))
k8s.api.core_v1.patch_node(master_node, node_label_body)

# add node affinity to cluster
patch_node_affinity_config = {
Expand Down Expand Up @@ -984,17 +992,17 @@ def test_node_affinity(self):
plural="postgresqls",
name="acid-minimal-cluster",
body=patch_node_affinity_config)
self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")

# bounce replica and check if it has migrated to proper node that has a label
k8s.api.core_v1.delete_namespaced_pod("acid-minimal-cluster-1", "default")
# wait for pod to be started
k8s.wait_for_pod_start('spilo-role=replica')
# node affinity change should cause replica to relocate from replica node to master node due to node affinity requirement
k8s.wait_for_pod_failover(master_node, 'spilo-role=replica,' + cluster_label)
k8s.wait_for_pod_start('spilo-role=replica,' + cluster_label)

podsList = k8s.api.core_v1.list_namespaced_pod('default', label_selector=cluster_label)
for pod in podsList.items:
if pod.metadata.labels.get('spilo-role') == 'replica':
self.assertEqual(current_master_node, pod.spec.node_name,
"Sanity check: expected replica to relocate to master node {}, but found on {}".format(current_master_node, pod.spec.node_name))
self.assertEqual(master_node, pod.spec.node_name,
"Sanity check: expected replica to relocate to master node {}, but found on {}".format(master_node, pod.spec.node_name))

# check that pod has correct node affinity
key = pod.spec.affinity.node_affinity.required_during_scheduling_ignored_during_execution.node_selector_terms[0].match_expressions[0].key
Expand All @@ -1016,6 +1024,12 @@ def test_node_affinity(self):
plural="postgresqls",
name="acid-minimal-cluster",
body=patch_node_remove_affinity_config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the affinity is another rolling update. Therefore, we should guarantee that everything is running when we leave the test.. Check other e2e tests like test_zz_node_readiness_label or test_zzz_taint_based_eviction how it is handled there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update!

self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")

# remove node affinity to move replica away from master node
nm, new_replica_nodes = k8s.get_cluster_nodes()
new_master_node = nm[0]
self.assert_distributed_pods(new_master_node, new_replica_nodes, cluster_label)

except timeout_decorator.TimeoutError:
print('Operator log: {}'.format(k8s.get_operator_log()))
Expand Down