Skip to content

Commit 3d0848c

Browse files
authored
Merge pull request kubernetes#92251 from nikhita/client-go-pod-proxy
client-go: add ProxyGet expansion method for pods
2 parents 5968bc4 + 72ab111 commit 3d0848c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

staging/src/k8s.io/client-go/kubernetes/typed/core/v1/fake/fake_pod_expansion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ func (c *FakePods) Evict(ctx context.Context, eviction *policy.Eviction) error {
8989
_, err := c.Fake.Invokes(action, eviction)
9090
return err
9191
}
92+
93+
func (c *FakePods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
94+
return c.Fake.InvokesProxy(core.NewProxyGetAction(podsResource, c.ns, scheme, name, port, path, params))
95+
}

staging/src/k8s.io/client-go/kubernetes/typed/core/v1/pod_expansion.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
v1 "k8s.io/api/core/v1"
2323
policy "k8s.io/api/policy/v1beta1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/util/net"
2526
"k8s.io/client-go/kubernetes/scheme"
2627
restclient "k8s.io/client-go/rest"
2728
)
@@ -31,6 +32,7 @@ type PodExpansion interface {
3132
Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error
3233
Evict(ctx context.Context, eviction *policy.Eviction) error
3334
GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request
35+
ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper
3436
}
3537

3638
// 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 {
4648
func (c *pods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
4749
return c.client.Get().Namespace(c.ns).Name(name).Resource("pods").SubResource("log").VersionedParams(opts, scheme.ParameterCodec)
4850
}
51+
52+
// ProxyGet returns a response of the pod by calling it through the proxy.
53+
func (c *pods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
54+
request := c.client.Get().
55+
Namespace(c.ns).
56+
Resource("pods").
57+
SubResource("proxy").
58+
Name(net.JoinSchemeNamePort(scheme, name, port)).
59+
Suffix(path)
60+
for k, v := range params {
61+
request = request.Param(k, v)
62+
}
63+
return request
64+
}

0 commit comments

Comments
 (0)