Skip to content

Commit 272076b

Browse files
authored
Rename example scripts, reformat with Black (#304)
1 parent a09b62e commit 272076b

15 files changed

+142
-79
lines changed

examples/create_deployment_from_yaml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ async def main():
2525
k8s_client = client.ApiClient()
2626
await utils.create_from_yaml(k8s_client, "nginx-deployment.yaml")
2727
k8s_api = client.ExtensionsV1beta1Api(k8s_client)
28-
deps = await k8s_api.read_namespaced_deployment("nginx-deployment",
29-
"default")
28+
deps = await k8s_api.read_namespaced_deployment("nginx-deployment", "default")
3029
print("Deployment {0} created".format(deps.metadata.name))
3130

3231

33-
if __name__ == '__main__':
32+
if __name__ == "__main__":
3433
loop = asyncio.get_event_loop()
3534
loop.run_until_complete(main())
3635
loop.close()

examples/dynamic-client/accept_header.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ async def main():
3535
api = await client.resources.get(api_version="v1", kind="Node")
3636

3737
# Creating a custom header
38-
params = {'header_params': {'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}}
38+
params = {
39+
"header_params": {
40+
"Accept": "application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io"
41+
}
42+
}
3943

4044
resp = await api.get(**params)
4145

examples/dynamic-client/cluster_scoped_custom_resource.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def main():
6666
"fqdn": {"type": "string"},
6767
"tls": {
6868
"properties": {
69-
"secretName": {"type": "string"}
69+
"secretName": {
70+
"type": "string"
71+
}
7072
},
7173
"type": "object",
7274
},
@@ -100,7 +102,9 @@ async def main():
100102
"\n[INFO] custom resource definition `ingressroutes.apps.example.com` created\n"
101103
)
102104
print("SCOPE\t\tNAME")
103-
print(f"{crd_creation_response.spec.scope}\t\t{crd_creation_response.metadata.name}")
105+
print(
106+
f"{crd_creation_response.spec.scope}\t\t{crd_creation_response.metadata.name}"
107+
)
104108

105109
# Fetching the "ingressroutes" CRD api
106110

@@ -157,25 +161,35 @@ async def main():
157161
ingress_routes_list = await ingressroute_api.get()
158162
print("NAME\t\t\t\tFQDN\t\tTLS\t\t\t\tSTRATEGY")
159163
for item in ingress_routes_list.items:
160-
print(f"{item.metadata.name}\t{item.spec.virtualhost.fqdn}\t{item.spec.virtualhost.tls}\t"
161-
f"{item.spec.strategy}")
164+
print(
165+
f"{item.metadata.name}\t{item.spec.virtualhost.fqdn}\t{item.spec.virtualhost.tls}\t"
166+
f"{item.spec.strategy}"
167+
)
162168

163169
# Patching the ingressroutes custom resources
164170

165171
ingressroute_manifest_first["spec"]["strategy"] = "Random"
166172
ingressroute_manifest_second["spec"]["strategy"] = "WeightedLeastRequest"
167173

168-
await ingressroute_api.patch(body=ingressroute_manifest_first, content_type="application/merge-patch+json")
169-
await ingressroute_api.patch(body=ingressroute_manifest_second, content_type="application/merge-patch+json")
174+
await ingressroute_api.patch(
175+
body=ingressroute_manifest_first,
176+
content_type="application/merge-patch+json",
177+
)
178+
await ingressroute_api.patch(
179+
body=ingressroute_manifest_second,
180+
content_type="application/merge-patch+json",
181+
)
170182

171183
print(
172184
"\n[INFO] custom resources `ingress-route-*` patched to update the strategy\n"
173185
)
174186
patched_ingress_routes_list = await ingressroute_api.get()
175187
print("NAME\t\t\t\tFQDN\t\t\tTLS\t\t\tSTRATEGY")
176188
for item in patched_ingress_routes_list.items:
177-
print(f"{item.metadata.name}\t{item.spec.virtualhost.fqdn}\t{item.spec.virtualhost.tls}\t"
178-
f"{item.spec.strategy}")
189+
print(
190+
f"{item.metadata.name}\t{item.spec.virtualhost.fqdn}\t{item.spec.virtualhost.tls}\t"
191+
f"{item.spec.strategy}"
192+
)
179193

180194
# Deleting the ingressroutes custom resources
181195

examples/dynamic-client/deployment_rolling_restart.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ async def main():
7474
deployment_created = await api.get(name=name, namespace="default")
7575

7676
print("NAMESPACE\tNAME\t\t\t\tREVISION\t\t\t\t\t\t\t\t\t\tRESTARTED-AT")
77-
print(f"{deployment_created.metadata.namespace}\t\t{deployment_created.metadata.name}\t"
78-
f"{deployment_created.metadata.annotations}\t\t{deployment_created.spec.template.metadata.annotations}")
77+
print(
78+
f"{deployment_created.metadata.namespace}\t\t{deployment_created.metadata.name}\t"
79+
f"{deployment_created.metadata.annotations}\t\t{deployment_created.spec.template.metadata.annotations}"
80+
)
7981

8082
# Patching the `spec.template.metadata` section to add `kubectl.kubernetes.io/restartedAt` annotation
8183
# In order to perform a rolling restart on the deployment `nginx-deployment`
@@ -94,8 +96,10 @@ async def main():
9496

9597
print("\n[INFO] deployment `nginx-deployment` restarted\n")
9698
print("NAMESPACE\tNAME\t\t\t\tREVISION\t\t\t\t\t\t\t\t\tRESTARTED-AT")
97-
print(f"{deployment_patched.metadata.namespace}\t\t{deployment_patched.metadata.name}\t"
98-
f"{deployment_patched.metadata.annotations}\t{deployment_patched.spec.template.metadata.annotations}")
99+
print(
100+
f"{deployment_patched.metadata.namespace}\t\t{deployment_patched.metadata.name}\t"
101+
f"{deployment_patched.metadata.annotations}\t{deployment_patched.spec.template.metadata.annotations}"
102+
)
99103

100104
# Deleting deployment `nginx-deployment` from the `default` namespace
101105

examples/dynamic-client/namespaced_custom_resource.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ async def main():
7979
"fqdn": {"type": "string"},
8080
"tls": {
8181
"properties": {
82-
"secretName": {"type": "string"}
82+
"secretName": {
83+
"type": "string"
84+
}
8385
},
8486
"type": "object",
8587
},
@@ -172,8 +174,12 @@ async def main():
172174
},
173175
}
174176

