def check_calico_version(self): config.load_kube_config(os.environ.get('KUBECONFIG')) api = client.AppsV1Api(client.ApiClient()) node_ds = api.read_namespaced_daemon_set("calico-node", "kube-system", exact=True, export=True) for container in node_ds.spec.template.spec.containers: if container.name == "calico-node": if container.image != "calico/node:latest-amd64": container.image = "calico/node:latest-amd64" api.replace_namespaced_daemon_set("calico-node", "kube-system", node_ds) time.sleep(3) retry_until_success(self.check_pod_status, retries=20, wait_time=3, function_args=["kube-system"])
def delete_and_confirm(self, name, resource_type, ns="default"): try: kubectl("delete %s %s -n%s" % (resource_type, name, ns)) except subprocess.CalledProcessError: pass def is_it_gone_yet(res_name, res_type): try: kubectl("get %s %s -n%s" % (res_type, res_name, ns), logerr=False) raise self.StillThere except subprocess.CalledProcessError: # Success pass retry_until_success(is_it_gone_yet, retries=10, wait_time=10, function_args=[name, resource_type])
def wait_until_exists(self, name, resource_type, ns="default"): retry_until_success( kubectl, function_args=["get %s %s -n%s" % (resource_type, name, ns)])