additional check plus comments

This commit is contained in:
Felix Kunde 2019-05-20 14:52:15 +02:00
parent a00f0476ea
commit 461beec310
1 changed files with 12 additions and 0 deletions

View File

@ -100,6 +100,7 @@ class SmokeTestCase(unittest.TestCase):
master_pod_node = '' master_pod_node = ''
new_master_pod_node = '' new_master_pod_node = ''
# taint node with postgres=:NoExecute to force failover
body = { body = {
"spec": { "spec": {
"taints": [ "taints": [
@ -110,6 +111,8 @@ class SmokeTestCase(unittest.TestCase):
] ]
} }
} }
# get nodes of master and replica
podsList = k8s.core_v1.list_namespaced_pod("default", label_selector=labels) podsList = k8s.core_v1.list_namespaced_pod("default", label_selector=labels)
for pod in podsList.items: for pod in podsList.items:
if ('spilo-role', 'master') in pod.metadata.labels.items(): if ('spilo-role', 'master') in pod.metadata.labels.items():
@ -117,6 +120,15 @@ class SmokeTestCase(unittest.TestCase):
elif ('spilo-role', 'replica') in pod.metadata.labels.items(): elif ('spilo-role', 'replica') in pod.metadata.labels.items():
new_master_pod_node = pod.spec.node_name new_master_pod_node = pod.spec.node_name
# if both live on the same node, failover will happen to the other kind worker
if master_pod_node == new_master_pod_node:
nodes = k8s.core_v1.list_node()
for n in nodes.items:
if "node-role.kubernetes.io/master" not in n.metadata.labels & n.metadata.name != master_pod_node:
new_master_pod_node = n.metadata.name
break
# patch node and test if master is failing over to the expected node
k8s.core_v1.patch_node(master_pod_node, body) k8s.core_v1.patch_node(master_pod_node, body)
Utils.wait_for_master_failover(k8s, new_master_pod_node, self.RETRY_TIMEOUT_SEC) Utils.wait_for_master_failover(k8s, new_master_pod_node, self.RETRY_TIMEOUT_SEC)