@@ -246,8 +246,8 @@ func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOpti
246
246
return nil
247
247
}
248
248
249
- func ( kc KubeClient ) MapPorts ( ctx context. Context , opts PortMappingOptions ) error {
250
-
249
+ //MapPortsToLocalhost runs a port-forwarder daemon process
250
+ func ( kc KubeClient ) MapPortsToLocalhost ( ctx context. Context , opts PortMappingOptions ) error {
251
251
stopChannel := make (chan struct {}, 1 )
252
252
readyChannel := make (chan struct {})
253
253
@@ -260,19 +260,20 @@ func (kc KubeClient) MapPorts(ctx context.Context, opts PortMappingOptions) erro
260
260
return err
261
261
}
262
262
eg .Go (func () error {
263
+ ports := []string {}
264
+ for _ , p := range servicePorts {
265
+ ports = append (ports , fmt .Sprintf ("%d:%d" , p .PublishedPort , p .TargetPort ))
266
+ }
263
267
264
- req := kc .client .RESTClient ().Post ().Resource ("pods" ).Namespace (kc .namespace ).Name (pod .Name ).SubResource ("portforward" ) //fmt.Sprintf("service/%s", serviceName)).SubResource("portforward")
268
+ req := kc .client .CoreV1 ().RESTClient ().Post ().
269
+ Resource ("pods" ).
270
+ Name (pod .Name ).
271
+ Namespace (kc .namespace ).
272
+ SubResource ("portforward" )
265
273
transport , upgrader , err := spdy .RoundTripperFor (kc .config )
266
274
if err != nil {
267
275
return err
268
276
}
269
-
270
- ports := []string {}
271
- for _ , p := range servicePorts {
272
- ports = append (ports , fmt .Sprintf ("%d:%d" , p .PublishedPort , p .TargetPort ))
273
- }
274
- //println(req.URL().String())
275
- //os.Exit(0)
276
277
dialer := spdy .NewDialer (upgrader , & http.Client {Transport : transport }, "POST" , req .URL ())
277
278
fw , err := portforward .New (dialer , ports , stopChannel , readyChannel , os .Stdout , os .Stderr )
278
279
if err != nil {
0 commit comments