MCPcopy Index your code
hub / github.com/kubernetes-client/python / main

Function main

examples/dynamic-client/configmap.py:25–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23
24
25def main():
26 # Creating a dynamic client
27 client = dynamic.DynamicClient(
28 api_client.ApiClient(configuration=config.load_kube_config())
29 )
30
31 # fetching the configmap api
32 api = client.resources.get(api_version="v1", kind="ConfigMap")
33
34 configmap_name = "test-configmap"
35
36 configmap_manifest = {
37 "kind": "ConfigMap",
38 "apiVersion": "v1",
39 "metadata": {
40 "name": configmap_name,
41 "labels": {
42 "foo": "bar",
43 },
44 },
45 "data": {
46 "config.json": '{"command":"/usr/bin/mysqld_safe"}',
47 "frontend.cnf": "[mysqld]\nbind-address = 10.0.0.3\n",
48 },
49 }
50
51 # Creating configmap `test-configmap` in the `default` namespace
52
53 configmap = api.create(body=configmap_manifest, namespace="default")
54
55 print("\n[INFO] configmap `test-configmap` created\n")
56
57 # Listing the configmaps in the `default` namespace
58
59 configmap_list = api.get(
60 name=configmap_name, namespace="default", label_selector="foo=bar"
61 )
62
63 print("NAME:\n%s\n" % (configmap_list.metadata.name))
64 print("DATA:\n%s\n" % (configmap_list.data))
65
66 # Updating the configmap's data, `config.json`
67
68 configmap_manifest["data"]["config.json"] = "{}"
69
70 configmap_patched = api.patch(
71 name=configmap_name, namespace="default", body=configmap_manifest
72 )
73
74 print("\n[INFO] configmap `test-configmap` patched\n")
75 print("NAME:\n%s\n" % (configmap_patched.metadata.name))
76 print("DATA:\n%s\n" % (configmap_patched.data))
77
78 # Deleting configmap `test-configmap` from the `default` namespace
79
80 configmap_deleted = api.delete(name=configmap_name, body={}, namespace="default")
81 print("\n[INFO] configmap `test-configmap` deleted\n")
82

Callers 1

configmap.pyFile · 0.70

Calls 4

getMethod · 0.45
createMethod · 0.45
patchMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected