当前位置: 首页>>代码示例>>Golang>>正文


Golang portforward.New函数代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned/portforward.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ForwardPorts

// ForwardPorts will forward a set of ports from a pod, the stopChan will stop the forwarding
// when it's closed or receives a struct{}
func (f *portForwarder) ForwardPorts(ports []string, stopChan <-chan struct{}) error {
	req := f.Client.RESTClient.Post().
		Resource("pods").
		Namespace(f.Namespace).
		Name(f.PodName).
		SubResource("portforward")

	dialer, err := remotecommand.NewExecutor(f.Config, "POST", req.URL())
	if err != nil {
		return err
	}
	// TODO: Make os.Stdout/Stderr configurable
	// TODO: Accept a ready channel?
	fw, err := portforward.New(dialer, ports, stopChan, nil, f.Out, f.ErrOut)
	if err != nil {
		return err
	}
	ready := make(chan struct{})
	errChan := make(chan error)
	fw.Ready = ready
	go func() { errChan <- fw.ForwardPorts() }()
	select {
	case <-ready:
		return nil
	case err = <-errChan:
		return err
	}
}
开发者ID:pweil-,项目名称:origin,代码行数:30,代码来源:forwarder.go

示例2: ForwardPorts

func (*defaultPortForwarder) ForwardPorts(req *client.Request, config *client.Config, ports []string, stopChan <-chan struct{}) error {
	fw, err := portforward.New(req, config, ports, stopChan)
	if err != nil {
		return err
	}
	return fw.ForwardPorts()
}
开发者ID:ncantor,项目名称:origin,代码行数:7,代码来源:portforward.go

示例3: ForwardPort

// ForwardPort opens a tunnel to a kubernetes pod
func (c *Client) ForwardPort(namespace, podName string, remote int) (*Tunnel, error) {
	client, err := c.Client()
	if err != nil {
		return nil, err
	}

	config, err := c.ClientConfig()
	if err != nil {
		return nil, err
	}

	// Build a url to the portforward endpoing
	// example: http://localhost:8080/api/v1/namespaces/helm/pods/tiller-deploy-9itlq/portforward
	u := client.RESTClient.Post().
		Resource("pods").
		Namespace(namespace).
		Name(podName).
		SubResource("portforward").URL()

	dialer, err := remotecommand.NewExecutor(config, "POST", u)
	if err != nil {
		return nil, err
	}

	local, err := getAvailablePort()
	if err != nil {
		return nil, err
	}

	t := &Tunnel{
		Local:    local,
		Remote:   remote,
		stopChan: make(chan struct{}, 1),
	}

	ports := []string{fmt.Sprintf("%d:%d", local, remote)}

	var b bytes.Buffer
	pf, err := portforward.New(dialer, ports, t.stopChan, &b, &b)
	if err != nil {
		return nil, err
	}

	errChan := make(chan error)
	go func() {
		errChan <- pf.ForwardPorts()
	}()

	select {
	case err = <-errChan:
		return t, fmt.Errorf("Error forwarding ports: %v\n", err)
	case <-pf.Ready:
		return t, nil
	}
}
开发者ID:runseb,项目名称:helm,代码行数:56,代码来源:tunnel.go

示例4: ForwardPorts

func (f *defaultPortForwarder) ForwardPorts(method string, url *url.URL, opts PortForwardOptions) error {
	dialer, err := remotecommand.NewExecutor(opts.Config, method, url)
	if err != nil {
		return err
	}
	fw, err := portforward.New(dialer, opts.Ports, opts.StopChannel, opts.ReadyChannel, f.cmdOut, f.cmdErr)
	if err != nil {
		return err
	}
	return fw.ForwardPorts()
}
开发者ID:jumpkick,项目名称:kubernetes,代码行数:11,代码来源:portforward.go

示例5: ForwardPorts

func (f *defaultPortForwarder) ForwardPorts(method string, url *url.URL, config *restclient.Config, ports []string, stopChan <-chan struct{}) error {
	dialer, err := remotecommand.NewExecutor(config, method, url)
	if err != nil {
		return err
	}
	fw, err := portforward.New(dialer, ports, stopChan, f.cmdOut, f.cmdErr)
	if err != nil {
		return err
	}
	return fw.ForwardPorts()
}
开发者ID:gtank,项目名称:kubernetes,代码行数:11,代码来源:portforward.go

示例6: ForwardPort

// ForwardPort opens a tunnel to a kubernetes pod
func (t *Tunnel) ForwardPort() error {
	// Build a url to the portforward endpoint
	// example: http://localhost:8080/api/v1/namespaces/helm/pods/tiller-deploy-9itlq/portforward
	u := t.client.Post().
		Resource("pods").
		Namespace(t.Namespace).
		Name(t.PodName).
		SubResource("portforward").URL()

	dialer, err := remotecommand.NewExecutor(t.config, "POST", u)
	if err != nil {
		return err
	}

	local, err := getAvailablePort()
	if err != nil {
		return fmt.Errorf("could not find an available port: %s", err)
	}
	t.Local = local

	ports := []string{fmt.Sprintf("%d:%d", t.Local, t.Remote)}

	pf, err := portforward.New(dialer, ports, t.stopChan, t.readyChan, t.Out, t.Out)
	if err != nil {
		return err
	}

	errChan := make(chan error)
	go func() {
		errChan <- pf.ForwardPorts()
	}()

	select {
	case err = <-errChan:
		return fmt.Errorf("forwarding ports: %v", err)
	case <-pf.Ready:
		return nil
	}
}
开发者ID:kubernetes,项目名称:helm,代码行数:40,代码来源:tunnel.go

示例7: StartForwardingToPod

// StartForwardingToPod starts forwarding requests to the given pod on the given target port
// If no localPort has been defined on the tunnel, a random available port will be assigned
// The tunnel is started in the background (using a goroutine), and will need to be stopped with Stop()
// It returns an error if it can't start the tunnel.
func (tunnel *Tunnel) StartForwardingToPod(podName string, namespace string, targetPort int, restClient *kclientapi.RESTClient, clientConfig *kclientapi.Config) error {
	req := restClient.Post().
		Resource("pods").
		Namespace(namespace).
		Name(podName).
		SubResource("portforward")

	if tunnel.LocalPort == 0 {
		port, err := getRandomAvailableLocalPort()
		if err != nil {
			return err
		}
		tunnel.LocalPort = port
	}

	port := fmt.Sprintf("%v:%v", tunnel.LocalPort, targetPort)
	ports := []string{port}

	dialer, err := remotecommand.NewExecutor(clientConfig, "POST", req.URL())
	if err != nil {
		return err
	}

	fw, err := portforward.New(dialer, ports, tunnel.stopChan)
	if err != nil {
		return err
	}

	go func(localPort int) {
		err = fw.ForwardPorts()
		if err != nil {
			fmt.Printf("Failed to forward localPort %v to remotePort %v on pod %s: %v\n", localPort, targetPort, podName, err)
		}
	}(tunnel.LocalPort)

	return nil
}
开发者ID:AXA-GROUP-SOLUTIONS,项目名称:openshift-cucumber,代码行数:41,代码来源:tunnel.go


注:本文中的k8s/io/kubernetes/pkg/client/unversioned/portforward.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。