pass labelSelector to server side opaquely

This commit is contained in:
Di Xu
2017-09-25 14:32:52 +08:00
parent 57688bb64b
commit 279065aa6c
11 changed files with 39 additions and 54 deletions

View File

@@ -21,7 +21,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/watch"
)
@@ -30,13 +29,13 @@ type Selector struct {
Client RESTClient
Mapping *meta.RESTMapping
Namespace string
Selector labels.Selector
Selector string
Export bool
IncludeUninitialized bool
}
// NewSelector creates a resource selector which hides details of getting items by their label selector.
func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string, selector labels.Selector, export, includeUninitialized bool) *Selector {
func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string, selector string, export, includeUninitialized bool) *Selector {
return &Selector{
Client: client,
Mapping: mapping,
@@ -54,14 +53,14 @@ func (r *Selector) Visit(fn VisitorFunc) error {
if errors.IsBadRequest(err) || errors.IsNotFound(err) {
if se, ok := err.(*errors.StatusError); ok {
// modify the message without hiding this is an API error
if r.Selector.Empty() {
if len(r.Selector) == 0 {
se.ErrStatus.Message = fmt.Sprintf("Unable to list %q: %v", r.Mapping.Resource, se.ErrStatus.Message)
} else {
se.ErrStatus.Message = fmt.Sprintf("Unable to find %q that match the selector %q: %v", r.Mapping.Resource, r.Selector, se.ErrStatus.Message)
}
return se
}
if r.Selector.Empty() {
if len(r.Selector) == 0 {
return fmt.Errorf("Unable to list %q: %v", r.Mapping.Resource, err)
} else {
return fmt.Errorf("Unable to find %q that match the selector %q: %v", r.Mapping.Resource, r.Selector, err)