Exemplo n.º 1
0
    def deep_delete_and_create(self, kube_client: KubeClient) -> None:
        self.deep_delete(kube_client)
        timer = 0
        while (self.kube_deployment in set(list_all_deployments(kube_client))
               and timer < 60):
            sleep(1)
            timer += 1

        if timer >= 60 and self.kube_deployment in set(
                list_all_deployments(kube_client)):
            try:
                force_delete_pods(
                    self.item.metadata.name,
                    self.kube_deployment.service,
                    self.kube_deployment.instance,
                    self.item.metadata.namespace,
                    kube_client,
                )
            except ApiException as e:
                if e.status == 404:
                    # Deployment does not exist, nothing to delete but
                    # we can consider this a success.
                    self.logging.debug(
                        "not deleting nonexistent deploy/{} from namespace/{}".
                        format(self.kube_deployment.service,
                               self.item.metadata.namespace))
                else:
                    raise
        else:
            self.logging.info("deleted deploy/{} from namespace/{}".format(
                self.kube_deployment.service, self.item.metadata.namespace))
        self.create(kube_client=kube_client)
Exemplo n.º 2
0
    def deep_delete_and_create(self, kube_client: KubeClient) -> None:
        self.deep_delete(kube_client)
        timer = 0
        while (self.kube_deployment in set(list_all_deployments(kube_client))
               and timer < 60):
            sleep(1)
            timer += 1

        if timer >= 60 and self.kube_deployment in set(
                list_all_deployments(kube_client)):
            # When deleting then immediately creating, we need to use Background
            # deletion to ensure we can create the deployment immediately
            self.deep_delete(kube_client, propagation_policy="Background")

            try:
                force_delete_pods(
                    self.item.metadata.name,
                    self.kube_deployment.service,
                    self.kube_deployment.instance,
                    self.item.metadata.namespace,
                    kube_client,
                )
            except ApiException as e:
                if e.status == 404:
                    # Pod(s) may have been deleted by GC before we got to it
                    # We can consider this a success
                    self.logging.debug(
                        "pods already deleted for {} from namespace/{}. Continuing."
                        .format(self.kube_deployment.service,
                                self.item.metadata.namespace))
                else:
                    raise

        if self.kube_deployment in set(list_all_deployments(kube_client)):
            # deployment deletion failed, we cannot continue
            raise Exception(
                f"Could not delete deployment {self.item.metadata.name}")
        else:
            self.logging.info("deleted deploy/{} from namespace/{}".format(
                self.kube_deployment.service, self.item.metadata.namespace))
        self.create(kube_client=kube_client)