Skip to content

Commit 74453c9

Browse files
authored
Merge pull request #2124 from Ananya2001-an/chore-format-string
chore: use f-string in place of old-style formatted string
2 parents 397d06b + 298725d commit 74453c9

16 files changed

+42
-60
lines changed

examples/annotate_deployment.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def main():
6262
time.sleep(1)
6363
before_annotating = apps_v1_api.read_namespaced_deployment(
6464
'deploy-nginx', 'default')
65-
print('Before annotating, annotations: %s' %
66-
before_annotating.metadata.annotations)
65+
print(f"Before annotating, annotations: {before_annotating.metadata.annotations}")
6766

6867
annotations = [
6968
{
@@ -80,8 +79,7 @@ def main():
8079
time.sleep(1)
8180
after_annotating = apps_v1_api.read_namespaced_deployment(
8281
name='deploy-nginx', namespace='default')
83-
print('After annotating, annotations: %s' %
84-
after_annotating.metadata.annotations)
82+
print(f"After annotating, annotations: {after_annotating.metadata.annotations}")
8583

8684

8785
if __name__ == "__main__":

examples/api_discovery.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def main():
2727
config.load_kube_config()
2828

2929
print("Supported APIs (* is preferred version):")
30-
print("%-40s %s" %
31-
("core", ",".join(client.CoreApi().get_api_versions().versions)))
30+
print(f"{'core':<40} {','.join(client.CoreApi().get_api_versions().versions)}")
3231
for api in client.ApisApi().get_api_versions().groups:
3332
versions = []
3433
for v in api.versions:
@@ -38,7 +37,7 @@ def main():
3837
name += "*"
3938
name += v.version
4039
versions.append(name)
41-
print("%-40s %s" % (api.name, ",".join(versions)))
40+
print(f"{api.name:<40} {','.join(versions)}")
4241

4342

4443
if __name__ == '__main__':

examples/apply_from_directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from kubernetes import client,config,utils
1+
from kubernetes import client, config, utils
22

33
def main():
44
config.load_kube_config()

examples/apply_from_single_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from kubernetes import client,config,utils
1+
from kubernetes import client, config, utils
22

33
def main():
44
config.load_kube_config()
55
k8s_client = client.ApiClient()
6-
yaml_file = 'examples/configmap-demo-pod.yml'
6+
yaml_file = 'examples/yaml_dir/configmap-demo-pod.yml'
77
utils.create_from_yaml(k8s_client,yaml_file,verbose=True)
88

99
if __name__ == "__main__":

examples/cluster_scoped_custom_object.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ def main():
100100
plural="crontabs",
101101
)
102102
print("%s\t\t%s" % ("NAME", "CRON-SPEC"))
103-
print(
104-
"%s\t%s\n" %
105-
(resource["metadata"]["name"],
106-
resource["spec"]["cronSpec"]))
103+
print(f"{resource['metadata']['name']}\t{resource['spec']['cronSpec']}\n")
107104

108105
# patch the `spec.cronSpec` field of the custom resource
109106
patched_resource = api.patch_cluster_custom_object(
@@ -115,10 +112,7 @@ def main():
115112
)
116113
print("[INFO] Custom resource `test-crontab` patched to update the cronSpec schedule!\n")
117114
print("%s\t\t%s" % ("NAME", "PATCHED-CRON-SPEC"))
118-
print(
119-
"%s\t%s\n" %
120-
(patched_resource["metadata"]["name"],
121-
patched_resource["spec"]["cronSpec"]))
115+
print(f"{patched_resource['metadata']['name']}\t{patched_resource['spec']['cronSpec']}\n")
122116

123117
# patch the `metadata.labels` field of the custom resource
124118
patched_resource = api.patch_cluster_custom_object(
@@ -130,10 +124,7 @@ def main():
130124
)
131125
print("[INFO] Custom resource `test-crontab` patched to apply new metadata labels!\n")
132126
print("%s\t\t%s" % ("NAME", "PATCHED_LABELS"))
133-
print(
134-
"%s\t%s\n" %
135-
(patched_resource["metadata"]["name"],
136-
patched_resource["metadata"]["labels"]))
127+
print(f"{patched_resource['metadata']['name']}\t{patched_resource['metadata']['labels']}\n")
137128

138129
# delete the custom resource "test-crontab"
139130
api.delete_cluster_custom_object(

examples/deployment_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434
k8s_apps_v1 = client.AppsV1Api()
3535
resp = k8s_apps_v1.create_namespaced_deployment(
3636
body=dep, namespace="default")
37-
print("Deployment created. status='%s'" % resp.metadata.name)
37+
print(f"Deployment created. Status='{resp.metadata.name}'")
3838

3939

4040
if __name__ == '__main__':

examples/in_cluster_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def main():
5858
print("Listing pods with their IPs:")
5959
ret = v1.list_pod_for_all_namespaces(watch=False)
6060
for i in ret.items:
61-
print("%s\t%s\t%s" %
62-
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
61+
print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")
6362

6463

6564
if __name__ == '__main__':

examples/job_crud.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def create_job_object():
30-
# Configureate Pod template container
30+
# Configure Pod template container
3131
container = client.V1Container(
3232
name="pi",
3333
image="perl",
@@ -54,7 +54,7 @@ def create_job(api_instance, job):
5454
api_response = api_instance.create_namespaced_job(
5555
body=job,
5656
namespace="default")
57-
print("Job created. status='%s'" % str(api_response.status))
57+
print(f"Job created. status='{str(api_response.status)}'")
5858
get_job_status(api_instance)
5959

6060

@@ -68,7 +68,7 @@ def get_job_status(api_instance):
6868
api_response.status.failed is not None:
6969
job_completed = True
7070
sleep(1)
71-
print("Job status='%s'" % str(api_response.status))
71+
print(f"Job status='{str(api_response.status)}'")
7272

7373

7474
def update_job(api_instance, job):
@@ -78,7 +78,7 @@ def update_job(api_instance, job):
7878
name=JOB_NAME,
7979
namespace="default",
8080
body=job)
81-
print("Job updated. status='%s'" % str(api_response.status))
81+
print(f"Job updated. status='{str(api_response.status)}'")
8282

8383

8484
def delete_job(api_instance):
@@ -88,7 +88,7 @@ def delete_job(api_instance):
8888
body=client.V1DeleteOptions(
8989
propagation_policy='Foreground',
9090
grace_period_seconds=5))
91-
print("Job deleted. status='%s'" % str(api_response.status))
91+
print(f"Job deleted. status='{str(api_response.status)}'")
9292

9393

9494
def main():

examples/multiple_clusters.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ def main():
4343

4444
print("\nList of pods on %s:" % cluster1)
4545
for i in client1.list_pod_for_all_namespaces().items:
46-
print("%s\t%s\t%s" %
47-
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
46+
print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")
4847

49-
print("\n\nList of pods on %s:" % cluster2)
48+
print(f"\n\nList of pods on {cluster2}:")
5049
for i in client2.list_pod_for_all_namespaces().items:
51-
print("%s\t%s\t%s" %
52-
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
50+
print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")
5351

5452

5553
if __name__ == '__main__':

examples/node_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main():
4444
# Patching the node labels
4545
for node in node_list.items:
4646
api_response = api_instance.patch_node(node.metadata.name, body)
47-
print("%s\t%s" % (node.metadata.name, node.metadata.labels))
47+
print(f"{node.metadata.name}\t{node.metadata.labels}")
4848

4949

5050
if __name__ == '__main__':

0 commit comments

Comments
 (0)