def create_configmap(v1: CoreV1Api, namespace, body) -> str: """ Create a config-map based on a dict. :param v1: CoreV1Api :param namespace: namespace name :param body: a dict :return: str """ print("Create a configMap:") v1.create_namespaced_config_map(namespace, body) print(f"Config map created with name '{body['metadata']['name']}'") return body["metadata"]["name"]
def create_configmap(v1: CoreV1Api, namespace, body) -> str: """ Create a config-map based on a dict. :param v1: CoreV1Api :param namespace: namespace name :param body: a dict :return: str """ print("Create a configMap:") v1.create_namespaced_config_map(namespace, body) print(f"Config map created with name '{body['metadata']['name']}'") return body["metadata"]["name"]
def test_configmap_apis(self, k8s: client.CoreV1Api): name = 'test-' + str(uuid.uuid4()) test_configmap = { "kind": "ConfigMap", "apiVersion": "v1", "metadata": { "name": name, }, "data": { "config.json": "{\"command\":\"/usr/bin/mysqld_safe\"}", "frontend.cnf": "[mysqld]\nbind-address = 10.0.0.3\nport = 3306\n" } } resp = k8s.create_namespaced_config_map( body=test_configmap, namespace='default' ) assert name == resp.metadata.name resp = k8s.read_namespaced_config_map( name=name, namespace='default') assert name == resp.metadata.name # test_configmap['data']['config.json'] = "{}" # resp = k8s.patch_namespaced_config_map( # name=name, namespace='default', body=test_configmap) resp = k8s.delete_namespaced_config_map( name=name, body={}, namespace='default')
def set_config_map(config_map_name, multiaddress_data, kubernetes_api: client.CoreV1Api): try: config_map = kubernetes_api.read_namespaced_config_map( name=config_map_name, namespace="default") patch = {"data": multiaddress_data} kubernetes_api.patch_namespaced_config_map(name=config_map_name, namespace="default", body=patch) except client.rest.ApiException as api_exception: if api_exception.status != 404: raise config_map = { "apiVersion": "v1", "kind": "ConfigMap", "metadata": { "name": config_map_name }, "data": multiaddress_data } kubernetes_api.create_namespaced_config_map("default", config_map)