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

Function main

examples_asyncio/patch.py:23–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21
22
23async def main():
24
25 await config.load_kube_config()
26
27 async with ApiClient() as api:
28
29 v1 = client.CoreV1Api(api)
30
31 print(f"Recreate {SERVICE_NAME}...")
32 try:
33 await v1.read_namespaced_service(SERVICE_NAME, SERVICE_NS)
34 await v1.delete_namespaced_service(SERVICE_NAME, SERVICE_NS)
35 except client.exceptions.ApiException as ex:
36 if ex.status == 404:
37 pass
38
39 await v1.create_namespaced_service(SERVICE_NS, SERVICE_SPEC)
40
41 print("Patch using JSON patch - replace port-80 with port-1000")
42 patch = [
43 {
44 "op": "replace",
45 "path": "/spec/ports/0",
46 "value": {
47 "name": "port-1000",
48 "protocol": "TCP",
49 "port": 1000,
50 "targetPort": 1000,
51 },
52 }
53 ]
54 await v1.patch_namespaced_service(
55 SERVICE_NAME,
56 SERVICE_NS,
57 patch,
58 # _content_type='application/json-patch+json' # (optional, default if patch is a list)
59 )
60
61 print(
62 "Patch using strategic merge patch - add port-2000, service will have two ports: port-1000 and port-2000"
63 )
64 patch = {
65 "spec": {
66 "ports": [
67 {
68 "name": "port-2000",
69 "protocol": "TCP",
70 "port": 2000,
71 "targetPort": 2000,
72 }
73 ]
74 }
75 }
76 await v1.patch_namespaced_service(
77 SERVICE_NAME,
78 SERVICE_NS,
79 patch,
80 # _content_type='application/strategic-merge-patch+json' # (optional, default if patch is a dict)

Callers 1

patch.pyFile · 0.70

Calls 5

ApiClientClass · 0.90

Tested by

no test coverage detected