Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare containers by name, not by pointer equality. #2817

Merged
merged 1 commit into from
Dec 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (kl *Kubelet) runHandler(podFullName, uuid string, container *api.Container
func fieldPath(pod *api.BoundPod, container *api.Container) (string, error) {
for i := range pod.Spec.Containers {
here := &pod.Spec.Containers[i]
if here == container {
if here.Name == container.Name {
return fmt.Sprintf("spec.containers[%d]", i), nil
}
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,42 @@ func TestCheckHostPortConflicts(t *testing.T) {
}
}

func TestFieldPath(t *testing.T) {
pod := &api.BoundPod{Spec: api.PodSpec{Containers: []api.Container{
{Name: "foo"},
{Name: "bar"},
{Name: "baz"},
}}}
table := map[string]struct {
pod *api.BoundPod
container *api.Container
path string
success bool
}{
"basic": {pod, &api.Container{Name: "foo"}, "spec.containers[0]", true},
"basic2": {pod, &api.Container{Name: "baz"}, "spec.containers[2]", true},
"basicSamePointer": {pod, &pod.Spec.Containers[0], "spec.containers[0]", true},
"missing": {pod, &api.Container{Name: "qux"}, "", false},
}

for name, item := range table {
res, err := fieldPath(item.pod, item.container)
if item.success == false {
if err == nil {
t.Errorf("%v: unexpected non-error", name)
}
continue
}
if err != nil {
t.Errorf("%v: unexpected error: %v", name, err)
continue
}
if e, a := item.path, res; e != a {
t.Errorf("%v: wanted %v, got %v", name, e, a)
}
}
}

type mockCadvisorClient struct {
mock.Mock
}
Expand Down