Esempio n. 1
0
    def delete(self, timeout=None):
        """
        Delete the deployment.

        Idempotency: This function is idempotent. If deployment does not exist then
        delete will silently fail without raising any exceptions.
        Args:
            timeout: In seconds or None for infinite
        """
        options = swagger_client.V1DeleteOptions()
        options.grace_period_seconds = 1
        options.orphan_dependents = False

        def check_result(result):
            # True for retry False for done
            return not result

        @retry(retry_on_result=check_result, wait_fixed=2000, stop_max_delay=timeout)
        def wait_for_scale_to_zero():
            logger.debug("Wait for scale of deployment to 0 for {} {}".format(self.application, self.name))

            @retry_unless(swallow_code=[404])
            def get_scale_from_provider():
                return self.client.apisappsv1beta1_api.read_namespaced_scale_scale(self.application, self.name)

            scale = get_scale_from_provider()
            if scale is None:
                return True
            if scale.status.replicas == 0:
                return True

            return False

        @retry_unless(swallow_code=[404, 409])
        def delete_in_provider():
            logger.debug("Deleting deployment for {} {}".format(self.application, self.name))
            self.client.apisappsv1beta1_api.delete_namespaced_deployment(options, self.application, self.name)

        def delete_rs_in_provider():
            logger.debug("Deleting replica set for {} {}".format(self.application, self.name))
            self.client.extensionsv1beta1.deletecollection_namespaced_replica_set(self.application, label_selector="deployment={}".format(self.name))

        # now delete deployment object and replication set
        with DeploymentOperation(self):
            dep_obj = self._deployment_status()
            self._scale_to(0)
            wait_for_scale_to_zero()

            if dep_obj:
                resources = AXResources(existing=dep_obj)
                resources.delete_all()

            delete_in_provider()
            delete_rs_in_provider()
Esempio n. 2
0
    def delete(self, force=False):
        """
        Delete the task from kubernetes and returns the final status
        Returns: Last status of the job
        """
        logger.debug("Task delete for {}".format(self.name))
        with TaskOperation(self):
            status_obj = Pod(self.name, self.namespace)._get_status_obj()
            status = self.status(status_obj=status_obj)
            p = Pod(self.name, self.namespace)
            if not force:
                p.stop()

            # delete dependents
            resources = AXResources(existing=status_obj)
            resources.delete_all()

            # finally delete pod
            p.delete()
            return status