コード例 #1
0
ファイル: factory.go プロジェクト: rimey/kubernetes
func getSchemaAndValidate(c *client.RESTClient, data []byte, group, version string) error {
	schemaData, err := c.Get().
		AbsPath("/swaggerapi", group, version).
		Do().
		Raw()
	if err != nil {
		return err
	}
	schema, err := validation.NewSwaggerSchemaFromBytes(schemaData)
	if err != nil {
		return err
	}
	return schema.ValidateBytes(data)
}
コード例 #2
0
// 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
}
コード例 #3
0
ファイル: factory.go プロジェクト: arilivigni/origin
// OriginSwaggerSchema returns a swagger API doc for an Origin schema under the /oapi prefix.
func (f *Factory) OriginSwaggerSchema(client *kclient.RESTClient, version unversioned.GroupVersion) (*swagger.ApiDeclaration, error) {
	if version.IsEmpty() {
		return nil, fmt.Errorf("groupVersion cannot be empty")
	}
	body, err := client.Get().AbsPath("/").Suffix("swaggerapi", "oapi", version.Version).Do().Raw()
	if err != nil {
		return nil, err
	}
	var schema swagger.ApiDeclaration
	err = json.Unmarshal(body, &schema)
	if err != nil {
		return nil, fmt.Errorf("got '%s': %v", string(body), err)
	}
	return &schema, nil
}