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

Use a constant for the pod infra container name #3878

Merged
merged 1 commit into from
Jan 30, 2015
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
32 changes: 16 additions & 16 deletions pkg/kubecfg/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestTemplateEmitsVersionedObjects(t *testing.T) {
}

func TestTemplatePanic(t *testing.T) {
tmpl := `{{and ((index .currentState.info "update-demo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}`
tmpl := `{{and ((index .currentState.info "foo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}`
printer, err := NewTemplatePrinter([]byte(tmpl))
if err != nil {
t.Fatalf("tmpl fail: %v", err)
Expand All @@ -204,18 +204,18 @@ func TestTemplateStrings(t *testing.T) {
}{
"nilInfo": {api.Pod{}, "false"},
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
"containerExists": {
"fooExists": {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{"update-demo": api.ContainerStatus{}},
Info: api.PodInfo{"foo": api.ContainerStatus{}},
},
},
"false",
},
"podExists": {
"barExists": {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{"POD": api.ContainerStatus{}},
Info: api.PodInfo{"bar": api.ContainerStatus{}},
},
},
"false",
Expand All @@ -224,8 +224,8 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{},
"POD": api.ContainerStatus{},
"foo": api.ContainerStatus{},
"bar": api.ContainerStatus{},
},
},
},
Expand All @@ -235,8 +235,8 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{},
"POD": api.ContainerStatus{
"foo": api.ContainerStatus{},
"bar": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
Expand All @@ -252,14 +252,14 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{
"foo": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
},
},
},
"POD": api.ContainerStatus{
"bar": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
Expand All @@ -276,14 +276,14 @@ func TestTemplateStrings(t *testing.T) {
// The point of this test is to verify that the below template works. If you change this
// template, you need to update hack/e2e-suite/update.sh.
tmpl :=
`{{and (exists . "currentState" "info" "update-demo" "state" "running") (exists . "currentState" "info" "POD" "state" "running")}}`
`{{and (exists . "currentState" "info" "foo" "state" "running") (exists . "currentState" "info" "bar" "state" "running")}}`
useThisToDebug := `
a: {{exists . "currentState"}}
b: {{exists . "currentState" "info"}}
c: {{exists . "currentState" "info" "update-demo"}}
d: {{exists . "currentState" "info" "update-demo" "state"}}
e: {{exists . "currentState" "info" "update-demo" "state" "running"}}
f: {{exists . "currentState" "info" "update-demo" "state" "running" "startedAt"}}`
c: {{exists . "currentState" "info" "foo"}}
d: {{exists . "currentState" "info" "foo" "state"}}
e: {{exists . "currentState" "info" "foo" "state" "running"}}
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
_ = useThisToDebug // don't complain about unused var

printer, err := NewTemplatePrinter([]byte(tmpl))
Expand Down
32 changes: 16 additions & 16 deletions pkg/kubectl/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestTemplateEmitsVersionedObjects(t *testing.T) {
}

func TestTemplatePanic(t *testing.T) {
tmpl := `{{and ((index .currentState.info "update-demo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}`
tmpl := `{{and ((index .currentState.info "foo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}`
printer, err := NewTemplatePrinter([]byte(tmpl))
if err != nil {
t.Fatalf("tmpl fail: %v", err)
Expand All @@ -328,18 +328,18 @@ func TestTemplateStrings(t *testing.T) {
}{
"nilInfo": {api.Pod{}, "false"},
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
"containerExists": {
"fooExists": {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{"update-demo": api.ContainerStatus{}},
Info: api.PodInfo{"foo": api.ContainerStatus{}},
},
},
"false",
},
"netExists": {
"barExists": {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{"POD": api.ContainerStatus{}},
Info: api.PodInfo{"bar": api.ContainerStatus{}},
},
},
"false",
Expand All @@ -348,8 +348,8 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{},
"POD": api.ContainerStatus{},
"foo": api.ContainerStatus{},
"bar": api.ContainerStatus{},
},
},
},
Expand All @@ -359,8 +359,8 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{},
"POD": api.ContainerStatus{
"foo": api.ContainerStatus{},
"bar": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
Expand All @@ -376,14 +376,14 @@ func TestTemplateStrings(t *testing.T) {
api.Pod{
Status: api.PodStatus{
Info: api.PodInfo{
"update-demo": api.ContainerStatus{
"foo": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
},
},
},
"POD": api.ContainerStatus{
"bar": api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Time{},
Expand All @@ -400,14 +400,14 @@ func TestTemplateStrings(t *testing.T) {
// The point of this test is to verify that the below template works. If you change this
// template, you need to update hack/e2e-suite/update.sh.
tmpl :=
`{{and (exists . "currentState" "info" "update-demo" "state" "running") (exists . "currentState" "info" "POD" "state" "running")}}`
`{{and (exists . "currentState" "info" "foo" "state" "running") (exists . "currentState" "info" "bar" "state" "running")}}`
useThisToDebug := `
a: {{exists . "currentState"}}
b: {{exists . "currentState" "info"}}
c: {{exists . "currentState" "info" "update-demo"}}
d: {{exists . "currentState" "info" "update-demo" "state"}}
e: {{exists . "currentState" "info" "update-demo" "state" "running"}}
f: {{exists . "currentState" "info" "update-demo" "state" "running" "startedAt"}}`
c: {{exists . "currentState" "info" "foo"}}
d: {{exists . "currentState" "info" "foo" "state"}}
e: {{exists . "currentState" "info" "foo" "state" "running"}}
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
_ = useThisToDebug // don't complain about unused var

p, err := NewTemplatePrinter([]byte(tmpl))
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
docker "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
)

const (
PodInfraContainerName = "POD" // This should match the constant defined in kubelet
PodInfraContainerName = leaky.PodInfraContainerName
)

// DockerInterface is an abstract interface for testability. It abstracts the interface of docker.Client.
Expand Down
25 changes: 25 additions & 0 deletions pkg/kubelet/leaky/leaky.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2015 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package leaky holds bits of kubelet that should be internal but have leaked
// out through bad abstractions. TODO: delete all of this.
package leaky

const (
// This is used in a few places outside of Kubelet, such as indexing
// into the container info.
PodInfraContainerName = "POD"
)
3 changes: 2 additions & 1 deletion pkg/master/pod_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"

Expand Down Expand Up @@ -169,7 +170,7 @@ func (p *PodCache) computePodStatus(pod *api.Pod) (api.PodStatus, error) {
} else {
newStatus.Info = result.Status.Info
newStatus.Phase = getPhase(&pod.Spec, newStatus.Info)
if netContainerInfo, ok := newStatus.Info["POD"]; ok {
if netContainerInfo, ok := newStatus.Info[leaky.PodInfraContainerName]; ok {
if netContainerInfo.PodIP != "" {
newStatus.PodIP = netContainerInfo.PodIP
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/master/pod_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -339,7 +340,7 @@ func TestFillPodStatus(t *testing.T) {
HostIP: "ip of machine",
PodIP: expectedIP,
Info: api.PodInfo{
"POD": {
leaky.PodInfraContainerName: {
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.NewTime(expectedTime),
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestFillPodInfoNoData(t *testing.T) {
Host: "machine",
HostIP: "ip of machine",
Info: api.PodInfo{
"POD": {},
leaky.PodInfraContainerName: {},
},
},
nodes: []api.Node{*makeHealthyNode("machine")},
Expand Down