Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c001deed
Commit
c001deed
authored
Mar 18, 2017
by
andrewsykim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch hostIP at runtime since status manager didn't update it yet
parent
824d0b11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
64 additions
and
38 deletions
+64
-38
helpers.go
pkg/kubelet/container/helpers.go
+5
-2
fake_runtime_helper.go
pkg/kubelet/container/testing/fake_runtime_helper.go
+7
-1
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+14
-7
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+6
-6
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+4
-6
kuberuntime_container.go
pkg/kubelet/kuberuntime/kuberuntime_container.go
+4
-4
kuberuntime_manager.go
pkg/kubelet/kuberuntime/kuberuntime_manager.go
+8
-2
kuberuntime_manager_test.go
pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
+1
-1
rkt.go
pkg/kubelet/rkt/rkt.go
+13
-7
rkt_test.go
pkg/kubelet/rkt/rkt_test.go
+1
-1
downward_api.go
test/e2e/common/downward_api.go
+1
-1
No files found.
pkg/kubelet/container/helpers.go
View file @
c001deed
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"fmt"
"fmt"
"hash/adler32"
"hash/adler32"
"hash/fnv"
"hash/fnv"
"net"
"strings"
"strings"
"time"
"time"
...
@@ -46,9 +47,9 @@ type HandlerRunner interface {
...
@@ -46,9 +47,9 @@ type HandlerRunner interface {
}
}
// RuntimeHelper wraps kubelet to make container runtime
// RuntimeHelper wraps kubelet to make container runtime
// able to get necessary informations like the RunContainerOptions, DNS settings.
// able to get necessary informations like the RunContainerOptions, DNS settings
, Host IP
.
type
RuntimeHelper
interface
{
type
RuntimeHelper
interface
{
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
string
)
(
contOpts
*
RunContainerOptions
,
useClusterFirstPolicy
bool
,
err
error
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
,
hostIP
string
)
(
contOpts
*
RunContainerOptions
,
useClusterFirstPolicy
bool
,
err
error
)
GetClusterDNS
(
pod
*
v1
.
Pod
)
(
dnsServers
[]
string
,
dnsSearches
[]
string
,
useClusterFirstPolicy
bool
,
err
error
)
GetClusterDNS
(
pod
*
v1
.
Pod
)
(
dnsServers
[]
string
,
dnsSearches
[]
string
,
useClusterFirstPolicy
bool
,
err
error
)
// GetPodCgroupParent returns the the CgroupName identifer, and its literal cgroupfs form on the host
// GetPodCgroupParent returns the the CgroupName identifer, and its literal cgroupfs form on the host
// of a pod.
// of a pod.
...
@@ -59,6 +60,8 @@ type RuntimeHelper interface {
...
@@ -59,6 +60,8 @@ type RuntimeHelper interface {
// supplemental groups for the Pod. These extra supplemental groups come
// supplemental groups for the Pod. These extra supplemental groups come
// from annotations on persistent volumes that the pod depends on.
// from annotations on persistent volumes that the pod depends on.
GetExtraSupplementalGroupsForPod
(
pod
*
v1
.
Pod
)
[]
int64
GetExtraSupplementalGroupsForPod
(
pod
*
v1
.
Pod
)
[]
int64
GetHostIP
()
(
net
.
IP
,
error
)
}
}
// ShouldContainerBeRestarted checks whether a container needs to be restarted.
// ShouldContainerBeRestarted checks whether a container needs to be restarted.
...
...
pkg/kubelet/container/testing/fake_runtime_helper.go
View file @
c001deed
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
testing
package
testing
import
(
import
(
"net"
kubetypes
"k8s.io/apimachinery/pkg/types"
kubetypes
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
...
@@ -32,7 +34,7 @@ type FakeRuntimeHelper struct {
...
@@ -32,7 +34,7 @@ type FakeRuntimeHelper struct {
Err
error
Err
error
}
}
func
(
f
*
FakeRuntimeHelper
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
string
)
(
*
kubecontainer
.
RunContainerOptions
,
bool
,
error
)
{
func
(
f
*
FakeRuntimeHelper
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
,
hostIP
string
)
(
*
kubecontainer
.
RunContainerOptions
,
bool
,
error
)
{
var
opts
kubecontainer
.
RunContainerOptions
var
opts
kubecontainer
.
RunContainerOptions
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
opts
.
PodContainerDir
=
f
.
PodContainerDir
opts
.
PodContainerDir
=
f
.
PodContainerDir
...
@@ -60,3 +62,7 @@ func (f *FakeRuntimeHelper) GetPodDir(podUID kubetypes.UID) string {
...
@@ -60,3 +62,7 @@ func (f *FakeRuntimeHelper) GetPodDir(podUID kubetypes.UID) string {
func
(
f
*
FakeRuntimeHelper
)
GetExtraSupplementalGroupsForPod
(
pod
*
v1
.
Pod
)
[]
int64
{
func
(
f
*
FakeRuntimeHelper
)
GetExtraSupplementalGroupsForPod
(
pod
*
v1
.
Pod
)
[]
int64
{
return
nil
return
nil
}
}
func
(
f
*
FakeRuntimeHelper
)
GetHostIP
()
(
net
.
IP
,
error
)
{
return
[]
byte
{},
nil
}
pkg/kubelet/dockertools/docker_manager.go
View file @
c001deed
...
@@ -1743,7 +1743,7 @@ func (dm *DockerManager) applyOOMScoreAdj(pod *v1.Pod, container *v1.Container,
...
@@ -1743,7 +1743,7 @@ func (dm *DockerManager) applyOOMScoreAdj(pod *v1.Pod, container *v1.Container,
// Run a single container from a pod. Returns the docker container ID
// Run a single container from a pod. Returns the docker container ID
// If do not need to pass labels, just pass nil.
// If do not need to pass labels, just pass nil.
func
(
dm
*
DockerManager
)
runContainerInPod
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
netMode
,
ipcMode
,
pidMode
,
podIP
,
imageRef
string
,
restartCount
int
)
(
kubecontainer
.
ContainerID
,
error
)
{
func
(
dm
*
DockerManager
)
runContainerInPod
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
netMode
,
ipcMode
,
pidMode
,
podIP
,
hostIP
,
imageRef
string
,
restartCount
int
)
(
kubecontainer
.
ContainerID
,
error
)
{
start
:=
time
.
Now
()
start
:=
time
.
Now
()
defer
func
()
{
defer
func
()
{
metrics
.
ContainerManagerLatency
.
WithLabelValues
(
"runContainerInPod"
)
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
metrics
.
ContainerManagerLatency
.
WithLabelValues
(
"runContainerInPod"
)
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
...
@@ -1756,7 +1756,7 @@ func (dm *DockerManager) runContainerInPod(pod *v1.Pod, container *v1.Container,
...
@@ -1756,7 +1756,7 @@ func (dm *DockerManager) runContainerInPod(pod *v1.Pod, container *v1.Container,
glog
.
V
(
5
)
.
Infof
(
"Generating ref for container %s: %#v"
,
container
.
Name
,
ref
)
glog
.
V
(
5
)
.
Infof
(
"Generating ref for container %s: %#v"
,
container
.
Name
,
ref
)
}
}
opts
,
useClusterFirstPolicy
,
err
:=
dm
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
opts
,
useClusterFirstPolicy
,
err
:=
dm
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
,
hostIP
)
if
err
!=
nil
{
if
err
!=
nil
{
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"GenerateRunContainerOptions: %v"
,
err
)
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"GenerateRunContainerOptions: %v"
,
err
)
}
}
...
@@ -1993,7 +1993,8 @@ func (dm *DockerManager) createPodInfraContainer(pod *v1.Pod) (kubecontainer.Doc
...
@@ -1993,7 +1993,8 @@ func (dm *DockerManager) createPodInfraContainer(pod *v1.Pod) (kubecontainer.Doc
}
}
// Currently we don't care about restart count of infra container, just set it to 0.
// Currently we don't care about restart count of infra container, just set it to 0.
id
,
err
:=
dm
.
runContainerInPod
(
pod
,
container
,
netNamespace
,
getIPCMode
(
pod
),
getPidMode
(
pod
),
""
,
imageRef
,
0
)
// We also don't care about podIP and hostIP since their only passed in during runtime because of downward API
id
,
err
:=
dm
.
runContainerInPod
(
pod
,
container
,
netNamespace
,
getIPCMode
(
pod
),
getPidMode
(
pod
),
""
,
""
,
imageRef
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
kubecontainer
.
ErrRunContainer
,
err
.
Error
()
return
""
,
kubecontainer
.
ErrRunContainer
,
err
.
Error
()
}
}
...
@@ -2269,6 +2270,12 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
...
@@ -2269,6 +2270,12 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
podIP
=
podStatus
.
IP
podIP
=
podStatus
.
IP
}
}
rawHostIP
,
err
:=
dm
.
runtimeHelper
.
GetHostIP
()
hostIP
:=
rawHostIP
.
String
()
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get Host IP for pod: %s; %v"
,
format
.
Pod
(
pod
),
err
)
}
// If we should create infra container then we do it first.
// If we should create infra container then we do it first.
podInfraContainerID
:=
containerChanges
.
InfraContainerId
podInfraContainerID
:=
containerChanges
.
InfraContainerId
if
containerChanges
.
StartInfraContainer
&&
(
len
(
containerChanges
.
ContainersToStart
)
>
0
)
{
if
containerChanges
.
StartInfraContainer
&&
(
len
(
containerChanges
.
ContainersToStart
)
>
0
)
{
...
@@ -2369,7 +2376,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
...
@@ -2369,7 +2376,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
}
}
glog
.
V
(
4
)
.
Infof
(
"Creating init container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
glog
.
V
(
4
)
.
Infof
(
"Creating init container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
if
err
,
msg
:=
dm
.
tryContainerStart
(
container
,
pod
,
podStatus
,
pullSecrets
,
namespaceMode
,
pidMode
,
podIP
);
err
!=
nil
{
if
err
,
msg
:=
dm
.
tryContainerStart
(
container
,
pod
,
podStatus
,
pullSecrets
,
namespaceMode
,
pidMode
,
podIP
,
hostIP
);
err
!=
nil
{
startContainerResult
.
Fail
(
err
,
msg
)
startContainerResult
.
Fail
(
err
,
msg
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
return
return
...
@@ -2407,7 +2414,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
...
@@ -2407,7 +2414,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
}
}
glog
.
V
(
4
)
.
Infof
(
"Creating container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
glog
.
V
(
4
)
.
Infof
(
"Creating container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
if
err
,
msg
:=
dm
.
tryContainerStart
(
container
,
pod
,
podStatus
,
pullSecrets
,
namespaceMode
,
pidMode
,
podIP
);
err
!=
nil
{
if
err
,
msg
:=
dm
.
tryContainerStart
(
container
,
pod
,
podStatus
,
pullSecrets
,
namespaceMode
,
pidMode
,
podIP
,
hostIP
);
err
!=
nil
{
startContainerResult
.
Fail
(
err
,
msg
)
startContainerResult
.
Fail
(
err
,
msg
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
continue
continue
...
@@ -2418,7 +2425,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
...
@@ -2418,7 +2425,7 @@ func (dm *DockerManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecon
// tryContainerStart attempts to pull and start the container, returning an error and a reason string if the start
// tryContainerStart attempts to pull and start the container, returning an error and a reason string if the start
// was not successful.
// was not successful.
func
(
dm
*
DockerManager
)
tryContainerStart
(
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
podStatus
*
kubecontainer
.
PodStatus
,
pullSecrets
[]
v1
.
Secret
,
namespaceMode
,
pidMode
,
podIP
string
)
(
err
error
,
reason
string
)
{
func
(
dm
*
DockerManager
)
tryContainerStart
(
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
podStatus
*
kubecontainer
.
PodStatus
,
pullSecrets
[]
v1
.
Secret
,
namespaceMode
,
pidMode
,
podIP
,
hostIP
string
)
(
err
error
,
reason
string
)
{
imageRef
,
msg
,
err
:=
dm
.
imagePuller
.
EnsureImageExists
(
pod
,
container
,
pullSecrets
)
imageRef
,
msg
,
err
:=
dm
.
imagePuller
.
EnsureImageExists
(
pod
,
container
,
pullSecrets
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
,
msg
return
err
,
msg
...
@@ -2445,7 +2452,7 @@ func (dm *DockerManager) tryContainerStart(container *v1.Container, pod *v1.Pod,
...
@@ -2445,7 +2452,7 @@ func (dm *DockerManager) tryContainerStart(container *v1.Container, pod *v1.Pod,
netMode
=
namespaceMode
netMode
=
namespaceMode
}
}
_
,
err
=
dm
.
runContainerInPod
(
pod
,
container
,
netMode
,
namespaceMode
,
pidMode
,
podIP
,
imageRef
,
restartCount
)
_
,
err
=
dm
.
runContainerInPod
(
pod
,
container
,
netMode
,
namespaceMode
,
pidMode
,
podIP
,
hostIP
,
imageRef
,
restartCount
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO(bburns) : Perhaps blacklist a container after N failures?
// TODO(bburns) : Perhaps blacklist a container after N failures?
return
kubecontainer
.
ErrRunContainer
,
err
.
Error
()
return
kubecontainer
.
ErrRunContainer
,
err
.
Error
()
...
...
pkg/kubelet/kubelet_pods.go
View file @
c001deed
...
@@ -275,7 +275,7 @@ func (kl *Kubelet) GetPodCgroupParent(pod *v1.Pod) string {
...
@@ -275,7 +275,7 @@ func (kl *Kubelet) GetPodCgroupParent(pod *v1.Pod) string {
// GenerateRunContainerOptions generates the RunContainerOptions, which can be used by
// GenerateRunContainerOptions generates the RunContainerOptions, which can be used by
// the container runtime to set parameters for launching a container.
// the container runtime to set parameters for launching a container.
func
(
kl
*
Kubelet
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
string
)
(
*
kubecontainer
.
RunContainerOptions
,
bool
,
error
)
{
func
(
kl
*
Kubelet
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
,
hostIP
string
)
(
*
kubecontainer
.
RunContainerOptions
,
bool
,
error
)
{
var
err
error
var
err
error
useClusterFirstPolicy
:=
false
useClusterFirstPolicy
:=
false
cgroupParent
:=
kl
.
GetPodCgroupParent
(
pod
)
cgroupParent
:=
kl
.
GetPodCgroupParent
(
pod
)
...
@@ -299,7 +299,7 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Contai
...
@@ -299,7 +299,7 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Contai
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
opts
.
Envs
,
err
=
kl
.
makeEnvironmentVariables
(
pod
,
container
,
podIP
)
opts
.
Envs
,
err
=
kl
.
makeEnvironmentVariables
(
pod
,
container
,
podIP
,
hostIP
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
@@ -386,7 +386,7 @@ func (kl *Kubelet) getServiceEnvVarMap(ns string) (map[string]string, error) {
...
@@ -386,7 +386,7 @@ func (kl *Kubelet) getServiceEnvVarMap(ns string) (map[string]string, error) {
}
}
// Make the environment variables for a pod in the given namespace.
// Make the environment variables for a pod in the given namespace.
func
(
kl
*
Kubelet
)
makeEnvironmentVariables
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
string
)
([]
kubecontainer
.
EnvVar
,
error
)
{
func
(
kl
*
Kubelet
)
makeEnvironmentVariables
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
,
hostIP
string
)
([]
kubecontainer
.
EnvVar
,
error
)
{
var
result
[]
kubecontainer
.
EnvVar
var
result
[]
kubecontainer
.
EnvVar
// Note: These are added to the docker Config, but are not included in the checksum computed
// Note: These are added to the docker Config, but are not included in the checksum computed
// by dockertools.BuildDockerName(...). That way, we can still determine whether an
// by dockertools.BuildDockerName(...). That way, we can still determine whether an
...
@@ -506,7 +506,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
...
@@ -506,7 +506,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
// Step 1b: resolve alternate env var sources
// Step 1b: resolve alternate env var sources
switch
{
switch
{
case
envVar
.
ValueFrom
.
FieldRef
!=
nil
:
case
envVar
.
ValueFrom
.
FieldRef
!=
nil
:
runtimeVal
,
err
=
kl
.
podFieldSelectorRuntimeValue
(
envVar
.
ValueFrom
.
FieldRef
,
pod
,
podIP
)
runtimeVal
,
err
=
kl
.
podFieldSelectorRuntimeValue
(
envVar
.
ValueFrom
.
FieldRef
,
pod
,
podIP
,
hostIP
)
if
err
!=
nil
{
if
err
!=
nil
{
return
result
,
err
return
result
,
err
}
}
...
@@ -607,7 +607,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
...
@@ -607,7 +607,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
// podFieldSelectorRuntimeValue returns the runtime value of the given
// podFieldSelectorRuntimeValue returns the runtime value of the given
// selector for a pod.
// selector for a pod.
func
(
kl
*
Kubelet
)
podFieldSelectorRuntimeValue
(
fs
*
v1
.
ObjectFieldSelector
,
pod
*
v1
.
Pod
,
podIP
string
)
(
string
,
error
)
{
func
(
kl
*
Kubelet
)
podFieldSelectorRuntimeValue
(
fs
*
v1
.
ObjectFieldSelector
,
pod
*
v1
.
Pod
,
podIP
,
hostIP
string
)
(
string
,
error
)
{
internalFieldPath
,
_
,
err
:=
api
.
Scheme
.
ConvertFieldLabel
(
fs
.
APIVersion
,
"Pod"
,
fs
.
FieldPath
,
""
)
internalFieldPath
,
_
,
err
:=
api
.
Scheme
.
ConvertFieldLabel
(
fs
.
APIVersion
,
"Pod"
,
fs
.
FieldPath
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -618,7 +618,7 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *v1.ObjectFieldSelector, pod
...
@@ -618,7 +618,7 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *v1.ObjectFieldSelector, pod
case
"spec.serviceAccountName"
:
case
"spec.serviceAccountName"
:
return
pod
.
Spec
.
ServiceAccountName
,
nil
return
pod
.
Spec
.
ServiceAccountName
,
nil
case
"status.hostIP"
:
case
"status.hostIP"
:
return
pod
.
Status
.
H
ostIP
,
nil
return
h
ostIP
,
nil
case
"status.podIP"
:
case
"status.podIP"
:
return
podIP
,
nil
return
podIP
,
nil
}
}
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
c001deed
...
@@ -187,7 +187,7 @@ func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
...
@@ -187,7 +187,7 @@ func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
options
:=
make
([]
*
kubecontainer
.
RunContainerOptions
,
4
)
options
:=
make
([]
*
kubecontainer
.
RunContainerOptions
,
4
)
for
i
,
pod
:=
range
pods
{
for
i
,
pod
:=
range
pods
{
var
err
error
var
err
error
options
[
i
],
_
,
err
=
kubelet
.
GenerateRunContainerOptions
(
pod
,
&
v1
.
Container
{},
""
)
options
[
i
],
_
,
err
=
kubelet
.
GenerateRunContainerOptions
(
pod
,
&
v1
.
Container
{},
""
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
}
}
...
@@ -220,7 +220,7 @@ func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
...
@@ -220,7 +220,7 @@ func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
kubelet
.
resolverConfig
=
"/etc/resolv.conf"
kubelet
.
resolverConfig
=
"/etc/resolv.conf"
for
i
,
pod
:=
range
pods
{
for
i
,
pod
:=
range
pods
{
var
err
error
var
err
error
options
[
i
],
_
,
err
=
kubelet
.
GenerateRunContainerOptions
(
pod
,
&
v1
.
Container
{},
""
)
options
[
i
],
_
,
err
=
kubelet
.
GenerateRunContainerOptions
(
pod
,
&
v1
.
Container
{},
""
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
}
}
...
@@ -1152,13 +1152,11 @@ func TestMakeEnvironmentVariables(t *testing.T) {
...
@@ -1152,13 +1152,11 @@ func TestMakeEnvironmentVariables(t *testing.T) {
ServiceAccountName
:
"special"
,
ServiceAccountName
:
"special"
,
NodeName
:
"node-name"
,
NodeName
:
"node-name"
,
},
},
Status
:
v1
.
PodStatus
{
HostIP
:
"5.6.7.8"
,
},
}
}
podIP
:=
"1.2.3.4"
podIP
:=
"1.2.3.4"
hostIP
:=
"5.6.7.8"
result
,
err
:=
kl
.
makeEnvironmentVariables
(
testPod
,
tc
.
container
,
podIP
)
result
,
err
:=
kl
.
makeEnvironmentVariables
(
testPod
,
tc
.
container
,
podIP
,
hostIP
)
select
{
select
{
case
e
:=
<-
fakeRecorder
.
Events
:
case
e
:=
<-
fakeRecorder
.
Events
:
assert
.
Equal
(
t
,
tc
.
expectedEvent
,
e
)
assert
.
Equal
(
t
,
tc
.
expectedEvent
,
e
)
...
...
pkg/kubelet/kuberuntime/kuberuntime_container.go
View file @
c001deed
...
@@ -51,7 +51,7 @@ import (
...
@@ -51,7 +51,7 @@ import (
// * create the container
// * create the container
// * start the container
// * start the container
// * run the post start lifecycle hooks (if applicable)
// * run the post start lifecycle hooks (if applicable)
func
(
m
*
kubeGenericRuntimeManager
)
startContainer
(
podSandboxID
string
,
podSandboxConfig
*
runtimeapi
.
PodSandboxConfig
,
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
podStatus
*
kubecontainer
.
PodStatus
,
pullSecrets
[]
v1
.
Secret
,
podIP
string
)
(
string
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
startContainer
(
podSandboxID
string
,
podSandboxConfig
*
runtimeapi
.
PodSandboxConfig
,
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
podStatus
*
kubecontainer
.
PodStatus
,
pullSecrets
[]
v1
.
Secret
,
podIP
,
hostIP
string
)
(
string
,
error
)
{
// Step 1: pull the image.
// Step 1: pull the image.
imageRef
,
msg
,
err
:=
m
.
imagePuller
.
EnsureImageExists
(
pod
,
container
,
pullSecrets
)
imageRef
,
msg
,
err
:=
m
.
imagePuller
.
EnsureImageExists
(
pod
,
container
,
pullSecrets
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -72,7 +72,7 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
...
@@ -72,7 +72,7 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
restartCount
=
containerStatus
.
RestartCount
+
1
restartCount
=
containerStatus
.
RestartCount
+
1
}
}
containerConfig
,
err
:=
m
.
generateContainerConfig
(
container
,
pod
,
restartCount
,
podIP
,
imageRef
)
containerConfig
,
err
:=
m
.
generateContainerConfig
(
container
,
pod
,
restartCount
,
podIP
,
hostIP
,
imageRef
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
recorder
.
Eventf
(
ref
,
v1
.
EventTypeWarning
,
events
.
FailedToCreateContainer
,
"Failed to create container with error: %v"
,
err
)
m
.
recorder
.
Eventf
(
ref
,
v1
.
EventTypeWarning
,
events
.
FailedToCreateContainer
,
"Failed to create container with error: %v"
,
err
)
return
"Generate Container Config Failed"
,
err
return
"Generate Container Config Failed"
,
err
...
@@ -131,8 +131,8 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
...
@@ -131,8 +131,8 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
}
}
// generateContainerConfig generates container config for kubelet runtime v1.
// generateContainerConfig generates container config for kubelet runtime v1.
func
(
m
*
kubeGenericRuntimeManager
)
generateContainerConfig
(
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
restartCount
int
,
podIP
,
imageRef
string
)
(
*
runtimeapi
.
ContainerConfig
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
generateContainerConfig
(
container
*
v1
.
Container
,
pod
*
v1
.
Pod
,
restartCount
int
,
podIP
,
hostIP
,
imageRef
string
)
(
*
runtimeapi
.
ContainerConfig
,
error
)
{
opts
,
_
,
err
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
opts
,
_
,
err
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
,
hostIP
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_manager.go
View file @
c001deed
...
@@ -604,6 +604,12 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
...
@@ -604,6 +604,12 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
podIP
=
podStatus
.
IP
podIP
=
podStatus
.
IP
}
}
rawHostIP
,
err
:=
m
.
runtimeHelper
.
GetHostIP
()
hostIP
:=
rawHostIP
.
String
()
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get Host IP for pod: %s; %v"
,
format
.
Pod
(
pod
),
err
)
}
// Step 4: Create a sandbox for the pod if necessary.
// Step 4: Create a sandbox for the pod if necessary.
podSandboxID
:=
podContainerChanges
.
SandboxID
podSandboxID
:=
podContainerChanges
.
SandboxID
if
podContainerChanges
.
CreateSandbox
&&
len
(
podContainerChanges
.
ContainersToStart
)
>
0
{
if
podContainerChanges
.
CreateSandbox
&&
len
(
podContainerChanges
.
ContainersToStart
)
>
0
{
...
@@ -680,7 +686,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
...
@@ -680,7 +686,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
}
}
glog
.
V
(
4
)
.
Infof
(
"Creating init container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
glog
.
V
(
4
)
.
Infof
(
"Creating init container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
if
msg
,
err
:=
m
.
startContainer
(
podSandboxID
,
podSandboxConfig
,
container
,
pod
,
podStatus
,
pullSecrets
,
podIP
);
err
!=
nil
{
if
msg
,
err
:=
m
.
startContainer
(
podSandboxID
,
podSandboxConfig
,
container
,
pod
,
podStatus
,
pullSecrets
,
podIP
,
hostIP
);
err
!=
nil
{
startContainerResult
.
Fail
(
err
,
msg
)
startContainerResult
.
Fail
(
err
,
msg
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"init container start failed: %v: %s"
,
err
,
msg
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"init container start failed: %v: %s"
,
err
,
msg
))
return
return
...
@@ -714,7 +720,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
...
@@ -714,7 +720,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStat
}
}
glog
.
V
(
4
)
.
Infof
(
"Creating container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
glog
.
V
(
4
)
.
Infof
(
"Creating container %+v in pod %v"
,
container
,
format
.
Pod
(
pod
))
if
msg
,
err
:=
m
.
startContainer
(
podSandboxID
,
podSandboxConfig
,
container
,
pod
,
podStatus
,
pullSecrets
,
podIP
);
err
!=
nil
{
if
msg
,
err
:=
m
.
startContainer
(
podSandboxID
,
podSandboxConfig
,
container
,
pod
,
podStatus
,
pullSecrets
,
podIP
,
hostIP
);
err
!=
nil
{
startContainerResult
.
Fail
(
err
,
msg
)
startContainerResult
.
Fail
(
err
,
msg
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"container start failed: %v: %s"
,
err
,
msg
))
continue
continue
...
...
pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
View file @
c001deed
...
@@ -146,7 +146,7 @@ func makeFakeContainer(t *testing.T, m *kubeGenericRuntimeManager, template cont
...
@@ -146,7 +146,7 @@ func makeFakeContainer(t *testing.T, m *kubeGenericRuntimeManager, template cont
sandboxConfig
,
err
:=
m
.
generatePodSandboxConfig
(
template
.
pod
,
template
.
sandboxAttempt
)
sandboxConfig
,
err
:=
m
.
generatePodSandboxConfig
(
template
.
pod
,
template
.
sandboxAttempt
)
assert
.
NoError
(
t
,
err
,
"generatePodSandboxConfig for container template %+v"
,
template
)
assert
.
NoError
(
t
,
err
,
"generatePodSandboxConfig for container template %+v"
,
template
)
containerConfig
,
err
:=
m
.
generateContainerConfig
(
template
.
container
,
template
.
pod
,
template
.
attempt
,
""
,
template
.
container
.
Image
)
containerConfig
,
err
:=
m
.
generateContainerConfig
(
template
.
container
,
template
.
pod
,
template
.
attempt
,
""
,
""
,
template
.
container
.
Image
)
assert
.
NoError
(
t
,
err
,
"generateContainerConfig for container template %+v"
,
template
)
assert
.
NoError
(
t
,
err
,
"generateContainerConfig for container template %+v"
,
template
)
podSandboxID
:=
apitest
.
BuildSandboxName
(
sandboxConfig
.
Metadata
)
podSandboxID
:=
apitest
.
BuildSandboxName
(
sandboxConfig
.
Metadata
)
...
...
pkg/kubelet/rkt/rkt.go
View file @
c001deed
...
@@ -607,7 +607,7 @@ func setApp(imgManifest *appcschema.ImageManifest, c *v1.Container,
...
@@ -607,7 +607,7 @@ func setApp(imgManifest *appcschema.ImageManifest, c *v1.Container,
}
}
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
func
(
r
*
Runtime
)
makePodManifest
(
pod
*
v1
.
Pod
,
podIP
string
,
pullSecrets
[]
v1
.
Secret
)
(
*
appcschema
.
PodManifest
,
error
)
{
func
(
r
*
Runtime
)
makePodManifest
(
pod
*
v1
.
Pod
,
podIP
,
hostIP
string
,
pullSecrets
[]
v1
.
Secret
)
(
*
appcschema
.
PodManifest
,
error
)
{
manifest
:=
appcschema
.
BlankPodManifest
()
manifest
:=
appcschema
.
BlankPodManifest
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
r
.
requestTimeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
r
.
requestTimeout
)
...
@@ -654,7 +654,7 @@ func (r *Runtime) makePodManifest(pod *v1.Pod, podIP string, pullSecrets []v1.Se
...
@@ -654,7 +654,7 @@ func (r *Runtime) makePodManifest(pod *v1.Pod, podIP string, pullSecrets []v1.Se
}
}
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
err
:=
r
.
newAppcRuntimeApp
(
pod
,
podIP
,
c
,
requiresPrivileged
,
pullSecrets
,
manifest
)
err
:=
r
.
newAppcRuntimeApp
(
pod
,
podIP
,
hostIP
,
c
,
requiresPrivileged
,
pullSecrets
,
manifest
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -776,7 +776,7 @@ func (r *Runtime) makeContainerLogMount(opts *kubecontainer.RunContainerOptions,
...
@@ -776,7 +776,7 @@ func (r *Runtime) makeContainerLogMount(opts *kubecontainer.RunContainerOptions,
return
&
mnt
,
nil
return
&
mnt
,
nil
}
}
func
(
r
*
Runtime
)
newAppcRuntimeApp
(
pod
*
v1
.
Pod
,
podIP
string
,
c
v1
.
Container
,
requiresPrivileged
bool
,
pullSecrets
[]
v1
.
Secret
,
manifest
*
appcschema
.
PodManifest
)
error
{
func
(
r
*
Runtime
)
newAppcRuntimeApp
(
pod
*
v1
.
Pod
,
podIP
,
hostIP
string
,
c
v1
.
Container
,
requiresPrivileged
bool
,
pullSecrets
[]
v1
.
Secret
,
manifest
*
appcschema
.
PodManifest
)
error
{
var
annotations
appctypes
.
Annotations
=
[]
appctypes
.
Annotation
{
var
annotations
appctypes
.
Annotations
=
[]
appctypes
.
Annotation
{
{
{
Name
:
*
appctypes
.
MustACIdentifier
(
k8sRktContainerHashAnno
),
Name
:
*
appctypes
.
MustACIdentifier
(
k8sRktContainerHashAnno
),
...
@@ -810,7 +810,7 @@ func (r *Runtime) newAppcRuntimeApp(pod *v1.Pod, podIP string, c v1.Container, r
...
@@ -810,7 +810,7 @@ func (r *Runtime) newAppcRuntimeApp(pod *v1.Pod, podIP string, c v1.Container, r
}
}
// TODO: determine how this should be handled for rkt
// TODO: determine how this should be handled for rkt
opts
,
_
,
err
:=
r
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
&
c
,
podIP
)
opts
,
_
,
err
:=
r
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
&
c
,
podIP
,
hostIP
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -1135,9 +1135,9 @@ func constructSyslogIdentifier(generateName string, podName string) string {
...
@@ -1135,9 +1135,9 @@ func constructSyslogIdentifier(generateName string, podName string) string {
//
//
// On success, it will return a string that represents name of the unit file
// On success, it will return a string that represents name of the unit file
// and the runtime pod.
// and the runtime pod.
func
(
r
*
Runtime
)
preparePod
(
pod
*
v1
.
Pod
,
podIP
string
,
pullSecrets
[]
v1
.
Secret
,
netnsName
string
)
(
string
,
*
kubecontainer
.
Pod
,
error
)
{
func
(
r
*
Runtime
)
preparePod
(
pod
*
v1
.
Pod
,
podIP
,
hostIP
string
,
pullSecrets
[]
v1
.
Secret
,
netnsName
string
)
(
string
,
*
kubecontainer
.
Pod
,
error
)
{
// Generate the appc pod manifest from the k8s pod spec.
// Generate the appc pod manifest from the k8s pod spec.
manifest
,
err
:=
r
.
makePodManifest
(
pod
,
podIP
,
pullSecrets
)
manifest
,
err
:=
r
.
makePodManifest
(
pod
,
podIP
,
hostIP
,
pullSecrets
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -1349,7 +1349,13 @@ func (r *Runtime) RunPod(pod *v1.Pod, pullSecrets []v1.Secret) error {
...
@@ -1349,7 +1349,13 @@ func (r *Runtime) RunPod(pod *v1.Pod, pullSecrets []v1.Secret) error {
return
err
return
err
}
}
name
,
runtimePod
,
prepareErr
:=
r
.
preparePod
(
pod
,
podIP
,
pullSecrets
,
netnsName
)
rawHostIP
,
err
:=
r
.
runtimeHelper
.
GetHostIP
()
hostIP
:=
rawHostIP
.
String
()
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get Host IP for pod: %s; %v"
,
format
.
Pod
(
pod
),
err
)
}
name
,
runtimePod
,
prepareErr
:=
r
.
preparePod
(
pod
,
podIP
,
hostIP
,
pullSecrets
,
netnsName
)
// Set container references and generate events.
// Set container references and generate events.
// If preparedPod fails, then send out 'failed' events for each container.
// If preparedPod fails, then send out 'failed' events for each container.
...
...
pkg/kubelet/rkt/rkt_test.go
View file @
c001deed
...
@@ -1902,7 +1902,7 @@ func TestMakePodManifestAnnotations(t *testing.T) {
...
@@ -1902,7 +1902,7 @@ func TestMakePodManifestAnnotations(t *testing.T) {
for
i
,
testCase
:=
range
testCases
{
for
i
,
testCase
:=
range
testCases
{
hint
:=
fmt
.
Sprintf
(
"case #%d"
,
i
)
hint
:=
fmt
.
Sprintf
(
"case #%d"
,
i
)
result
,
err
:=
r
.
makePodManifest
(
testCase
.
in
,
""
,
[]
v1
.
Secret
{})
result
,
err
:=
r
.
makePodManifest
(
testCase
.
in
,
""
,
""
,
[]
v1
.
Secret
{})
assert
.
Equal
(
t
,
testCase
.
outerr
,
err
,
hint
)
assert
.
Equal
(
t
,
testCase
.
outerr
,
err
,
hint
)
if
err
==
nil
{
if
err
==
nil
{
sort
.
Sort
(
annotationsByName
(
result
.
Annotations
))
sort
.
Sort
(
annotationsByName
(
result
.
Annotations
))
...
...
test/e2e/common/downward_api.go
View file @
c001deed
...
@@ -62,7 +62,7 @@ var _ = framework.KubeDescribe("Downward API", func() {
...
@@ -62,7 +62,7 @@ var _ = framework.KubeDescribe("Downward API", func() {
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
})
})
It
(
"should provide pod IP as an env var [Conformance]"
,
func
()
{
It
(
"should provide pod
and host
IP as an env var [Conformance]"
,
func
()
{
podName
:=
"downward-api-"
+
string
(
uuid
.
NewUUID
())
podName
:=
"downward-api-"
+
string
(
uuid
.
NewUUID
())
env
:=
[]
v1
.
EnvVar
{
env
:=
[]
v1
.
EnvVar
{
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment