From 3188e123a9831d16f0041eebd325e5590d46bb24 Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Thu, 29 Oct 2015 17:34:59 +0100 Subject: [PATCH] Add missing field label conversions Added missing field labels conversion functions for kinds: - ConfigMap - DaemonSet - Deployment - Endpoints - Event - Ingress - Job - PersistentVolume - PersistentVolumeClaim - ResourceQuota - Secret - Service Completed conversion functions of few other kinds: - Namespace - ServiceAccount Added tests suite for the above. Signed-off-by: Michal Minar --- pkg/api/testing/conversion.go | 72 +++++++++++++++++ pkg/api/v1/conversion.go | 79 +++++++++---------- pkg/apis/extensions/v1beta1/conversion.go | 32 ++++++++ pkg/registry/configmap/strategy_test.go | 12 +++ pkg/registry/controller/strategy_test.go | 12 +++ pkg/registry/daemonset/strategy_test.go | 36 +++++++++ pkg/registry/deployment/strategy_test.go | 36 +++++++++ pkg/registry/endpoint/strategy_test.go | 39 +++++++++ pkg/registry/event/strategy_test.go | 14 ++++ .../horizontalpodautoscaler/strategy_test.go | 36 +++++++++ pkg/registry/ingress/strategy_test.go | 12 +++ pkg/registry/job/strategy_test.go | 12 +++ pkg/registry/limitrange/strategy_test.go | 35 ++++++++ pkg/registry/namespace/strategy_test.go | 11 +++ pkg/registry/node/strategy_test.go | 12 +++ .../persistentvolume/strategy_test.go | 34 ++++++++ .../persistentvolumeclaim/strategy_test.go | 34 ++++++++ pkg/registry/pod/strategy_test.go | 12 +++ pkg/registry/podtemplate/strategy_test.go | 35 ++++++++ pkg/registry/resourcequota/strategy_test.go | 11 +++ pkg/registry/secret/strategy.go | 4 +- pkg/registry/secret/strategy_test.go | 11 +++ pkg/registry/service/strategy_test.go | 12 +++ pkg/registry/serviceaccount/strategy_test.go | 34 ++++++++ .../thirdpartyresource/strategy_test.go | 35 ++++++++ .../thirdpartyresourcedata/strategy_test.go | 35 ++++++++ 26 files changed, 664 insertions(+), 43 deletions(-) create mode 100644 pkg/api/testing/conversion.go create mode 100644 pkg/registry/daemonset/strategy_test.go create mode 100644 pkg/registry/deployment/strategy_test.go create mode 100644 pkg/registry/endpoint/strategy_test.go create mode 100644 pkg/registry/horizontalpodautoscaler/strategy_test.go create mode 100644 pkg/registry/limitrange/strategy_test.go create mode 100644 pkg/registry/persistentvolume/strategy_test.go create mode 100644 pkg/registry/persistentvolumeclaim/strategy_test.go create mode 100644 pkg/registry/podtemplate/strategy_test.go create mode 100644 pkg/registry/serviceaccount/strategy_test.go create mode 100644 pkg/registry/thirdpartyresource/strategy_test.go create mode 100644 pkg/registry/thirdpartyresourcedata/strategy_test.go diff --git a/pkg/api/testing/conversion.go b/pkg/api/testing/conversion.go new file mode 100644 index 0000000000..6f91427e71 --- /dev/null +++ b/pkg/api/testing/conversion.go @@ -0,0 +1,72 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/labels" +) + +// TestSelectableFieldLabelConversions verifies that given resource have field +// label conversion defined for each its selectable field. +// fields contains selectable fields of the resource. +// labelMap maps deprecated labels to their canonical names. +func TestSelectableFieldLabelConversionsOfKind(t *testing.T, apiVersion string, kind string, fields labels.Set, labelMap map[string]string) { + badFieldLabels := []string{ + "name", + ".name", + "bad", + "metadata", + "foo.bar", + } + + value := "value" + + if len(fields) == 0 { + t.Logf("no selectable fields for kind %q, skipping", kind) + } + for label := range fields { + if label == "name" { + t.Logf("FIXME: \"name\" is deprecated by \"metadata.name\", it should be removed from selectable fields of kind=%s", kind) + continue + } + newLabel, newValue, err := api.Scheme.ConvertFieldLabel(apiVersion, kind, label, value) + if err != nil { + t.Errorf("kind=%s label=%s: got unexpected error: %v", kind, label, err) + } else { + expectedLabel := label + if l, exists := labelMap[label]; exists { + expectedLabel = l + } + if newLabel != expectedLabel { + t.Errorf("kind=%s label=%s: got unexpected label name (%q != %q)", kind, label, newLabel, expectedLabel) + } + if newValue != value { + t.Errorf("kind=%s label=%s: got unexpected new value (%q != %q)", kind, label, newValue, value) + } + } + } + + for _, label := range badFieldLabels { + _, _, err := api.Scheme.ConvertFieldLabel(apiVersion, kind, label, "value") + if err == nil { + t.Errorf("kind=%s label=%s: got unexpected non-error", kind, label) + } + } +} diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index c235f4b9b0..d7ad8013f3 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -52,6 +52,30 @@ func addConversionFuncs(scheme *runtime.Scheme) { panic(err) } + // Add field label conversions for kinds having selectable nothing but ObjectMeta fields. + for _, kind := range []string{ + "Endpoints", + "ResourceQuota", + "PersistentVolumeClaim", + "Service", + "ServiceAccount", + } { + err = api.Scheme.AddFieldLabelConversionFunc("v1", kind, + func(label, value string) (string, string, error) { + switch label { + case "metadata.namespace", + "metadata.name": + return label, value, nil + default: + return "", "", fmt.Errorf("field label %q not supported for %q", label, kind) + } + }) + if err != nil { + // If one of the conversion functions is malformed, detect it immediately. + panic(err) + } + } + // Add field conversion funcs. err = api.Scheme.AddFieldLabelConversionFunc("v1", "Pod", func(label, value string) (string, string, error) { @@ -143,6 +167,19 @@ func addConversionFuncs(scheme *runtime.Scheme) { // If one of the conversion functions is malformed, detect it immediately. panic(err) } + err = api.Scheme.AddFieldLabelConversionFunc("v1", "PersistentVolume", + func(label, value string) (string, string, error) { + switch label { + case "metadata.name": + return label, value, nil + default: + return "", "", fmt.Errorf("field label not supported: %s", label) + } + }) + if err != nil { + // If one of the conversion functions is malformed, detect it immediately. + panic(err) + } err = api.Scheme.AddFieldLabelConversionFunc("v1", "Secret", func(label, value string) (string, string, error) { switch label { @@ -158,48 +195,6 @@ func addConversionFuncs(scheme *runtime.Scheme) { // If one of the conversion functions is malformed, detect it immediately. panic(err) } - err = api.Scheme.AddFieldLabelConversionFunc("v1", "ServiceAccount", - func(label, value string) (string, string, error) { - switch label { - case "metadata.name", - "metadata.namespace": - return label, value, nil - default: - return "", "", fmt.Errorf("field label not supported: %s", label) - } - }) - if err != nil { - // If one of the conversion functions is malformed, detect it immediately. - panic(err) - } - err = api.Scheme.AddFieldLabelConversionFunc("v1", "Endpoints", - func(label, value string) (string, string, error) { - switch label { - case "metadata.namespace", - "metadata.name": - return label, value, nil - default: - return "", "", fmt.Errorf("field label not supported: %s", label) - } - }) - if err != nil { - // If one of the conversion functions is malformed, detect it immediately. - panic(err) - } - err = api.Scheme.AddFieldLabelConversionFunc("v1", "Service", - func(label, value string) (string, string, error) { - switch label { - case "metadata.namespace", - "metadata.name": - return label, value, nil - default: - return "", "", fmt.Errorf("field label not supported: %s", label) - } - }) - if err != nil { - // If one of the conversion functions is malformed, detect it immediately. - panic(err) - } } func Convert_api_ReplicationControllerSpec_To_v1_ReplicationControllerSpec(in *api.ReplicationControllerSpec, out *ReplicationControllerSpec, s conversion.Scope) error { diff --git a/pkg/apis/extensions/v1beta1/conversion.go b/pkg/apis/extensions/v1beta1/conversion.go index 7228aa986c..f465c24d44 100644 --- a/pkg/apis/extensions/v1beta1/conversion.go +++ b/pkg/apis/extensions/v1beta1/conversion.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta1 import ( + "fmt" "reflect" "k8s.io/kubernetes/pkg/api" @@ -43,6 +44,37 @@ func addConversionFuncs(scheme *runtime.Scheme) { // If one of the conversion functions is malformed, detect it immediately. panic(err) } + + // Add field label conversions for kinds having selectable nothing but ObjectMeta fields. + for _, kind := range []string{"ConfigMap", "DaemonSet", "Deployment", "Ingress"} { + err = api.Scheme.AddFieldLabelConversionFunc("extensions/v1beta1", kind, + func(label, value string) (string, string, error) { + switch label { + case "metadata.name", "metadata.namespace": + return label, value, nil + default: + return "", "", fmt.Errorf("field label %q not supported for %q", label, kind) + } + }) + if err != nil { + // If one of the conversion functions is malformed, detect it immediately. + panic(err) + } + } + + err = api.Scheme.AddFieldLabelConversionFunc("extensions/v1beta1", "Job", + func(label, value string) (string, string, error) { + switch label { + case "metadata.name", "metadata.namespace", "status.successful": + return label, value, nil + default: + return "", "", fmt.Errorf("field label not supported: %s", label) + } + }) + if err != nil { + // If one of the conversion functions is malformed, detect it immediately. + panic(err) + } } // The following two PodSpec conversions functions where copied from pkg/api/conversion.go diff --git a/pkg/registry/configmap/strategy_test.go b/pkg/registry/configmap/strategy_test.go index 8cc4734222..47f0e68e8c 100644 --- a/pkg/registry/configmap/strategy_test.go +++ b/pkg/registry/configmap/strategy_test.go @@ -20,7 +20,10 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" ) func TestConfigMapStrategy(t *testing.T) { @@ -67,3 +70,12 @@ func TestConfigMapStrategy(t *testing.T) { t.Errorf("Expected a validation error") } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "ConfigMap", + labels.Set(ConfigMapToSelectableFields(&extensions.ConfigMap{})), + nil, + ) +} diff --git a/pkg/registry/controller/strategy_test.go b/pkg/registry/controller/strategy_test.go index afea95019d..bf530b584e 100644 --- a/pkg/registry/controller/strategy_test.go +++ b/pkg/registry/controller/strategy_test.go @@ -20,6 +20,9 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" ) func TestControllerStrategy(t *testing.T) { @@ -138,3 +141,12 @@ func TestControllerStatusStrategy(t *testing.T) { t.Errorf("Unexpected error %v", errs) } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "ReplicationController", + labels.Set(ControllerToSelectableFields(&api.ReplicationController{})), + nil, + ) +} diff --git a/pkg/registry/daemonset/strategy_test.go b/pkg/registry/daemonset/strategy_test.go new file mode 100644 index 0000000000..dd5ef836de --- /dev/null +++ b/pkg/registry/daemonset/strategy_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package daemonset + +import ( + "testing" + + _ "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "DaemonSet", + labels.Set(DaemonSetToSelectableFields(&extensions.DaemonSet{})), + nil, + ) +} diff --git a/pkg/registry/deployment/strategy_test.go b/pkg/registry/deployment/strategy_test.go new file mode 100644 index 0000000000..3d3d606ac2 --- /dev/null +++ b/pkg/registry/deployment/strategy_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package deployment + +import ( + "testing" + + _ "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "Deployment", + labels.Set(DeploymentToSelectableFields(&extensions.Deployment{})), + nil, + ) +} diff --git a/pkg/registry/endpoint/strategy_test.go b/pkg/registry/endpoint/strategy_test.go new file mode 100644 index 0000000000..915e5e6936 --- /dev/null +++ b/pkg/registry/endpoint/strategy_test.go @@ -0,0 +1,39 @@ +/* +Copyright 2014 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package endpoint + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + _, fieldsSet, err := EndpointsAttributes(&api.Endpoints{}) + if err != nil { + t.Fatal(err) + } + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Endpoints", + labels.Set(fieldsSet), + nil, + ) +} diff --git a/pkg/registry/event/strategy_test.go b/pkg/registry/event/strategy_test.go index 0e7ddc551f..bd9bc02e54 100644 --- a/pkg/registry/event/strategy_test.go +++ b/pkg/registry/event/strategy_test.go @@ -22,6 +22,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util" @@ -84,3 +85,16 @@ func TestGetAttrs(t *testing.T) { t.Errorf("diff: %s", util.ObjectDiff(e, a)) } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + _, fset, err := getAttrs(&api.Event{}) + if err != nil { + t.Fatalf("Unexpected error %v", err) + } + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Event", + labels.Set(fset), + nil, + ) +} diff --git a/pkg/registry/horizontalpodautoscaler/strategy_test.go b/pkg/registry/horizontalpodautoscaler/strategy_test.go new file mode 100644 index 0000000000..992238bae6 --- /dev/null +++ b/pkg/registry/horizontalpodautoscaler/strategy_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package horizontalpodautoscaler + +import ( + "testing" + + _ "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "Autoscaler", + labels.Set(AutoscalerToSelectableFields(&extensions.HorizontalPodAutoscaler{})), + nil, + ) +} diff --git a/pkg/registry/ingress/strategy_test.go b/pkg/registry/ingress/strategy_test.go index 00cd7df836..88cbeb3e53 100644 --- a/pkg/registry/ingress/strategy_test.go +++ b/pkg/registry/ingress/strategy_test.go @@ -20,7 +20,10 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util/intstr" ) @@ -128,3 +131,12 @@ func TestIngressStatusStrategy(t *testing.T) { t.Errorf("Unexpected error %v", errs) } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "Ingress", + labels.Set(IngressToSelectableFields(&extensions.Ingress{})), + nil, + ) +} diff --git a/pkg/registry/job/strategy_test.go b/pkg/registry/job/strategy_test.go index d04a8a5459..45b5a89b18 100644 --- a/pkg/registry/job/strategy_test.go +++ b/pkg/registry/job/strategy_test.go @@ -20,7 +20,10 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/labels" ) func TestJobStrategy(t *testing.T) { @@ -158,3 +161,12 @@ func TestJobStatusStrategy(t *testing.T) { t.Errorf("Incoming resource version on update should not be mutated") } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "Job", + labels.Set(JobToSelectableFields(&extensions.Job{})), + nil, + ) +} diff --git a/pkg/registry/limitrange/strategy_test.go b/pkg/registry/limitrange/strategy_test.go new file mode 100644 index 0000000000..38ceb8c238 --- /dev/null +++ b/pkg/registry/limitrange/strategy_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package limitrange + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "LimitRange", + labels.Set(LimitRangeToSelectableFields(&api.LimitRange{})), + nil, + ) +} diff --git a/pkg/registry/namespace/strategy_test.go b/pkg/registry/namespace/strategy_test.go index 49ba814601..fb06a302f9 100644 --- a/pkg/registry/namespace/strategy_test.go +++ b/pkg/registry/namespace/strategy_test.go @@ -20,6 +20,8 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/api/unversioned" ) @@ -130,3 +132,12 @@ func TestNamespaceFinalizeStrategy(t *testing.T) { t.Errorf("Incoming resource version on update should not be mutated") } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Namespace", + NamespaceToSelectableFields(&api.Namespace{}), + map[string]string{"name": "metadata.name"}, + ) +} diff --git a/pkg/registry/node/strategy_test.go b/pkg/registry/node/strategy_test.go index 4b0f998ea5..3a8552d2c6 100644 --- a/pkg/registry/node/strategy_test.go +++ b/pkg/registry/node/strategy_test.go @@ -19,6 +19,9 @@ package node import ( "testing" + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" ) @@ -43,3 +46,12 @@ func TestMatchNode(t *testing.T) { } } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Node", + labels.Set(NodeToSelectableFields(&api.Node{})), + nil, + ) +} diff --git a/pkg/registry/persistentvolume/strategy_test.go b/pkg/registry/persistentvolume/strategy_test.go new file mode 100644 index 0000000000..423aa7364e --- /dev/null +++ b/pkg/registry/persistentvolume/strategy_test.go @@ -0,0 +1,34 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package persistentvolume + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "PersistentVolume", + PersistentVolumeToSelectableFields(&api.PersistentVolume{}), + map[string]string{"name": "metadata.name"}, + ) +} diff --git a/pkg/registry/persistentvolumeclaim/strategy_test.go b/pkg/registry/persistentvolumeclaim/strategy_test.go new file mode 100644 index 0000000000..ecbdba3bd1 --- /dev/null +++ b/pkg/registry/persistentvolumeclaim/strategy_test.go @@ -0,0 +1,34 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package persistentvolumeclaim + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "PersistentVolumeClaim", + PersistentVolumeClaimToSelectableFields(&api.PersistentVolumeClaim{}), + map[string]string{"name": "metadata.name"}, + ) +} diff --git a/pkg/registry/pod/strategy_test.go b/pkg/registry/pod/strategy_test.go index 60f31531e9..17e746dd9b 100644 --- a/pkg/registry/pod/strategy_test.go +++ b/pkg/registry/pod/strategy_test.go @@ -22,6 +22,9 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/errors" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/runtime" ) @@ -167,3 +170,12 @@ func TestCheckLogLocation(t *testing.T) { } } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Pod", + labels.Set(PodToSelectableFields(&api.Pod{})), + nil, + ) +} diff --git a/pkg/registry/podtemplate/strategy_test.go b/pkg/registry/podtemplate/strategy_test.go new file mode 100644 index 0000000000..e26c13b86b --- /dev/null +++ b/pkg/registry/podtemplate/strategy_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package podtemplate + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "PodTemplate", + labels.Set(PodTemplateToSelectableFields(&api.PodTemplate{})), + nil, + ) +} diff --git a/pkg/registry/resourcequota/strategy_test.go b/pkg/registry/resourcequota/strategy_test.go index 32d1f71a30..9bc8a70ad4 100644 --- a/pkg/registry/resourcequota/strategy_test.go +++ b/pkg/registry/resourcequota/strategy_test.go @@ -21,6 +21,8 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/resource" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" ) func TestResourceQuotaStrategy(t *testing.T) { @@ -56,3 +58,12 @@ func TestResourceQuotaStrategy(t *testing.T) { t.Errorf("ResourceQuota does not allow setting status on create") } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "ResourceQuota", + ResourceQuotaToSelectableFields(&api.ResourceQuota{}), + nil, + ) +} diff --git a/pkg/registry/secret/strategy.go b/pkg/registry/secret/strategy.go index 18138e8c76..d06c86b330 100644 --- a/pkg/registry/secret/strategy.go +++ b/pkg/registry/secret/strategy.go @@ -107,7 +107,9 @@ func Matcher(label labels.Selector, field fields.Selector) generic.Matcher { // SelectableFields returns a label set that can be used for filter selection func SelectableFields(obj *api.Secret) labels.Set { - return labels.Set{ + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(obj.ObjectMeta, true) + secretSpecificFieldsSet := fields.Set{ "type": string(obj.Type), } + return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, secretSpecificFieldsSet)) } diff --git a/pkg/registry/secret/strategy_test.go b/pkg/registry/secret/strategy_test.go index 0ce8cf72d1..c9f2afdf6e 100644 --- a/pkg/registry/secret/strategy_test.go +++ b/pkg/registry/secret/strategy_test.go @@ -21,6 +21,8 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/runtime" ) @@ -97,3 +99,12 @@ func TestExportSecret(t *testing.T) { } } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Secret", + SelectableFields(&api.Secret{}), + nil, + ) +} diff --git a/pkg/registry/service/strategy_test.go b/pkg/registry/service/strategy_test.go index 5252d95744..89420a26f3 100644 --- a/pkg/registry/service/strategy_test.go +++ b/pkg/registry/service/strategy_test.go @@ -23,6 +23,9 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/rest" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/util/intstr" ) @@ -205,3 +208,12 @@ func TestBeforeUpdate(t *testing.T) { } } } + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "Service", + labels.Set(ServiceToSelectableFields(&api.Service{})), + nil, + ) +} diff --git a/pkg/registry/serviceaccount/strategy_test.go b/pkg/registry/serviceaccount/strategy_test.go new file mode 100644 index 0000000000..8530d24ff2 --- /dev/null +++ b/pkg/registry/serviceaccount/strategy_test.go @@ -0,0 +1,34 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package serviceaccount + +import ( + "testing" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Default.GroupVersion().String(), + "ServiceAccount", + SelectableFields(&api.ServiceAccount{}), + nil, + ) +} diff --git a/pkg/registry/thirdpartyresource/strategy_test.go b/pkg/registry/thirdpartyresource/strategy_test.go new file mode 100644 index 0000000000..cbe8f43903 --- /dev/null +++ b/pkg/registry/thirdpartyresource/strategy_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package thirdpartyresource + +import ( + "testing" + + _ "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/apis/extensions" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "ThirdPartyResource", + SelectableFields(&extensions.ThirdPartyResource{}), + nil, + ) +} diff --git a/pkg/registry/thirdpartyresourcedata/strategy_test.go b/pkg/registry/thirdpartyresourcedata/strategy_test.go new file mode 100644 index 0000000000..75e821944b --- /dev/null +++ b/pkg/registry/thirdpartyresourcedata/strategy_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package thirdpartyresourcedata + +import ( + "testing" + + _ "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/testapi" + apitesting "k8s.io/kubernetes/pkg/api/testing" + "k8s.io/kubernetes/pkg/apis/extensions" +) + +func TestSelectableFieldLabelConversions(t *testing.T) { + apitesting.TestSelectableFieldLabelConversionsOfKind(t, + testapi.Extensions.GroupVersion().String(), + "ThirdPartyResourceData", + SelectableFields(&extensions.ThirdPartyResourceData{}), + nil, + ) +}