Ejemplo n.º 1
0
// Matcher returns a generic matcher for a given label and field selector.
func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
	return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
		groupObj, ok := obj.(*api.Group)
		if !ok {
			return false, fmt.Errorf("not a group")
		}
		fields := api.GroupToSelectableFields(groupObj)
		return label.Matches(labels.Set(groupObj.Labels)) && field.Matches(fields), nil
	})
}
Ejemplo n.º 2
0
func TestFieldSelectorConversions(t *testing.T) {
	testutil.CheckFieldLabelConversions(t, "v1", "Group",
		// Ensure all currently returned labels are supported
		api.GroupToSelectableFields(&api.Group{}),
	)

	testutil.CheckFieldLabelConversions(t, "v1", "Identity",
		// Ensure all currently returned labels are supported
		api.IdentityToSelectableFields(&api.Identity{}),
		// Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST
		"providerName", "providerUserName", "user.name", "user.uid",
	)

	testutil.CheckFieldLabelConversions(t, "v1", "User",
		// Ensure all currently returned labels are supported
		api.UserToSelectableFields(&api.User{}),
	)
}
Ejemplo n.º 3
0
func init() {
	if err := kapi.Scheme.AddFieldLabelConversionFunc("v1", "Group",
		oapi.GetFieldLabelConversionFunc(api.GroupToSelectableFields(&api.Group{}), nil),
	); err != nil {
		panic(err)
	}

	if err := kapi.Scheme.AddFieldLabelConversionFunc("v1", "Identity",
		oapi.GetFieldLabelConversionFunc(api.IdentityToSelectableFields(&api.Identity{}), nil),
	); err != nil {
		panic(err)
	}

	if err := kapi.Scheme.AddFieldLabelConversionFunc("v1", "User",
		oapi.GetFieldLabelConversionFunc(api.UserToSelectableFields(&api.User{}), nil),
	); err != nil {
		panic(err)
	}
}
Ejemplo n.º 4
0
func addConversionFuncs(scheme *runtime.Scheme) error {
	if err := scheme.AddFieldLabelConversionFunc("v1", "Group",
		oapi.GetFieldLabelConversionFunc(api.GroupToSelectableFields(&api.Group{}), nil),
	); err != nil {
		return err
	}

	if err := scheme.AddFieldLabelConversionFunc("v1", "Identity",
		oapi.GetFieldLabelConversionFunc(api.IdentityToSelectableFields(&api.Identity{}), nil),
	); err != nil {
		return err
	}

	if err := scheme.AddFieldLabelConversionFunc("v1", "User",
		oapi.GetFieldLabelConversionFunc(api.UserToSelectableFields(&api.User{}), nil),
	); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 5
0
// SelectableFields returns a field set that can be used for filter selection
func SelectableFields(obj *api.Group) fields.Set {
	return api.GroupToSelectableFields(obj)
}