コード例 #1
0
func (c *Controller) purgeStaleServiceRefs(fip *types.FloatingIp, refs contrail.ReferenceList, podIdMap map[string]*api.Pod) {
	update := false
	for _, ref := range refs {
		vmi, err := types.VirtualMachineInterfaceByUuid(c.client, ref.Uuid)
		if err != nil {
			glog.Errorf("%v", err)
			continue
		}
		instanceRefs, err := vmi.GetVirtualMachineRefs()
		if err != nil {
			glog.Errorf("%v", err)
			continue
		}
		if len(instanceRefs) == 0 {
			continue
		}
		if _, ok := podIdMap[instanceRefs[0].Uuid]; ok {
			continue
		}
		glog.V(3).Infof("Delete reference from pod %s to %s", ref.Uuid, fip.GetFloatingIpAddress())
		fip.DeleteVirtualMachineInterface(vmi.GetUuid())
		update = true
	}

	if update {
		err := c.client.Update(fip)
		if err != nil {
			glog.Errorf("%v", err)
		}
	}
}
コード例 #2
0
func (c *consistencyChecker) vmiCompare(pod *api.Pod, interfaceId string) bool {
	vmi, err := types.VirtualMachineInterfaceByUuid(c.client, interfaceId)
	if err != nil {
		return false
	}

	var serviceIpNames sort.StringSlice
	refs, err := vmi.GetFloatingIpBackRefs()
	if err == nil {
		serviceIpMap := make(map[string]bool)
		for _, ref := range refs {
			name := strings.Join(ref.To, ":")
			if _, ok := serviceIpMap[name]; !ok {
				serviceIpMap[name] = true
				serviceIpNames = append(serviceIpNames, name)
			}
		}
	}
	serviceIpNames.Sort()

	var serviceCacheNames sort.StringSlice
	services, err := c.serviceStore.GetPodServices(pod)
	if err == nil {
		for _, service := range services {
			serviceName := ServiceName(c.config, service.Labels)
			serviceNet := fmt.Sprintf(ServiceNetworkFmt, serviceName)
			fqn := []string{c.config.DefaultDomain, service.Namespace, serviceNet, serviceNet, service.Name}
			if service.Spec.ClusterIP != "" {
				serviceCacheNames = append(serviceCacheNames, strings.Join(fqn, ":"))
			}
			if service.Spec.Type == api.ServiceTypeLoadBalancer || len(service.Spec.ExternalIPs) > 0 {
				publicFQN := strings.Split(c.config.PublicNetwork, ":")
				id := fmt.Sprintf("%s:%s:%s_%s",
					c.config.PublicNetwork, publicFQN[len(publicFQN)-1], service.Namespace, service.Name)
				serviceCacheNames = append(serviceCacheNames, id)
			}
		}
	}
	serviceCacheNames.Sort()

	result := CompareSortedLists(
		serviceCacheNames,
		serviceIpNames,
		func(key string) {
			glog.Errorf("interface %s: missing floating-ip for %s", vmi.GetName(), key)
		},
		func(key string) {
			glog.Errorf("interface %s: invalid floating-ip %s", vmi.GetName(), key)
		},
		func(key string) bool {
			return true
		},
	)
	return result
}
コード例 #3
0
func (c *consistencyChecker) vmiCompare(pod *api.Pod, interfaceId string) bool {
	vmi, err := types.VirtualMachineInterfaceByUuid(c.client, interfaceId)
	if err != nil {
		return false
	}

	var serviceIpNames sort.StringSlice
	refs, err := vmi.GetFloatingIpBackRefs()
	if err == nil {
		serviceIpMap := make(map[string]bool)
		for _, ref := range refs {
			name := ref.To[len(ref.To)-1]
			if _, ok := serviceIpMap[name]; !ok {
				serviceIpMap[name] = true
				serviceIpNames = append(serviceIpNames, name)
			}
		}
	}
	serviceIpNames.Sort()

	var serviceCacheNames sort.StringSlice
	services, err := c.serviceStore.GetPodServices(pod)
	if err == nil {
		for _, service := range services {
			serviceCacheNames = append(serviceCacheNames, service.Name)
		}
	}
	serviceCacheNames.Sort()

	result := CompareSortedLists(
		serviceCacheNames,
		serviceIpNames,
		func(key string) {
			glog.Errorf("interface %s: missing floating-ip for %s", vmi.GetName(), key)
		},
		func(key string) {
			glog.Errorf("interface %s: invalid floating-ip %s", vmi.GetName(), key)
		},
		func(key string) bool {
			return true
		},
	)
	return result
}
コード例 #4
0
func getFloatingIpToInstanceList(client contrail.ApiClient, fip *types.FloatingIp) ([]string, error) {
	vmList := make([]string, 0)
	refs, err := fip.GetVirtualMachineInterfaceRefs()
	if err != nil {
		return vmList, err
	}
	for _, ref := range refs {
		vmi, err := types.VirtualMachineInterfaceByUuid(client, ref.Uuid)
		if err != nil {
			continue
		}
		instanceRefs, err := vmi.GetVirtualMachineRefs()
		if err != nil || len(instanceRefs) == 0 {
			continue
		}
		vmList = append(vmList, instanceRefs[0].Uuid)
	}
	return vmList, nil
}