Beispiel #1
0
func (daemon *Daemon) CreatePod(podId string, podSpec *apitypes.UserPod) (*pod.XPod, error) {
	//FIXME: why restrict to 1024
	if daemon.PodList.CountRunning() >= 1024 {
		return nil, fmt.Errorf("There have already been %d running Pods", 1024)
	}
	if podId == "" {
		podId = fmt.Sprintf("pod-%s", utils.RandStr(10, "alpha"))
	}

	if podSpec.Id == "" {
		podSpec.Id = podId
	}

	if _, ok := daemon.PodList.Get(podSpec.Id); ok {
		return nil, fmt.Errorf("pod %s already exist", podSpec.Id)
	}

	if err := podSpec.Validate(); err != nil {
		return nil, err
	}

	factory := pod.NewPodFactory(daemon.Factory, daemon.PodList, daemon.db, daemon.Storage, daemon.Daemon, daemon.DefaultLog)

	p, err := pod.CreateXPod(factory, podSpec)
	if err != nil {
		glog.Errorf("%s: failed to add pod: %v", podSpec.Id, err)
		return nil, err
	}

	return p, nil
}
Beispiel #2
0
func (daemon *Daemon) createPodInternal(podId string, podSpec *apitypes.UserPod, withinLock bool) (*Pod, error) {
	glog.V(2).Infof("podArgs: %s", podSpec.String())

	pod, err := NewPod(podSpec, podId, daemon)
	if err != nil {
		return nil, err
	}

	// Creation
	if err = pod.DoCreate(daemon); err != nil {
		return nil, err
	}

	return pod, nil
}
Beispiel #3
0
func (p *XPod) ParseServiceDiscovery(spec *apitypes.UserPod) *apitypes.UserContainer {
	var serviceType string = "service-discovery"

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

	spec.Type = serviceType

	return p.generateServiceContainer(spec.Services)
}
Beispiel #4
0
func (daemon *Daemon) createPodInternal(podId string, podSpec *apitypes.UserPod, withinLock bool) (*Pod, error) {
	glog.V(2).Infof("podArgs: %s", podSpec.String())

	pod, err := NewPod(podSpec, podId, daemon)
	if err != nil {
		return nil, err
	}

	defer func() {
		if err != nil {
			pod.Lock()
			glog.Infof("create pod %s failed, cleanup", podId)
			pod.Cleanup(daemon)
			pod.Unlock()
		}
	}()

	// Creation
	if err = pod.DoCreate(daemon); err != nil {
		return nil, err
	}

	return pod, nil
}