@@ -124,6 +124,7 @@ def portforward_commands(api_instance):
124124 # urllib.request. The same can be done with urllib3.util.connection.create_connection
125125 # if the "requests" package is used.
126126 socket_create_connection = socket .create_connection
127+
127128 def kubernetes_create_connection (address , * args , ** kwargs ):
128129 dns_name = address [0 ]
129130 if isinstance (dns_name , bytes ):
@@ -144,7 +145,8 @@ def kubernetes_create_connection(address, *args, **kwargs):
144145 port = service_port .target_port
145146 break
146147 else :
147- raise RuntimeError ("Unable to find service port: %s" % port )
148+ raise RuntimeError (
149+ "Unable to find service port: %s" % port )
148150 label_selector = []
149151 for key , value in service .spec .selector .items ():
150152 label_selector .append ("%s=%s" % (key , value ))
@@ -164,16 +166,21 @@ def kubernetes_create_connection(address, *args, **kwargs):
164166 continue
165167 break
166168 else :
167- raise RuntimeError ("Unable to find service port name: %s" % port )
169+ raise RuntimeError (
170+ "Unable to find service port name: %s" % port )
168171 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 ])
170175 pf = portforward (api_instance .connect_get_namespaced_pod_portforward ,
171176 name , namespace , ports = str (port ))
172177 return pf .socket (port )
173178 socket .create_connection = kubernetes_create_connection
174179
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 )
177184 html = response .read ().decode ('utf-8' )
178185 response .close ()
179186 print ('Status:' , response .status )
0 commit comments