mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
logs: Use resource builder
This commit is contained in:
@@ -38,6 +38,7 @@ type PodInterface interface {
|
||||
Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error)
|
||||
Bind(binding *api.Binding) error
|
||||
UpdateStatus(pod *api.Pod) (*api.Pod, error)
|
||||
GetLogs(name string, opts *api.PodLogOptions) *Request
|
||||
}
|
||||
|
||||
// pods implements PodsNamespacer interface
|
||||
@@ -118,3 +119,8 @@ func (c *pods) UpdateStatus(pod *api.Pod) (result *api.Pod, err error) {
|
||||
err = c.r.Put().Namespace(c.ns).Resource("pods").Name(pod.Name).SubResource("status").Body(pod).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Get constructs a request for getting the logs for a pod
|
||||
func (c *pods) GetLogs(name string, opts *api.PodLogOptions) *Request {
|
||||
return c.r.Get().Namespace(c.ns).Name(name).Resource("pods").SubResource("log").VersionedParams(opts, api.Scheme)
|
||||
}
|
||||
|
||||
@@ -187,3 +187,29 @@ func TestUpdatePod(t *testing.T) {
|
||||
receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestPodGetLogs(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
opts := &api.PodLogOptions{
|
||||
Follow: true,
|
||||
Timestamps: true,
|
||||
}
|
||||
c := &testClient{}
|
||||
|
||||
request := c.Setup(t).Pods(ns).GetLogs("podName", opts)
|
||||
if request.verb != "GET" {
|
||||
t.Fatalf("unexpected verb %q, expected %q", request.verb, "GET")
|
||||
}
|
||||
if request.resource != "pods" {
|
||||
t.Fatalf("unexpected resource %q, expected %q", request.subresource, "pods")
|
||||
}
|
||||
if request.subresource != "log" {
|
||||
t.Fatalf("unexpected subresource %q, expected %q", request.subresource, "log")
|
||||
}
|
||||
expected := map[string]string{"container": "", "follow": "true", "previous": "false", "timestamps": "true"}
|
||||
for gotKey, gotValue := range request.params {
|
||||
if gotValue[0] != expected[gotKey] {
|
||||
t.Fatalf("unexpected key-value %s=%s, expected %s=%s", gotKey, gotValue[0], gotKey, expected[gotKey])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package testclient
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
@@ -99,3 +100,15 @@ func (c *FakePods) UpdateStatus(pod *api.Pod) (*api.Pod, error) {
|
||||
|
||||
return obj.(*api.Pod), err
|
||||
}
|
||||
|
||||
func (c *FakePods) GetLogs(name string, opts *api.PodLogOptions) *client.Request {
|
||||
action := GenericActionImpl{}
|
||||
action.Verb = "get"
|
||||
action.Namespace = c.Namespace
|
||||
action.Resource = "pod"
|
||||
action.Subresource = "logs"
|
||||
action.Value = opts
|
||||
|
||||
_, _ = c.Fake.Invokes(action, &api.Pod{})
|
||||
return &client.Request{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user