mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-04 08:35:10 +00:00
published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub) copied from https://github.com/kubernetes/kubernetes.git, branch master, last commit is e56cfc5322138aa23e6418ee30a6ab54c7c6fe8c
This commit is contained in:
@@ -17,14 +17,16 @@ limitations under the License.
|
||||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/fields"
|
||||
"k8s.io/client-go/1.5/pkg/labels"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/fields"
|
||||
"k8s.io/client-go/pkg/labels"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
)
|
||||
|
||||
func NewRootGetAction(resource unversioned.GroupVersionResource, name string) GetActionImpl {
|
||||
@@ -46,36 +48,22 @@ func NewGetAction(resource unversioned.GroupVersionResource, namespace, name str
|
||||
return action
|
||||
}
|
||||
|
||||
func NewRootListAction(resource unversioned.GroupVersionResource, opts api.ListOptions) ListActionImpl {
|
||||
func NewRootListAction(resource unversioned.GroupVersionResource, opts interface{}) ListActionImpl {
|
||||
action := ListActionImpl{}
|
||||
action.Verb = "list"
|
||||
action.Resource = resource
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
|
||||
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
func NewListAction(resource unversioned.GroupVersionResource, namespace string, opts api.ListOptions) ListActionImpl {
|
||||
func NewListAction(resource unversioned.GroupVersionResource, namespace string, opts interface{}) ListActionImpl {
|
||||
action := ListActionImpl{}
|
||||
action.Verb = "list"
|
||||
action.Resource = resource
|
||||
action.Namespace = namespace
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
|
||||
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
|
||||
|
||||
return action
|
||||
@@ -202,72 +190,73 @@ func NewDeleteAction(resource unversioned.GroupVersionResource, namespace, name
|
||||
return action
|
||||
}
|
||||
|
||||
func NewRootDeleteCollectionAction(resource unversioned.GroupVersionResource, opts api.ListOptions) DeleteCollectionActionImpl {
|
||||
func NewRootDeleteCollectionAction(resource unversioned.GroupVersionResource, opts interface{}) DeleteCollectionActionImpl {
|
||||
action := DeleteCollectionActionImpl{}
|
||||
action.Verb = "delete-collection"
|
||||
action.Resource = resource
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
|
||||
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
func NewDeleteCollectionAction(resource unversioned.GroupVersionResource, namespace string, opts api.ListOptions) DeleteCollectionActionImpl {
|
||||
func NewDeleteCollectionAction(resource unversioned.GroupVersionResource, namespace string, opts interface{}) DeleteCollectionActionImpl {
|
||||
action := DeleteCollectionActionImpl{}
|
||||
action.Verb = "delete-collection"
|
||||
action.Resource = resource
|
||||
action.Namespace = namespace
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
|
||||
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
func NewRootWatchAction(resource unversioned.GroupVersionResource, opts api.ListOptions) WatchActionImpl {
|
||||
func NewRootWatchAction(resource unversioned.GroupVersionResource, opts interface{}) WatchActionImpl {
|
||||
action := WatchActionImpl{}
|
||||
action.Verb = "watch"
|
||||
action.Resource = resource
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, opts.ResourceVersion}
|
||||
labelSelector, fieldSelector, resourceVersion := ExtractFromListOptions(opts)
|
||||
action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, resourceVersion}
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
func NewWatchAction(resource unversioned.GroupVersionResource, namespace string, opts api.ListOptions) WatchActionImpl {
|
||||
func ExtractFromListOptions(opts interface{}) (labelSelector labels.Selector, fieldSelector fields.Selector, resourceVersion string) {
|
||||
var err error
|
||||
switch t := opts.(type) {
|
||||
case api.ListOptions:
|
||||
labelSelector = t.LabelSelector
|
||||
fieldSelector = t.FieldSelector
|
||||
resourceVersion = t.ResourceVersion
|
||||
case v1.ListOptions:
|
||||
labelSelector, err = labels.Parse(t.LabelSelector)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fieldSelector, err = fields.ParseSelector(t.FieldSelector)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resourceVersion = t.ResourceVersion
|
||||
default:
|
||||
panic(fmt.Errorf("expect a ListOptions"))
|
||||
}
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
return labelSelector, fieldSelector, resourceVersion
|
||||
}
|
||||
|
||||
func NewWatchAction(resource unversioned.GroupVersionResource, namespace string, opts interface{}) WatchActionImpl {
|
||||
action := WatchActionImpl{}
|
||||
action.Verb = "watch"
|
||||
action.Resource = resource
|
||||
action.Namespace = namespace
|
||||
labelSelector := opts.LabelSelector
|
||||
if labelSelector == nil {
|
||||
labelSelector = labels.Everything()
|
||||
}
|
||||
fieldSelector := opts.FieldSelector
|
||||
if fieldSelector == nil {
|
||||
fieldSelector = fields.Everything()
|
||||
}
|
||||
action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, opts.ResourceVersion}
|
||||
labelSelector, fieldSelector, resourceVersion := ExtractFromListOptions(opts)
|
||||
action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, resourceVersion}
|
||||
|
||||
return action
|
||||
}
|
||||
|
Reference in New Issue
Block a user