mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
fix watch of single object
This commit is contained in:
@@ -75,20 +75,17 @@ func (endpointsStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object
|
||||
|
||||
// MatchEndpoints returns a generic matcher for a given label and field selector.
|
||||
func MatchEndpoints(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
|
||||
endpoints, ok := obj.(*api.Endpoints)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("not a endpoints")
|
||||
}
|
||||
fields := EndpointsToSelectableFields(endpoints)
|
||||
return label.Matches(labels.Set(endpoints.Labels)) && field.Matches(fields), nil
|
||||
})
|
||||
return &generic.SelectionPredicate{label, field, EndpointsAttributes}
|
||||
}
|
||||
|
||||
// EndpointsToSelectableFields returns a label set that represents the object
|
||||
// TODO: fields are not labels, and the validation rules for them do not apply.
|
||||
func EndpointsToSelectableFields(endpoints *api.Endpoints) labels.Set {
|
||||
return labels.Set{
|
||||
"name": endpoints.Name,
|
||||
// EndpointsAttributes returns the attributes of an endpoint such that a
|
||||
// generic.SelectionPredicate can match appropriately.
|
||||
func EndpointsAttributes(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, err error) {
|
||||
endpoints, ok := obj.(*api.Endpoints)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("invalid object type %#v", obj)
|
||||
}
|
||||
return endpoints.Labels, fields.Set{
|
||||
"metadata.name": endpoints.Name,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user