Merge pull request #1288 from brendandburns/privilege
Add support for privileged containers.
This commit is contained in:
		| @@ -58,6 +58,7 @@ var ( | |||||||
| 	dockerEndpoint     = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with") | 	dockerEndpoint     = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with") | ||||||
| 	etcdServerList     util.StringList | 	etcdServerList     util.StringList | ||||||
| 	rootDirectory      = flag.String("root_dir", defaultRootDir, "Directory path for managing kubelet files (volume mounts,etc).") | 	rootDirectory      = flag.String("root_dir", defaultRootDir, "Directory path for managing kubelet files (volume mounts,etc).") | ||||||
|  | 	allowPrivileged    = flag.Bool("allow_privileged", false, "If true, allow containers to request privileged mode.") | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| @@ -150,7 +151,8 @@ func main() { | |||||||
| 		cadvisorClient, | 		cadvisorClient, | ||||||
| 		etcdClient, | 		etcdClient, | ||||||
| 		*rootDirectory, | 		*rootDirectory, | ||||||
| 		*syncFrequency) | 		*syncFrequency, | ||||||
|  | 		*allowPrivileged) | ||||||
|  |  | ||||||
| 	health.AddHealthChecker("exec", health.NewExecHealthChecker(k)) | 	health.AddHealthChecker("exec", health.NewExecHealthChecker(k)) | ||||||
| 	health.AddHealthChecker("http", health.NewHTTPHealthChecker(&http.Client{})) | 	health.AddHealthChecker("http", health.NewHTTPHealthChecker(&http.Client{})) | ||||||
|   | |||||||
| @@ -195,6 +195,8 @@ type Container struct { | |||||||
| 	VolumeMounts  []VolumeMount  `yaml:"volumeMounts,omitempty" json:"volumeMounts,omitempty"` | 	VolumeMounts  []VolumeMount  `yaml:"volumeMounts,omitempty" json:"volumeMounts,omitempty"` | ||||||
| 	LivenessProbe *LivenessProbe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` | 	LivenessProbe *LivenessProbe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` | ||||||
| 	Lifecycle     *Lifecycle     `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` | 	Lifecycle     *Lifecycle     `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` | ||||||
|  | 	// Optional: Default to false. | ||||||
|  | 	Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // Handler defines a specific action that should be taken | // Handler defines a specific action that should be taken | ||||||
|   | |||||||
| @@ -205,6 +205,8 @@ type Container struct { | |||||||
| 	VolumeMounts  []VolumeMount  `yaml:"volumeMounts,omitempty" json:"volumeMounts,omitempty"` | 	VolumeMounts  []VolumeMount  `yaml:"volumeMounts,omitempty" json:"volumeMounts,omitempty"` | ||||||
| 	LivenessProbe *LivenessProbe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` | 	LivenessProbe *LivenessProbe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` | ||||||
| 	Lifecycle     *Lifecycle     `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` | 	Lifecycle     *Lifecycle     `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` | ||||||
|  | 	// Optional: Default to false. | ||||||
|  | 	Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // Handler defines a specific action that should be taken | // Handler defines a specific action that should be taken | ||||||
|   | |||||||
| @@ -67,7 +67,8 @@ func NewMainKubelet( | |||||||
| 	cc CadvisorInterface, | 	cc CadvisorInterface, | ||||||
| 	ec tools.EtcdClient, | 	ec tools.EtcdClient, | ||||||
| 	rd string, | 	rd string, | ||||||
| 	ri time.Duration) *Kubelet { | 	ri time.Duration, | ||||||
|  | 	privileged bool) *Kubelet { | ||||||
| 	return &Kubelet{ | 	return &Kubelet{ | ||||||
| 		hostname:        hn, | 		hostname:        hn, | ||||||
| 		dockerClient:    dc, | 		dockerClient:    dc, | ||||||
| @@ -78,6 +79,7 @@ func NewMainKubelet( | |||||||
| 		podWorkers:      newPodWorkers(), | 		podWorkers:      newPodWorkers(), | ||||||
| 		runner:          dockertools.NewDockerContainerCommandRunner(), | 		runner:          dockertools.NewDockerContainerCommandRunner(), | ||||||
| 		httpClient:      &http.Client{}, | 		httpClient:      &http.Client{}, | ||||||
|  | 		allowPrivileged: privileged, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -119,6 +121,8 @@ type Kubelet struct { | |||||||
| 	runner dockertools.ContainerCommandRunner | 	runner dockertools.ContainerCommandRunner | ||||||
| 	// Optional, client for http requests, defaults to empty client | 	// Optional, client for http requests, defaults to empty client | ||||||
| 	httpClient httpGetInterface | 	httpClient httpGetInterface | ||||||
|  | 	// Optional, allow privileged containers, defaults to false | ||||||
|  | 	allowPrivileged bool | ||||||
| } | } | ||||||
|  |  | ||||||
| // Run starts the kubelet reacting to config updates | // Run starts the kubelet reacting to config updates | ||||||
| @@ -335,10 +339,17 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
|  | 	privileged := false | ||||||
|  | 	if kl.allowPrivileged { | ||||||
|  | 		privileged = container.Privileged | ||||||
|  | 	} else if container.Privileged { | ||||||
|  | 		return "", fmt.Errorf("Container requested privileged mode, but it is disallowed globally.") | ||||||
|  | 	} | ||||||
| 	err = kl.dockerClient.StartContainer(dockerContainer.ID, &docker.HostConfig{ | 	err = kl.dockerClient.StartContainer(dockerContainer.ID, &docker.HostConfig{ | ||||||
| 		PortBindings: portBindings, | 		PortBindings: portBindings, | ||||||
| 		Binds:        binds, | 		Binds:        binds, | ||||||
| 		NetworkMode:  netMode, | 		NetworkMode:  netMode, | ||||||
|  | 		Privileged:   privileged, | ||||||
| 	}) | 	}) | ||||||
| 	if err == nil && container.Lifecycle != nil && container.Lifecycle.PostStart != nil { | 	if err == nil && container.Lifecycle != nil && container.Lifecycle.PostStart != nil { | ||||||
| 		handlerErr := kl.runHandler(GetPodFullName(pod), pod.Manifest.UUID, container, container.Lifecycle.PostStart) | 		handlerErr := kl.runHandler(GetPodFullName(pod), pod.Manifest.UUID, container, container.Lifecycle.PostStart) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tim Hockin
					Tim Hockin