mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Adds tests for --all-containers=true
Fixes regression in kubectl logs --all-containers=true
This commit is contained in:
parent
6274590518
commit
89dd809ee3
@ -87,7 +87,7 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
|
||||
for _, c := range t.Spec.InitContainers {
|
||||
currOpts := opts.DeepCopy()
|
||||
currOpts.Container = c.Name
|
||||
currRet, err := logsForObjectWithClient(clientset, t, options, timeout, false)
|
||||
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -96,7 +96,7 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
|
||||
for _, c := range t.Spec.Containers {
|
||||
currOpts := opts.DeepCopy()
|
||||
currOpts.Container = c.Name
|
||||
currRet, err := logsForObjectWithClient(clientset, t, options, timeout, false)
|
||||
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -115,7 +115,7 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
|
||||
for _, c := range t.Spec.InitContainers {
|
||||
currOpts := opts.DeepCopy()
|
||||
currOpts.Container = c.Name
|
||||
currRet, err := logsForObjectWithClient(clientset, t, options, timeout, false)
|
||||
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -124,7 +124,7 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt
|
||||
for _, c := range t.Spec.Containers {
|
||||
currOpts := opts.DeepCopy()
|
||||
currOpts.Container = c.Name
|
||||
currRet, err := logsForObjectWithClient(clientset, t, options, timeout, false)
|
||||
currRet, err := logsForObjectWithClient(clientset, t, currOpts, timeout, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -40,11 +40,12 @@ var (
|
||||
|
||||
func TestLogsForObject(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
obj runtime.Object
|
||||
opts *corev1.PodLogOptions
|
||||
pods []runtime.Object
|
||||
actions []testclient.Action
|
||||
name string
|
||||
obj runtime.Object
|
||||
opts *corev1.PodLogOptions
|
||||
allContainers bool
|
||||
pods []runtime.Object
|
||||
actions []testclient.Action
|
||||
}{
|
||||
{
|
||||
name: "pod logs",
|
||||
@ -56,6 +57,84 @@ func TestLogsForObject(t *testing.T) {
|
||||
getLogsAction("test", nil),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pod logs: all containers",
|
||||
obj: &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "hello", Namespace: "test"},
|
||||
Spec: corev1.PodSpec{
|
||||
InitContainers: []corev1.Container{
|
||||
{Name: "initc1"},
|
||||
{Name: "initc2"},
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
{Name: "c1"},
|
||||
{Name: "c2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
opts: &corev1.PodLogOptions{},
|
||||
allContainers: true,
|
||||
pods: []runtime.Object{testPod()},
|
||||
actions: []testclient.Action{
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "initc1"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pods list logs",
|
||||
obj: &corev1.PodList{
|
||||
Items: []corev1.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "hello", Namespace: "test"},
|
||||
Spec: corev1.PodSpec{
|
||||
InitContainers: []corev1.Container{
|
||||
{Name: "initc1"},
|
||||
{Name: "initc2"},
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
{Name: "c1"},
|
||||
{Name: "c2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pods: []runtime.Object{testPod()},
|
||||
actions: []testclient.Action{
|
||||
getLogsAction("test", nil),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pods list logs: all containers",
|
||||
obj: &corev1.PodList{
|
||||
Items: []corev1.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "hello", Namespace: "test"},
|
||||
Spec: corev1.PodSpec{
|
||||
InitContainers: []corev1.Container{
|
||||
{Name: "initc1"},
|
||||
{Name: "initc2"},
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
{Name: "c1"},
|
||||
{Name: "c2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
opts: &corev1.PodLogOptions{},
|
||||
allContainers: true,
|
||||
pods: []runtime.Object{testPod()},
|
||||
actions: []testclient.Action{
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "initc1"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "initc2"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "c1"}),
|
||||
getLogsAction("test", &corev1.PodLogOptions{Container: "c2"}),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "replication controller logs",
|
||||
obj: &corev1.ReplicationController{
|
||||
@ -130,11 +209,12 @@ func TestLogsForObject(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
fakeClientset := fakeexternal.NewSimpleClientset(test.pods...)
|
||||
_, err := logsForObjectWithClient(fakeClientset.CoreV1(), test.obj, test.opts, 20*time.Second, false)
|
||||
_, err := logsForObjectWithClient(fakeClientset.CoreV1(), test.obj, test.opts, 20*time.Second, test.allContainers)
|
||||
if err != nil {
|
||||
t.Errorf("%s: unexpected error: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
for i := range test.actions {
|
||||
if len(fakeClientset.Actions()) < i {
|
||||
t.Errorf("%s: action %d does not exists in actual actions: %#v",
|
||||
@ -160,7 +240,10 @@ func testPod() runtime.Object {
|
||||
Spec: corev1.PodSpec{
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
DNSPolicy: corev1.DNSClusterFirst,
|
||||
Containers: []corev1.Container{{Name: "c1"}},
|
||||
Containers: []corev1.Container{
|
||||
{Name: "c1"},
|
||||
{Name: "c2"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user