コード例 #1
0
// Run a single container from a pod. Returns the docker container ID
func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, generator kubecontainer.RunContainerOptionsGenerator, runner kubecontainer.HandlerRunner, netMode, ipcMode string) (DockerID, error) {
	ref, err := kubecontainer.GenerateContainerRef(pod, container)
	if err != nil {
		glog.Errorf("Couldn't make a ref to pod %v, container %v: '%v'", pod.Name, container.Name, err)
	}

	opts, err := generator.GenerateRunContainerOptions(pod, container, netMode, ipcMode)
	if err != nil {
		return "", err
	}

	id, err := dm.runContainerRecordErrorReason(pod, container, opts, ref)
	if err != nil {
		return "", err
	}

	// Remember this reference so we can report events about this container
	if ref != nil {
		dm.containerRefManager.SetRef(id, ref)
	}

	if container.Lifecycle != nil && container.Lifecycle.PostStart != nil {
		handlerErr := runner.Run(id, pod, container, container.Lifecycle.PostStart)
		if handlerErr != nil {
			dm.KillContainer(types.UID(id))
			return DockerID(""), fmt.Errorf("failed to call event handler: %v", handlerErr)
		}
	}
	return DockerID(id), err
}
コード例 #2
0
func (kr *kubeletRuntimeHooks) ReportImagePull(pod *api.Pod, container *api.Container, pullError error) {
	ref, err := kubecontainer.GenerateContainerRef(pod, container)
	if err != nil {
		glog.Errorf("Couldn't make a ref to pod %q, container %q: '%v'", pod.Name, container.Name, err)
		return
	}

	if pullError != nil {
		kr.recorder.Eventf(ref, "failed", "Failed to pull image %q: %v", container.Image, pullError)
	} else {
		kr.recorder.Eventf(ref, "pulled", "Successfully pulled image %q", container.Image)
	}
}