175-
await ingressroute_api.create(body=ingressroute_manifest_first, namespace=namespace_first)
176-
await ingressroute_api.create(body=ingressroute_manifest_second, namespace=namespace_second)
177+
await ingressroute_api.create(
178+
body=ingressroute_manifest_first, namespace=namespace_first
179+
)
180+
await ingressroute_api.create(
181+
body=ingressroute_manifest_second, namespace=namespace_second
182+
)
177183
print("\n[INFO] custom resources `ingress-route-*` created\n")
178184

179185
# Listing the `ingress-route-*` custom resources
@@ -192,7 +198,7 @@ async def main():
192198
item["metadata"]["namespace"],
193199
item["spec"]["virtualhost"]["fqdn"],
194200
item["spec"]["virtualhost"]["tls"],
195-
item["spec"]["strategy"]
201+
item["spec"]["strategy"],
196202
)
197203
)
198204

@@ -202,10 +208,12 @@ async def main():
202208
ingressroute_manifest_second["spec"]["strategy"] = "WeightedLeastRequest"
203209

204210
await ingressroute_api.patch(
205-
body=ingressroute_manifest_first, content_type="application/merge-patch+json"
211+
body=ingressroute_manifest_first,
212+
content_type="application/merge-patch+json",
206213
)
207214
await ingressroute_api.patch(
208-
body=ingressroute_manifest_second, content_type="application/merge-patch+json"
215+
body=ingressroute_manifest_second,
216+
content_type="application/merge-patch+json",
209217
)
210218

