Пример #1
0
func ProcessPodBytes(body []byte, podId string) (*pod.UserPod, error) {
	var containers []pod.UserContainer
	var serviceDir string = path.Join(utils.HYPER_ROOT, "services", podId)

	userPod, err := pod.ProcessPodBytes(body)
	if err != nil {
		glog.V(1).Infof("Process POD file error: %s", err.Error())
		return nil, err
	}

	if len(userPod.Services) == 0 {
		return userPod, nil
	}

	userPod.Type = "service-discovery"
	serviceContainer := pod.UserContainer{
		Name:    ServiceDiscoveryContainerName(userPod.Name),
		Image:   servicediscovery.ServiceImage,
		Command: []string{"haproxy", "-D", "-f", "/usr/local/etc/haproxy/haproxy.cfg", "-p", "/var/run/haproxy.pid"},
	}

	serviceVolRef := pod.UserVolumeReference{
		Volume:   "service-volume",
		Path:     servicediscovery.ServiceVolume,
		ReadOnly: false,
	}

	/* PrepareServices will check service volume */
	serviceVolume := pod.UserVolume{
		Name:   "service-volume",
		Source: serviceDir,
		Driver: "vfs",
	}

	userPod.Volumes = append(userPod.Volumes, serviceVolume)

	serviceContainer.Volumes = append(serviceContainer.Volumes, serviceVolRef)

	containers = append(containers, serviceContainer)

	for _, c := range userPod.Containers {
		containers = append(containers, c)
	}

	userPod.Containers = containers

	return userPod, nil
}
Пример #2
0
Файл: pod.go Проект: juito/hyper
func (p *Pod) processImageVolumes(config *dockertypes.ContainerJSON, id string, container *pod.UserContainer) {
	if config.Config.Volumes == nil {
		return
	}

	userPod := p.Spec

	existed := make(map[string]bool)
	for _, v := range container.Volumes {
		existed[v.Path] = true
	}

	for tgt := range config.Config.Volumes {
		if _, ok := existed[tgt]; ok {
			continue
		}

		n := id + strings.Replace(tgt, "/", "_", -1)
		v := pod.UserVolume{
			Name:   n,
			Source: "",
		}
		r := pod.UserVolumeReference{
			Volume:   n,
			Path:     tgt,
			ReadOnly: false,
		}

		p.volumes[n] = &hypervisor.VolumeInfo{Name: n, DockerVolume: true}
		userPod.Volumes = append(userPod.Volumes, v)
		container.Volumes = append(container.Volumes, r)
	}
}
Пример #3
0
func ParseServiceDiscovery(id string, spec *pod.UserPod) error {
	var containers []pod.UserContainer
	var serviceType string = "service-discovery"
	var serviceDir string = path.Join(utils.HYPER_ROOT, "services", id)

	if len(spec.Services) == 0 || spec.Type == serviceType {
		return nil
	}

	spec.Type = serviceType
	serviceContainer := pod.UserContainer{
		Name:    ServiceDiscoveryContainerName(spec.Name),
		Image:   servicediscovery.ServiceImage,
		Command: []string{"haproxy", "-D", "-f", "/usr/local/etc/haproxy/haproxy.cfg", "-p", "/var/run/haproxy.pid"},
	}

	serviceVolRef := pod.UserVolumeReference{
		Volume:   "service-volume",
		Path:     servicediscovery.ServiceVolume,
		ReadOnly: false,
	}

	/* PrepareServices will check service volume */
	serviceVolume := pod.UserVolume{
		Name:   "service-volume",
		Source: serviceDir,
		Driver: "vfs",
	}

	spec.Volumes = append(spec.Volumes, serviceVolume)

	serviceContainer.Volumes = append(serviceContainer.Volumes, serviceVolRef)

	containers = append(containers, serviceContainer)

	for _, c := range spec.Containers {
		containers = append(containers, c)
	}

	spec.Containers = containers

	return nil
}
Пример #4
0
func processImageVolumes(config *dockertypes.ContainerJSONRaw, id string, userPod *pod.UserPod, container *pod.UserContainer) {
	if config.Config.Volumes == nil {
		return
	}

	for tgt := range config.Config.Volumes {
		n := id + strings.Replace(tgt, "/", "_", -1)
		v := pod.UserVolume{
			Name:   n,
			Source: "",
		}
		r := pod.UserVolumeReference{
			Volume:   n,
			Path:     tgt,
			ReadOnly: false,
		}
		userPod.Volumes = append(userPod.Volumes, v)
		container.Volumes = append(container.Volumes, r)
	}
}
Пример #5
0
func processImageVolumes(config *dockertypes.ContainerJSONRaw, id string, userPod *pod.UserPod, container *pod.UserContainer) {
	if config.Config.Volumes == nil {
		return
	}

	for tgt := range config.Config.Volumes {
		n := id + "-" + tgt
		v := pod.UserVolume{
			Name:   n,
			Source: "",
			Driver: "vfs", //will check if it should equal to the storage engine, and it should be reclaim after
			//after the container finished
		}
		r := pod.UserVolumeReference{
			Volume:   n,
			Path:     tgt,
			ReadOnly: false,
		}
		userPod.Volumes = append(userPod.Volumes, v)
		container.Volumes = append(container.Volumes, r)
	}
}
Пример #6
0
Файл: pod.go Проект: juito/hyper
func convertToRunvContainerSpec(v *apitypes.UserContainer, podTTY bool) pod.UserContainer {
	container := pod.UserContainer{
		Tty:           v.Tty || podTTY,
		Name:          v.Name,
		Image:         v.Image,
		Command:       v.Command,
		Workdir:       v.Workdir,
		Entrypoint:    v.Entrypoint,
		Sysctl:        v.Sysctl,
		RestartPolicy: v.RestartPolicy,
		Labels:        v.Labels,
	}

	if v.User != nil {
		container.User = pod.UserUser{
			Name:             v.User.Name,
			Group:            v.User.Group,
			AdditionalGroups: v.User.AdditionalGroups,
		}
	}

	if len(v.Ports) > 0 {
		ports := make([]pod.UserContainerPort, 0, len(v.Ports))
		for _, p := range v.Ports {
			ports = append(ports, pod.UserContainerPort{
				Protocol:      p.Protocol,
				ContainerPort: int(p.ContainerPort),
				ServicePort:   int(p.ServicePort),
				HostPort:      int(p.HostPort),
			})
		}
		container.Ports = ports
	}

	if len(v.Envs) > 0 {
		envs := make([]pod.UserEnvironmentVar, 0, len(v.Envs))
		for _, env := range v.Envs {
			envs = append(envs, pod.UserEnvironmentVar{
				Env:   env.Env,
				Value: env.Value,
			})
		}
		container.Envs = envs
	}

	if len(v.Volumes) > 0 {
		volumes := make([]pod.UserVolumeReference, 0, len(v.Volumes))
		for _, vol := range v.Volumes {
			volumes = append(volumes, pod.UserVolumeReference{
				Path:     vol.Path,
				ReadOnly: vol.ReadOnly,
				Volume:   vol.Volume,
			})
		}
		container.Volumes = volumes
	}

	if len(v.Files) > 0 {
		files := make([]pod.UserFileReference, 0, len(v.Files))
		for _, f := range v.Files {
			files = append(files, pod.UserFileReference{
				Path:     f.Path,
				Filename: f.Filename,
				Perm:     f.Perm,
				User:     f.User,
				Group:    f.Group,
			})
		}
		container.Files = files
	}

	return container
}