mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	Merge pull request #18476 from caesarxuchao/fix-query-convert
Fix queryparams convert
This commit is contained in:
		| @@ -22,6 +22,7 @@ import ( | ||||
| ) | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"testing" | ||||
|  | ||||
| @@ -29,6 +30,7 @@ import ( | ||||
| 	"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 { | ||||
| @@ -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) | ||||
| } | ||||
|   | ||||
| @@ -22,6 +22,7 @@ import ( | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
|  | ||||
| 	"k8s.io/kubernetes/pkg/api/unversioned" | ||||
| 	"k8s.io/kubernetes/pkg/runtime" | ||||
| ) | ||||
|  | ||||
| @@ -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) | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Filip Grzadkowski
					Filip Grzadkowski