Beispiel #1
0
func (c *consulApplicator) GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error) {
	// TODO: Label selector result caching
	allMatches, _, err := c.kv.List(path.Join(labelRoot, labelType.String()), nil)
	if err != nil {
		return nil, err
	}

	res := []Labeled{}
	for _, kvp := range allMatches {
		l, err := convertKVPToLabeled(kvp)
		if err != nil {
			return res, err
		}
		if selector.Matches(l.Labels) {
			res = append(res, l)
		}
	}
	return res, nil
}
Beispiel #2
0
func (app *fakeApplicator) GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error) {
	forType, ok := app.data[labelType]
	if !ok {
		return []Labeled{}, nil
	}

	results := []Labeled{}

	for id, set := range forType {
		if selector.Matches(set) {
			results = append(results, Labeled{
				ID:        id,
				LabelType: labelType,
				Labels:    set,
			})
		}
	}

	return results, nil
}