Skip to content

Commit

Permalink
Merge pull request kubernetes#18476 from caesarxuchao/fix-query-convert
Browse files Browse the repository at this point in the history
Fix queryparams convert
  • Loading branch information
fgrzadkowski committed Dec 14, 2015
2 parents 0fba3e4 + 367872a commit 4ef062c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/client/unversioned/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
)

import (
"net/http"
"net/url"
"testing"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/labels"
)

func getDeploymentsResoureName() string {
Expand Down Expand Up @@ -175,3 +177,35 @@ func TestDeploymentWatch(t *testing.T) {
_, err := c.Setup(t).Deployments(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)
}

func TestListDeploymentsLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Extensions.GroupVersion().String())
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath("deployments", ns, ""),
Query: simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: simple.Response{
StatusCode: http.StatusOK,
Body: &extensions.DeploymentList{
Items: []extensions.Deployment{
{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
},
},
},
},
}
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
options := unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{selector}}
receivedPodList, err := c.Deployments(ns).List(options)
c.Validate(t, receivedPodList, err)
}
7 changes: 7 additions & 0 deletions pkg/conversion/queryparams/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"
"strings"

"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
)

Expand Down Expand Up @@ -144,6 +145,12 @@ func convertStruct(result url.Values, st reflect.Type, sv reflect.Value) {
addListOfParams(result, tag, omitempty, field)
}
case isStructKind(kind) && !(zeroValue(field) && omitempty):
if selector, ok := field.Interface().(unversioned.LabelSelector); ok {
addParam(result, tag, omitempty, reflect.ValueOf(selector.Selector.String()))
}
if selector, ok := field.Interface().(unversioned.FieldSelector); ok {
addParam(result, tag, omitempty, reflect.ValueOf(selector.Selector.String()))
}
convertStruct(result, ft, field)
}
}
Expand Down

0 comments on commit 4ef062c

Please sign in to comment.