Skip to content

Commit

Permalink
Merge pull request kubernetes#3878 from thockin/infra_name
Browse files Browse the repository at this point in the history
Use a constant for the pod infra container name
  • Loading branch information
bgrant0607 committed Jan 30, 2015
2 parents 2e9cb5e + 70ab406 commit 207d0f5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 36 deletions.
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 @@ -193,7 +194,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 @@ -370,7 +371,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 @@ -405,7 +406,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

0 comments on commit 207d0f5

Please sign in to comment.