Beispiel #1
0
func (daemon *Daemon) UpdateService(podId string, srvs []pod.UserService) error {
	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return err
	}

	if err := servicediscovery.ApplyServices(vm, container, srvs); err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func (p *XPod) DeleteService(srvs []*apitypes.UserService) error {
	if p.globalSpec.Type != "service-discovery" {
		err := fmt.Errorf("pod does not support service discovery")
		p.Log(ERROR, err)
		return err
	}
	p.resourceLock.Lock()
	defer p.resourceLock.Unlock()

	tbd := make(map[struct {
		IP   string
		Port int32
	}]bool, len(srvs))
	for _, srv := range srvs {
		tbd[struct {
			IP   string
			Port int32
		}{srv.ServiceIP, srv.ServicePort}] = true
	}
	target := make([]*apitypes.UserService, 0, len(p.services))
	for _, srv := range p.services {
		if tbd[struct {
			IP   string
			Port int32
		}{srv.ServiceIP, srv.ServicePort}] {
			p.Log(TRACE, "remove service %#v", srv)
			continue
		}
		target = append(target, srv)
	}

	if p.IsRunning() {
		sc := p.getServiceContainer()
		if err := servicediscovery.ApplyServices(p.sandbox, sc, target); err != nil {
			p.Log(ERROR, "failed to update services %#v: %v", target, err)
			return err
		}
	}
	p.services = target
	return nil
}
Beispiel #3
0
func (p *XPod) UpdateService(srvs []*apitypes.UserService) error {
	if p.globalSpec.Type != "service-discovery" {
		p.globalSpec.Type = "service-discovery"
		p.Log(INFO, "change pod type to service discovery")
		return p.NewServiceContainer(srvs)
	}
	p.Log(INFO, "update service %v", srvs)
	p.resourceLock.Lock()
	defer p.resourceLock.Unlock()

	if p.IsRunning() {
		sc := p.getServiceContainer()
		p.Log(DEBUG, "apply service to service container")
		if err := servicediscovery.ApplyServices(p.sandbox, sc, srvs); err != nil {
			p.Log(ERROR, "failed to update services %#v: %v", srvs, err)
			return err
		}
	}
	p.services = srvs
	return nil
}
Beispiel #4
0
func (p *XPod) AddService(srvs []*apitypes.UserService) error {
	if p.globalSpec.Type != "service-discovery" {
		p.globalSpec.Type = "service-discovery"
		p.Log(INFO, "change pod type to service discovery")
		return p.NewServiceContainer(srvs)
	}
	p.resourceLock.Lock()
	defer p.resourceLock.Unlock()

	target := append(p.services, srvs...)

	if p.IsRunning() {
		sc := p.getServiceContainer()
		if err := servicediscovery.ApplyServices(p.sandbox, sc, target); err != nil {
			p.Log(ERROR, "failed to update services %#v: %v", target, err)
			return err
		}
	}
	p.services = target
	return nil
}
Beispiel #5
0
func (daemon *Daemon) AddService(podId string, srvs []pod.UserService) error {
	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return err
	}

	services, err := servicediscovery.GetServices(vm, container)
	if err != nil {
		return err
	}

	for _, s := range srvs {
		services = append(services, s)
	}

	if err := servicediscovery.ApplyServices(vm, container, services); err != nil {
		return err
	}

	return nil
}
Beispiel #6
0
func (daemon *Daemon) DeleteService(podId string, srvs []pod.UserService) error {
	var services []pod.UserService
	var services2 []pod.UserService
	var found int = 0

	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return err
	}

	services, err = servicediscovery.GetServices(vm, container)
	if err != nil {
		return err
	}

	for _, s := range services {
		shouldRemain := true
		for _, srv := range srvs {
			if s.ServiceIP == srv.ServiceIP && s.ServicePort == srv.ServicePort {
				shouldRemain = false
				found = 1
				break
			}
		}

		if shouldRemain {
			services2 = append(services2, s)
		}
	}

	if found == 0 {
		return fmt.Errorf("Pod %s doesn't use this service", podId)
	}

	if err := servicediscovery.ApplyServices(vm, container, services2); err != nil {
		return err
	}

	return nil
}