mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Fix loss of selector during RC/RS conversion.
The `out` parameter in Convert_map_to_unversioned_LabelSelector was being ignored.
This commit is contained in:
parent
5adfb24f8f
commit
f290819f75
@ -46,6 +46,7 @@ go_test(
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
|
@ -236,6 +236,7 @@ func Convert_v1_ReplicationController_to_extensions_ReplicaSet(in *v1.Replicatio
|
||||
func Convert_v1_ReplicationControllerSpec_to_extensions_ReplicaSetSpec(in *v1.ReplicationControllerSpec, out *extensions.ReplicaSetSpec, s conversion.Scope) error {
|
||||
out.Replicas = *in.Replicas
|
||||
if in.Selector != nil {
|
||||
out.Selector = new(metav1.LabelSelector)
|
||||
metav1.Convert_map_to_unversioned_LabelSelector(&in.Selector, out.Selector, s)
|
||||
}
|
||||
if in.Template != nil {
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
@ -31,6 +32,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
|
||||
// enforce that all types are installed
|
||||
_ "k8s.io/kubernetes/pkg/api/testapi"
|
||||
@ -226,3 +228,53 @@ func TestResourceListConversion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplicationControllerConversion(t *testing.T) {
|
||||
// If we start with a RC, we should always have round-trip fidelity.
|
||||
replicas := int32(1)
|
||||
in := &v1.ReplicationController{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "name",
|
||||
Namespace: "namespace",
|
||||
},
|
||||
Spec: v1.ReplicationControllerSpec{
|
||||
Replicas: &replicas,
|
||||
Selector: map[string]string{"foo": "bar", "bar": "foo"},
|
||||
Template: &v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{"foo": "bar", "bar": "foo"},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "container",
|
||||
Image: "image",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: v1.ReplicationControllerStatus{
|
||||
Replicas: 1,
|
||||
FullyLabeledReplicas: 2,
|
||||
ReadyReplicas: 3,
|
||||
AvailableReplicas: 4,
|
||||
ObservedGeneration: 5,
|
||||
Conditions: []v1.ReplicationControllerCondition{},
|
||||
},
|
||||
}
|
||||
in = roundTrip(t, in).(*v1.ReplicationController)
|
||||
rs := &extensions.ReplicaSet{}
|
||||
if err := k8s_api_v1.Convert_v1_ReplicationController_to_extensions_ReplicaSet(in, rs, nil); err != nil {
|
||||
t.Fatalf("can't convert RC to RS: %v", err)
|
||||
}
|
||||
out := &v1.ReplicationController{}
|
||||
if err := k8s_api_v1.Convert_extensions_ReplicaSet_to_v1_ReplicationController(rs, out, nil); err != nil {
|
||||
t.Fatalf("can't convert RS to RC: %v", err)
|
||||
}
|
||||
if !apiequality.Semantic.DeepEqual(in, out) {
|
||||
instr, _ := json.MarshalIndent(in, "", " ")
|
||||
outstr, _ := json.MarshalIndent(out, "", " ")
|
||||
t.Errorf("RC-RS conversion round-trip failed:\nin:\n%s\nout:\n%s", instr, outstr)
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +252,6 @@ func Convert_map_to_unversioned_LabelSelector(in *map[string]string, out *LabelS
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out = new(LabelSelector)
|
||||
for labelKey, labelValue := range *in {
|
||||
AddLabelToSelector(out, labelKey, labelValue)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user