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 ExperimentalFlannelOverlay bool
NodeIP net.IP NodeIP net.IP
ContainerRuntimeOptions []kubecontainer.Option
} }
func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.PodConfig, err error) { 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.Reservation,
kc.EnableCustomMetrics, kc.EnableCustomMetrics,
kc.VolumeStatsAggPeriod, kc.VolumeStatsAggPeriod,
kc.ContainerRuntimeOptions,
) )
if err != nil { if err != nil {

View File

@ -464,3 +464,7 @@ func ParsePodFullName(podFullName string) (string, string, error) {
} }
return parts[0], parts[1], nil 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. // The image name of the pod infra container.
podInfraContainerImage string 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? // TODO(yifan): Record the pull failure so we can eliminate the image checking?
// Lower level docker image puller. // Lower level docker image puller.
@ -140,6 +142,18 @@ type DockerManager struct {
enableCustomMetrics bool 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( func NewDockerManager(
client DockerInterface, client DockerInterface,
recorder record.EventRecorder, recorder record.EventRecorder,
@ -160,7 +174,8 @@ func NewDockerManager(
cpuCFSQuota bool, cpuCFSQuota bool,
imageBackOff *util.Backoff, imageBackOff *util.Backoff,
serializeImagePulls bool, serializeImagePulls bool,
enableCustomMetrics bool) *DockerManager { enableCustomMetrics bool,
options ...kubecontainer.Option) *DockerManager {
// Work out the location of the Docker runtime, defaulting to /var/lib/docker // Work out the location of the Docker runtime, defaulting to /var/lib/docker
// if there are any problems. // if there are any problems.
@ -201,6 +216,11 @@ func NewDockerManager(
} }
dm.containerGC = NewContainerGC(client, containerLogsDir) dm.containerGC = NewContainerGC(client, containerLogsDir)
// apply optional settings..
for _, optf := range options {
optf(dm)
}
return dm return dm
} }
@ -763,6 +783,7 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
Image: dm.podInfraContainerImage, Image: dm.podInfraContainerImage,
Ports: ports, Ports: ports,
ImagePullPolicy: podInfraContainerImagePullPolicy, ImagePullPolicy: podInfraContainerImagePullPolicy,
Env: dm.podInfraContainerEnv,
} }
return podInfraContainerStatus.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil return podInfraContainerStatus.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil
} }
@ -1489,6 +1510,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.Do
Image: dm.podInfraContainerImage, Image: dm.podInfraContainerImage,
Ports: ports, Ports: ports,
ImagePullPolicy: podInfraContainerImagePullPolicy, ImagePullPolicy: podInfraContainerImagePullPolicy,
Env: dm.podInfraContainerEnv,
} }
// No pod secrets for the infra container. // No pod secrets for the infra container.

View File

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