create/delete the operator deployment
This commit is contained in:
		
							parent
							
								
									0474be923f
								
							
						
					
					
						commit
						02c2d488bc
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import unittest, yaml
 | 
					import unittest, yaml, time
 | 
				
			||||||
from kubernetes import client, config, utils
 | 
					from kubernetes import client, config, utils
 | 
				
			||||||
from pprint import pprint
 | 
					from pprint import pprint
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ class SampleTestCase(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nodes = set(["kind-test-postgres-operator-worker", "kind-test-postgres-operator-worker2", "kind-test-postgres-operator-worker3"])
 | 
					    nodes = set(["kind-test-postgres-operator-worker", "kind-test-postgres-operator-worker2", "kind-test-postgres-operator-worker3"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    config = None
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def setUpClass(cls):
 | 
					    def setUpClass(cls):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,19 +17,28 @@ class SampleTestCase(unittest.TestCase):
 | 
				
			||||||
        _ = config.load_kube_config()
 | 
					        _ = config.load_kube_config()
 | 
				
			||||||
        k8s_client = client.ApiClient()
 | 
					        k8s_client = client.ApiClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # HACK create_from_yaml fails with multiple object defined within a single file
 | 
					        # TODO split into multiple files
 | 
				
			||||||
        # which is exactly the case with RBAC definition
 | 
					 | 
				
			||||||
        subprocess.run(["kubectl", "create", "-f", "manifests/operator-service-account-rbac.yaml"])
 | 
					        subprocess.run(["kubectl", "create", "-f", "manifests/operator-service-account-rbac.yaml"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for filename in ["configmap.yaml", "postgres-operator.yaml"]:
 | 
					        for filename in ["configmap.yaml", "postgres-operator.yaml"]:
 | 
				
			||||||
            path = "manifests/" + filename
 | 
					            path = "manifests/" + filename
 | 
				
			||||||
            utils.create_from_yaml(k8s_client, path)
 | 
					            utils.create_from_yaml(k8s_client, path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #TODO wait until operator pod starts up label ; name=postgres-operator
 | 
					        v1 = client.CoreV1Api()
 | 
				
			||||||
 | 
					        pod_phase = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while pod_phase != 'Running':
 | 
				
			||||||
 | 
					            pods = v1.list_namespaced_pod('default', label_selector='name=postgres-operator').items
 | 
				
			||||||
 | 
					            if pods:
 | 
				
			||||||
 | 
					               operator_pod = pods[0]
 | 
				
			||||||
 | 
					               pod_phase = operator_pod.status.phase
 | 
				
			||||||
 | 
					               print("Waiting for the operator pod to start. Current phase: " + pod_phase)
 | 
				
			||||||
 | 
					               time.sleep(5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def tearDownClass(cls):
 | 
					    def tearDownClass(cls):
 | 
				
			||||||
        pass
 | 
					        apps_v1 = client.AppsV1Api()
 | 
				
			||||||
 | 
					        _ = apps_v1.delete_namespaced_deployment("postgres-operator", "default")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        self.config = config.load_kube_config()
 | 
					        self.config = config.load_kube_config()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue