@@ -124,6 +124,7 @@ def portforward_commands(api_instance):
124
124
# urllib.request. The same can be done with urllib3.util.connection.create_connection
125
125
# if the "requests" package is used.
126
126
socket_create_connection = socket .create_connection
127
+
127
128
def kubernetes_create_connection (address , * args , ** kwargs ):
128
129
dns_name = address [0 ]
129
130
if isinstance (dns_name , bytes ):
@@ -144,7 +145,8 @@ def kubernetes_create_connection(address, *args, **kwargs):
144
145
port = service_port .target_port
145
146
break
146
147
else :
147
- raise RuntimeError ("Unable to find service port: %s" % port )
148
+ raise RuntimeError (
149
+ "Unable to find service port: %s" % port )
148
150
label_selector = []
149
151
for key , value in service .spec .selector .items ():
150
152
label_selector .append ("%s=%s" % (key , value ))
@@ -164,16 +166,21 @@ def kubernetes_create_connection(address, *args, **kwargs):
164
166
continue
165
167
break
166
168
else :
167
- raise RuntimeError ("Unable to find service port name: %s" % port )
169
+ raise RuntimeError (
170
+ "Unable to find service port name: %s" % port )
168
171
elif dns_name [1 ] != 'pod' :
169
- raise RuntimeError ("Unsupported resource type: %s" % dns_name [1 ])
172
+ raise RuntimeError (
173
+ "Unsupported resource type: %s" %
174
+ dns_name [1 ])
170
175
pf = portforward (api_instance .connect_get_namespaced_pod_portforward ,
171
176
name , namespace , ports = str (port ))
172
177
return pf .socket (port )
173
178
socket .create_connection = kubernetes_create_connection
174
179
175
- # Access the nginx http server using the "<pod-name>.pod.<namespace>.kubernetes" dns name.
176
- response = urllib .request .urlopen ('http://%s.pod.default.kubernetes' % name )
180
+ # Access the nginx http server using the
181
+ # "<pod-name>.pod.<namespace>.kubernetes" dns name.
182
+ response = urllib .request .urlopen (
183
+ 'http://%s.pod.default.kubernetes' % name )
177
184
html = response .read ().decode ('utf-8' )
178
185
response .close ()
179
186
print ('Status:' , response .status )
0 commit comments