mirror of https://github.com/k3s-io/k3s
Merge pull request #3878 from thockin/infra_name
Use a constant for the pod infra container namepull/6/head
commit
207d0f5d40
|
@ -181,7 +181,7 @@ func TestTemplateEmitsVersionedObjects(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplatePanic(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))
|
printer, err := NewTemplatePrinter([]byte(tmpl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("tmpl fail: %v", err)
|
t.Fatalf("tmpl fail: %v", err)
|
||||||
|
@ -204,18 +204,18 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
"nilInfo": {api.Pod{}, "false"},
|
"nilInfo": {api.Pod{}, "false"},
|
||||||
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
|
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
|
||||||
"containerExists": {
|
"fooExists": {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{"update-demo": api.ContainerStatus{}},
|
Info: api.PodInfo{"foo": api.ContainerStatus{}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"false",
|
"false",
|
||||||
},
|
},
|
||||||
"podExists": {
|
"barExists": {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{"POD": api.ContainerStatus{}},
|
Info: api.PodInfo{"bar": api.ContainerStatus{}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"false",
|
"false",
|
||||||
|
@ -224,8 +224,8 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{},
|
"foo": api.ContainerStatus{},
|
||||||
"POD": api.ContainerStatus{},
|
"bar": api.ContainerStatus{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -235,8 +235,8 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{},
|
"foo": api.ContainerStatus{},
|
||||||
"POD": api.ContainerStatus{
|
"bar": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
|
@ -252,14 +252,14 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{
|
"foo": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"POD": api.ContainerStatus{
|
"bar": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
|
@ -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
|
// 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.
|
// template, you need to update hack/e2e-suite/update.sh.
|
||||||
tmpl :=
|
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 := `
|
useThisToDebug := `
|
||||||
a: {{exists . "currentState"}}
|
a: {{exists . "currentState"}}
|
||||||
b: {{exists . "currentState" "info"}}
|
b: {{exists . "currentState" "info"}}
|
||||||
c: {{exists . "currentState" "info" "update-demo"}}
|
c: {{exists . "currentState" "info" "foo"}}
|
||||||
d: {{exists . "currentState" "info" "update-demo" "state"}}
|
d: {{exists . "currentState" "info" "foo" "state"}}
|
||||||
e: {{exists . "currentState" "info" "update-demo" "state" "running"}}
|
e: {{exists . "currentState" "info" "foo" "state" "running"}}
|
||||||
f: {{exists . "currentState" "info" "update-demo" "state" "running" "startedAt"}}`
|
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
|
||||||
_ = useThisToDebug // don't complain about unused var
|
_ = useThisToDebug // don't complain about unused var
|
||||||
|
|
||||||
printer, err := NewTemplatePrinter([]byte(tmpl))
|
printer, err := NewTemplatePrinter([]byte(tmpl))
|
||||||
|
|
|
@ -305,7 +305,7 @@ func TestTemplateEmitsVersionedObjects(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplatePanic(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))
|
printer, err := NewTemplatePrinter([]byte(tmpl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("tmpl fail: %v", err)
|
t.Fatalf("tmpl fail: %v", err)
|
||||||
|
@ -328,18 +328,18 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
"nilInfo": {api.Pod{}, "false"},
|
"nilInfo": {api.Pod{}, "false"},
|
||||||
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
|
"emptyInfo": {api.Pod{Status: api.PodStatus{Info: api.PodInfo{}}}, "false"},
|
||||||
"containerExists": {
|
"fooExists": {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{"update-demo": api.ContainerStatus{}},
|
Info: api.PodInfo{"foo": api.ContainerStatus{}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"false",
|
"false",
|
||||||
},
|
},
|
||||||
"netExists": {
|
"barExists": {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{"POD": api.ContainerStatus{}},
|
Info: api.PodInfo{"bar": api.ContainerStatus{}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"false",
|
"false",
|
||||||
|
@ -348,8 +348,8 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{},
|
"foo": api.ContainerStatus{},
|
||||||
"POD": api.ContainerStatus{},
|
"bar": api.ContainerStatus{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -359,8 +359,8 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{},
|
"foo": api.ContainerStatus{},
|
||||||
"POD": api.ContainerStatus{
|
"bar": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
|
@ -376,14 +376,14 @@ func TestTemplateStrings(t *testing.T) {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"update-demo": api.ContainerStatus{
|
"foo": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"POD": api.ContainerStatus{
|
"bar": api.ContainerStatus{
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.Time{},
|
StartedAt: util.Time{},
|
||||||
|
@ -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
|
// 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.
|
// template, you need to update hack/e2e-suite/update.sh.
|
||||||
tmpl :=
|
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 := `
|
useThisToDebug := `
|
||||||
a: {{exists . "currentState"}}
|
a: {{exists . "currentState"}}
|
||||||
b: {{exists . "currentState" "info"}}
|
b: {{exists . "currentState" "info"}}
|
||||||
c: {{exists . "currentState" "info" "update-demo"}}
|
c: {{exists . "currentState" "info" "foo"}}
|
||||||
d: {{exists . "currentState" "info" "update-demo" "state"}}
|
d: {{exists . "currentState" "info" "foo" "state"}}
|
||||||
e: {{exists . "currentState" "info" "update-demo" "state" "running"}}
|
e: {{exists . "currentState" "info" "foo" "state" "running"}}
|
||||||
f: {{exists . "currentState" "info" "update-demo" "state" "running" "startedAt"}}`
|
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
|
||||||
_ = useThisToDebug // don't complain about unused var
|
_ = useThisToDebug // don't complain about unused var
|
||||||
|
|
||||||
p, err := NewTemplatePrinter([]byte(tmpl))
|
p, err := NewTemplatePrinter([]byte(tmpl))
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
|
@ -38,7 +39,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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.
|
// DockerInterface is an abstract interface for testability. It abstracts the interface of docker.Client.
|
||||||
|
|
|
@ -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"
|
||||||
|
)
|
|
@ -21,6 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
||||||
|
|
||||||
|
@ -193,7 +194,7 @@ func (p *PodCache) computePodStatus(pod *api.Pod) (api.PodStatus, error) {
|
||||||
} else {
|
} else {
|
||||||
newStatus.Info = result.Status.Info
|
newStatus.Info = result.Status.Info
|
||||||
newStatus.Phase = getPhase(&pod.Spec, newStatus.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 != "" {
|
if netContainerInfo.PodIP != "" {
|
||||||
newStatus.PodIP = netContainerInfo.PodIP
|
newStatus.PodIP = netContainerInfo.PodIP
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"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/registry/registrytest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -370,7 +371,7 @@ func TestFillPodStatus(t *testing.T) {
|
||||||
HostIP: "ip of machine",
|
HostIP: "ip of machine",
|
||||||
PodIP: expectedIP,
|
PodIP: expectedIP,
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"POD": {
|
leaky.PodInfraContainerName: {
|
||||||
State: api.ContainerState{
|
State: api.ContainerState{
|
||||||
Running: &api.ContainerStateRunning{
|
Running: &api.ContainerStateRunning{
|
||||||
StartedAt: util.NewTime(expectedTime),
|
StartedAt: util.NewTime(expectedTime),
|
||||||
|
@ -405,7 +406,7 @@ func TestFillPodInfoNoData(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
HostIP: "ip of machine",
|
HostIP: "ip of machine",
|
||||||
Info: api.PodInfo{
|
Info: api.PodInfo{
|
||||||
"POD": {},
|
leaky.PodInfraContainerName: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
nodes: []api.Node{*makeHealthyNode("machine")},
|
nodes: []api.Node{*makeHealthyNode("machine")},
|
||||||
|
|
Loading…
Reference in New Issue