Exemplo n.º 1
0
    def _run_with_kubectl(self, operation):
        err_msg = ''
        with self.make_kubectl_client() as (client, err):
            if err is not None:
                if isinstance(err, ApiException):
                    err = f'Code: {err.status}, Reason: {err.reason}'
                raise error_codes.APIError(f'make client failed: {err}')

            manifests = self._to_manifests()
            try:
                if operation == 'apply':
                    client.ensure_namespace(self.namespace)
                    client.apply(manifests, self.namespace)

                elif operation == 'delete':
                    client.ensure_namespace(self.namespace)
                    client.delete(manifests, self.namespace)
            except Exception as e:
                err_msg = f'client {operation} failed: {e}'

        if err_msg:
            self._log_activity('failed', err_msg)
            raise error_codes.APIError(err_msg)

        self._log_activity('succeed')
Exemplo n.º 2
0
    def delete(self, request, project_id, namespace_id, is_validate_perm=True):
        # NOTE: open mesos delete namespace, when mesos api ready
        if request.project.kind == ProjectKind.MESOS.value:
            raise error_codes.NotOpen('mesos api not ready')

        access_token = request.user.token.access_token

        # perm
        perm = bcs_perm.Namespace(request, project_id, namespace_id)
        perm.can_delete(raise_exception=is_validate_perm)

        # start delete oper
        client = Namespace(access_token, project_id, request.project.kind)
        resp = client.delete(namespace_id)

        # delete ns registered perm
        perm.delete()

        return response.Response(resp)
Exemplo n.º 3
0
    def delete(self, request, project_id, namespace_id, is_validate_perm=True):
        access_token = request.user.token.access_token

        # 针对mesos,需要删除完对应的资源才允许操作
        if request.project.kind == ProjectKind.MESOS.value:
            res_names = self._get_resources(request, project_id, namespace_id)
            if [name for name_list in res_names.values() for name in name_list]:
                raise error_codes.CheckFailed(_("请先删除命名空间下的资源"))

        # perm
        perm = bcs_perm.Namespace(request, project_id, namespace_id)
        perm.can_delete(raise_exception=is_validate_perm)

        # start delete oper
        client = Namespace(access_token, project_id, request.project.kind)
        resp = client.delete(namespace_id)

        # delete ns registered perm
        perm.delete()

        return response.Response(resp)