support optional envvars for pod-infra-container

This commit is contained in:
James DeFelice 2016-02-05 15:47:06 +00:00
parent c78f3a68fd
commit 1aec798aa0
4 changed files with 31 additions and 1 deletions

View File

@ -733,6 +733,7 @@ type KubeletConfig struct {
ExperimentalFlannelOverlay bool
NodeIP net.IP
ContainerRuntimeOptions []kubecontainer.Option
}
func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.PodConfig, err error) {
@ -820,6 +821,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
kc.Reservation,
kc.EnableCustomMetrics,
kc.VolumeStatsAggPeriod,
kc.ContainerRuntimeOptions,
)
if err != nil {

View File

@ -464,3 +464,7 @@ func ParsePodFullName(podFullName string) (string, string, error) {
}
return parts[0], parts[1], nil
}
// Option is a functional option type for Runtime, useful for
// completely optional settings.
type Option func(Runtime)

View File

@ -95,6 +95,8 @@ type DockerManager struct {
// The image name of the pod infra container.
podInfraContainerImage string
// (Optional) Additional environment variables to be set for the pod infra container.
podInfraContainerEnv []api.EnvVar
// TODO(yifan): Record the pull failure so we can eliminate the image checking?
// Lower level docker image puller.
@ -140,6 +142,18 @@ type DockerManager struct {
enableCustomMetrics bool
}
func PodInfraContainerEnv(env map[string]string) kubecontainer.Option {
return func(rt kubecontainer.Runtime) {
dm := rt.(*DockerManager)
for k, v := range env {
dm.podInfraContainerEnv = append(dm.podInfraContainerEnv, api.EnvVar{
Name: k,
Value: v,
})
}
}
}
func NewDockerManager(
client DockerInterface,
recorder record.EventRecorder,
@ -160,7 +174,8 @@ func NewDockerManager(
cpuCFSQuota bool,
imageBackOff *util.Backoff,
serializeImagePulls bool,
enableCustomMetrics bool) *DockerManager {
enableCustomMetrics bool,
options ...kubecontainer.Option) *DockerManager {
// Work out the location of the Docker runtime, defaulting to /var/lib/docker
// if there are any problems.
@ -201,6 +216,11 @@ func NewDockerManager(
}
dm.containerGC = NewContainerGC(client, containerLogsDir)
// apply optional settings..
for _, optf := range options {
optf(dm)
}
return dm
}
@ -763,6 +783,7 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
Image: dm.podInfraContainerImage,
Ports: ports,
ImagePullPolicy: podInfraContainerImagePullPolicy,
Env: dm.podInfraContainerEnv,
}
return podInfraContainerStatus.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil
}
@ -1489,6 +1510,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.Do
Image: dm.podInfraContainerImage,
Ports: ports,
ImagePullPolicy: podInfraContainerImagePullPolicy,
Env: dm.podInfraContainerEnv,
}
// No pod secrets for the infra container.

View File

@ -206,6 +206,7 @@ func NewMainKubelet(
reservation kubetypes.Reservation,
enableCustomMetrics bool,
volumeStatsAggPeriod time.Duration,
containerRuntimeOptions []kubecontainer.Option,
) (*Kubelet, error) {
if rootDirectory == "" {
return nil, fmt.Errorf("invalid root directory %q", rootDirectory)
@ -387,6 +388,7 @@ func NewMainKubelet(
imageBackOff,
serializeImagePulls,
enableCustomMetrics,
containerRuntimeOptions...,
)
case "rkt":
conf := &rkt.Config{