From 8c1e3c3fbd23cb01300c7e571b8d40ac81c0cdca Mon Sep 17 00:00:00 2001 From: Nikhita Raghunath Date: Thu, 18 Jun 2020 16:28:23 +0530 Subject: [PATCH] client-go: add ProxyGet expansion method for pods Currently, the proxy subresource is not supported for pods in client-go. Today, invoking this requires using the REST client directly. To make using the proxy resource easier, this commit adds a ProxyGet method for pods in pod_expansion.go similar to the ProxyGet method for services in service_expansion.go. Ref: https://github.com/kubernetes/kubernetes/blob/d8febccacfc9d51a017be9531247689e0e36df04/staging/src/k8s.io/client-go/kubernetes/typed/core/v1/service_expansion.go Kubernetes-commit: 72ab11193a419f0e0e66e86c4e6be9991c3682f2 --- .../typed/core/v1/fake/fake_pod_expansion.go | 4 ++++ kubernetes/typed/core/v1/pod_expansion.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/kubernetes/typed/core/v1/fake/fake_pod_expansion.go b/kubernetes/typed/core/v1/fake/fake_pod_expansion.go index d3fd8f59..d9a718a5 100644 --- a/kubernetes/typed/core/v1/fake/fake_pod_expansion.go +++ b/kubernetes/typed/core/v1/fake/fake_pod_expansion.go @@ -89,3 +89,7 @@ func (c *FakePods) Evict(ctx context.Context, eviction *policy.Eviction) error { _, err := c.Fake.Invokes(action, eviction) return err } + +func (c *FakePods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper { + return c.Fake.InvokesProxy(core.NewProxyGetAction(podsResource, c.ns, scheme, name, port, path, params)) +} diff --git a/kubernetes/typed/core/v1/pod_expansion.go b/kubernetes/typed/core/v1/pod_expansion.go index 8710a2c0..759fe0ff 100644 --- a/kubernetes/typed/core/v1/pod_expansion.go +++ b/kubernetes/typed/core/v1/pod_expansion.go @@ -22,6 +22,7 @@ import ( v1 "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/kubernetes/scheme" restclient "k8s.io/client-go/rest" ) @@ -31,6 +32,7 @@ type PodExpansion interface { Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error Evict(ctx context.Context, eviction *policy.Eviction) error GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request + ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper } // Bind applies the provided binding to the named pod in the current namespace (binding.Namespace is ignored). @@ -46,3 +48,17 @@ func (c *pods) Evict(ctx context.Context, eviction *policy.Eviction) error { func (c *pods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request { return c.client.Get().Namespace(c.ns).Name(name).Resource("pods").SubResource("log").VersionedParams(opts, scheme.ParameterCodec) } + +// ProxyGet returns a response of the pod by calling it through the proxy. +func (c *pods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper { + request := c.client.Get(). + Namespace(c.ns). + Resource("pods"). + SubResource("proxy"). + Name(net.JoinSchemeNamePort(scheme, name, port)). + Suffix(path) + for k, v := range params { + request = request.Param(k, v) + } + return request +}