mirror of https://github.com/k3s-io/k3s
Support Node/NodeList as a valid name in all versions
Also refactor v1beta1/conversion_test.go `v1beta` -> `current` to allow easier cut and paste of tests.pull/6/head
parent
5447e74129
commit
650aead4c4
|
@ -46,6 +46,9 @@ func init() {
|
|||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
)
|
||||
// Legacy names are supported
|
||||
Scheme.AddKnownTypeWithName("", "Node", &Minion{})
|
||||
Scheme.AddKnownTypeWithName("", "NodeList", &MinionList{})
|
||||
}
|
||||
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
|
|
|
@ -21,13 +21,36 @@ import (
|
|||
"testing"
|
||||
|
||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
)
|
||||
|
||||
var Convert = newer.Scheme.Convert
|
||||
|
||||
func TestNodeConversion(t *testing.T) {
|
||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.Minion); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.MinionList); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj = &newer.Node{}
|
||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvConversion(t *testing.T) {
|
||||
nonCanonical := []v1beta1.EnvVar{
|
||||
nonCanonical := []current.EnvVar{
|
||||
{Key: "EV"},
|
||||
{Key: "EV", Name: "EX"},
|
||||
}
|
||||
|
@ -48,7 +71,7 @@ func TestEnvConversion(t *testing.T) {
|
|||
|
||||
// Test conversion the other way, too.
|
||||
for i := range canonical {
|
||||
var got v1beta1.EnvVar
|
||||
var got current.EnvVar
|
||||
err := Convert(&canonical[i], &got)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -65,15 +88,15 @@ func TestEnvConversion(t *testing.T) {
|
|||
func TestVolumeMountConversionToOld(t *testing.T) {
|
||||
table := []struct {
|
||||
in newer.VolumeMount
|
||||
out v1beta1.VolumeMount
|
||||
out current.VolumeMount
|
||||
}{
|
||||
{
|
||||
in: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
out: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
|
||||
out: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
|
||||
},
|
||||
}
|
||||
for _, item := range table {
|
||||
got := v1beta1.VolumeMount{}
|
||||
got := current.VolumeMount{}
|
||||
err := Convert(&item.in, &got)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
|
@ -87,17 +110,17 @@ func TestVolumeMountConversionToOld(t *testing.T) {
|
|||
|
||||
func TestVolumeMountConversionToNew(t *testing.T) {
|
||||
table := []struct {
|
||||
in v1beta1.VolumeMount
|
||||
in current.VolumeMount
|
||||
out newer.VolumeMount
|
||||
}{
|
||||
{
|
||||
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
}, {
|
||||
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
|
||||
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
|
||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
}, {
|
||||
in: v1beta1.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
|
||||
in: current.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
|
||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
|
||||
},
|
||||
}
|
||||
|
@ -115,13 +138,13 @@ func TestVolumeMountConversionToNew(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMinionListConversionToNew(t *testing.T) {
|
||||
oldMinion := func(id string) v1beta1.Minion {
|
||||
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
|
||||
oldMinion := func(id string) current.Minion {
|
||||
return current.Minion{TypeMeta: current.TypeMeta{ID: id}}
|
||||
}
|
||||
newMinion := func(id string) newer.Minion {
|
||||
return newer.Minion{ObjectMeta: newer.ObjectMeta{Name: id}}
|
||||
}
|
||||
oldMinions := []v1beta1.Minion{
|
||||
oldMinions := []current.Minion{
|
||||
oldMinion("foo"),
|
||||
oldMinion("bar"),
|
||||
}
|
||||
|
@ -131,19 +154,19 @@ func TestMinionListConversionToNew(t *testing.T) {
|
|||
}
|
||||
|
||||
table := []struct {
|
||||
oldML *v1beta1.MinionList
|
||||
oldML *current.MinionList
|
||||
newML *newer.MinionList
|
||||
}{
|
||||
{
|
||||
oldML: &v1beta1.MinionList{Items: oldMinions},
|
||||
oldML: ¤t.MinionList{Items: oldMinions},
|
||||
newML: &newer.MinionList{Items: newMinions},
|
||||
}, {
|
||||
oldML: &v1beta1.MinionList{Minions: oldMinions},
|
||||
oldML: ¤t.MinionList{Minions: oldMinions},
|
||||
newML: &newer.MinionList{Items: newMinions},
|
||||
}, {
|
||||
oldML: &v1beta1.MinionList{
|
||||
oldML: ¤t.MinionList{
|
||||
Items: oldMinions,
|
||||
Minions: []v1beta1.Minion{oldMinion("baz")},
|
||||
Minions: []current.Minion{oldMinion("baz")},
|
||||
},
|
||||
newML: &newer.MinionList{Items: newMinions},
|
||||
},
|
||||
|
@ -162,13 +185,13 @@ func TestMinionListConversionToNew(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMinionListConversionToOld(t *testing.T) {
|
||||
oldMinion := func(id string) v1beta1.Minion {
|
||||
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
|
||||
oldMinion := func(id string) current.Minion {
|
||||
return current.Minion{TypeMeta: current.TypeMeta{ID: id}}
|
||||
}
|
||||
newMinion := func(id string) newer.Minion {
|
||||
return newer.Minion{ObjectMeta: newer.ObjectMeta{Name: id}}
|
||||
}
|
||||
oldMinions := []v1beta1.Minion{
|
||||
oldMinions := []current.Minion{
|
||||
oldMinion("foo"),
|
||||
oldMinion("bar"),
|
||||
}
|
||||
|
@ -178,12 +201,12 @@ func TestMinionListConversionToOld(t *testing.T) {
|
|||
}
|
||||
|
||||
newML := &newer.MinionList{Items: newMinions}
|
||||
oldML := &v1beta1.MinionList{
|
||||
oldML := ¤t.MinionList{
|
||||
Items: oldMinions,
|
||||
Minions: oldMinions,
|
||||
}
|
||||
|
||||
got := &v1beta1.MinionList{}
|
||||
got := ¤t.MinionList{}
|
||||
err := Convert(newML, got)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
|
@ -195,7 +218,7 @@ func TestMinionListConversionToOld(t *testing.T) {
|
|||
|
||||
func TestServiceEmptySelector(t *testing.T) {
|
||||
// Nil map should be preserved
|
||||
svc := &v1beta1.Service{Selector: nil}
|
||||
svc := ¤t.Service{Selector: nil}
|
||||
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta1")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -210,7 +233,7 @@ func TestServiceEmptySelector(t *testing.T) {
|
|||
}
|
||||
|
||||
// Empty map should be preserved
|
||||
svc2 := &v1beta1.Service{Selector: map[string]string{}}
|
||||
svc2 := ¤t.Service{Selector: map[string]string{}}
|
||||
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta1")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
|
@ -51,6 +51,9 @@ func init() {
|
|||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
)
|
||||
// Future names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{})
|
||||
api.Scheme.AddKnownTypeWithName("v1beta1", "NodeList", &MinionList{})
|
||||
}
|
||||
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
|
|
|
@ -20,12 +20,12 @@ import (
|
|||
"testing"
|
||||
|
||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
)
|
||||
|
||||
func TestServiceEmptySelector(t *testing.T) {
|
||||
// Nil map should be preserved
|
||||
svc := &v1beta2.Service{Selector: nil}
|
||||
svc := ¤t.Service{Selector: nil}
|
||||
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta2")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -40,7 +40,7 @@ func TestServiceEmptySelector(t *testing.T) {
|
|||
}
|
||||
|
||||
// Empty map should be preserved
|
||||
svc2 := &v1beta2.Service{Selector: map[string]string{}}
|
||||
svc2 := ¤t.Service{Selector: map[string]string{}}
|
||||
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta2")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -54,3 +54,26 @@ func TestServiceEmptySelector(t *testing.T) {
|
|||
t.Errorf("unexpected selector: %#v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeConversion(t *testing.T) {
|
||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.Minion); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta2"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.MinionList); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj = &newer.Node{}
|
||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`), obj); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,9 @@ func init() {
|
|||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
)
|
||||
// Future names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta2", "Node", &Minion{})
|
||||
api.Scheme.AddKnownTypeWithName("v1beta2", "NodeList", &MinionList{})
|
||||
}
|
||||
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright 2014 Google Inc. 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 v1beta3_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
)
|
||||
|
||||
func TestNodeConversion(t *testing.T) {
|
||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.Minion); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj, err = current.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*newer.MinionList); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj = &newer.Node{}
|
||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
|
@ -47,6 +47,9 @@ func init() {
|
|||
&Event{},
|
||||
&EventList{},
|
||||
)
|
||||
// Legacy names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta3", "Minion", &Node{})
|
||||
api.Scheme.AddKnownTypeWithName("v1beta3", "MinionList", &NodeList{})
|
||||
}
|
||||
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
|
|
Loading…
Reference in New Issue