// 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) { identityObj, ok := obj.(*api.Identity) if !ok { return false, fmt.Errorf("not an identity") } fields := api.IdentityToSelectableFields(identityObj) return label.Matches(labels.Set(identityObj.Labels)) && field.Matches(fields), nil }) }
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{}), ) }
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) } }
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 }
// SelectableFields returns a field set that can be used for filter selection func SelectableFields(obj *api.Identity) fields.Set { return api.IdentityToSelectableFields(obj) }