Skip to content

Commit bdea3c0

Browse files
authored
Merge pull request kubernetes#82010 from verb/range-kubectl
Update kubectl polymorphic logs helper for ephemeral containers
2 parents cd9519f + 66d0778 commit bdea3c0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
8989
}
9090
ret = append(ret, currRet...)
9191
}
92+
for _, c := range t.Spec.EphemeralContainers {
93+
currOpts := opts.DeepCopy()
94+
currOpts.Container = c.Name
95+
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
96+
if err != nil {
97+
return nil, err
98+
}
99+
ret = append(ret, currRet...)
100+
}
92101

93102
return ret, nil
94103
}

staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func TestLogsForObject(t *testing.T) {
7070
{Name: "c1"},
7171
{Name: "c2"},
7272
},
73+
EphemeralContainers: []corev1.EphemeralContainer{
74+
{
75+
EphemeralContainerCommon: corev1.EphemeralContainerCommon{Name: "e1"},
76+
},
77+
},
7378
},
7479
},
7580
opts: &corev1.PodLogOptions{},
@@ -80,6 +85,7 @@ func TestLogsForObject(t *testing.T) {
8085
getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}),
8186
getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}),
8287
getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}),
88+
getLogsAction("test", &corev1.PodLogOptions{Container: "e1"}),
8389
},
8490
},
8591
{
@@ -215,18 +221,22 @@ func TestLogsForObject(t *testing.T) {
215221
continue
216222
}
217223

218-
for i := range test.actions {
224+
var i int
225+
for i = range test.actions {
219226
if len(fakeClientset.Actions()) < i {
220-
t.Errorf("%s: action %d does not exists in actual actions: %#v",
227+
t.Errorf("%s: expected action %d does not exists in actual actions: %#v",
221228
test.name, i, fakeClientset.Actions())
222229
continue
223230
}
224231
got := fakeClientset.Actions()[i]
225232
want := test.actions[i]
226233
if !reflect.DeepEqual(got, want) {
227-
t.Errorf("%s: unexpected action: %s", test.name, diff.ObjectDiff(got, want))
234+
t.Errorf("%s: unexpected diff for action: %s", test.name, diff.ObjectDiff(got, want))
228235
}
229236
}
237+
for i++; i < len(fakeClientset.Actions()); i++ {
238+
t.Errorf("%s: actual action %d does not exist in expected: %v", test.name, i, fakeClientset.Actions()[i])
239+
}
230240
}
231241
}
232242

0 commit comments

Comments
 (0)