client-go: keep fake pod log action compatible

Kubernetes-commit: 60c697419d2695108a054d704334778e3d945a6c
This commit is contained in:
dhruv7539
2026-02-23 10:35:50 -08:00
committed by Kubernetes Publisher
parent e8eab37058
commit f1d9ba91c7
2 changed files with 11 additions and 31 deletions

View File

@@ -56,30 +56,13 @@ func (c *fakePods) GetBinding(name string) (result *v1.Binding, err error) {
return obj.(*v1.Binding), err
}
// getPodLogsActionImpl carries the standard get action shape (including pod name)
// along with pod log options so reactors can inspect both.
type getPodLogsActionImpl struct {
core.GetActionImpl
Value interface{}
}
func (a getPodLogsActionImpl) GetValue() interface{} {
return a.Value
}
func (a getPodLogsActionImpl) DeepCopy() core.Action {
return getPodLogsActionImpl{
GetActionImpl: a.GetActionImpl.DeepCopy().(core.GetActionImpl),
// Keep existing fake GenericAction semantics for value copying.
Value: a.Value,
}
}
func (c *fakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
action := getPodLogsActionImpl{
GetActionImpl: core.NewGetSubresourceAction(c.Resource(), c.Namespace(), "log", name),
Value: opts,
}
action := core.GenericActionImpl{}
action.Verb = "get"
action.Namespace = c.Namespace()
action.Resource = c.Resource()
action.Subresource = "log"
action.Value = opts
obj, err := c.Fake.Invokes(action, &runtime.Unknown{Raw: []byte("fake logs")})
logs := []byte("fake logs")

View File

@@ -54,13 +54,6 @@ func TestFakePodsGetLogsReactorError(t *testing.T) {
fp := newFakePods(&FakeCoreV1{Fake: fake}, "default")
expectedErr := errors.New("reactor get logs failure")
fake.PrependReactor("get", "pods/log", func(action cgtesting.Action) (bool, runtime.Object, error) {
getAction, ok := action.(cgtesting.GetAction)
if !ok {
t.Fatalf("expected GetAction, got %T", action)
}
if getAction.GetName() != "foo" {
t.Fatalf("expected pod name foo, got %q", getAction.GetName())
}
genericAction, ok := action.(cgtesting.GenericAction)
if !ok {
t.Fatalf("expected GenericAction, got %T", action)
@@ -95,7 +88,11 @@ func TestFakePodsGetLogsReactorResponse(t *testing.T) {
if err != nil {
t.Fatalf("Stream pod logs: %v", err)
}
defer body.Close()
defer func() {
if err := body.Close(); err != nil {
t.Fatalf("Close response body: %v", err)
}
}()
logs, err := io.ReadAll(body)
if err != nil {