def create_namespace(config, ns_name): metadata = {'name': ns_name} namespace = V1Namespace(metadata=metadata) k8s_api = client_from_config(config) k8s_api.create_namespace(namespace)
def send_create_namespace_request(self, name): return self.apiV1.create_namespace( V1Namespace(metadata=V1ObjectMeta( name=name, deletion_grace_period_seconds=1, )))
def create_namespace(self, namespace: str): '''Creates a new namespace and returns it''' ensure_not_empty(namespace) metadata = V1ObjectMeta(name=namespace) ns = V1Namespace(metadata=metadata) return self.core_api.create_namespace(ns)
specific language governing permissions and limitations under the License. """ import pytest from kubernetes.client import V1Namespace, V1ObjectMeta from kubernetes.client.rest import ApiException, RESTResponse from urllib3.response import HTTPResponse from backend.components.bcs.resources.api_response import response from backend.tests.testing_utils.base import dict_is_subequal @pytest.mark.parametrize( 'result,format_data,expected_resp', [ # Kubernetes object response (V1Namespace(metadata=V1ObjectMeta(name='foo')), True, {'result': True, 'code': 0, 'message': 'success'}), # Normal data type ({'foo': 'bar'}, False, {'code': 0, 'data': {'foo': 'bar'}, 'message': 'success', 'result': True}), # Raises APIException error ( ApiException(status=404, http_resp=RESTResponse(HTTPResponse(status=404))), True, {'code': 4001, 'message': 'request bcs api error, (404)\nReason: None\n', 'result': False}, ), ( ApiException(status=400, http_resp=RESTResponse(HTTPResponse(status=404, body='{"message": "foobar"}'))), True, {'code': 4001, 'message': 'foobar', 'result': False}, ), # Raises other exceptions (ValueError('unknown error'), True, {'code': 4001, 'message': 'unknown error', 'result': False}),