211219
print(
@@ -227,7 +235,7 @@ async def main():
227235
item["metadata"]["namespace"],
228236
item["spec"]["virtualhost"]["fqdn"],
229237
item["spec"]["virtualhost"]["tls"],
230-
item["spec"]["strategy"]
238+
item["spec"]["strategy"],
231239
)
232240
)
233241

examples/dynamic-client/replication_controller.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ async def main():
5959
}
6060

6161
# Creating replication-controller `frontend-replication-controller` in the `default` namespace
62-
await api.create(
63-
body=replication_controller_manifest, namespace="default"
64-
)
62+
await api.create(body=replication_controller_manifest, namespace="default")
6563

66-
print("\n[INFO] replication-controller `frontend-replication-controller` created\n")
64+
print(
65+
"\n[INFO] replication-controller `frontend-replication-controller` created\n"
66+
)
6767

6868
# Listing replication-controllers in the `default` namespace
6969
replication_controller_created = await api.get(name=name, namespace="default")
@@ -81,7 +81,9 @@ async def main():
8181
# Deleting replication-controller `frontend-service` from the `default` namespace
8282
await api.delete(name=name, body={}, namespace="default")
8383

84-
print("[INFO] replication-controller `frontend-replication-controller` deleted\n")
84+
print(
85+
"[INFO] replication-controller `frontend-replication-controller` deleted\n"
86+
)
8587

8688

8789
if __name__ == "__main__":

examples/dynamic-client/request_timeout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ async def main():
6464
# Client-side timeout to 60 seconds
6565

6666
configmap_list = await api.get(
67-
name=configmap_name, namespace="default", label_selector="foo=bar", _request_time=60
67+
name=configmap_name,
68+
namespace="default",
69+
label_selector="foo=bar",
70+
_request_time=60,
6871
)
6972

7073
print(f"NAME:\n{configmap_list.metadata.name}\n")

examples/dynamic-client/service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ async def main():
4141
service_manifest = {
4242
"apiVersion": "v1",
4343
"kind": "Service",
44-
"metadata": {"labels": {"name": name}, "name": name, "resourceversion": "v1"},
44+
"metadata": {
45+
"labels": {"name": name},
46+
"name": name,
47+
"resourceversion": "v1",
48+
},
4549
"spec": {
4650
"ports": [
4751
{"name": "port", "port": 80, "protocol": "TCP", "targetPort": 80}
@@ -71,7 +75,9 @@ async def main():
7175
{"name": "new", "port": 8080, "protocol": "TCP", "targetPort": 8080}
7276
]
7377

74-
service_patched = await api.patch(body=service_manifest, name=name, namespace="default")
78+
service_patched = await api.patch(
79+
body=service_manifest, name=name, namespace="default"
80+
)
7581

7682
print("\n[INFO] service `frontend-service` patched\n")
7783
print("%s\t%s\t\t\t%s" % ("NAMESPACE", "NAME", "PORTS"))

examples/in_cluster_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def main():
8080
await asyncio.sleep(10)
8181

8282

83-
if __name__ == '__main__':
83+
if __name__ == "__main__":
8484
loop = asyncio.get_event_loop()
8585
loop.run_until_complete(main())
8686
loop.close()

examples/example1.py renamed to examples/list_pods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def main():
2121
print(i.status.pod_ip, i.metadata.namespace, i.metadata.name)
2222

2323

24-
if __name__ == '__main__':
24+
if __name__ == "__main__":
2525
loop = asyncio.get_event_loop()
2626
loop.run_until_complete(main())
2727
loop.close()

0 commit comments

Comments
 (0)