mirror of https://github.com/k3s-io/k3s
Portforward API
parent
4f8f6006cf
commit
eb5d59467e
|
@ -18,6 +18,8 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
|
@ -67,6 +69,8 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
|
|||
|
||||
Convert_map_to_unversioned_LabelSelector,
|
||||
Convert_unversioned_LabelSelector_to_map,
|
||||
|
||||
Convert_Slice_string_To_Slice_int32,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -248,3 +252,19 @@ func Convert_unversioned_LabelSelector_to_map(in *metav1.LabelSelector, out *map
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Convert_Slice_string_To_Slice_int32 converts multiple query parameters or
|
||||
// a single query parameter with a comma delimited value to multiple int32.
|
||||
// This is used for port forwarding which needs the ports as int32.
|
||||
func Convert_Slice_string_To_Slice_int32(in *[]string, out *[]int32, s conversion.Scope) error {
|
||||
for _, s := range *in {
|
||||
for _, v := range strings.Split(s, ",") {
|
||||
x, err := strconv.ParseUint(v, 10, 16)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot convert to []int32: %v", err)
|
||||
}
|
||||
*out = append(*out, int32(x))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ func newRESTMapper(externalVersions []schema.GroupVersion) meta.RESTMapper {
|
|||
"PodLogOptions",
|
||||
"PodExecOptions",
|
||||
"PodAttachOptions",
|
||||
"PodPortForwardOptions",
|
||||
"PodProxyOptions",
|
||||
"NodeProxyOptions",
|
||||
"ServiceProxyOptions",
|
||||
|
|
|
@ -125,6 +125,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
|
|||
&PodAttachOptions{},
|
||||
&PodLogOptions{},
|
||||
&PodExecOptions{},
|
||||
&PodPortForwardOptions{},
|
||||
&PodProxyOptions{},
|
||||
&ComponentStatus{},
|
||||
&ComponentStatusList{},
|
||||
|
|
|
@ -117,6 +117,14 @@ func FuzzerFor(t *testing.T, version schema.GroupVersion, src rand.Source) *fuzz
|
|||
j.Stdout = true
|
||||
j.Stderr = true
|
||||
},
|
||||
func(j *api.PodPortForwardOptions, c fuzz.Continue) {
|
||||
if c.RandBool() {
|
||||
j.Ports = make([]int32, c.Intn(10))
|
||||
for i := range j.Ports {
|
||||
j.Ports[i] = c.Int31n(65535)
|
||||
}
|
||||
}
|
||||
},
|
||||
func(s *api.PodSpec, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(s)
|
||||
// has a default value
|
||||
|
|
|
@ -2953,6 +2953,15 @@ type PodExecOptions struct {
|
|||
Command []string
|
||||
}
|
||||
|
||||
// PodPortForwardOptions is the query options to a Pod's port forward call
|
||||
type PodPortForwardOptions struct {
|
||||
metav1.TypeMeta
|
||||
|
||||
// The list of ports to forward
|
||||
// +optional
|
||||
Ports []int32
|
||||
}
|
||||
|
||||
// PodProxyOptions is the query options to a Pod's proxy call
|
||||
type PodProxyOptions struct {
|
||||
metav1.TypeMeta
|
||||
|
|
|
@ -81,6 +81,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
|
|||
&PodAttachOptions{},
|
||||
&PodLogOptions{},
|
||||
&PodExecOptions{},
|
||||
&PodPortForwardOptions{},
|
||||
&PodProxyOptions{},
|
||||
&ComponentStatus{},
|
||||
&ComponentStatusList{},
|
||||
|
|
|
@ -3423,6 +3423,21 @@ type PodExecOptions struct {
|
|||
Command []string `json:"command" protobuf:"bytes,6,rep,name=command"`
|
||||
}
|
||||
|
||||
// PodPortForwardOptions is the query options to a Pod's port forward call
|
||||
// when using WebSockets.
|
||||
// The `port` query parameter must specify the port or
|
||||
// ports (comma separated) to forward over.
|
||||
// Port forwarding over SPDY does not use these options. It requires the port
|
||||
// to be passed in the `port` header as part of request.
|
||||
type PodPortForwardOptions struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
||||
// List of ports to forward
|
||||
// Required when using WebSockets
|
||||
// +optional
|
||||
Ports []int32 `json:"ports,omitempty" protobuf:"varint,1,rep,name=ports"`
|
||||
}
|
||||
|
||||
// PodProxyOptions is the query options to a Pod's proxy call.
|
||||
type PodProxyOptions struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
Loading…
Reference in New Issue