func ConvertMesosContainerToPodSpec()

in pkg/common/api/api_converter.go [734:836]


func ConvertMesosContainerToPodSpec(
	containerInfo *mesosv1.ContainerInfo, // input
	spec *pod.PodSpec, // output
	container *pod.ContainerSpec, //output
) {
	if containerInfo == nil {
		return
	}

	if spec.GetMesosSpec() == nil {
		spec.MesosSpec = &apachemesos.PodSpec{}
	}

	// populate container type
	switch containerInfo.GetType() {
	case mesosv1.ContainerInfo_DOCKER:
		spec.MesosSpec.Type = apachemesos.PodSpec_CONTAINER_TYPE_DOCKER
	case mesosv1.ContainerInfo_MESOS:
		spec.MesosSpec.Type = apachemesos.PodSpec_CONTAINER_TYPE_MESOS
	}

	// Populate volumes
	var volumeSpecs []*volume.VolumeSpec
	var volumeMounts []*pod.VolumeMount

	for _, v := range containerInfo.GetVolumes() {
		// TBD original name is lost, store it with v0 api
		volumeSpec := FindVolumeInPodSpec(spec, v.GetHostPath())
		if volumeSpec == nil {
			volumeSpec = &volume.VolumeSpec{
				HostPath: &volume.VolumeSpec_HostPathVolumeSource{
					Path: v.GetHostPath(),
				},
				Type: volume.VolumeSpec_VOLUME_TYPE_HOST_PATH,
				Name: v.GetHostPath(),
			}
			volumeSpecs = append(volumeSpecs, volumeSpec)
		}

		readOnly := false
		if v.GetMode() == mesosv1.Volume_RO {
			readOnly = true
		}

		volumeMount := &pod.VolumeMount{
			Name:      v.GetHostPath(),
			ReadOnly:  readOnly,
			MountPath: v.GetContainerPath(),
		}
		volumeMounts = append(volumeMounts, volumeMount)
	}

	if len(volumeSpecs) > 0 {
		spec.Volumes = volumeSpecs
	}

	if len(volumeMounts) > 0 {
		container.VolumeMounts = volumeMounts
	}

	// Populate container type specific info
	if containerInfo.GetType() == mesosv1.ContainerInfo_DOCKER {
		dockerInfo := containerInfo.GetDocker()

		var parameters []*apachemesos.PodSpec_DockerParameter
		for _, parameter := range dockerInfo.GetParameters() {
			p := &apachemesos.PodSpec_DockerParameter{
				Key:   parameter.GetKey(),
				Value: parameter.GetValue(),
			}
			parameters = append(parameters, p)
		}

		if len(parameters) > 0 {
			spec.MesosSpec.DockerParameters = parameters
		}

		if len(dockerInfo.GetImage()) > 0 {
			container.Image = dockerInfo.GetImage()
		}

		spec.MesosSpec.NetworkSpec = &apachemesos.PodSpec_NetworkSpec{}
		switch dockerInfo.GetNetwork() {
		case mesosv1.ContainerInfo_DockerInfo_HOST:
			spec.MesosSpec.NetworkSpec.Type = apachemesos.PodSpec_NetworkSpec_NETWORK_TYPE_HOST
		case mesosv1.ContainerInfo_DockerInfo_BRIDGE:
			spec.MesosSpec.NetworkSpec.Type = apachemesos.PodSpec_NetworkSpec_NETWORK_TYPE_BRIDGE
		case mesosv1.ContainerInfo_DockerInfo_NONE:
			spec.MesosSpec.NetworkSpec.Type = apachemesos.PodSpec_NetworkSpec_NETWORK_TYPE_NONE
		case mesosv1.ContainerInfo_DockerInfo_USER:
			spec.MesosSpec.NetworkSpec.Type = apachemesos.PodSpec_NetworkSpec_NETWORK_TYPE_USER
		}

		if len(containerInfo.GetNetworkInfos()) > 0 {
			spec.MesosSpec.NetworkSpec.Name = containerInfo.GetNetworkInfos()[0].GetName()
		}

	} else {
		if len(containerInfo.GetMesos().GetImage().GetDocker().GetName()) > 0 {
			container.Image = containerInfo.GetMesos().GetImage().GetDocker().GetName()
		}
	}
}