Update kubectl polymorphic logs helper for ephemeral containers

This also updates the test to check there were actual actions that
weren't expected.
This commit is contained in:
Lee Verberne 2019-08-27 09:35:16 +00:00
parent 1810bc8d82
commit 66d0778828
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...)
}
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
}

View File

@ -70,6 +70,11 @@ func TestLogsForObject(t *testing.T) {
{Name: "c1"},
{Name: "c2"},
},
EphemeralContainers: []corev1.EphemeralContainer{
{
EphemeralContainerCommon: corev1.EphemeralContainerCommon{Name: "e1"},
},
},
},
},
opts: &corev1.PodLogOptions{},
@ -80,6 +85,7 @@ func TestLogsForObject(t *testing.T) {
getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}),
getLogsAction("test", &corev1.PodLogOptions{Container: "e1"}),
},
},
{
@ -215,18 +221,22 @@ func TestLogsForObject(t *testing.T) {
continue
}
for i := range test.actions {
var i int
for i = range test.actions {
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())
continue
}
got := fakeClientset.Actions()[i]
want := test.actions[i]
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])
}
}
}