本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.LabelSelectorQueryParam函数的典型用法代码示例。如果您正苦于以下问题:Golang LabelSelectorQueryParam函数的具体用法?Golang LabelSelectorQueryParam怎么用?Golang LabelSelectorQueryParam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LabelSelectorQueryParam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Watch
// Watch returns a watch.Interface that watches the requested pods.
func (c *pods) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("pods").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
FieldsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), field).
Watch()
}
示例2: TestSelector
func TestSelector(t *testing.T) {
pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version())
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
})).
SelectorParam("a=b").
NamespaceParam("test").
Flatten()
test := &testVisitor{}
singular := false
if b.Do().Err() == nil {
t.Errorf("unexpected non-error")
}
b.ResourceTypeOrNameArgs(true, "pods,service")
err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 3 {
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svc.Items[0]}, test.Objects()) {
t.Errorf("unexpected visited objects: %#v", test.Objects())
}
if _, err := b.Do().ResourceMapping(); err == nil {
t.Errorf("unexpected non-error")
}
}
示例3: TestListPodsLabels
func TestListPodsLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("pods", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
StatusCode: 200,
Body: &api.PodList{
Items: []api.Pod{
{
Status: api.PodStatus{
Phase: api.PodRunning,
},
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
},
},
},
},
}
c.Setup()
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.Pods(ns).List(selector, fields.Everything())
c.Validate(t, receivedPodList, err)
}
示例4: TestListObjectWithDifferentVersions
func TestListObjectWithDifferentVersions(t *testing.T) {
pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version())
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
})).
SelectorParam("a=b").
NamespaceParam("test").
ResourceTypeOrNameArgs(true, "pods,services").
Flatten().
Do().Object()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
list, ok := obj.(*api.List)
if !ok {
t.Fatalf("unexpected object: %#v", obj)
}
// resource version differs between type lists, so it's not possible to get a single version.
if list.ResourceVersion != "" || len(list.Items) != 3 {
t.Errorf("unexpected list: %#v", list)
}
}
示例5: TestListMinionsLabels
func TestListMinionsLabels(t *testing.T) {
ns := api.NamespaceNone
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
Query: buildQueryValues(ns, url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
StatusCode: 200,
Body: &api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
},
},
},
},
}
c.Setup()
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedNodeList, err := c.Nodes().List(selector, fields.Everything())
c.Validate(t, receivedNodeList, err)
}
示例6: TestDoRequestNewWayObj
func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqBodyExpected, _ := v1beta2.Codec.Encode(reqObj)
expectedObj := &api.Service{Spec: api.ServiceSpec{Port: 12345}}
expectedBody, _ := v1beta2.Codec.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"})
obj, err := c.Verb("POST").
Suffix("baz").
Name("bar").
Resource("foo").
LabelsSelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
Timeout(time.Second).
Body(reqObj).
Do().Get()
if err != nil {
t.Errorf("Unexpected error: %v %#v", err, err)
return
}
if obj == nil {
t.Error("nil obj")
} else if !api.Semantic.DeepDerivative(expectedObj, obj) {
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
}
tmpStr := string(reqBodyExpected)
fakeHandler.ValidateRequest(t, "/api/v1beta2/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
}
示例7: TestEventSearch
func TestEventSearch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", "baz", ""),
Query: url.Values{
api.FieldSelectorQueryParam(testapi.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,",
"involvedObject.namespace=baz,",
"involvedObject.kind=Pod",
},
api.LabelSelectorQueryParam(testapi.Version()): []string{},
},
},
Response: Response{StatusCode: 200, Body: &api.EventList{}},
}
eventList, err := c.Setup().Events("baz").Search(
&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: "baz",
SelfLink: testapi.SelfLink("pods", ""),
},
},
)
c.Validate(t, eventList, err)
}
示例8: TestListServicesLabels
func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, ""),
Query: buildQueryValues(ns, url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{StatusCode: 200,
Body: &api.ServiceList{
Items: []api.Service{
{
ObjectMeta: api.ObjectMeta{
Name: "name",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.ServiceSpec{
Selector: map[string]string{
"one": "two",
},
},
},
},
},
},
}
c.Setup()
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.Services(ns).List(selector)
c.Validate(t, receivedServiceList, err)
}
示例9: TestListObject
func TestListObject(t *testing.T) {
pods, _ := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version())
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
})).
SelectorParam("a=b").
NamespaceParam("test").
ResourceTypeOrNameArgs(true, "pods").
Flatten()
obj, err := b.Do().Object()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
list, ok := obj.(*api.List)
if !ok {
t.Fatalf("unexpected object: %#v", obj)
}
if list.ResourceVersion != pods.ResourceVersion || len(list.Items) != 2 {
t.Errorf("unexpected list: %#v", list)
}
mapping, err := b.Do().ResourceMapping()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mapping.Resource != "pods" {
t.Errorf("unexpected resource mapping: %#v", mapping)
}
}
示例10: List
func (m *Helper) List(namespace, apiVersion string, selector labels.Selector) (runtime.Object, error) {
return m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
LabelsSelectorParam(api.LabelSelectorQueryParam(apiVersion), selector).
Do().
Get()
}
示例11: LabelsSelectorParam
// LabelsSelectorParam adds the given selector as a query parameter
func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
if r.err != nil {
return r
}
if s.Empty() {
return r
}
return r.setParam(api.LabelSelectorQueryParam(r.apiVersion), s.String())
}
示例12: Watch
// Watch starts watching for secrets matching the given selectors.
func (s *secrets) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return s.client.Get().
Prefix("watch").
Namespace(s.namespace).
Resource("secrets").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
FieldsSelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
Watch()
}
示例13: Watch
// Watch starts watching for events matching the given selectors.
func (e *events) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return e.client.Get().
Prefix("watch").
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
Resource("events").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
Watch()
}
示例14: Watch
func (m *Helper) Watch(namespace, resourceVersion, apiVersion string, labelSelector labels.Selector, fieldSelector fields.Selector) (watch.Interface, error) {
return m.RESTClient.Get().
Prefix("watch").
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(api.LabelSelectorQueryParam(apiVersion), labelSelector).
FieldsSelectorParam(api.FieldSelectorQueryParam(apiVersion), fieldSelector).
Watch()
}
示例15: List
// List takes a selector, and returns the list of endpoints that match that selector
func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, err error) {
result = &api.EndpointsList{}
err = c.r.Get().
Namespace(c.ns).
Resource("endpoints").
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
Do().
Into(result)
return
}