mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Don't rename api imports in conversions
This commit is contained in:
parent
d689ba9b01
commit
70c94fad6d
@ -56,8 +56,6 @@ func main() {
|
|||||||
generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw())
|
generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw())
|
||||||
// TODO(wojtek-t): Change the overwrites to a flag.
|
// TODO(wojtek-t): Change the overwrites to a flag.
|
||||||
generator.OverwritePackage(*version, "")
|
generator.OverwritePackage(*version, "")
|
||||||
// TODO(wojtek-t): Get rid of this overwrite.
|
|
||||||
generator.OverwritePackage("api", "newer")
|
|
||||||
for _, knownType := range api.Scheme.KnownTypes(*version) {
|
for _, knownType := range api.Scheme.KnownTypes(*version) {
|
||||||
if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
|
if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
|
||||||
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
|
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
|
||||||
|
@ -255,7 +255,7 @@ regenerate auto-generated ones. To regenerate them:
|
|||||||
```
|
```
|
||||||
- replace all conversion functions (convert\* functions) in the
|
- replace all conversion functions (convert\* functions) in the
|
||||||
`pkg/api/<version>/conversion_generated.go` with the contents of \<file1.txt\>
|
`pkg/api/<version>/conversion_generated.go` with the contents of \<file1.txt\>
|
||||||
- replace arguments of `newer.Scheme.AddGeneratedConversionFuncs` in the
|
- replace arguments of `api.Scheme.AddGeneratedConversionFuncs` in the
|
||||||
`pkg/api/<version>/conversion_generated.go` with the contents of \<file2.txt\>
|
`pkg/api/<version>/conversion_generated.go` with the contents of \<file2.txt\>
|
||||||
|
|
||||||
Unsurprisingly, adding manually written conversion also requires you to add tests to
|
Unsurprisingly, adding manually written conversion also requires you to add tests to
|
||||||
|
@ -34,7 +34,7 @@ package ${version}
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||||
)
|
)
|
||||||
|
@ -19,18 +19,18 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addConversionFuncs() {
|
func addConversionFuncs() {
|
||||||
err := newer.Scheme.AddConversionFuncs()
|
err := api.Scheme.AddConversionFuncs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add field conversion funcs.
|
// Add field conversion funcs.
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Pod",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Pod",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name",
|
case "metadata.name",
|
||||||
@ -46,7 +46,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Node",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Node",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name":
|
case "metadata.name":
|
||||||
@ -61,7 +61,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "ReplicationController",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "ReplicationController",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name",
|
case "metadata.name",
|
||||||
@ -75,7 +75,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Event",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Event",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "involvedObject.kind",
|
case "involvedObject.kind",
|
||||||
@ -96,7 +96,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Namespace",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Namespace",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "status.phase":
|
case "status.phase":
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,29 +19,29 @@ package v1_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeConversion(t *testing.T) {
|
func TestNodeConversion(t *testing.T) {
|
||||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1"}`))
|
obj, err := versioned.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.Node); !ok {
|
if _, ok := obj.(*api.Node); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err = current.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1"}`))
|
obj, err = versioned.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.NodeList); !ok {
|
if _, ok := obj.(*api.NodeList); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1"}`), obj); err != nil {
|
if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1"}`), obj); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,16 +21,16 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Convert = newer.Scheme.Convert
|
var Convert = api.Scheme.Convert
|
||||||
|
|
||||||
func TestEmptyObjectConversion(t *testing.T) {
|
func TestEmptyObjectConversion(t *testing.T) {
|
||||||
s, err := current.Codec.Encode(¤t.LimitRange{})
|
s, err := versioned.Codec.Encode(&versioned.LimitRange{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ func TestEmptyObjectConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeConversion(t *testing.T) {
|
func TestNodeConversion(t *testing.T) {
|
||||||
version, kind, err := newer.Scheme.ObjectVersionAndKind(¤t.Minion{})
|
version, kind, err := api.Scheme.ObjectVersionAndKind(&versioned.Minion{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -49,30 +49,30 @@ func TestNodeConversion(t *testing.T) {
|
|||||||
t.Errorf("unexpected version and kind: %s %s", version, kind)
|
t.Errorf("unexpected version and kind: %s %s", version, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
newer.Scheme.Log(t)
|
api.Scheme.Log(t)
|
||||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`))
|
obj, err := versioned.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.Node); !ok {
|
if _, ok := obj.(*api.Node); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`))
|
obj, err = versioned.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.NodeList); !ok {
|
if _, ok := obj.(*api.NodeList); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil {
|
if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
data, err := current.Codec.Encode(obj)
|
data, err := versioned.Codec.Encode(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -86,16 +86,16 @@ func TestNodeConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvConversion(t *testing.T) {
|
func TestEnvConversion(t *testing.T) {
|
||||||
nonCanonical := []current.EnvVar{
|
nonCanonical := []versioned.EnvVar{
|
||||||
{Key: "EV"},
|
{Key: "EV"},
|
||||||
{Key: "EV", Name: "EX"},
|
{Key: "EV", Name: "EX"},
|
||||||
}
|
}
|
||||||
canonical := []newer.EnvVar{
|
canonical := []api.EnvVar{
|
||||||
{Name: "EV"},
|
{Name: "EV"},
|
||||||
{Name: "EX"},
|
{Name: "EX"},
|
||||||
}
|
}
|
||||||
for i := range nonCanonical {
|
for i := range nonCanonical {
|
||||||
var got newer.EnvVar
|
var got api.EnvVar
|
||||||
err := Convert(&nonCanonical[i], &got)
|
err := Convert(&nonCanonical[i], &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
@ -107,7 +107,7 @@ func TestEnvConversion(t *testing.T) {
|
|||||||
|
|
||||||
// Test conversion the other way, too.
|
// Test conversion the other way, too.
|
||||||
for i := range canonical {
|
for i := range canonical {
|
||||||
var got current.EnvVar
|
var got versioned.EnvVar
|
||||||
err := Convert(&canonical[i], &got)
|
err := Convert(&canonical[i], &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
@ -123,16 +123,16 @@ func TestEnvConversion(t *testing.T) {
|
|||||||
|
|
||||||
func TestVolumeMountConversionToOld(t *testing.T) {
|
func TestVolumeMountConversionToOld(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
in newer.VolumeMount
|
in api.VolumeMount
|
||||||
out current.VolumeMount
|
out versioned.VolumeMount
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
in: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
in: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||||
out: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
|
out: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
got := current.VolumeMount{}
|
got := versioned.VolumeMount{}
|
||||||
err := Convert(&item.in, &got)
|
err := Convert(&item.in, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
@ -146,22 +146,22 @@ func TestVolumeMountConversionToOld(t *testing.T) {
|
|||||||
|
|
||||||
func TestVolumeMountConversionToNew(t *testing.T) {
|
func TestVolumeMountConversionToNew(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
in current.VolumeMount
|
in versioned.VolumeMount
|
||||||
out newer.VolumeMount
|
out api.VolumeMount
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
in: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
out: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||||
}, {
|
}, {
|
||||||
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
|
in: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
|
||||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
out: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||||
}, {
|
}, {
|
||||||
in: current.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
|
in: versioned.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
|
||||||
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
|
out: api.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
got := newer.VolumeMount{}
|
got := api.VolumeMount{}
|
||||||
err := Convert(&item.in, &got)
|
err := Convert(&item.in, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
@ -174,116 +174,116 @@ func TestVolumeMountConversionToNew(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMinionListConversionToNew(t *testing.T) {
|
func TestMinionListConversionToNew(t *testing.T) {
|
||||||
oldMinion := func(id string) current.Minion {
|
oldMinion := func(id string) versioned.Minion {
|
||||||
return current.Minion{
|
return versioned.Minion{
|
||||||
TypeMeta: current.TypeMeta{ID: id},
|
TypeMeta: versioned.TypeMeta{ID: id},
|
||||||
ExternalID: id}
|
ExternalID: id}
|
||||||
}
|
}
|
||||||
newNode := func(id string) newer.Node {
|
newNode := func(id string) api.Node {
|
||||||
return newer.Node{
|
return api.Node{
|
||||||
ObjectMeta: newer.ObjectMeta{Name: id},
|
ObjectMeta: api.ObjectMeta{Name: id},
|
||||||
Spec: newer.NodeSpec{ExternalID: id},
|
Spec: api.NodeSpec{ExternalID: id},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldMinions := []current.Minion{
|
oldMinions := []versioned.Minion{
|
||||||
oldMinion("foo"),
|
oldMinion("foo"),
|
||||||
oldMinion("bar"),
|
oldMinion("bar"),
|
||||||
}
|
}
|
||||||
newMinions := []newer.Node{
|
newMinions := []api.Node{
|
||||||
newNode("foo"),
|
newNode("foo"),
|
||||||
newNode("bar"),
|
newNode("bar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
oldML *current.MinionList
|
oldML *versioned.MinionList
|
||||||
newML *newer.NodeList
|
newML *api.NodeList
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
oldML: ¤t.MinionList{Items: oldMinions},
|
oldML: &versioned.MinionList{Items: oldMinions},
|
||||||
newML: &newer.NodeList{Items: newMinions},
|
newML: &api.NodeList{Items: newMinions},
|
||||||
}, {
|
}, {
|
||||||
oldML: ¤t.MinionList{Minions: oldMinions},
|
oldML: &versioned.MinionList{Minions: oldMinions},
|
||||||
newML: &newer.NodeList{Items: newMinions},
|
newML: &api.NodeList{Items: newMinions},
|
||||||
}, {
|
}, {
|
||||||
oldML: ¤t.MinionList{
|
oldML: &versioned.MinionList{
|
||||||
Items: oldMinions,
|
Items: oldMinions,
|
||||||
Minions: []current.Minion{oldMinion("baz")},
|
Minions: []versioned.Minion{oldMinion("baz")},
|
||||||
},
|
},
|
||||||
newML: &newer.NodeList{Items: newMinions},
|
newML: &api.NodeList{Items: newMinions},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
got := &newer.NodeList{}
|
got := &api.NodeList{}
|
||||||
err := Convert(item.oldML, got)
|
err := Convert(item.oldML, got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if e, a := item.newML, got; !newer.Semantic.DeepEqual(e, a) {
|
if e, a := item.newML, got; !api.Semantic.DeepEqual(e, a) {
|
||||||
t.Errorf("Expected: %#v, got %#v", e, a)
|
t.Errorf("Expected: %#v, got %#v", e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMinionListConversionToOld(t *testing.T) {
|
func TestMinionListConversionToOld(t *testing.T) {
|
||||||
oldMinion := func(id string) current.Minion {
|
oldMinion := func(id string) versioned.Minion {
|
||||||
return current.Minion{TypeMeta: current.TypeMeta{ID: id}}
|
return versioned.Minion{TypeMeta: versioned.TypeMeta{ID: id}}
|
||||||
}
|
}
|
||||||
newNode := func(id string) newer.Node {
|
newNode := func(id string) api.Node {
|
||||||
return newer.Node{ObjectMeta: newer.ObjectMeta{Name: id}}
|
return api.Node{ObjectMeta: api.ObjectMeta{Name: id}}
|
||||||
}
|
}
|
||||||
oldMinions := []current.Minion{
|
oldMinions := []versioned.Minion{
|
||||||
oldMinion("foo"),
|
oldMinion("foo"),
|
||||||
oldMinion("bar"),
|
oldMinion("bar"),
|
||||||
}
|
}
|
||||||
newMinions := []newer.Node{
|
newMinions := []api.Node{
|
||||||
newNode("foo"),
|
newNode("foo"),
|
||||||
newNode("bar"),
|
newNode("bar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
newML := &newer.NodeList{Items: newMinions}
|
newML := &api.NodeList{Items: newMinions}
|
||||||
oldML := ¤t.MinionList{
|
oldML := &versioned.MinionList{
|
||||||
Items: oldMinions,
|
Items: oldMinions,
|
||||||
Minions: oldMinions,
|
Minions: oldMinions,
|
||||||
}
|
}
|
||||||
|
|
||||||
got := ¤t.MinionList{}
|
got := &versioned.MinionList{}
|
||||||
err := Convert(newML, got)
|
err := Convert(newML, got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if e, a := oldML, got; !newer.Semantic.DeepEqual(e, a) {
|
if e, a := oldML, got; !api.Semantic.DeepEqual(e, a) {
|
||||||
t.Errorf("Expected: %#v, got %#v", e, a)
|
t.Errorf("Expected: %#v, got %#v", e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceEmptySelector(t *testing.T) {
|
func TestServiceEmptySelector(t *testing.T) {
|
||||||
// Nil map should be preserved
|
// Nil map should be preserved
|
||||||
svc := ¤t.Service{Selector: nil}
|
svc := &versioned.Service{Selector: nil}
|
||||||
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta1")
|
data, err := api.Scheme.EncodeToVersion(svc, "v1beta1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
obj, err := newer.Scheme.Decode(data)
|
obj, err := api.Scheme.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
selector := obj.(*newer.Service).Spec.Selector
|
selector := obj.(*api.Service).Spec.Selector
|
||||||
if selector != nil {
|
if selector != nil {
|
||||||
t.Errorf("unexpected selector: %#v", obj)
|
t.Errorf("unexpected selector: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty map should be preserved
|
// Empty map should be preserved
|
||||||
svc2 := ¤t.Service{Selector: map[string]string{}}
|
svc2 := &versioned.Service{Selector: map[string]string{}}
|
||||||
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta1")
|
data, err = api.Scheme.EncodeToVersion(svc2, "v1beta1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
obj, err = newer.Scheme.Decode(data)
|
obj, err = api.Scheme.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
selector = obj.(*newer.Service).Spec.Selector
|
selector = obj.(*api.Service).Spec.Selector
|
||||||
if selector == nil || len(selector) != 0 {
|
if selector == nil || len(selector) != 0 {
|
||||||
t.Errorf("unexpected selector: %#v", obj)
|
t.Errorf("unexpected selector: %#v", obj)
|
||||||
}
|
}
|
||||||
@ -291,160 +291,160 @@ func TestServiceEmptySelector(t *testing.T) {
|
|||||||
|
|
||||||
func TestServicePorts(t *testing.T) {
|
func TestServicePorts(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
given current.Service
|
given versioned.Service
|
||||||
expected newer.Service
|
expected api.Service
|
||||||
roundtrip current.Service
|
roundtrip versioned.Service
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "legacy-with-defaults",
|
ID: "legacy-with-defaults",
|
||||||
},
|
},
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "legacy-full",
|
ID: "legacy-full",
|
||||||
},
|
},
|
||||||
PortName: "p",
|
PortName: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
TargetPort: util.NewIntOrStringFromString("p"),
|
TargetPort: util.NewIntOrStringFromString("p"),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "both",
|
ID: "both",
|
||||||
},
|
},
|
||||||
PortName: "p",
|
PortName: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one",
|
ID: "one",
|
||||||
},
|
},
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "two",
|
ID: "two",
|
||||||
},
|
},
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(76),
|
ContainerPort: util.NewIntOrStringFromInt(76),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(76),
|
TargetPort: util.NewIntOrStringFromInt(76),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(76),
|
ContainerPort: util.NewIntOrStringFromInt(76),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -453,7 +453,7 @@ func TestServicePorts(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
// Convert versioned -> internal.
|
// Convert versioned -> internal.
|
||||||
got := newer.Service{}
|
got := api.Service{}
|
||||||
if err := Convert(&tc.given, &got); err != nil {
|
if err := Convert(&tc.given, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
@ -463,7 +463,7 @@ func TestServicePorts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert internal -> versioned.
|
// Convert internal -> versioned.
|
||||||
got2 := current.Service{}
|
got2 := versioned.Service{}
|
||||||
if err := Convert(&got, &got2); err != nil {
|
if err := Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
@ -476,18 +476,18 @@ func TestServicePorts(t *testing.T) {
|
|||||||
|
|
||||||
func TestPullPolicyConversion(t *testing.T) {
|
func TestPullPolicyConversion(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
versioned current.PullPolicy
|
versioned versioned.PullPolicy
|
||||||
internal newer.PullPolicy
|
internal api.PullPolicy
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
versioned: current.PullAlways,
|
versioned: versioned.PullAlways,
|
||||||
internal: newer.PullAlways,
|
internal: api.PullAlways,
|
||||||
}, {
|
}, {
|
||||||
versioned: current.PullNever,
|
versioned: versioned.PullNever,
|
||||||
internal: newer.PullNever,
|
internal: api.PullNever,
|
||||||
}, {
|
}, {
|
||||||
versioned: current.PullIfNotPresent,
|
versioned: versioned.PullIfNotPresent,
|
||||||
internal: newer.PullIfNotPresent,
|
internal: api.PullIfNotPresent,
|
||||||
}, {
|
}, {
|
||||||
versioned: "",
|
versioned: "",
|
||||||
internal: "",
|
internal: "",
|
||||||
@ -497,7 +497,7 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
var got newer.PullPolicy
|
var got api.PullPolicy
|
||||||
err := Convert(&item.versioned, &got)
|
err := Convert(&item.versioned, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
@ -508,7 +508,7 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
var got current.PullPolicy
|
var got versioned.PullPolicy
|
||||||
err := Convert(&item.internal, &got)
|
err := Convert(&item.internal, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
@ -520,14 +520,14 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResourceRequirements(cpu, memory resource.Quantity) current.ResourceRequirements {
|
func getResourceRequirements(cpu, memory resource.Quantity) versioned.ResourceRequirements {
|
||||||
res := current.ResourceRequirements{}
|
res := versioned.ResourceRequirements{}
|
||||||
res.Limits = current.ResourceList{}
|
res.Limits = versioned.ResourceList{}
|
||||||
if cpu.Value() > 0 {
|
if cpu.Value() > 0 {
|
||||||
res.Limits[current.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
|
res.Limits[versioned.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
|
||||||
}
|
}
|
||||||
if memory.Value() > 0 {
|
if memory.Value() > 0 {
|
||||||
res.Limits[current.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
|
res.Limits[versioned.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -537,7 +537,7 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
cpuLimit := resource.MustParse("10")
|
cpuLimit := resource.MustParse("10")
|
||||||
memoryLimit := resource.MustParse("10M")
|
memoryLimit := resource.MustParse("10M")
|
||||||
null := resource.Quantity{}
|
null := resource.Quantity{}
|
||||||
testCases := []current.Container{
|
testCases := []versioned.Container{
|
||||||
{
|
{
|
||||||
Name: "container",
|
Name: "container",
|
||||||
Resources: getResourceRequirements(cpuLimit, memoryLimit),
|
Resources: getResourceRequirements(cpuLimit, memoryLimit),
|
||||||
@ -570,7 +570,7 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
got := newer.Container{}
|
got := api.Container{}
|
||||||
if err := Convert(&tc, &got); err != nil {
|
if err := Convert(&tc, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
@ -586,114 +586,114 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
|
|
||||||
func TestEndpointsConversion(t *testing.T) {
|
func TestEndpointsConversion(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
given current.Endpoints
|
given versioned.Endpoints
|
||||||
expected newer.Endpoints
|
expected api.Endpoints
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "empty",
|
ID: "empty",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{},
|
Endpoints: []string{},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{},
|
Subsets: []api.EndpointSubset{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one legacy",
|
ID: "one legacy",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{"1.2.3.4:88"},
|
Endpoints: []string{"1.2.3.4:88"},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{{
|
Subsets: []api.EndpointSubset{{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "several legacy",
|
ID: "several legacy",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
|
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{
|
Subsets: []api.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 90, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 90, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one subset",
|
ID: "one subset",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{"1.2.3.4:88"},
|
Endpoints: []string{"1.2.3.4:88"},
|
||||||
Subsets: []current.EndpointSubset{{
|
Subsets: []versioned.EndpointSubset{{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolTCP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolTCP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{{
|
Subsets: []api.EndpointSubset{{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "several subset",
|
ID: "several subset",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
|
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
|
||||||
Subsets: []current.EndpointSubset{
|
Subsets: []versioned.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 89, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 89, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "named", Port: 90, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "named", Port: 90, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{
|
Subsets: []api.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "named", Port: 90, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "named", Port: 90, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -701,39 +701,39 @@ func TestEndpointsConversion(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
// Convert versioned -> internal.
|
// Convert versioned -> internal.
|
||||||
got := newer.Endpoints{}
|
got := api.Endpoints{}
|
||||||
if err := Convert(&tc.given, &got); err != nil {
|
if err := Convert(&tc.given, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !newer.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
|
if !api.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
|
||||||
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
|
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert internal -> versioned.
|
// Convert internal -> versioned.
|
||||||
got2 := current.Endpoints{}
|
got2 := versioned.Endpoints{}
|
||||||
if err := Convert(&got, &got2); err != nil {
|
if err := Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if got2.Protocol != tc.given.Protocol || !newer.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
|
if got2.Protocol != tc.given.Protocol || !api.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
|
||||||
t.Errorf("[Case: %d] Expected %s %#v, got %s %#v", i, tc.given.Protocol, tc.given.Endpoints, got2.Protocol, got2.Endpoints)
|
t.Errorf("[Case: %d] Expected %s %#v, got %s %#v", i, tc.given.Protocol, tc.given.Endpoints, got2.Protocol, got2.Endpoints)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretVolumeSourceConversion(t *testing.T) {
|
func TestSecretVolumeSourceConversion(t *testing.T) {
|
||||||
given := current.SecretVolumeSource{
|
given := versioned.SecretVolumeSource{
|
||||||
Target: current.ObjectReference{
|
Target: versioned.ObjectReference{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := newer.SecretVolumeSource{
|
expected := api.SecretVolumeSource{
|
||||||
SecretName: "foo",
|
SecretName: "foo",
|
||||||
}
|
}
|
||||||
|
|
||||||
got := newer.SecretVolumeSource{}
|
got := api.SecretVolumeSource{}
|
||||||
if err := Convert(&given, &got); err != nil {
|
if err := Convert(&given, &got); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -741,7 +741,7 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
|
|||||||
t.Errorf("Expected %v; got %v", expected, got)
|
t.Errorf("Expected %v; got %v", expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
got2 := current.SecretVolumeSource{}
|
got2 := versioned.SecretVolumeSource{}
|
||||||
if err := Convert(&got, &got2); err != nil {
|
if err := Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -753,42 +753,42 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
|
|||||||
func TestBadSecurityContextConversion(t *testing.T) {
|
func TestBadSecurityContextConversion(t *testing.T) {
|
||||||
priv := false
|
priv := false
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
c *current.Container
|
c *versioned.Container
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
||||||
// will assume privileged was left undefined (since it is the default value) and copy the
|
// will assume privileged was left undefined (since it is the default value) and copy the
|
||||||
// sc setting upwards
|
// sc setting upwards
|
||||||
"mismatched privileged": {
|
"mismatched privileged": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container privileged settings do not match security context settings, cannot convert",
|
err: "container privileged settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps add": {
|
"mismatched caps add": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"bar"},
|
Add: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container capability settings do not match security context settings, cannot convert",
|
err: "container capability settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps drop": {
|
"mismatched caps drop": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Drop: []current.Capability{"foo"},
|
Drop: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -797,7 +797,7 @@ func TestBadSecurityContextConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range testCases {
|
for k, v := range testCases {
|
||||||
got := newer.Container{}
|
got := api.Container{}
|
||||||
err := Convert(v.c, &got)
|
err := Convert(v.c, &got)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected error for case %s but got none", k)
|
t.Errorf("expected error for case %s but got none", k)
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -30,34 +30,34 @@ import (
|
|||||||
|
|
||||||
func addConversionFuncs() {
|
func addConversionFuncs() {
|
||||||
// Our TypeMeta was split into two different structs.
|
// Our TypeMeta was split into two different structs.
|
||||||
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.TypeMeta{}, "TypeMeta")
|
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.TypeMeta{}, "TypeMeta")
|
||||||
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.ObjectMeta{}, "ObjectMeta")
|
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ObjectMeta{}, "ObjectMeta")
|
||||||
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.ListMeta{}, "ListMeta")
|
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ListMeta{}, "ListMeta")
|
||||||
|
|
||||||
newer.Scheme.AddStructFieldConversion(newer.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
|
api.Scheme.AddStructFieldConversion(api.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
|
||||||
newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
|
api.Scheme.AddStructFieldConversion(api.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
|
||||||
newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
|
api.Scheme.AddStructFieldConversion(api.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
|
||||||
newer.Scheme.AddStructFieldConversion(newer.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
|
api.Scheme.AddStructFieldConversion(api.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
|
||||||
|
|
||||||
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
|
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
|
||||||
// newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
|
// api.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
|
||||||
// newer.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status")
|
// api.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status")
|
||||||
|
|
||||||
err := newer.Scheme.AddConversionFuncs(
|
err := api.Scheme.AddConversionFuncs(
|
||||||
// TypeMeta must be split into two objects
|
// TypeMeta must be split into two objects
|
||||||
func(in *newer.TypeMeta, out *TypeMeta, s conversion.Scope) error {
|
func(in *api.TypeMeta, out *TypeMeta, s conversion.Scope) error {
|
||||||
out.Kind = in.Kind
|
out.Kind = in.Kind
|
||||||
out.APIVersion = in.APIVersion
|
out.APIVersion = in.APIVersion
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *TypeMeta, out *newer.TypeMeta, s conversion.Scope) error {
|
func(in *TypeMeta, out *api.TypeMeta, s conversion.Scope) error {
|
||||||
out.Kind = in.Kind
|
out.Kind = in.Kind
|
||||||
out.APIVersion = in.APIVersion
|
out.APIVersion = in.APIVersion
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
// ListMeta must be converted to TypeMeta
|
// ListMeta must be converted to TypeMeta
|
||||||
func(in *newer.ListMeta, out *TypeMeta, s conversion.Scope) error {
|
func(in *api.ListMeta, out *TypeMeta, s conversion.Scope) error {
|
||||||
out.SelfLink = in.SelfLink
|
out.SelfLink = in.SelfLink
|
||||||
if len(in.ResourceVersion) > 0 {
|
if len(in.ResourceVersion) > 0 {
|
||||||
v, err := strconv.ParseUint(in.ResourceVersion, 10, 64)
|
v, err := strconv.ParseUint(in.ResourceVersion, 10, 64)
|
||||||
@ -68,7 +68,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *TypeMeta, out *newer.ListMeta, s conversion.Scope) error {
|
func(in *TypeMeta, out *api.ListMeta, s conversion.Scope) error {
|
||||||
out.SelfLink = in.SelfLink
|
out.SelfLink = in.SelfLink
|
||||||
if in.ResourceVersion != 0 {
|
if in.ResourceVersion != 0 {
|
||||||
out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10)
|
out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10)
|
||||||
@ -79,7 +79,7 @@ func addConversionFuncs() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// ObjectMeta must be converted to TypeMeta
|
// ObjectMeta must be converted to TypeMeta
|
||||||
func(in *newer.ObjectMeta, out *TypeMeta, s conversion.Scope) error {
|
func(in *api.ObjectMeta, out *TypeMeta, s conversion.Scope) error {
|
||||||
out.Namespace = in.Namespace
|
out.Namespace = in.Namespace
|
||||||
out.ID = in.Name
|
out.ID = in.Name
|
||||||
out.GenerateName = in.GenerateName
|
out.GenerateName = in.GenerateName
|
||||||
@ -96,7 +96,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return s.Convert(&in.Annotations, &out.Annotations, 0)
|
return s.Convert(&in.Annotations, &out.Annotations, 0)
|
||||||
},
|
},
|
||||||
func(in *TypeMeta, out *newer.ObjectMeta, s conversion.Scope) error {
|
func(in *TypeMeta, out *api.ObjectMeta, s conversion.Scope) error {
|
||||||
out.Namespace = in.Namespace
|
out.Namespace = in.Namespace
|
||||||
out.Name = in.ID
|
out.Name = in.ID
|
||||||
out.GenerateName = in.GenerateName
|
out.GenerateName = in.GenerateName
|
||||||
@ -113,22 +113,22 @@ func addConversionFuncs() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Convert all to the new PodPhase constants
|
// Convert all to the new PodPhase constants
|
||||||
func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error {
|
func(in *api.PodPhase, out *PodStatus, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
case newer.PodPending:
|
case api.PodPending:
|
||||||
*out = PodWaiting
|
*out = PodWaiting
|
||||||
case newer.PodRunning:
|
case api.PodRunning:
|
||||||
*out = PodRunning
|
*out = PodRunning
|
||||||
case newer.PodSucceeded:
|
case api.PodSucceeded:
|
||||||
*out = PodSucceeded
|
*out = PodSucceeded
|
||||||
case newer.PodFailed:
|
case api.PodFailed:
|
||||||
*out = PodTerminated
|
*out = PodTerminated
|
||||||
case newer.PodUnknown:
|
case api.PodUnknown:
|
||||||
*out = PodUnknown
|
*out = PodUnknown
|
||||||
default:
|
default:
|
||||||
return &newer.ConversionError{
|
return &api.ConversionError{
|
||||||
In: in,
|
In: in,
|
||||||
Out: out,
|
Out: out,
|
||||||
Message: "The string provided is not a valid PodPhase constant value",
|
Message: "The string provided is not a valid PodPhase constant value",
|
||||||
@ -138,23 +138,23 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error {
|
func(in *PodStatus, out *api.PodPhase, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
case PodWaiting:
|
case PodWaiting:
|
||||||
*out = newer.PodPending
|
*out = api.PodPending
|
||||||
case PodRunning:
|
case PodRunning:
|
||||||
*out = newer.PodRunning
|
*out = api.PodRunning
|
||||||
case PodTerminated:
|
case PodTerminated:
|
||||||
// Older API versions did not contain enough info to map to PodSucceeded
|
// Older API versions did not contain enough info to map to PodSucceeded
|
||||||
*out = newer.PodFailed
|
*out = api.PodFailed
|
||||||
case PodSucceeded:
|
case PodSucceeded:
|
||||||
*out = newer.PodSucceeded
|
*out = api.PodSucceeded
|
||||||
case PodUnknown:
|
case PodUnknown:
|
||||||
*out = newer.PodUnknown
|
*out = api.PodUnknown
|
||||||
default:
|
default:
|
||||||
return &newer.ConversionError{
|
return &api.ConversionError{
|
||||||
In: in,
|
In: in,
|
||||||
Out: out,
|
Out: out,
|
||||||
Message: "The string provided is not a valid PodPhase constant value",
|
Message: "The string provided is not a valid PodPhase constant value",
|
||||||
@ -164,7 +164,7 @@ func addConversionFuncs() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Convert all the standard objects
|
// Convert all the standard objects
|
||||||
func(in *newer.Pod, out *Pod, s conversion.Scope) error {
|
func(in *api.Pod, out *Pod, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *Pod, out *newer.Pod, s conversion.Scope) error {
|
func(in *Pod, out *api.Pod, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ReplicationController, out *ReplicationController, s conversion.Scope) error {
|
func(in *api.ReplicationController, out *ReplicationController, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ func addConversionFuncs() {
|
|||||||
out.CurrentState.Replicas = in.Status.Replicas
|
out.CurrentState.Replicas = in.Status.Replicas
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ReplicationController, out *newer.ReplicationController, s conversion.Scope) error {
|
func(in *ReplicationController, out *api.ReplicationController, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -248,13 +248,13 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ReplicationControllerSpec, out *ReplicationControllerState, s conversion.Scope) error {
|
func(in *api.ReplicationControllerSpec, out *ReplicationControllerState, s conversion.Scope) error {
|
||||||
out.Replicas = in.Replicas
|
out.Replicas = in.Replicas
|
||||||
if err := s.Convert(&in.Selector, &out.ReplicaSelector, 0); err != nil {
|
if err := s.Convert(&in.Selector, &out.ReplicaSelector, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if in.TemplateRef != nil && in.Template == nil {
|
if in.TemplateRef != nil && in.Template == nil {
|
||||||
return &newer.ConversionError{
|
return &api.ConversionError{
|
||||||
In: in,
|
In: in,
|
||||||
Out: out,
|
Out: out,
|
||||||
Message: "objects with a template ref cannot be converted to older objects, must populate template",
|
Message: "objects with a template ref cannot be converted to older objects, must populate template",
|
||||||
@ -267,19 +267,19 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ReplicationControllerState, out *newer.ReplicationControllerSpec, s conversion.Scope) error {
|
func(in *ReplicationControllerState, out *api.ReplicationControllerSpec, s conversion.Scope) error {
|
||||||
out.Replicas = in.Replicas
|
out.Replicas = in.Replicas
|
||||||
if err := s.Convert(&in.ReplicaSelector, &out.Selector, 0); err != nil {
|
if err := s.Convert(&in.ReplicaSelector, &out.Selector, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Template = &newer.PodTemplateSpec{}
|
out.Template = &api.PodTemplateSpec{}
|
||||||
if err := s.Convert(&in.PodTemplate, out.Template, 0); err != nil {
|
if err := s.Convert(&in.PodTemplate, out.Template, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodTemplateSpec, out *PodTemplate, s conversion.Scope) error {
|
func(in *api.PodTemplateSpec, out *PodTemplate, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
|
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error {
|
func(in *PodTemplate, out *api.PodTemplateSpec, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
|
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ func addConversionFuncs() {
|
|||||||
// Converts internal Container to v1beta2.Container.
|
// Converts internal Container to v1beta2.Container.
|
||||||
// Fields 'CPU' and 'Memory' are not present in the internal Container object.
|
// Fields 'CPU' and 'Memory' are not present in the internal Container object.
|
||||||
// Hence the need for a custom conversion function.
|
// Hence the need for a custom conversion function.
|
||||||
func(in *newer.Container, out *Container, s conversion.Scope) error {
|
func(in *api.Container, out *Container, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
|
if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ func addConversionFuncs() {
|
|||||||
},
|
},
|
||||||
// Internal API does not support CPU to be specified via an explicit field.
|
// Internal API does not support CPU to be specified via an explicit field.
|
||||||
// Hence it must be stored in Container.Resources.
|
// Hence it must be stored in Container.Resources.
|
||||||
func(in *int, out *newer.ResourceList, s conversion.Scope) error {
|
func(in *int, out *api.ResourceList, s conversion.Scope) error {
|
||||||
if *in == 0 {
|
if *in == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -388,13 +388,13 @@ func addConversionFuncs() {
|
|||||||
if err := s.Convert(in, &quantity, 0); err != nil {
|
if err := s.Convert(in, &quantity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*out)[newer.ResourceCPU] = quantity
|
(*out)[api.ResourceCPU] = quantity
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// Internal API does not support Memory to be specified via an explicit field.
|
// Internal API does not support Memory to be specified via an explicit field.
|
||||||
// Hence it must be stored in Container.Resources.
|
// Hence it must be stored in Container.Resources.
|
||||||
func(in *int64, out *newer.ResourceList, s conversion.Scope) error {
|
func(in *int64, out *api.ResourceList, s conversion.Scope) error {
|
||||||
if *in == 0 {
|
if *in == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -402,14 +402,14 @@ func addConversionFuncs() {
|
|||||||
if err := s.Convert(in, &quantity, 0); err != nil {
|
if err := s.Convert(in, &quantity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*out)[newer.ResourceMemory] = quantity
|
(*out)[api.ResourceMemory] = quantity
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// Converts v1beta2.Container to internal newer.Container.
|
// Converts v1beta2.Container to internal api.Container.
|
||||||
// Fields 'CPU' and 'Memory' are not present in the internal newer.Container object.
|
// Fields 'CPU' and 'Memory' are not present in the internal api.Container object.
|
||||||
// Hence the need for a custom conversion function.
|
// Hence the need for a custom conversion function.
|
||||||
func(in *Container, out *newer.Container, s conversion.Scope) error {
|
func(in *Container, out *api.Container, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
|
if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
|
func(in *api.PodSpec, out *ContainerManifest, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
|
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -502,7 +502,7 @@ func addConversionFuncs() {
|
|||||||
out.HostNetwork = in.HostNetwork
|
out.HostNetwork = in.HostNetwork
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error {
|
func(in *ContainerManifest, out *api.PodSpec, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
|
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -523,12 +523,12 @@ func addConversionFuncs() {
|
|||||||
out.ActiveDeadlineSeconds = new(int64)
|
out.ActiveDeadlineSeconds = new(int64)
|
||||||
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
|
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
|
||||||
}
|
}
|
||||||
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy)
|
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
|
||||||
out.HostNetwork = in.HostNetwork
|
out.HostNetwork = in.HostNetwork
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
|
func(in *api.PodStatus, out *PodState, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Phase, &out.Status, 0); err != nil {
|
if err := s.Convert(&in.Phase, &out.Status, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -543,7 +543,7 @@ func addConversionFuncs() {
|
|||||||
out.PodIP = in.PodIP
|
out.PodIP = in.PodIP
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error {
|
func(in *PodState, out *api.PodStatus, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Status, &out.Phase, 0); err != nil {
|
if err := s.Convert(&in.Status, &out.Phase, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -559,7 +559,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *[]newer.ContainerStatus, out *PodInfo, s conversion.Scope) error {
|
func(in *[]api.ContainerStatus, out *PodInfo, s conversion.Scope) error {
|
||||||
*out = make(map[string]ContainerStatus)
|
*out = make(map[string]ContainerStatus)
|
||||||
for _, st := range *in {
|
for _, st := range *in {
|
||||||
v := ContainerStatus{}
|
v := ContainerStatus{}
|
||||||
@ -570,9 +570,9 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodInfo, out *[]newer.ContainerStatus, s conversion.Scope) error {
|
func(in *PodInfo, out *[]api.ContainerStatus, s conversion.Scope) error {
|
||||||
for k, v := range *in {
|
for k, v := range *in {
|
||||||
st := newer.ContainerStatus{}
|
st := api.ContainerStatus{}
|
||||||
if err := s.Convert(&v, &st, 0); err != nil {
|
if err := s.Convert(&v, &st, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -582,7 +582,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ContainerStatus, out *ContainerStatus, s conversion.Scope) error {
|
func(in *api.ContainerStatus, out *ContainerStatus, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.State, &out.State, 0); err != nil {
|
if err := s.Convert(&in.State, &out.State, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -606,7 +606,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ContainerStatus, out *newer.ContainerStatus, s conversion.Scope) error {
|
func(in *ContainerStatus, out *api.ContainerStatus, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.State, &out.State, 0); err != nil {
|
if err := s.Convert(&in.State, &out.State, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodStatusResult, out *PodStatusResult, s conversion.Scope) error {
|
func(in *api.PodStatusResult, out *PodStatusResult, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodStatusResult, out *newer.PodStatusResult, s conversion.Scope) error {
|
func(in *PodStatusResult, out *api.PodStatusResult, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -656,21 +656,21 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodSpec, out *PodState, s conversion.Scope) error {
|
func(in *api.PodSpec, out *PodState, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in, &out.Manifest, 0); err != nil {
|
if err := s.Convert(&in, &out.Manifest, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Host = in.Host
|
out.Host = in.Host
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodState, out *newer.PodSpec, s conversion.Scope) error {
|
func(in *PodState, out *api.PodSpec, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Manifest, &out, 0); err != nil {
|
if err := s.Convert(&in.Manifest, &out, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Host = in.Host
|
out.Host = in.Host
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.Service, out *Service, s conversion.Scope) error {
|
func(in *api.Service, out *Service, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -711,7 +711,7 @@ func addConversionFuncs() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *Service, out *newer.Service, s conversion.Scope) error {
|
func(in *Service, out *api.Service, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -724,19 +724,19 @@ func addConversionFuncs() {
|
|||||||
|
|
||||||
if len(in.Ports) == 0 && in.Port != 0 {
|
if len(in.Ports) == 0 && in.Port != 0 {
|
||||||
// Use legacy fields to produce modern fields.
|
// Use legacy fields to produce modern fields.
|
||||||
out.Spec.Ports = append(out.Spec.Ports, newer.ServicePort{
|
out.Spec.Ports = append(out.Spec.Ports, api.ServicePort{
|
||||||
Name: in.PortName,
|
Name: in.PortName,
|
||||||
Port: in.Port,
|
Port: in.Port,
|
||||||
Protocol: newer.Protocol(in.Protocol),
|
Protocol: api.Protocol(in.Protocol),
|
||||||
TargetPort: in.ContainerPort,
|
TargetPort: in.ContainerPort,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Use modern fields, ignore legacy.
|
// Use modern fields, ignore legacy.
|
||||||
for i := range in.Ports {
|
for i := range in.Ports {
|
||||||
out.Spec.Ports = append(out.Spec.Ports, newer.ServicePort{
|
out.Spec.Ports = append(out.Spec.Ports, api.ServicePort{
|
||||||
Name: in.Ports[i].Name,
|
Name: in.Ports[i].Name,
|
||||||
Port: in.Ports[i].Port,
|
Port: in.Ports[i].Port,
|
||||||
Protocol: newer.Protocol(in.Ports[i].Protocol),
|
Protocol: api.Protocol(in.Ports[i].Protocol),
|
||||||
TargetPort: in.Ports[i].ContainerPort,
|
TargetPort: in.Ports[i].ContainerPort,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -755,7 +755,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.Node, out *Minion, s conversion.Scope) error {
|
func(in *api.Node, out *Minion, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -779,7 +779,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, address := range in.Status.Addresses {
|
for _, address := range in.Status.Addresses {
|
||||||
if address.Type == newer.NodeLegacyHostIP {
|
if address.Type == api.NodeLegacyHostIP {
|
||||||
out.HostIP = address.Address
|
out.HostIP = address.Address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -788,7 +788,7 @@ func addConversionFuncs() {
|
|||||||
out.Unschedulable = in.Spec.Unschedulable
|
out.Unschedulable = in.Spec.Unschedulable
|
||||||
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
|
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
|
||||||
},
|
},
|
||||||
func(in *Minion, out *newer.Node, s conversion.Scope) error {
|
func(in *Minion, out *api.Node, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -812,8 +812,8 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if in.HostIP != "" {
|
if in.HostIP != "" {
|
||||||
newer.AddToNodeAddresses(&out.Status.Addresses,
|
api.AddToNodeAddresses(&out.Status.Addresses,
|
||||||
newer.NodeAddress{Type: newer.NodeLegacyHostIP, Address: in.HostIP})
|
api.NodeAddress{Type: api.NodeLegacyHostIP, Address: in.HostIP})
|
||||||
}
|
}
|
||||||
out.Spec.PodCIDR = in.PodCIDR
|
out.Spec.PodCIDR = in.PodCIDR
|
||||||
out.Spec.ExternalID = in.ExternalID
|
out.Spec.ExternalID = in.ExternalID
|
||||||
@ -821,7 +821,7 @@ func addConversionFuncs() {
|
|||||||
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
|
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error {
|
func(in *api.LimitRange, out *LimitRange, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -833,7 +833,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *LimitRange, out *newer.LimitRange, s conversion.Scope) error {
|
func(in *LimitRange, out *api.LimitRange, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -846,7 +846,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *Namespace, out *newer.Namespace, s conversion.Scope) error {
|
func(in *Namespace, out *api.Namespace, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -865,7 +865,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.LimitRangeSpec, out *LimitRangeSpec, s conversion.Scope) error {
|
func(in *api.LimitRangeSpec, out *LimitRangeSpec, s conversion.Scope) error {
|
||||||
*out = LimitRangeSpec{}
|
*out = LimitRangeSpec{}
|
||||||
out.Limits = make([]LimitRangeItem, len(in.Limits), len(in.Limits))
|
out.Limits = make([]LimitRangeItem, len(in.Limits), len(in.Limits))
|
||||||
for i := range in.Limits {
|
for i := range in.Limits {
|
||||||
@ -875,9 +875,9 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *LimitRangeSpec, out *newer.LimitRangeSpec, s conversion.Scope) error {
|
func(in *LimitRangeSpec, out *api.LimitRangeSpec, s conversion.Scope) error {
|
||||||
*out = newer.LimitRangeSpec{}
|
*out = api.LimitRangeSpec{}
|
||||||
out.Limits = make([]newer.LimitRangeItem, len(in.Limits), len(in.Limits))
|
out.Limits = make([]api.LimitRangeItem, len(in.Limits), len(in.Limits))
|
||||||
for i := range in.Limits {
|
for i := range in.Limits {
|
||||||
if err := s.Convert(&in.Limits[i], &out.Limits[i], 0); err != nil {
|
if err := s.Convert(&in.Limits[i], &out.Limits[i], 0); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -886,7 +886,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.LimitRangeItem, out *LimitRangeItem, s conversion.Scope) error {
|
func(in *api.LimitRangeItem, out *LimitRangeItem, s conversion.Scope) error {
|
||||||
*out = LimitRangeItem{}
|
*out = LimitRangeItem{}
|
||||||
out.Type = LimitType(in.Type)
|
out.Type = LimitType(in.Type)
|
||||||
if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
|
if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
|
||||||
@ -900,9 +900,9 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *LimitRangeItem, out *newer.LimitRangeItem, s conversion.Scope) error {
|
func(in *LimitRangeItem, out *api.LimitRangeItem, s conversion.Scope) error {
|
||||||
*out = newer.LimitRangeItem{}
|
*out = api.LimitRangeItem{}
|
||||||
out.Type = newer.LimitType(in.Type)
|
out.Type = api.LimitType(in.Type)
|
||||||
if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
|
if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -915,7 +915,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ResourceQuota, out *ResourceQuota, s conversion.Scope) error {
|
func(in *api.ResourceQuota, out *ResourceQuota, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -933,7 +933,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ResourceQuota, out *newer.ResourceQuota, s conversion.Scope) error {
|
func(in *ResourceQuota, out *api.ResourceQuota, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -952,22 +952,22 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ResourceQuotaSpec, out *ResourceQuotaSpec, s conversion.Scope) error {
|
func(in *api.ResourceQuotaSpec, out *ResourceQuotaSpec, s conversion.Scope) error {
|
||||||
*out = ResourceQuotaSpec{}
|
*out = ResourceQuotaSpec{}
|
||||||
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ResourceQuotaSpec, out *newer.ResourceQuotaSpec, s conversion.Scope) error {
|
func(in *ResourceQuotaSpec, out *api.ResourceQuotaSpec, s conversion.Scope) error {
|
||||||
*out = newer.ResourceQuotaSpec{}
|
*out = api.ResourceQuotaSpec{}
|
||||||
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ResourceQuotaStatus, out *ResourceQuotaStatus, s conversion.Scope) error {
|
func(in *api.ResourceQuotaStatus, out *ResourceQuotaStatus, s conversion.Scope) error {
|
||||||
*out = ResourceQuotaStatus{}
|
*out = ResourceQuotaStatus{}
|
||||||
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -977,8 +977,8 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ResourceQuotaStatus, out *newer.ResourceQuotaStatus, s conversion.Scope) error {
|
func(in *ResourceQuotaStatus, out *api.ResourceQuotaStatus, s conversion.Scope) error {
|
||||||
*out = newer.ResourceQuotaStatus{}
|
*out = api.ResourceQuotaStatus{}
|
||||||
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -990,7 +990,7 @@ func addConversionFuncs() {
|
|||||||
|
|
||||||
// Object ID <-> Name
|
// Object ID <-> Name
|
||||||
// TODO: amend the conversion package to allow overriding specific fields.
|
// TODO: amend the conversion package to allow overriding specific fields.
|
||||||
func(in *ObjectReference, out *newer.ObjectReference, s conversion.Scope) error {
|
func(in *ObjectReference, out *api.ObjectReference, s conversion.Scope) error {
|
||||||
out.Kind = in.Kind
|
out.Kind = in.Kind
|
||||||
out.Namespace = in.Namespace
|
out.Namespace = in.Namespace
|
||||||
out.Name = in.ID
|
out.Name = in.ID
|
||||||
@ -1000,7 +1000,7 @@ func addConversionFuncs() {
|
|||||||
out.FieldPath = in.FieldPath
|
out.FieldPath = in.FieldPath
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.ObjectReference, out *ObjectReference, s conversion.Scope) error {
|
func(in *api.ObjectReference, out *ObjectReference, s conversion.Scope) error {
|
||||||
out.Kind = in.Kind
|
out.Kind = in.Kind
|
||||||
out.Namespace = in.Namespace
|
out.Namespace = in.Namespace
|
||||||
out.ID = in.Name
|
out.ID = in.Name
|
||||||
@ -1015,7 +1015,7 @@ func addConversionFuncs() {
|
|||||||
// Event Source <-> Source.Component
|
// Event Source <-> Source.Component
|
||||||
// Event Host <-> Source.Host
|
// Event Host <-> Source.Host
|
||||||
// TODO: remove this when it becomes possible to specify a field name conversion on a specific type
|
// TODO: remove this when it becomes possible to specify a field name conversion on a specific type
|
||||||
func(in *newer.Event, out *Event, s conversion.Scope) error {
|
func(in *api.Event, out *Event, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1032,7 +1032,7 @@ func addConversionFuncs() {
|
|||||||
out.Count = in.Count
|
out.Count = in.Count
|
||||||
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
||||||
},
|
},
|
||||||
func(in *Event, out *newer.Event, s conversion.Scope) error {
|
func(in *Event, out *api.Event, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1081,28 +1081,28 @@ func addConversionFuncs() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Convert resource lists.
|
// Convert resource lists.
|
||||||
func(in *ResourceList, out *newer.ResourceList, s conversion.Scope) error {
|
func(in *ResourceList, out *api.ResourceList, s conversion.Scope) error {
|
||||||
*out = newer.ResourceList{}
|
*out = api.ResourceList{}
|
||||||
for k, v := range *in {
|
for k, v := range *in {
|
||||||
fv, err := strconv.ParseFloat(v.String(), 64)
|
fv, err := strconv.ParseFloat(v.String(), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &newer.ConversionError{
|
return &api.ConversionError{
|
||||||
In: in, Out: out,
|
In: in, Out: out,
|
||||||
Message: fmt.Sprintf("value '%v' of '%v': %v", v, k, err),
|
Message: fmt.Sprintf("value '%v' of '%v': %v", v, k, err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if k == ResourceCPU {
|
if k == ResourceCPU {
|
||||||
(*out)[newer.ResourceCPU] = *resource.NewMilliQuantity(int64(fv*1000), resource.DecimalSI)
|
(*out)[api.ResourceCPU] = *resource.NewMilliQuantity(int64(fv*1000), resource.DecimalSI)
|
||||||
} else {
|
} else {
|
||||||
(*out)[newer.ResourceName(k)] = *resource.NewQuantity(int64(fv), resource.BinarySI)
|
(*out)[api.ResourceName(k)] = *resource.NewQuantity(int64(fv), resource.BinarySI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.ResourceList, out *ResourceList, s conversion.Scope) error {
|
func(in *api.ResourceList, out *ResourceList, s conversion.Scope) error {
|
||||||
*out = ResourceList{}
|
*out = ResourceList{}
|
||||||
for k, v := range *in {
|
for k, v := range *in {
|
||||||
if k == newer.ResourceCPU {
|
if k == api.ResourceCPU {
|
||||||
(*out)[ResourceCPU] = util.NewIntOrStringFromString(fmt.Sprintf("%v", float64(v.MilliValue())/1000))
|
(*out)[ResourceCPU] = util.NewIntOrStringFromString(fmt.Sprintf("%v", float64(v.MilliValue())/1000))
|
||||||
} else {
|
} else {
|
||||||
(*out)[ResourceName(k)] = util.NewIntOrStringFromInt(int(v.Value()))
|
(*out)[ResourceName(k)] = util.NewIntOrStringFromInt(int(v.Value()))
|
||||||
@ -1111,14 +1111,14 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.Volume, out *Volume, s conversion.Scope) error {
|
func(in *api.Volume, out *Volume, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil {
|
if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Name = in.Name
|
out.Name = in.Name
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *Volume, out *newer.Volume, s conversion.Scope) error {
|
func(in *Volume, out *api.Volume, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil {
|
if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1126,7 +1126,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.VolumeSource, out *VolumeSource, s conversion.Scope) error {
|
func(in *api.VolumeSource, out *VolumeSource, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
|
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1159,7 +1159,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *VolumeSource, out *newer.VolumeSource, s conversion.Scope) error {
|
func(in *VolumeSource, out *api.VolumeSource, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
|
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1193,13 +1193,13 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PullPolicy, out *PullPolicy, s conversion.Scope) error {
|
func(in *api.PullPolicy, out *PullPolicy, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case newer.PullAlways:
|
case api.PullAlways:
|
||||||
*out = PullAlways
|
*out = PullAlways
|
||||||
case newer.PullNever:
|
case api.PullNever:
|
||||||
*out = PullNever
|
*out = PullNever
|
||||||
case newer.PullIfNotPresent:
|
case api.PullIfNotPresent:
|
||||||
*out = PullIfNotPresent
|
*out = PullIfNotPresent
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
@ -1209,51 +1209,51 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PullPolicy, out *newer.PullPolicy, s conversion.Scope) error {
|
func(in *PullPolicy, out *api.PullPolicy, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case PullAlways:
|
case PullAlways:
|
||||||
*out = newer.PullAlways
|
*out = api.PullAlways
|
||||||
case PullNever:
|
case PullNever:
|
||||||
*out = newer.PullNever
|
*out = api.PullNever
|
||||||
case PullIfNotPresent:
|
case PullIfNotPresent:
|
||||||
*out = newer.PullIfNotPresent
|
*out = api.PullIfNotPresent
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
default:
|
default:
|
||||||
// Let unknown values through - they will get caught by validation
|
// Let unknown values through - they will get caught by validation
|
||||||
*out = newer.PullPolicy(*in)
|
*out = api.PullPolicy(*in)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.RestartPolicy, out *RestartPolicy, s conversion.Scope) error {
|
func(in *api.RestartPolicy, out *RestartPolicy, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case newer.RestartPolicyAlways:
|
case api.RestartPolicyAlways:
|
||||||
*out = RestartPolicy{Always: &RestartPolicyAlways{}}
|
*out = RestartPolicy{Always: &RestartPolicyAlways{}}
|
||||||
case newer.RestartPolicyNever:
|
case api.RestartPolicyNever:
|
||||||
*out = RestartPolicy{Never: &RestartPolicyNever{}}
|
*out = RestartPolicy{Never: &RestartPolicyNever{}}
|
||||||
case newer.RestartPolicyOnFailure:
|
case api.RestartPolicyOnFailure:
|
||||||
*out = RestartPolicy{OnFailure: &RestartPolicyOnFailure{}}
|
*out = RestartPolicy{OnFailure: &RestartPolicyOnFailure{}}
|
||||||
default:
|
default:
|
||||||
*out = RestartPolicy{}
|
*out = RestartPolicy{}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *RestartPolicy, out *newer.RestartPolicy, s conversion.Scope) error {
|
func(in *RestartPolicy, out *api.RestartPolicy, s conversion.Scope) error {
|
||||||
switch {
|
switch {
|
||||||
case in.Always != nil:
|
case in.Always != nil:
|
||||||
*out = newer.RestartPolicyAlways
|
*out = api.RestartPolicyAlways
|
||||||
case in.Never != nil:
|
case in.Never != nil:
|
||||||
*out = newer.RestartPolicyNever
|
*out = api.RestartPolicyNever
|
||||||
case in.OnFailure != nil:
|
case in.OnFailure != nil:
|
||||||
*out = newer.RestartPolicyOnFailure
|
*out = api.RestartPolicyOnFailure
|
||||||
default:
|
default:
|
||||||
*out = ""
|
*out = ""
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.Probe, out *LivenessProbe, s conversion.Scope) error {
|
func(in *api.Probe, out *LivenessProbe, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
|
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1267,7 +1267,7 @@ func addConversionFuncs() {
|
|||||||
out.TimeoutSeconds = in.TimeoutSeconds
|
out.TimeoutSeconds = in.TimeoutSeconds
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *LivenessProbe, out *newer.Probe, s conversion.Scope) error {
|
func(in *LivenessProbe, out *api.Probe, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
|
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1282,7 +1282,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.Endpoints, out *Endpoints, s conversion.Scope) error {
|
func(in *api.Endpoints, out *Endpoints, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1329,7 +1329,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *Endpoints, out *newer.Endpoints, s conversion.Scope) error {
|
func(in *Endpoints, out *api.Endpoints, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1343,7 +1343,7 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.NodeCondition, out *NodeCondition, s conversion.Scope) error {
|
func(in *api.NodeCondition, out *NodeCondition, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
|
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1364,7 +1364,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *NodeCondition, out *newer.NodeCondition, s conversion.Scope) error {
|
func(in *NodeCondition, out *api.NodeCondition, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
|
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1386,9 +1386,9 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.NodeConditionType, out *NodeConditionKind, s conversion.Scope) error {
|
func(in *api.NodeConditionType, out *NodeConditionKind, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case newer.NodeReady:
|
case api.NodeReady:
|
||||||
*out = NodeReady
|
*out = NodeReady
|
||||||
break
|
break
|
||||||
case "":
|
case "":
|
||||||
@ -1399,26 +1399,26 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *NodeConditionKind, out *newer.NodeConditionType, s conversion.Scope) error {
|
func(in *NodeConditionKind, out *api.NodeConditionType, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case NodeReady:
|
case NodeReady:
|
||||||
*out = newer.NodeReady
|
*out = api.NodeReady
|
||||||
break
|
break
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
default:
|
default:
|
||||||
*out = newer.NodeConditionType(*in)
|
*out = api.NodeConditionType(*in)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.ConditionStatus, out *ConditionStatus, s conversion.Scope) error {
|
func(in *api.ConditionStatus, out *ConditionStatus, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case newer.ConditionTrue:
|
case api.ConditionTrue:
|
||||||
*out = ConditionFull
|
*out = ConditionFull
|
||||||
break
|
break
|
||||||
case newer.ConditionFalse:
|
case api.ConditionFalse:
|
||||||
*out = ConditionNone
|
*out = ConditionNone
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@ -1427,22 +1427,22 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *ConditionStatus, out *newer.ConditionStatus, s conversion.Scope) error {
|
func(in *ConditionStatus, out *api.ConditionStatus, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case ConditionFull:
|
case ConditionFull:
|
||||||
*out = newer.ConditionTrue
|
*out = api.ConditionTrue
|
||||||
break
|
break
|
||||||
case ConditionNone:
|
case ConditionNone:
|
||||||
*out = newer.ConditionFalse
|
*out = api.ConditionFalse
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
*out = newer.ConditionStatus(*in)
|
*out = api.ConditionStatus(*in)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodCondition, out *PodCondition, s conversion.Scope) error {
|
func(in *api.PodCondition, out *PodCondition, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
|
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1451,7 +1451,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodCondition, out *newer.PodCondition, s conversion.Scope) error {
|
func(in *PodCondition, out *api.PodCondition, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
|
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1461,9 +1461,9 @@ func addConversionFuncs() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.PodConditionType, out *PodConditionKind, s conversion.Scope) error {
|
func(in *api.PodConditionType, out *PodConditionKind, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case newer.PodReady:
|
case api.PodReady:
|
||||||
*out = PodReady
|
*out = PodReady
|
||||||
break
|
break
|
||||||
case "":
|
case "":
|
||||||
@ -1474,31 +1474,31 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *PodConditionKind, out *newer.PodConditionType, s conversion.Scope) error {
|
func(in *PodConditionKind, out *api.PodConditionType, s conversion.Scope) error {
|
||||||
switch *in {
|
switch *in {
|
||||||
case PodReady:
|
case PodReady:
|
||||||
*out = newer.PodReady
|
*out = api.PodReady
|
||||||
break
|
break
|
||||||
case "":
|
case "":
|
||||||
*out = ""
|
*out = ""
|
||||||
default:
|
default:
|
||||||
*out = newer.PodConditionType(*in)
|
*out = api.PodConditionType(*in)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *Binding, out *newer.Binding, s conversion.Scope) error {
|
func(in *Binding, out *api.Binding, s conversion.Scope) error {
|
||||||
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
|
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Target = newer.ObjectReference{
|
out.Target = api.ObjectReference{
|
||||||
Name: in.Host,
|
Name: in.Host,
|
||||||
}
|
}
|
||||||
out.Name = in.PodID
|
out.Name = in.PodID
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.Binding, out *Binding, s conversion.Scope) error {
|
func(in *api.Binding, out *Binding, s conversion.Scope) error {
|
||||||
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
|
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1506,11 +1506,11 @@ func addConversionFuncs() {
|
|||||||
out.PodID = in.Name
|
out.PodID = in.Name
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.SecretVolumeSource, out *SecretVolumeSource, s conversion.Scope) error {
|
func(in *api.SecretVolumeSource, out *SecretVolumeSource, s conversion.Scope) error {
|
||||||
out.Target.ID = in.SecretName
|
out.Target.ID = in.SecretName
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *SecretVolumeSource, out *newer.SecretVolumeSource, s conversion.Scope) error {
|
func(in *SecretVolumeSource, out *api.SecretVolumeSource, s conversion.Scope) error {
|
||||||
out.SecretName = in.Target.ID
|
out.SecretName = in.Target.ID
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -1521,7 +1521,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add field conversion funcs.
|
// Add field conversion funcs.
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Pod",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Pod",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "name":
|
case "name":
|
||||||
@ -1530,8 +1530,8 @@ func addConversionFuncs() {
|
|||||||
return "spec.host", value, nil
|
return "spec.host", value, nil
|
||||||
case "DesiredState.Status":
|
case "DesiredState.Status":
|
||||||
podStatus := PodStatus(value)
|
podStatus := PodStatus(value)
|
||||||
var internalValue newer.PodPhase
|
var internalValue api.PodPhase
|
||||||
newer.Scheme.Convert(&podStatus, &internalValue)
|
api.Scheme.Convert(&podStatus, &internalValue)
|
||||||
return "status.phase", string(internalValue), nil
|
return "status.phase", string(internalValue), nil
|
||||||
default:
|
default:
|
||||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||||
@ -1541,7 +1541,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Node",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Node",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "name":
|
case "name":
|
||||||
@ -1556,7 +1556,7 @@ func addConversionFuncs() {
|
|||||||
// if one of the conversion functions is malformed, detect it immediately.
|
// if one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "ReplicationController",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "ReplicationController",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "name":
|
case "name":
|
||||||
@ -1571,7 +1571,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Event",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Event",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "involvedObject.kind",
|
case "involvedObject.kind",
|
||||||
@ -1593,7 +1593,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Namespace",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Namespace",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "status.phase":
|
case "status.phase":
|
||||||
@ -1606,7 +1606,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Secret",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Secret",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "type":
|
case "type":
|
||||||
@ -1619,7 +1619,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "ServiceAccount",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "ServiceAccount",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "name":
|
case "name":
|
||||||
|
@ -21,39 +21,39 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceEmptySelector(t *testing.T) {
|
func TestServiceEmptySelector(t *testing.T) {
|
||||||
// Nil map should be preserved
|
// Nil map should be preserved
|
||||||
svc := ¤t.Service{Selector: nil}
|
svc := &versioned.Service{Selector: nil}
|
||||||
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta2")
|
data, err := api.Scheme.EncodeToVersion(svc, "v1beta2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
obj, err := newer.Scheme.Decode(data)
|
obj, err := api.Scheme.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
selector := obj.(*newer.Service).Spec.Selector
|
selector := obj.(*api.Service).Spec.Selector
|
||||||
if selector != nil {
|
if selector != nil {
|
||||||
t.Errorf("unexpected selector: %#v", obj)
|
t.Errorf("unexpected selector: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty map should be preserved
|
// Empty map should be preserved
|
||||||
svc2 := ¤t.Service{Selector: map[string]string{}}
|
svc2 := &versioned.Service{Selector: map[string]string{}}
|
||||||
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta2")
|
data, err = api.Scheme.EncodeToVersion(svc2, "v1beta2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
obj, err = newer.Scheme.Decode(data)
|
obj, err = api.Scheme.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
selector = obj.(*newer.Service).Spec.Selector
|
selector = obj.(*api.Service).Spec.Selector
|
||||||
if selector == nil || len(selector) != 0 {
|
if selector == nil || len(selector) != 0 {
|
||||||
t.Errorf("unexpected selector: %#v", obj)
|
t.Errorf("unexpected selector: %#v", obj)
|
||||||
}
|
}
|
||||||
@ -61,160 +61,160 @@ func TestServiceEmptySelector(t *testing.T) {
|
|||||||
|
|
||||||
func TestServicePorts(t *testing.T) {
|
func TestServicePorts(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
given current.Service
|
given versioned.Service
|
||||||
expected newer.Service
|
expected api.Service
|
||||||
roundtrip current.Service
|
roundtrip versioned.Service
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "legacy-with-defaults",
|
ID: "legacy-with-defaults",
|
||||||
},
|
},
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "legacy-full",
|
ID: "legacy-full",
|
||||||
},
|
},
|
||||||
PortName: "p",
|
PortName: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
TargetPort: util.NewIntOrStringFromString("p"),
|
TargetPort: util.NewIntOrStringFromString("p"),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "both",
|
ID: "both",
|
||||||
},
|
},
|
||||||
PortName: "p",
|
PortName: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromString("p"),
|
ContainerPort: util.NewIntOrStringFromString("p"),
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one",
|
ID: "one",
|
||||||
},
|
},
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Service{
|
given: versioned.Service{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "two",
|
ID: "two",
|
||||||
},
|
},
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(76),
|
ContainerPort: util.NewIntOrStringFromInt(76),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Service{
|
expected: api.Service{
|
||||||
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{
|
Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: newer.ProtocolUDP,
|
Protocol: api.ProtocolUDP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(93),
|
TargetPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: newer.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
TargetPort: util.NewIntOrStringFromInt(76),
|
TargetPort: util.NewIntOrStringFromInt(76),
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
roundtrip: current.Service{
|
roundtrip: versioned.Service{
|
||||||
Ports: []current.ServicePort{{
|
Ports: []versioned.ServicePort{{
|
||||||
Name: "p",
|
Name: "p",
|
||||||
Port: 111,
|
Port: 111,
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(93),
|
ContainerPort: util.NewIntOrStringFromInt(93),
|
||||||
}, {
|
}, {
|
||||||
Name: "q",
|
Name: "q",
|
||||||
Port: 222,
|
Port: 222,
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(76),
|
ContainerPort: util.NewIntOrStringFromInt(76),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -223,8 +223,8 @@ func TestServicePorts(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
// Convert versioned -> internal.
|
// Convert versioned -> internal.
|
||||||
got := newer.Service{}
|
got := api.Service{}
|
||||||
if err := newer.Scheme.Convert(&tc.given, &got); err != nil {
|
if err := api.Scheme.Convert(&tc.given, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -233,8 +233,8 @@ func TestServicePorts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert internal -> versioned.
|
// Convert internal -> versioned.
|
||||||
got2 := current.Service{}
|
got2 := versioned.Service{}
|
||||||
if err := newer.Scheme.Convert(&got, &got2); err != nil {
|
if err := api.Scheme.Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ func TestServicePorts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeConversion(t *testing.T) {
|
func TestNodeConversion(t *testing.T) {
|
||||||
version, kind, err := newer.Scheme.ObjectVersionAndKind(¤t.Minion{})
|
version, kind, err := api.Scheme.ObjectVersionAndKind(&versioned.Minion{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -253,30 +253,30 @@ func TestNodeConversion(t *testing.T) {
|
|||||||
t.Errorf("unexpected version and kind: %s %s", version, kind)
|
t.Errorf("unexpected version and kind: %s %s", version, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
newer.Scheme.Log(t)
|
api.Scheme.Log(t)
|
||||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`))
|
obj, err := versioned.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.Node); !ok {
|
if _, ok := obj.(*api.Node); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta2"}`))
|
obj, err = versioned.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta2"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.NodeList); !ok {
|
if _, ok := obj.(*api.NodeList); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`), obj); err != nil {
|
if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`), obj); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
data, err := current.Codec.Encode(obj)
|
data, err := versioned.Codec.Encode(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -291,18 +291,18 @@ func TestNodeConversion(t *testing.T) {
|
|||||||
|
|
||||||
func TestPullPolicyConversion(t *testing.T) {
|
func TestPullPolicyConversion(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
versioned current.PullPolicy
|
versioned versioned.PullPolicy
|
||||||
internal newer.PullPolicy
|
internal api.PullPolicy
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
versioned: current.PullAlways,
|
versioned: versioned.PullAlways,
|
||||||
internal: newer.PullAlways,
|
internal: api.PullAlways,
|
||||||
}, {
|
}, {
|
||||||
versioned: current.PullNever,
|
versioned: versioned.PullNever,
|
||||||
internal: newer.PullNever,
|
internal: api.PullNever,
|
||||||
}, {
|
}, {
|
||||||
versioned: current.PullIfNotPresent,
|
versioned: versioned.PullIfNotPresent,
|
||||||
internal: newer.PullIfNotPresent,
|
internal: api.PullIfNotPresent,
|
||||||
}, {
|
}, {
|
||||||
versioned: "",
|
versioned: "",
|
||||||
internal: "",
|
internal: "",
|
||||||
@ -312,8 +312,8 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
var got newer.PullPolicy
|
var got api.PullPolicy
|
||||||
err := newer.Scheme.Convert(&item.versioned, &got)
|
err := api.Scheme.Convert(&item.versioned, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
continue
|
continue
|
||||||
@ -323,8 +323,8 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
var got current.PullPolicy
|
var got versioned.PullPolicy
|
||||||
err := newer.Scheme.Convert(&item.internal, &got)
|
err := api.Scheme.Convert(&item.internal, &got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
continue
|
continue
|
||||||
@ -335,14 +335,14 @@ func TestPullPolicyConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResourceRequirements(cpu, memory resource.Quantity) current.ResourceRequirements {
|
func getResourceRequirements(cpu, memory resource.Quantity) versioned.ResourceRequirements {
|
||||||
res := current.ResourceRequirements{}
|
res := versioned.ResourceRequirements{}
|
||||||
res.Limits = current.ResourceList{}
|
res.Limits = versioned.ResourceList{}
|
||||||
if cpu.Value() > 0 {
|
if cpu.Value() > 0 {
|
||||||
res.Limits[current.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
|
res.Limits[versioned.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
|
||||||
}
|
}
|
||||||
if memory.Value() > 0 {
|
if memory.Value() > 0 {
|
||||||
res.Limits[current.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
|
res.Limits[versioned.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -352,7 +352,7 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
cpuLimit := resource.MustParse("10")
|
cpuLimit := resource.MustParse("10")
|
||||||
memoryLimit := resource.MustParse("10M")
|
memoryLimit := resource.MustParse("10M")
|
||||||
null := resource.Quantity{}
|
null := resource.Quantity{}
|
||||||
testCases := []current.Container{
|
testCases := []versioned.Container{
|
||||||
{
|
{
|
||||||
Name: "container",
|
Name: "container",
|
||||||
Resources: getResourceRequirements(cpuLimit, memoryLimit),
|
Resources: getResourceRequirements(cpuLimit, memoryLimit),
|
||||||
@ -385,8 +385,8 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
got := newer.Container{}
|
got := api.Container{}
|
||||||
if err := newer.Scheme.Convert(&tc, &got); err != nil {
|
if err := api.Scheme.Convert(&tc, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -401,114 +401,114 @@ func TestContainerConversion(t *testing.T) {
|
|||||||
|
|
||||||
func TestEndpointsConversion(t *testing.T) {
|
func TestEndpointsConversion(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
given current.Endpoints
|
given versioned.Endpoints
|
||||||
expected newer.Endpoints
|
expected api.Endpoints
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "empty",
|
ID: "empty",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{},
|
Endpoints: []string{},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{},
|
Subsets: []api.EndpointSubset{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one legacy",
|
ID: "one legacy",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{"1.2.3.4:88"},
|
Endpoints: []string{"1.2.3.4:88"},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{{
|
Subsets: []api.EndpointSubset{{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "several legacy",
|
ID: "several legacy",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
|
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{
|
Subsets: []api.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 90, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 90, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "one subset",
|
ID: "one subset",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolTCP,
|
Protocol: versioned.ProtocolTCP,
|
||||||
Endpoints: []string{"1.2.3.4:88"},
|
Endpoints: []string{"1.2.3.4:88"},
|
||||||
Subsets: []current.EndpointSubset{{
|
Subsets: []versioned.EndpointSubset{{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolTCP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolTCP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{{
|
Subsets: []api.EndpointSubset{{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
given: current.Endpoints{
|
given: versioned.Endpoints{
|
||||||
TypeMeta: current.TypeMeta{
|
TypeMeta: versioned.TypeMeta{
|
||||||
ID: "several subset",
|
ID: "several subset",
|
||||||
},
|
},
|
||||||
Protocol: current.ProtocolUDP,
|
Protocol: versioned.ProtocolUDP,
|
||||||
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
|
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
|
||||||
Subsets: []current.EndpointSubset{
|
Subsets: []versioned.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "", Port: 89, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "", Port: 89, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []current.EndpointPort{{Name: "named", Port: 90, Protocol: current.ProtocolUDP}},
|
Ports: []versioned.EndpointPort{{Name: "named", Port: 90, Protocol: versioned.ProtocolUDP}},
|
||||||
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: newer.Endpoints{
|
expected: api.Endpoints{
|
||||||
Subsets: []newer.EndpointSubset{
|
Subsets: []api.EndpointSubset{
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Ports: []newer.EndpointPort{{Name: "named", Port: 90, Protocol: newer.ProtocolUDP}},
|
Ports: []api.EndpointPort{{Name: "named", Port: 90, Protocol: api.ProtocolUDP}},
|
||||||
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -516,48 +516,48 @@ func TestEndpointsConversion(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
// Convert versioned -> internal.
|
// Convert versioned -> internal.
|
||||||
got := newer.Endpoints{}
|
got := api.Endpoints{}
|
||||||
if err := newer.Scheme.Convert(&tc.given, &got); err != nil {
|
if err := api.Scheme.Convert(&tc.given, &got); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !newer.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
|
if !api.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
|
||||||
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
|
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert internal -> versioned.
|
// Convert internal -> versioned.
|
||||||
got2 := current.Endpoints{}
|
got2 := versioned.Endpoints{}
|
||||||
if err := newer.Scheme.Convert(&got, &got2); err != nil {
|
if err := api.Scheme.Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
t.Errorf("[Case: %d] Unexpected error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if got2.Protocol != tc.given.Protocol || !newer.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
|
if got2.Protocol != tc.given.Protocol || !api.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
|
||||||
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.given.Endpoints, got2.Endpoints)
|
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.given.Endpoints, got2.Endpoints)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretVolumeSourceConversion(t *testing.T) {
|
func TestSecretVolumeSourceConversion(t *testing.T) {
|
||||||
given := current.SecretVolumeSource{
|
given := versioned.SecretVolumeSource{
|
||||||
Target: current.ObjectReference{
|
Target: versioned.ObjectReference{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := newer.SecretVolumeSource{
|
expected := api.SecretVolumeSource{
|
||||||
SecretName: "foo",
|
SecretName: "foo",
|
||||||
}
|
}
|
||||||
|
|
||||||
got := newer.SecretVolumeSource{}
|
got := api.SecretVolumeSource{}
|
||||||
if err := newer.Scheme.Convert(&given, &got); err != nil {
|
if err := api.Scheme.Convert(&given, &got); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if got.SecretName != expected.SecretName {
|
if got.SecretName != expected.SecretName {
|
||||||
t.Errorf("Expected %v; got %v", expected, got)
|
t.Errorf("Expected %v; got %v", expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
got2 := current.SecretVolumeSource{}
|
got2 := versioned.SecretVolumeSource{}
|
||||||
if err := newer.Scheme.Convert(&got, &got2); err != nil {
|
if err := api.Scheme.Convert(&got, &got2); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if got2.Target.ID != given.Target.ID {
|
if got2.Target.ID != given.Target.ID {
|
||||||
@ -568,42 +568,42 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
|
|||||||
func TestBadSecurityContextConversion(t *testing.T) {
|
func TestBadSecurityContextConversion(t *testing.T) {
|
||||||
priv := false
|
priv := false
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
c *current.Container
|
c *versioned.Container
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
||||||
// will assume privileged was left undefined (since it is the default value) and copy the
|
// will assume privileged was left undefined (since it is the default value) and copy the
|
||||||
// sc setting upwards
|
// sc setting upwards
|
||||||
"mismatched privileged": {
|
"mismatched privileged": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container privileged settings do not match security context settings, cannot convert",
|
err: "container privileged settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps add": {
|
"mismatched caps add": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"bar"},
|
Add: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container capability settings do not match security context settings, cannot convert",
|
err: "container capability settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps drop": {
|
"mismatched caps drop": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Drop: []current.Capability{"foo"},
|
Drop: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -612,8 +612,8 @@ func TestBadSecurityContextConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range testCases {
|
for k, v := range testCases {
|
||||||
got := newer.Container{}
|
got := api.Container{}
|
||||||
err := newer.Scheme.Convert(v.c, &got)
|
err := api.Scheme.Convert(v.c, &got)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected error for case %s but got none", k)
|
t.Errorf("expected error for case %s but got none", k)
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addConversionFuncs() {
|
func addConversionFuncs() {
|
||||||
// Add non-generated conversion functions
|
// Add non-generated conversion functions
|
||||||
err := newer.Scheme.AddConversionFuncs(
|
err := api.Scheme.AddConversionFuncs(
|
||||||
convert_v1beta3_Container_To_api_Container,
|
convert_v1beta3_Container_To_api_Container,
|
||||||
convert_api_Container_To_v1beta3_Container,
|
convert_api_Container_To_v1beta3_Container,
|
||||||
)
|
)
|
||||||
@ -36,7 +36,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add field conversion funcs.
|
// Add field conversion funcs.
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name",
|
case "metadata.name",
|
||||||
@ -52,7 +52,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name":
|
case "metadata.name":
|
||||||
@ -67,7 +67,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name",
|
case "metadata.name",
|
||||||
@ -81,7 +81,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Event",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Event",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "involvedObject.kind",
|
case "involvedObject.kind",
|
||||||
@ -102,7 +102,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Namespace",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Namespace",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "status.phase":
|
case "status.phase":
|
||||||
@ -115,7 +115,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Secret",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Secret",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "type":
|
case "type":
|
||||||
@ -128,7 +128,7 @@ func addConversionFuncs() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ServiceAccount",
|
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ServiceAccount",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "metadata.name":
|
case "metadata.name":
|
||||||
@ -143,7 +143,7 @@ func addConversionFuncs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Container, s conversion.Scope) error {
|
func convert_v1beta3_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error {
|
||||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||||
defaulting.(func(*Container))(in)
|
defaulting.(func(*Container))(in)
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
}
|
}
|
||||||
out.WorkingDir = in.WorkingDir
|
out.WorkingDir = in.WorkingDir
|
||||||
if in.Ports != nil {
|
if in.Ports != nil {
|
||||||
out.Ports = make([]newer.ContainerPort, len(in.Ports))
|
out.Ports = make([]api.ContainerPort, len(in.Ports))
|
||||||
for i := range in.Ports {
|
for i := range in.Ports {
|
||||||
if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -171,7 +171,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.Env != nil {
|
if in.Env != nil {
|
||||||
out.Env = make([]newer.EnvVar, len(in.Env))
|
out.Env = make([]api.EnvVar, len(in.Env))
|
||||||
for i := range in.Env {
|
for i := range in.Env {
|
||||||
if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
|
if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -182,7 +182,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if in.VolumeMounts != nil {
|
if in.VolumeMounts != nil {
|
||||||
out.VolumeMounts = make([]newer.VolumeMount, len(in.VolumeMounts))
|
out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts))
|
||||||
for i := range in.VolumeMounts {
|
for i := range in.VolumeMounts {
|
||||||
if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
|
if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -190,7 +190,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.LivenessProbe != nil {
|
if in.LivenessProbe != nil {
|
||||||
out.LivenessProbe = new(newer.Probe)
|
out.LivenessProbe = new(api.Probe)
|
||||||
if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
|
if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
out.LivenessProbe = nil
|
out.LivenessProbe = nil
|
||||||
}
|
}
|
||||||
if in.ReadinessProbe != nil {
|
if in.ReadinessProbe != nil {
|
||||||
out.ReadinessProbe = new(newer.Probe)
|
out.ReadinessProbe = new(api.Probe)
|
||||||
if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
|
if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
out.ReadinessProbe = nil
|
out.ReadinessProbe = nil
|
||||||
}
|
}
|
||||||
if in.Lifecycle != nil {
|
if in.Lifecycle != nil {
|
||||||
out.Lifecycle = new(newer.Lifecycle)
|
out.Lifecycle = new(api.Lifecycle)
|
||||||
if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
|
if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
out.Lifecycle = nil
|
out.Lifecycle = nil
|
||||||
}
|
}
|
||||||
out.TerminationMessagePath = in.TerminationMessagePath
|
out.TerminationMessagePath = in.TerminationMessagePath
|
||||||
out.ImagePullPolicy = newer.PullPolicy(in.ImagePullPolicy)
|
out.ImagePullPolicy = api.PullPolicy(in.ImagePullPolicy)
|
||||||
if in.SecurityContext != nil {
|
if in.SecurityContext != nil {
|
||||||
if in.SecurityContext.Capabilities != nil {
|
if in.SecurityContext.Capabilities != nil {
|
||||||
if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) ||
|
if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) ||
|
||||||
@ -229,7 +229,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.SecurityContext != nil {
|
if in.SecurityContext != nil {
|
||||||
out.SecurityContext = new(newer.SecurityContext)
|
out.SecurityContext = new(api.SecurityContext)
|
||||||
if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -239,9 +239,9 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convert_api_Container_To_v1beta3_Container(in *newer.Container, out *Container, s conversion.Scope) error {
|
func convert_api_Container_To_v1beta3_Container(in *api.Container, out *Container, s conversion.Scope) error {
|
||||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||||
defaulting.(func(*newer.Container))(in)
|
defaulting.(func(*api.Container))(in)
|
||||||
}
|
}
|
||||||
out.Name = in.Name
|
out.Name = in.Name
|
||||||
out.Image = in.Image
|
out.Image = in.Image
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,29 +19,29 @@ package v1beta3_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeConversion(t *testing.T) {
|
func TestNodeConversion(t *testing.T) {
|
||||||
obj, err := current.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`))
|
obj, err := versioned.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.Node); !ok {
|
if _, ok := obj.(*api.Node); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err = current.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`))
|
obj, err = versioned.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := obj.(*newer.NodeList); !ok {
|
if _, ok := obj.(*api.NodeList); !ok {
|
||||||
t.Errorf("unexpected type: %#v", obj)
|
t.Errorf("unexpected type: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = &newer.Node{}
|
obj = &api.Node{}
|
||||||
if err := current.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil {
|
if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,42 +49,42 @@ func TestNodeConversion(t *testing.T) {
|
|||||||
func TestBadSecurityContextConversion(t *testing.T) {
|
func TestBadSecurityContextConversion(t *testing.T) {
|
||||||
priv := false
|
priv := false
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
c *current.Container
|
c *versioned.Container
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
||||||
// will assume privileged was left undefined (since it is the default value) and copy the
|
// will assume privileged was left undefined (since it is the default value) and copy the
|
||||||
// sc setting upwards
|
// sc setting upwards
|
||||||
"mismatched privileged": {
|
"mismatched privileged": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container privileged settings do not match security context settings, cannot convert",
|
err: "container privileged settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps add": {
|
"mismatched caps add": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"bar"},
|
Add: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
err: "container capability settings do not match security context settings, cannot convert",
|
err: "container capability settings do not match security context settings, cannot convert",
|
||||||
},
|
},
|
||||||
"mismatched caps drop": {
|
"mismatched caps drop": {
|
||||||
c: ¤t.Container{
|
c: &versioned.Container{
|
||||||
Capabilities: current.Capabilities{
|
Capabilities: versioned.Capabilities{
|
||||||
Drop: []current.Capability{"foo"},
|
Drop: []versioned.Capability{"foo"},
|
||||||
},
|
},
|
||||||
SecurityContext: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -93,8 +93,8 @@ func TestBadSecurityContextConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range testCases {
|
for k, v := range testCases {
|
||||||
got := newer.Container{}
|
got := api.Container{}
|
||||||
err := newer.Scheme.Convert(v.c, &got)
|
err := api.Scheme.Convert(v.c, &got)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected error for case %s but got none", k)
|
t.Errorf("expected error for case %s but got none", k)
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,53 +19,53 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := newer.Scheme.AddConversionFuncs(
|
err := api.Scheme.AddConversionFuncs(
|
||||||
func(in *Cluster, out *newer.Cluster, s conversion.Scope) error {
|
func(in *Cluster, out *api.Cluster, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *newer.Cluster, out *Cluster, s conversion.Scope) error {
|
func(in *api.Cluster, out *Cluster, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *Preferences, out *newer.Preferences, s conversion.Scope) error {
|
func(in *Preferences, out *api.Preferences, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *newer.Preferences, out *Preferences, s conversion.Scope) error {
|
func(in *api.Preferences, out *Preferences, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *AuthInfo, out *newer.AuthInfo, s conversion.Scope) error {
|
func(in *AuthInfo, out *api.AuthInfo, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *newer.AuthInfo, out *AuthInfo, s conversion.Scope) error {
|
func(in *api.AuthInfo, out *AuthInfo, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *Context, out *newer.Context, s conversion.Scope) error {
|
func(in *Context, out *api.Context, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
func(in *newer.Context, out *Context, s conversion.Scope) error {
|
func(in *api.Context, out *Context, s conversion.Scope) error {
|
||||||
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *Config, out *newer.Config, s conversion.Scope) error {
|
func(in *Config, out *api.Config, s conversion.Scope) error {
|
||||||
out.CurrentContext = in.CurrentContext
|
out.CurrentContext = in.CurrentContext
|
||||||
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
|
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Clusters = make(map[string]newer.Cluster)
|
out.Clusters = make(map[string]api.Cluster)
|
||||||
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
|
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.AuthInfos = make(map[string]newer.AuthInfo)
|
out.AuthInfos = make(map[string]api.AuthInfo)
|
||||||
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
|
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Contexts = make(map[string]newer.Context)
|
out.Contexts = make(map[string]api.Context)
|
||||||
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
|
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *newer.Config, out *Config, s conversion.Scope) error {
|
func(in *api.Config, out *Config, s conversion.Scope) error {
|
||||||
out.CurrentContext = in.CurrentContext
|
out.CurrentContext = in.CurrentContext
|
||||||
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
|
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -99,9 +99,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *[]NamedCluster, out *map[string]newer.Cluster, s conversion.Scope) error {
|
func(in *[]NamedCluster, out *map[string]api.Cluster, s conversion.Scope) error {
|
||||||
for _, curr := range *in {
|
for _, curr := range *in {
|
||||||
newCluster := newer.NewCluster()
|
newCluster := api.NewCluster()
|
||||||
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
|
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ func init() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *map[string]newer.Cluster, out *[]NamedCluster, s conversion.Scope) error {
|
func(in *map[string]api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
|
||||||
allKeys := make([]string, 0, len(*in))
|
allKeys := make([]string, 0, len(*in))
|
||||||
for key := range *in {
|
for key := range *in {
|
||||||
allKeys = append(allKeys, key)
|
allKeys = append(allKeys, key)
|
||||||
@ -130,9 +130,9 @@ func init() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *[]NamedAuthInfo, out *map[string]newer.AuthInfo, s conversion.Scope) error {
|
func(in *[]NamedAuthInfo, out *map[string]api.AuthInfo, s conversion.Scope) error {
|
||||||
for _, curr := range *in {
|
for _, curr := range *in {
|
||||||
newAuthInfo := newer.NewAuthInfo()
|
newAuthInfo := api.NewAuthInfo()
|
||||||
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
|
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ func init() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *map[string]newer.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
|
func(in *map[string]api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
|
||||||
allKeys := make([]string, 0, len(*in))
|
allKeys := make([]string, 0, len(*in))
|
||||||
for key := range *in {
|
for key := range *in {
|
||||||
allKeys = append(allKeys, key)
|
allKeys = append(allKeys, key)
|
||||||
@ -161,9 +161,9 @@ func init() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *[]NamedContext, out *map[string]newer.Context, s conversion.Scope) error {
|
func(in *[]NamedContext, out *map[string]api.Context, s conversion.Scope) error {
|
||||||
for _, curr := range *in {
|
for _, curr := range *in {
|
||||||
newContext := newer.NewContext()
|
newContext := api.NewContext()
|
||||||
if err := s.Convert(&curr.Context, newContext, 0); err != nil {
|
if err := s.Convert(&curr.Context, newContext, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ func init() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(in *map[string]newer.Context, out *[]NamedContext, s conversion.Scope) error {
|
func(in *map[string]api.Context, out *[]NamedContext, s conversion.Scope) error {
|
||||||
allKeys := make([]string, 0, len(*in))
|
allKeys := make([]string, 0, len(*in))
|
||||||
for key := range *in {
|
for key := range *in {
|
||||||
allKeys = append(allKeys, key)
|
allKeys = append(allKeys, key)
|
||||||
|
@ -36,7 +36,6 @@ import (
|
|||||||
func generateConversions(t *testing.T, version string) bytes.Buffer {
|
func generateConversions(t *testing.T, version string) bytes.Buffer {
|
||||||
g := runtime.NewConversionGenerator(api.Scheme.Raw())
|
g := runtime.NewConversionGenerator(api.Scheme.Raw())
|
||||||
g.OverwritePackage(version, "")
|
g.OverwritePackage(version, "")
|
||||||
g.OverwritePackage("api", "newer")
|
|
||||||
for _, knownType := range api.Scheme.KnownTypes(version) {
|
for _, knownType := range api.Scheme.KnownTypes(version) {
|
||||||
if err := g.GenerateConversionsForType(version, knownType); err != nil {
|
if err := g.GenerateConversionsForType(version, knownType); err != nil {
|
||||||
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
|
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
|
||||||
@ -126,8 +125,8 @@ func compareBuffers(t *testing.T, generatedFile string, existing, generated byte
|
|||||||
}
|
}
|
||||||
if existingLine != generatedLine {
|
if existingLine != generatedLine {
|
||||||
ok = false
|
ok = false
|
||||||
diff := fmt.Sprintf("first difference: expected %s, got %s", generatedLine, existingLine)
|
diff := fmt.Sprintf("\nexpected: %s\n got: %s", generatedLine, existingLine)
|
||||||
t.Errorf("please update conversion functions; generated: %s; diff: %s", generatedFile, diff)
|
t.Errorf("please update conversion functions; generated: %s; first diff: %s", generatedFile, diff)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func (g *conversionGenerator) WriteConversionFunctions(w io.Writer) error {
|
|||||||
|
|
||||||
func (g *conversionGenerator) writeRegisterHeader(b *buffer, indent int) {
|
func (g *conversionGenerator) writeRegisterHeader(b *buffer, indent int) {
|
||||||
b.addLine("func init() {\n", indent)
|
b.addLine("func init() {\n", indent)
|
||||||
b.addLine("err := newer.Scheme.AddGeneratedConversionFuncs(\n", indent+1)
|
b.addLine("err := api.Scheme.AddGeneratedConversionFuncs(\n", indent+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *conversionGenerator) writeRegisterFooter(b *buffer, indent int) {
|
func (g *conversionGenerator) writeRegisterFooter(b *buffer, indent int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user