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