當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。