@@ -66,11 +66,11 @@ def portforward_commands(api_instance):
66
66
namespace = 'default' )
67
67
except ApiException as e :
68
68
if e .status != 404 :
69
- print ("Unknown error: %s" % e )
69
+ print (f "Unknown error: { e } " )
70
70
exit (1 )
71
71
72
72
if not resp :
73
- print ("Pod %s does not exist. Creating it..." % name )
73
+ print (f "Pod { name } does not exist. Creating it..." )
74
74
pod_manifest = {
75
75
'apiVersion' : 'v1' ,
76
76
'kind' : 'Pod' ,
@@ -119,7 +119,7 @@ def portforward_commands(api_instance):
119
119
if error is None :
120
120
print ("No port forward errors on port 80." )
121
121
else :
122
- print ("Port 80 has the following error: %s" % error )
122
+ print (f "Port 80 has the following error: { error } " )
123
123
124
124
# Monkey patch socket.create_connection which is used by http.client and
125
125
# urllib.request. The same can be done with urllib3.util.connection.create_connection
@@ -147,10 +147,10 @@ def kubernetes_create_connection(address, *args, **kwargs):
147
147
break
148
148
else :
149
149
raise RuntimeError (
150
- "Unable to find service port: %s" % port )
150
+ f "Unable to find service port: { port } " )
151
151
label_selector = []
152
152
for key , value in service .spec .selector .items ():
153
- label_selector .append ("%s=%s" % ( key , value ) )
153
+ label_selector .append (f" { key } = { value } " )
154
154
pods = api_instance .list_namespaced_pod (
155
155
namespace , label_selector = "," .join (label_selector )
156
156
)
@@ -168,11 +168,10 @@ def kubernetes_create_connection(address, *args, **kwargs):
168
168
break
169
169
else :
170
170
raise RuntimeError (
171
- "Unable to find service port name: %s" % port )
171
+ f "Unable to find service port name: { port } " )
172
172
elif dns_name [1 ] != 'pod' :
173
173
raise RuntimeError (
174
- "Unsupported resource type: %s" %
175
- dns_name [1 ])
174
+ f"Unsupported resource type: { dns_name [1 ]} " )
176
175
pf = portforward (api_instance .connect_get_namespaced_pod_portforward ,
177
176
name , namespace , ports = str (port ))
178
177
return pf .socket (port )
@@ -181,10 +180,10 @@ def kubernetes_create_connection(address, *args, **kwargs):
181
180
# Access the nginx http server using the
182
181
# "<pod-name>.pod.<namespace>.kubernetes" dns name.
183
182
response = urllib_request .urlopen (
184
- 'http://%s .pod.default.kubernetes' % name )
183
+ f 'http://{ name } .pod.default.kubernetes' )
185
184
html = response .read ().decode ('utf-8' )
186
185
response .close ()
187
- print ('Status Code: %s' % response .code )
186
+ print (f 'Status Code: { response .code } ' )
188
187
print (html )
189
188
190
189
0 commit comments