Merge pull request #82010 from verb/range-kubectl

Update kubectl polymorphic logs helper for ephemeral containers
This commit is contained in:
Kubernetes Prow Robot 2019-08-29 09:30:41 -07:00 committed by GitHub
commit bdea3c0181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -89,6 +89,15 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
} }
ret = append(ret, currRet...) ret = append(ret, currRet...)
} }
for _, c := range t.Spec.EphemeralContainers {
currOpts := opts.DeepCopy()
currOpts.Container = c.Name
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
if err != nil {
return nil, err
}
ret = append(ret, currRet...)
}
return ret, nil return ret, nil
} }

View File

@ -70,6 +70,11 @@ func TestLogsForObject(t *testing.T) {
{Name: "c1"}, {Name: "c1"},
{Name: "c2"}, {Name: "c2"},
}, },
EphemeralContainers: []corev1.EphemeralContainer{
{
EphemeralContainerCommon: corev1.EphemeralContainerCommon{Name: "e1"},
},
},
}, },
}, },
opts: &corev1.PodLogOptions{}, opts: &corev1.PodLogOptions{},
@ -80,6 +85,7 @@ func TestLogsForObject(t *testing.T) {
getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}), getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}), getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}), getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "e1"}),
}, },
}, },
{ {
@ -215,18 +221,22 @@ func TestLogsForObject(t *testing.T) {
continue continue
} }
for i := range test.actions { var i int
for i = range test.actions {
if len(fakeClientset.Actions()) < i { if len(fakeClientset.Actions()) < i {
t.Errorf("%s: action %d does not exists in actual actions: %#v", t.Errorf("%s: expected action %d does not exists in actual actions: %#v",
test.name, i, fakeClientset.Actions()) test.name, i, fakeClientset.Actions())
continue continue
} }
got := fakeClientset.Actions()[i] got := fakeClientset.Actions()[i]
want := test.actions[i] want := test.actions[i]
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("%s: unexpected action: %s", test.name, diff.ObjectDiff(got, want)) t.Errorf("%s: unexpected diff for action: %s", test.name, diff.ObjectDiff(got, want))
} }
} }
for i++; i < len(fakeClientset.Actions()); i++ {
t.Errorf("%s: actual action %d does not exist in expected: %v", test.name, i, fakeClientset.Actions()[i])
}
} }
} }