Merge pull request #8299 from thockin/import-names

rename imported pkgs for readability
This commit is contained in:
Tim Hockin
2015-05-19 12:01:57 -07:00
20 changed files with 2168 additions and 2171 deletions

View File

@@ -56,8 +56,6 @@ func main() {
generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw()) generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw())
// TODO(wojtek-t): Change the overwrites to a flag. // TODO(wojtek-t): Change the overwrites to a flag.
generator.OverwritePackage(*version, "") generator.OverwritePackage(*version, "")
// TODO(wojtek-t): Get rid of this overwrite.
generator.OverwritePackage("api", "newer")
for _, knownType := range api.Scheme.KnownTypes(*version) { for _, knownType := range api.Scheme.KnownTypes(*version) {
if err := generator.GenerateConversionsForType(*version, knownType); err != nil { if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err) glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)

View File

@@ -255,7 +255,7 @@ regenerate auto-generated ones. To regenerate them:
``` ```
- replace all conversion functions (convert\* functions) in the - replace all conversion functions (convert\* functions) in the
`pkg/api/<version>/conversion_generated.go` with the contents of \<file1.txt\> `pkg/api/<version>/conversion_generated.go` with the contents of \<file1.txt\>
- replace arguments of `newer.Scheme.AddGeneratedConversionFuncs` in the - replace arguments of `api.Scheme.AddGeneratedConversionFuncs` in the
`pkg/api/<version>/conversion_generated.go` with the contents of \<file2.txt\> `pkg/api/<version>/conversion_generated.go` with the contents of \<file2.txt\>
Unsurprisingly, adding manually written conversion also requires you to add tests to Unsurprisingly, adding manually written conversion also requires you to add tests to

View File

@@ -34,7 +34,7 @@ package ${version}
import ( import (
"reflect" "reflect"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
) )

View File

@@ -19,18 +19,18 @@ package v1
import ( import (
"fmt" "fmt"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func addConversionFuncs() { func addConversionFuncs() {
err := newer.Scheme.AddConversionFuncs() err := api.Scheme.AddConversionFuncs()
if err != nil { if err != nil {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
// Add field conversion funcs. // Add field conversion funcs.
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Pod", err = api.Scheme.AddFieldLabelConversionFunc("v1", "Pod",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name", case "metadata.name",
@@ -46,7 +46,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Node", err = api.Scheme.AddFieldLabelConversionFunc("v1", "Node",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name": case "metadata.name":
@@ -61,7 +61,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "ReplicationController", err = api.Scheme.AddFieldLabelConversionFunc("v1", "ReplicationController",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name", case "metadata.name",
@@ -75,7 +75,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Event", err = api.Scheme.AddFieldLabelConversionFunc("v1", "Event",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "involvedObject.kind", case "involvedObject.kind",
@@ -96,7 +96,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1", "Namespace", err = api.Scheme.AddFieldLabelConversionFunc("v1", "Namespace",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "status.phase": case "status.phase":

File diff suppressed because it is too large Load Diff

View File

@@ -19,29 +19,29 @@ package v1_test
import ( import (
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
) )
func TestNodeConversion(t *testing.T) { func TestNodeConversion(t *testing.T) {
obj, err := current.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1"}`)) obj, err := versioned.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.Node); !ok { if _, ok := obj.(*api.Node); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj, err = current.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1"}`)) obj, err = versioned.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.NodeList); !ok { if _, ok := obj.(*api.NodeList); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj = &newer.Node{} obj = &api.Node{}
if err := current.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1"}`), obj); err != nil { if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1"}`), obj); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
} }

View File

@@ -20,25 +20,25 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Errorf("%v\n %#v", err, obj) t.Errorf("%v\n %#v", err, obj)
return nil return nil
} }
obj2, err := newer.Codec.Decode(data) obj2, err := api.Codec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj) t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil return nil
} }
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = newer.Scheme.Convert(obj2, obj3) err = api.Scheme.Convert(obj2, obj3)
if err != nil { if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2) t.Errorf("%v\nSource: %#v", err, obj2)
return nil return nil
@@ -48,15 +48,15 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultReplicationController(t *testing.T) { func TestSetDefaultReplicationController(t *testing.T) {
tests := []struct { tests := []struct {
rc *current.ReplicationController rc *versioned.ReplicationController
expectLabels bool expectLabels bool
expectSelector bool expectSelector bool
}{ }{
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -68,15 +68,15 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
}, },
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -88,18 +88,18 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
}, },
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Selector: map[string]string{ Selector: map[string]string{
"some": "other", "some": "other",
}, },
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -111,13 +111,13 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: false, expectSelector: false,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Selector: map[string]string{ Selector: map[string]string{
"some": "other", "some": "other",
}, },
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -133,7 +133,7 @@ func TestSetDefaultReplicationController(t *testing.T) {
for _, test := range tests { for _, test := range tests {
rc := test.rc rc := test.rc
obj2 := roundTrip(t, runtime.Object(rc)) obj2 := roundTrip(t, runtime.Object(rc))
rc2, ok := obj2.(*current.ReplicationController) rc2, ok := obj2.(*versioned.ReplicationController)
if !ok { if !ok {
t.Errorf("unexpected object: %v", rc2) t.Errorf("unexpected object: %v", rc2)
t.FailNow() t.FailNow()
@@ -156,56 +156,56 @@ func TestSetDefaultReplicationController(t *testing.T) {
} }
func TestSetDefaultService(t *testing.T) { func TestSetDefaultService(t *testing.T) {
svc := &current.Service{} svc := &versioned.Service{}
obj2 := roundTrip(t, runtime.Object(svc)) obj2 := roundTrip(t, runtime.Object(svc))
svc2 := obj2.(*current.Service) svc2 := obj2.(*versioned.Service)
if svc2.Spec.SessionAffinity != current.ServiceAffinityNone { if svc2.Spec.SessionAffinity != versioned.ServiceAffinityNone {
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.Spec.SessionAffinity) t.Errorf("Expected default sesseion affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.Spec.SessionAffinity)
} }
} }
func TestSetDefaultSecret(t *testing.T) { func TestSetDefaultSecret(t *testing.T) {
s := &current.Secret{} s := &versioned.Secret{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Secret) s2 := obj2.(*versioned.Secret)
if s2.Type != current.SecretTypeOpaque { if s2.Type != versioned.SecretTypeOpaque {
t.Errorf("Expected secret type %v, got %v", current.SecretTypeOpaque, s2.Type) t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
} }
} }
func TestSetDefaultPersistentVolume(t *testing.T) { func TestSetDefaultPersistentVolume(t *testing.T) {
pv := &current.PersistentVolume{} pv := &versioned.PersistentVolume{}
obj2 := roundTrip(t, runtime.Object(pv)) obj2 := roundTrip(t, runtime.Object(pv))
pv2 := obj2.(*current.PersistentVolume) pv2 := obj2.(*versioned.PersistentVolume)
if pv2.Status.Phase != current.VolumePending { if pv2.Status.Phase != versioned.VolumePending {
t.Errorf("Expected volume phase %v, got %v", current.VolumePending, pv2.Status.Phase) t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
} }
} }
func TestSetDefaultPersistentVolumeClaim(t *testing.T) { func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
pvc := &current.PersistentVolumeClaim{} pvc := &versioned.PersistentVolumeClaim{}
obj2 := roundTrip(t, runtime.Object(pvc)) obj2 := roundTrip(t, runtime.Object(pvc))
pvc2 := obj2.(*current.PersistentVolumeClaim) pvc2 := obj2.(*versioned.PersistentVolumeClaim)
if pvc2.Status.Phase != current.ClaimPending { if pvc2.Status.Phase != versioned.ClaimPending {
t.Errorf("Expected claim phase %v, got %v", current.ClaimPending, pvc2.Status.Phase) t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
} }
} }
func TestSetDefaulEndpointsProtocol(t *testing.T) { func TestSetDefaulEndpointsProtocol(t *testing.T) {
in := &current.Endpoints{Subsets: []current.EndpointSubset{ in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
{Ports: []current.EndpointPort{{}, {Protocol: "UDP"}, {}}}, {Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
}} }}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
for i := range out.Subsets { for i := range out.Subsets {
for j := range out.Subsets[i].Ports { for j := range out.Subsets[i].Ports {
if in.Subsets[i].Ports[j].Protocol == "" { if in.Subsets[i].Ports[j].Protocol == "" {
if out.Subsets[i].Ports[j].Protocol != current.ProtocolTCP { if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Subsets[i].Ports[j].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
} }
} else { } else {
if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol { if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol {
@@ -217,16 +217,16 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
} }
func TestSetDefaulServiceTargetPort(t *testing.T) { func TestSetDefaulServiceTargetPort(t *testing.T) {
in := &current.Service{Spec: current.ServiceSpec{Ports: []current.ServicePort{{Port: 1234}}}} in := &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234}}}}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Service) out := obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) {
t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.Ports[0].TargetPort) t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.Ports[0].TargetPort)
} }
in = &current.Service{Spec: current.ServiceSpec{Ports: []current.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}} in = &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}}
obj = roundTrip(t, runtime.Object(in)) obj = roundTrip(t, runtime.Object(in))
out = obj.(*current.Service) out = obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) {
t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.Ports[0].TargetPort) t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.Ports[0].TargetPort)
} }
@@ -234,42 +234,42 @@ func TestSetDefaulServiceTargetPort(t *testing.T) {
func TestSetDefaultServicePort(t *testing.T) { func TestSetDefaultServicePort(t *testing.T) {
// Unchanged if set. // Unchanged if set.
in := &current.Service{Spec: current.ServiceSpec{ in := &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []current.ServicePort{ Ports: []versioned.ServicePort{
{Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")}, {Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")},
{Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)}, {Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)},
}, },
}} }}
out := roundTrip(t, runtime.Object(in)).(*current.Service) out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != current.ProtocolUDP { if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
} }
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") {
t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort) t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
} }
if out.Spec.Ports[1].Protocol != current.ProtocolUDP { if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[1].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
} }
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) { if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) {
t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort) t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Spec: current.ServiceSpec{ in = &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []current.ServicePort{ Ports: []versioned.ServicePort{
{Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")}, {Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")},
{Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)}, {Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)},
}, },
}} }}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != current.ProtocolTCP { if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
} }
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) {
t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort) t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
} }
if out.Spec.Ports[1].Protocol != current.ProtocolTCP { if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[1].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
} }
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) { if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) {
t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort) t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
@@ -277,33 +277,33 @@ func TestSetDefaultServicePort(t *testing.T) {
} }
func TestSetDefaultNamespace(t *testing.T) { func TestSetDefaultNamespace(t *testing.T) {
s := &current.Namespace{} s := &versioned.Namespace{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Namespace) s2 := obj2.(*versioned.Namespace)
if s2.Status.Phase != current.NamespaceActive { if s2.Status.Phase != versioned.NamespaceActive {
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase) t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
} }
} }
func TestSetDefaultPodSpecHostNetwork(t *testing.T) { func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
portNum := 8080 portNum := 8080
s := current.PodSpec{} s := versioned.PodSpec{}
s.HostNetwork = true s.HostNetwork = true
s.Containers = []current.Container{ s.Containers = []versioned.Container{
{ {
Ports: []current.ContainerPort{ Ports: []versioned.ContainerPort{
{ {
ContainerPort: portNum, ContainerPort: portNum,
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
Spec: s, Spec: s,
} }
obj2 := roundTrip(t, runtime.Object(pod)) obj2 := roundTrip(t, runtime.Object(pod))
pod2 := obj2.(*current.Pod) pod2 := obj2.(*versioned.Pod)
s2 := pod2.Spec s2 := pod2.Spec
hostPortNum := s2.Containers[0].Ports[0].HostPort hostPortNum := s2.Containers[0].Ports[0].HostPort
@@ -314,34 +314,34 @@ func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
func TestSetDefaultNodeExternalID(t *testing.T) { func TestSetDefaultNodeExternalID(t *testing.T) {
name := "node0" name := "node0"
n := &current.Node{} n := &versioned.Node{}
n.Name = name n.Name = name
obj2 := roundTrip(t, runtime.Object(n)) obj2 := roundTrip(t, runtime.Object(n))
n2 := obj2.(*current.Node) n2 := obj2.(*versioned.Node)
if n2.Spec.ExternalID != name { if n2.Spec.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID) t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
} }
} }
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) { func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
s := current.PodSpec{ s := versioned.PodSpec{
Containers: []current.Container{ Containers: []versioned.Container{
{ {
Env: []current.EnvVar{ Env: []versioned.EnvVar{
{ {
ValueFrom: &current.EnvVarSource{ ValueFrom: &versioned.EnvVarSource{
FieldRef: &current.ObjectFieldSelector{}, FieldRef: &versioned.ObjectFieldSelector{},
}, },
}, },
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
Spec: s, Spec: s,
} }
obj2 := roundTrip(t, runtime.Object(pod)) obj2 := roundTrip(t, runtime.Object(pod))
pod2 := obj2.(*current.Pod) pod2 := obj2.(*versioned.Pod)
s2 := pod2.Spec s2 := pod2.Spec
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion

File diff suppressed because it is too large Load Diff

View File

@@ -21,16 +21,16 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
var Convert = newer.Scheme.Convert var Convert = api.Scheme.Convert
func TestEmptyObjectConversion(t *testing.T) { func TestEmptyObjectConversion(t *testing.T) {
s, err := current.Codec.Encode(&current.LimitRange{}) s, err := versioned.Codec.Encode(&versioned.LimitRange{})
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -41,7 +41,7 @@ func TestEmptyObjectConversion(t *testing.T) {
} }
func TestNodeConversion(t *testing.T) { func TestNodeConversion(t *testing.T) {
version, kind, err := newer.Scheme.ObjectVersionAndKind(&current.Minion{}) version, kind, err := api.Scheme.ObjectVersionAndKind(&versioned.Minion{})
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -49,30 +49,30 @@ func TestNodeConversion(t *testing.T) {
t.Errorf("unexpected version and kind: %s %s", version, kind) t.Errorf("unexpected version and kind: %s %s", version, kind)
} }
newer.Scheme.Log(t) api.Scheme.Log(t)
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`)) obj, err := versioned.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.Node); !ok { if _, ok := obj.(*api.Node); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`)) obj, err = versioned.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.NodeList); !ok { if _, ok := obj.(*api.NodeList); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj = &newer.Node{} obj = &api.Node{}
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil { if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj = &newer.Node{} obj = &api.Node{}
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -86,16 +86,16 @@ func TestNodeConversion(t *testing.T) {
} }
func TestEnvConversion(t *testing.T) { func TestEnvConversion(t *testing.T) {
nonCanonical := []current.EnvVar{ nonCanonical := []versioned.EnvVar{
{Key: "EV"}, {Key: "EV"},
{Key: "EV", Name: "EX"}, {Key: "EV", Name: "EX"},
} }
canonical := []newer.EnvVar{ canonical := []api.EnvVar{
{Name: "EV"}, {Name: "EV"},
{Name: "EX"}, {Name: "EX"},
} }
for i := range nonCanonical { for i := range nonCanonical {
var got newer.EnvVar var got api.EnvVar
err := Convert(&nonCanonical[i], &got) err := Convert(&nonCanonical[i], &got)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -107,7 +107,7 @@ func TestEnvConversion(t *testing.T) {
// Test conversion the other way, too. // Test conversion the other way, too.
for i := range canonical { for i := range canonical {
var got current.EnvVar var got versioned.EnvVar
err := Convert(&canonical[i], &got) err := Convert(&canonical[i], &got)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -123,16 +123,16 @@ func TestEnvConversion(t *testing.T) {
func TestVolumeMountConversionToOld(t *testing.T) { func TestVolumeMountConversionToOld(t *testing.T) {
table := []struct { table := []struct {
in newer.VolumeMount in api.VolumeMount
out current.VolumeMount out versioned.VolumeMount
}{ }{
{ {
in: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true}, in: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
out: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true}, out: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
}, },
} }
for _, item := range table { for _, item := range table {
got := current.VolumeMount{} got := versioned.VolumeMount{}
err := Convert(&item.in, &got) err := Convert(&item.in, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@@ -146,22 +146,22 @@ func TestVolumeMountConversionToOld(t *testing.T) {
func TestVolumeMountConversionToNew(t *testing.T) { func TestVolumeMountConversionToNew(t *testing.T) {
table := []struct { table := []struct {
in current.VolumeMount in versioned.VolumeMount
out newer.VolumeMount out api.VolumeMount
}{ }{
{ {
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true}, in: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true}, out: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
}, { }, {
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true}, in: versioned.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true}, out: api.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
}, { }, {
in: current.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true}, in: versioned.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true}, out: api.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
}, },
} }
for _, item := range table { for _, item := range table {
got := newer.VolumeMount{} got := api.VolumeMount{}
err := Convert(&item.in, &got) err := Convert(&item.in, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@@ -174,116 +174,116 @@ func TestVolumeMountConversionToNew(t *testing.T) {
} }
func TestMinionListConversionToNew(t *testing.T) { func TestMinionListConversionToNew(t *testing.T) {
oldMinion := func(id string) current.Minion { oldMinion := func(id string) versioned.Minion {
return current.Minion{ return versioned.Minion{
TypeMeta: current.TypeMeta{ID: id}, TypeMeta: versioned.TypeMeta{ID: id},
ExternalID: id} ExternalID: id}
} }
newNode := func(id string) newer.Node { newNode := func(id string) api.Node {
return newer.Node{ return api.Node{
ObjectMeta: newer.ObjectMeta{Name: id}, ObjectMeta: api.ObjectMeta{Name: id},
Spec: newer.NodeSpec{ExternalID: id}, Spec: api.NodeSpec{ExternalID: id},
} }
} }
oldMinions := []current.Minion{ oldMinions := []versioned.Minion{
oldMinion("foo"), oldMinion("foo"),
oldMinion("bar"), oldMinion("bar"),
} }
newMinions := []newer.Node{ newMinions := []api.Node{
newNode("foo"), newNode("foo"),
newNode("bar"), newNode("bar"),
} }
table := []struct { table := []struct {
oldML *current.MinionList oldML *versioned.MinionList
newML *newer.NodeList newML *api.NodeList
}{ }{
{ {
oldML: &current.MinionList{Items: oldMinions}, oldML: &versioned.MinionList{Items: oldMinions},
newML: &newer.NodeList{Items: newMinions}, newML: &api.NodeList{Items: newMinions},
}, { }, {
oldML: &current.MinionList{Minions: oldMinions}, oldML: &versioned.MinionList{Minions: oldMinions},
newML: &newer.NodeList{Items: newMinions}, newML: &api.NodeList{Items: newMinions},
}, { }, {
oldML: &current.MinionList{ oldML: &versioned.MinionList{
Items: oldMinions, Items: oldMinions,
Minions: []current.Minion{oldMinion("baz")}, Minions: []versioned.Minion{oldMinion("baz")},
}, },
newML: &newer.NodeList{Items: newMinions}, newML: &api.NodeList{Items: newMinions},
}, },
} }
for _, item := range table { for _, item := range table {
got := &newer.NodeList{} got := &api.NodeList{}
err := Convert(item.oldML, got) err := Convert(item.oldML, got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
if e, a := item.newML, got; !newer.Semantic.DeepEqual(e, a) { if e, a := item.newML, got; !api.Semantic.DeepEqual(e, a) {
t.Errorf("Expected: %#v, got %#v", e, a) t.Errorf("Expected: %#v, got %#v", e, a)
} }
} }
} }
func TestMinionListConversionToOld(t *testing.T) { func TestMinionListConversionToOld(t *testing.T) {
oldMinion := func(id string) current.Minion { oldMinion := func(id string) versioned.Minion {
return current.Minion{TypeMeta: current.TypeMeta{ID: id}} return versioned.Minion{TypeMeta: versioned.TypeMeta{ID: id}}
} }
newNode := func(id string) newer.Node { newNode := func(id string) api.Node {
return newer.Node{ObjectMeta: newer.ObjectMeta{Name: id}} return api.Node{ObjectMeta: api.ObjectMeta{Name: id}}
} }
oldMinions := []current.Minion{ oldMinions := []versioned.Minion{
oldMinion("foo"), oldMinion("foo"),
oldMinion("bar"), oldMinion("bar"),
} }
newMinions := []newer.Node{ newMinions := []api.Node{
newNode("foo"), newNode("foo"),
newNode("bar"), newNode("bar"),
} }
newML := &newer.NodeList{Items: newMinions} newML := &api.NodeList{Items: newMinions}
oldML := &current.MinionList{ oldML := &versioned.MinionList{
Items: oldMinions, Items: oldMinions,
Minions: oldMinions, Minions: oldMinions,
} }
got := &current.MinionList{} got := &versioned.MinionList{}
err := Convert(newML, got) err := Convert(newML, got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
if e, a := oldML, got; !newer.Semantic.DeepEqual(e, a) { if e, a := oldML, got; !api.Semantic.DeepEqual(e, a) {
t.Errorf("Expected: %#v, got %#v", e, a) t.Errorf("Expected: %#v, got %#v", e, a)
} }
} }
func TestServiceEmptySelector(t *testing.T) { func TestServiceEmptySelector(t *testing.T) {
// Nil map should be preserved // Nil map should be preserved
svc := &current.Service{Selector: nil} svc := &versioned.Service{Selector: nil}
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta1") data, err := api.Scheme.EncodeToVersion(svc, "v1beta1")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := newer.Scheme.Decode(data) obj, err := api.Scheme.Decode(data)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
selector := obj.(*newer.Service).Spec.Selector selector := obj.(*api.Service).Spec.Selector
if selector != nil { if selector != nil {
t.Errorf("unexpected selector: %#v", obj) t.Errorf("unexpected selector: %#v", obj)
} }
// Empty map should be preserved // Empty map should be preserved
svc2 := &current.Service{Selector: map[string]string{}} svc2 := &versioned.Service{Selector: map[string]string{}}
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta1") data, err = api.Scheme.EncodeToVersion(svc2, "v1beta1")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err = newer.Scheme.Decode(data) obj, err = api.Scheme.Decode(data)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
selector = obj.(*newer.Service).Spec.Selector selector = obj.(*api.Service).Spec.Selector
if selector == nil || len(selector) != 0 { if selector == nil || len(selector) != 0 {
t.Errorf("unexpected selector: %#v", obj) t.Errorf("unexpected selector: %#v", obj)
} }
@@ -291,160 +291,160 @@ func TestServiceEmptySelector(t *testing.T) {
func TestServicePorts(t *testing.T) { func TestServicePorts(t *testing.T) {
testCases := []struct { testCases := []struct {
given current.Service given versioned.Service
expected newer.Service expected api.Service
roundtrip current.Service roundtrip versioned.Service
}{ }{
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "legacy-with-defaults", ID: "legacy-with-defaults",
}, },
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Port: 111, Port: 111,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "legacy-full", ID: "legacy-full",
}, },
PortName: "p", PortName: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromString("p"), TargetPort: util.NewIntOrStringFromString("p"),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "both", ID: "both",
}, },
PortName: "p", PortName: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one", ID: "one",
}, },
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "two", ID: "two",
}, },
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromInt(76), ContainerPort: util.NewIntOrStringFromInt(76),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(76), TargetPort: util.NewIntOrStringFromInt(76),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromInt(76), ContainerPort: util.NewIntOrStringFromInt(76),
}}, }},
}, },
@@ -453,7 +453,7 @@ func TestServicePorts(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
// Convert versioned -> internal. // Convert versioned -> internal.
got := newer.Service{} got := api.Service{}
if err := Convert(&tc.given, &got); err != nil { if err := Convert(&tc.given, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
@@ -463,7 +463,7 @@ func TestServicePorts(t *testing.T) {
} }
// Convert internal -> versioned. // Convert internal -> versioned.
got2 := current.Service{} got2 := versioned.Service{}
if err := Convert(&got, &got2); err != nil { if err := Convert(&got, &got2); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
@@ -476,18 +476,18 @@ func TestServicePorts(t *testing.T) {
func TestPullPolicyConversion(t *testing.T) { func TestPullPolicyConversion(t *testing.T) {
table := []struct { table := []struct {
versioned current.PullPolicy versioned versioned.PullPolicy
internal newer.PullPolicy internal api.PullPolicy
}{ }{
{ {
versioned: current.PullAlways, versioned: versioned.PullAlways,
internal: newer.PullAlways, internal: api.PullAlways,
}, { }, {
versioned: current.PullNever, versioned: versioned.PullNever,
internal: newer.PullNever, internal: api.PullNever,
}, { }, {
versioned: current.PullIfNotPresent, versioned: versioned.PullIfNotPresent,
internal: newer.PullIfNotPresent, internal: api.PullIfNotPresent,
}, { }, {
versioned: "", versioned: "",
internal: "", internal: "",
@@ -497,7 +497,7 @@ func TestPullPolicyConversion(t *testing.T) {
}, },
} }
for _, item := range table { for _, item := range table {
var got newer.PullPolicy var got api.PullPolicy
err := Convert(&item.versioned, &got) err := Convert(&item.versioned, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@@ -508,7 +508,7 @@ func TestPullPolicyConversion(t *testing.T) {
} }
} }
for _, item := range table { for _, item := range table {
var got current.PullPolicy var got versioned.PullPolicy
err := Convert(&item.internal, &got) err := Convert(&item.internal, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@@ -520,14 +520,14 @@ func TestPullPolicyConversion(t *testing.T) {
} }
} }
func getResourceRequirements(cpu, memory resource.Quantity) current.ResourceRequirements { func getResourceRequirements(cpu, memory resource.Quantity) versioned.ResourceRequirements {
res := current.ResourceRequirements{} res := versioned.ResourceRequirements{}
res.Limits = current.ResourceList{} res.Limits = versioned.ResourceList{}
if cpu.Value() > 0 { if cpu.Value() > 0 {
res.Limits[current.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value())) res.Limits[versioned.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
} }
if memory.Value() > 0 { if memory.Value() > 0 {
res.Limits[current.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value())) res.Limits[versioned.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
} }
return res return res
@@ -537,7 +537,7 @@ func TestContainerConversion(t *testing.T) {
cpuLimit := resource.MustParse("10") cpuLimit := resource.MustParse("10")
memoryLimit := resource.MustParse("10M") memoryLimit := resource.MustParse("10M")
null := resource.Quantity{} null := resource.Quantity{}
testCases := []current.Container{ testCases := []versioned.Container{
{ {
Name: "container", Name: "container",
Resources: getResourceRequirements(cpuLimit, memoryLimit), Resources: getResourceRequirements(cpuLimit, memoryLimit),
@@ -570,7 +570,7 @@ func TestContainerConversion(t *testing.T) {
} }
for i, tc := range testCases { for i, tc := range testCases {
got := newer.Container{} got := api.Container{}
if err := Convert(&tc, &got); err != nil { if err := Convert(&tc, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
@@ -586,114 +586,114 @@ func TestContainerConversion(t *testing.T) {
func TestEndpointsConversion(t *testing.T) { func TestEndpointsConversion(t *testing.T) {
testCases := []struct { testCases := []struct {
given current.Endpoints given versioned.Endpoints
expected newer.Endpoints expected api.Endpoints
}{ }{
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "empty", ID: "empty",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{}, Endpoints: []string{},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{}, Subsets: []api.EndpointSubset{},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one legacy", ID: "one legacy",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{"1.2.3.4:88"}, Endpoints: []string{"1.2.3.4:88"},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{{ Subsets: []api.EndpointSubset{{
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "several legacy", ID: "several legacy",
}, },
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"}, Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{ Subsets: []api.EndpointSubset{
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 90, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 90, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
}}, }},
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one subset", ID: "one subset",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{"1.2.3.4:88"}, Endpoints: []string{"1.2.3.4:88"},
Subsets: []current.EndpointSubset{{ Subsets: []versioned.EndpointSubset{{
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolTCP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolTCP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{{ Subsets: []api.EndpointSubset{{
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "several subset", ID: "several subset",
}, },
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"}, Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
Subsets: []current.EndpointSubset{ Subsets: []versioned.EndpointSubset{
{ {
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []current.EndpointPort{{Name: "", Port: 89, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 89, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []current.EndpointPort{{Name: "named", Port: 90, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "named", Port: 90, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
}, },
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{ Subsets: []api.EndpointSubset{
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "named", Port: 90, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "named", Port: 90, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
}}, }},
}, },
@@ -701,39 +701,39 @@ func TestEndpointsConversion(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
// Convert versioned -> internal. // Convert versioned -> internal.
got := newer.Endpoints{} got := api.Endpoints{}
if err := Convert(&tc.given, &got); err != nil { if err := Convert(&tc.given, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
if !newer.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) { if !api.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets) t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
} }
// Convert internal -> versioned. // Convert internal -> versioned.
got2 := current.Endpoints{} got2 := versioned.Endpoints{}
if err := Convert(&got, &got2); err != nil { if err := Convert(&got, &got2); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
if got2.Protocol != tc.given.Protocol || !newer.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) { if got2.Protocol != tc.given.Protocol || !api.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
t.Errorf("[Case: %d] Expected %s %#v, got %s %#v", i, tc.given.Protocol, tc.given.Endpoints, got2.Protocol, got2.Endpoints) t.Errorf("[Case: %d] Expected %s %#v, got %s %#v", i, tc.given.Protocol, tc.given.Endpoints, got2.Protocol, got2.Endpoints)
} }
} }
} }
func TestSecretVolumeSourceConversion(t *testing.T) { func TestSecretVolumeSourceConversion(t *testing.T) {
given := current.SecretVolumeSource{ given := versioned.SecretVolumeSource{
Target: current.ObjectReference{ Target: versioned.ObjectReference{
ID: "foo", ID: "foo",
}, },
} }
expected := newer.SecretVolumeSource{ expected := api.SecretVolumeSource{
SecretName: "foo", SecretName: "foo",
} }
got := newer.SecretVolumeSource{} got := api.SecretVolumeSource{}
if err := Convert(&given, &got); err != nil { if err := Convert(&given, &got); err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
@@ -741,7 +741,7 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
t.Errorf("Expected %v; got %v", expected, got) t.Errorf("Expected %v; got %v", expected, got)
} }
got2 := current.SecretVolumeSource{} got2 := versioned.SecretVolumeSource{}
if err := Convert(&got, &got2); err != nil { if err := Convert(&got, &got2); err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
@@ -753,42 +753,42 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
func TestBadSecurityContextConversion(t *testing.T) { func TestBadSecurityContextConversion(t *testing.T) {
priv := false priv := false
testCases := map[string]struct { testCases := map[string]struct {
c *current.Container c *versioned.Container
err string err string
}{ }{
// this use case must use true for the container and false for the sc. Otherwise the defaulter // this use case must use true for the container and false for the sc. Otherwise the defaulter
// will assume privileged was left undefined (since it is the default value) and copy the // will assume privileged was left undefined (since it is the default value) and copy the
// sc setting upwards // sc setting upwards
"mismatched privileged": { "mismatched privileged": {
c: &current.Container{ c: &versioned.Container{
Privileged: true, Privileged: true,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
err: "container privileged settings do not match security context settings, cannot convert", err: "container privileged settings do not match security context settings, cannot convert",
}, },
"mismatched caps add": { "mismatched caps add": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"bar"}, Add: []versioned.Capability{"bar"},
}, },
}, },
}, },
err: "container capability settings do not match security context settings, cannot convert", err: "container capability settings do not match security context settings, cannot convert",
}, },
"mismatched caps drop": { "mismatched caps drop": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Drop: []current.Capability{"foo"}, Drop: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
@@ -797,7 +797,7 @@ func TestBadSecurityContextConversion(t *testing.T) {
} }
for k, v := range testCases { for k, v := range testCases {
got := newer.Container{} got := api.Container{}
err := Convert(v.c, &got) err := Convert(v.c, &got)
if err == nil { if err == nil {
t.Errorf("expected error for case %s but got none", k) t.Errorf("expected error for case %s but got none", k)

View File

@@ -20,25 +20,25 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Errorf("%v\n %#v", err, obj) t.Errorf("%v\n %#v", err, obj)
return nil return nil
} }
obj2, err := newer.Codec.Decode(data) obj2, err := api.Codec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj) t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil return nil
} }
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = newer.Scheme.Convert(obj2, obj3) err = api.Scheme.Convert(obj2, obj3)
if err != nil { if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2) t.Errorf("%v\nSource: %#v", err, obj2)
return nil return nil
@@ -48,14 +48,14 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultReplicationController(t *testing.T) { func TestSetDefaultReplicationController(t *testing.T) {
tests := []struct { tests := []struct {
rc *current.ReplicationController rc *versioned.ReplicationController
expectLabels bool expectLabels bool
expectSelector bool expectSelector bool
}{ }{
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -66,12 +66,12 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -82,15 +82,15 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
ReplicaSelector: map[string]string{ ReplicaSelector: map[string]string{
"some": "other", "some": "other",
}, },
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -101,12 +101,12 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: false, expectSelector: false,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
ReplicaSelector: map[string]string{ ReplicaSelector: map[string]string{
"some": "other", "some": "other",
}, },
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -120,7 +120,7 @@ func TestSetDefaultReplicationController(t *testing.T) {
for _, test := range tests { for _, test := range tests {
rc := test.rc rc := test.rc
obj2 := roundTrip(t, runtime.Object(rc)) obj2 := roundTrip(t, runtime.Object(rc))
rc2, ok := obj2.(*current.ReplicationController) rc2, ok := obj2.(*versioned.ReplicationController)
if !ok { if !ok {
t.Errorf("unexpected object: %v", rc2) t.Errorf("unexpected object: %v", rc2)
t.FailNow() t.FailNow()
@@ -143,68 +143,68 @@ func TestSetDefaultReplicationController(t *testing.T) {
} }
func TestSetDefaultService(t *testing.T) { func TestSetDefaultService(t *testing.T) {
svc := &current.Service{} svc := &versioned.Service{}
obj2 := roundTrip(t, runtime.Object(svc)) obj2 := roundTrip(t, runtime.Object(svc))
svc2 := obj2.(*current.Service) svc2 := obj2.(*versioned.Service)
if svc2.Protocol != current.ProtocolTCP { if svc2.Protocol != versioned.ProtocolTCP {
t.Errorf("Expected default protocol :%s, got: %s", current.ProtocolTCP, svc2.Protocol) t.Errorf("Expected default protocol :%s, got: %s", versioned.ProtocolTCP, svc2.Protocol)
} }
if svc2.SessionAffinity != current.ServiceAffinityNone { if svc2.SessionAffinity != versioned.ServiceAffinityNone {
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.SessionAffinity) t.Errorf("Expected default sesseion affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.SessionAffinity)
} }
} }
func TestSetDefaultSecret(t *testing.T) { func TestSetDefaultSecret(t *testing.T) {
s := &current.Secret{} s := &versioned.Secret{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Secret) s2 := obj2.(*versioned.Secret)
if s2.Type != current.SecretTypeOpaque { if s2.Type != versioned.SecretTypeOpaque {
t.Errorf("Expected secret type %v, got %v", current.SecretTypeOpaque, s2.Type) t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
} }
} }
func TestSetDefaultPersistentVolume(t *testing.T) { func TestSetDefaultPersistentVolume(t *testing.T) {
pv := &current.PersistentVolume{} pv := &versioned.PersistentVolume{}
obj2 := roundTrip(t, runtime.Object(pv)) obj2 := roundTrip(t, runtime.Object(pv))
pv2 := obj2.(*current.PersistentVolume) pv2 := obj2.(*versioned.PersistentVolume)
if pv2.Status.Phase != current.VolumePending { if pv2.Status.Phase != versioned.VolumePending {
t.Errorf("Expected volume phase %v, got %v", current.VolumePending, pv2.Status.Phase) t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
} }
} }
func TestSetDefaultPersistentVolumeClaim(t *testing.T) { func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
pvc := &current.PersistentVolumeClaim{} pvc := &versioned.PersistentVolumeClaim{}
obj2 := roundTrip(t, runtime.Object(pvc)) obj2 := roundTrip(t, runtime.Object(pvc))
pvc2 := obj2.(*current.PersistentVolumeClaim) pvc2 := obj2.(*versioned.PersistentVolumeClaim)
if pvc2.Status.Phase != current.ClaimPending { if pvc2.Status.Phase != versioned.ClaimPending {
t.Errorf("Expected claim phase %v, got %v", current.ClaimPending, pvc2.Status.Phase) t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
} }
} }
// Test that we use "legacy" fields if "modern" fields are not provided. // Test that we use "legacy" fields if "modern" fields are not provided.
func TestSetDefaulEndpointsLegacy(t *testing.T) { func TestSetDefaulEndpointsLegacy(t *testing.T) {
in := &current.Endpoints{ in := &versioned.Endpoints{
Protocol: "UDP", Protocol: "UDP",
Endpoints: []string{"1.2.3.4:93", "5.6.7.8:76"}, Endpoints: []string{"1.2.3.4:93", "5.6.7.8:76"},
TargetRefs: []current.EndpointObjectReference{{Endpoint: "1.2.3.4:93", ObjectReference: current.ObjectReference{ID: "foo"}}}, TargetRefs: []versioned.EndpointObjectReference{{Endpoint: "1.2.3.4:93", ObjectReference: versioned.ObjectReference{ID: "foo"}}},
} }
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
if len(out.Subsets) != 2 { if len(out.Subsets) != 2 {
t.Errorf("Expected 2 EndpointSubsets, got %d (%#v)", len(out.Subsets), out.Subsets) t.Errorf("Expected 2 EndpointSubsets, got %d (%#v)", len(out.Subsets), out.Subsets)
} }
expected := []current.EndpointSubset{ expected := []versioned.EndpointSubset{
{ {
Addresses: []current.EndpointAddress{{IP: "1.2.3.4", TargetRef: &current.ObjectReference{ID: "foo"}}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4", TargetRef: &versioned.ObjectReference{ID: "foo"}}},
Ports: []current.EndpointPort{{Protocol: current.ProtocolUDP, Port: 93}}, Ports: []versioned.EndpointPort{{Protocol: versioned.ProtocolUDP, Port: 93}},
}, },
{ {
Addresses: []current.EndpointAddress{{IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "5.6.7.8"}},
Ports: []current.EndpointPort{{Protocol: current.ProtocolUDP, Port: 76}}, Ports: []versioned.EndpointPort{{Protocol: versioned.ProtocolUDP, Port: 76}},
}, },
} }
if !reflect.DeepEqual(out.Subsets, expected) { if !reflect.DeepEqual(out.Subsets, expected) {
@@ -213,20 +213,20 @@ func TestSetDefaulEndpointsLegacy(t *testing.T) {
} }
func TestSetDefaulEndpointsProtocol(t *testing.T) { func TestSetDefaulEndpointsProtocol(t *testing.T) {
in := &current.Endpoints{Subsets: []current.EndpointSubset{ in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
{Ports: []current.EndpointPort{{}, {Protocol: "UDP"}, {}}}, {Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
}} }}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
if out.Protocol != current.ProtocolTCP { if out.Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Protocol)
} }
for i := range out.Subsets { for i := range out.Subsets {
for j := range out.Subsets[i].Ports { for j := range out.Subsets[i].Ports {
if in.Subsets[i].Ports[j].Protocol == "" { if in.Subsets[i].Ports[j].Protocol == "" {
if out.Subsets[i].Ports[j].Protocol != current.ProtocolTCP { if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Subsets[i].Ports[j].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
} }
} else { } else {
if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol { if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol {
@@ -238,32 +238,32 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
} }
func TestSetDefaultNamespace(t *testing.T) { func TestSetDefaultNamespace(t *testing.T) {
s := &current.Namespace{} s := &versioned.Namespace{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Namespace) s2 := obj2.(*versioned.Namespace)
if s2.Status.Phase != current.NamespaceActive { if s2.Status.Phase != versioned.NamespaceActive {
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase) t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
} }
} }
func TestSetDefaultContainerManifestHostNetwork(t *testing.T) { func TestSetDefaultContainerManifestHostNetwork(t *testing.T) {
portNum := 8080 portNum := 8080
s := current.ContainerManifest{} s := versioned.ContainerManifest{}
s.HostNetwork = true s.HostNetwork = true
s.Containers = []current.Container{ s.Containers = []versioned.Container{
{ {
Ports: []current.ContainerPort{ Ports: []versioned.ContainerPort{
{ {
ContainerPort: portNum, ContainerPort: portNum,
}, },
}, },
}, },
} }
obj2 := roundTrip(t, runtime.Object(&current.ContainerManifestList{ obj2 := roundTrip(t, runtime.Object(&versioned.ContainerManifestList{
Items: []current.ContainerManifest{s}, Items: []versioned.ContainerManifest{s},
})) }))
sList2 := obj2.(*current.ContainerManifestList) sList2 := obj2.(*versioned.ContainerManifestList)
s2 := sList2.Items[0] s2 := sList2.Items[0]
hostPortNum := s2.Containers[0].Ports[0].HostPort hostPortNum := s2.Containers[0].Ports[0].HostPort
@@ -274,30 +274,30 @@ func TestSetDefaultContainerManifestHostNetwork(t *testing.T) {
func TestSetDefaultServicePort(t *testing.T) { func TestSetDefaultServicePort(t *testing.T) {
// Unchanged if set. // Unchanged if set.
in := &current.Service{Ports: []current.ServicePort{{Protocol: "UDP", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(118)}}} in := &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "UDP", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(118)}}}
out := roundTrip(t, runtime.Object(in)).(*current.Service) out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolUDP { if out.Ports[0].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != in.Ports[0].ContainerPort { if out.Ports[0].ContainerPort != in.Ports[0].ContainerPort {
t.Errorf("Expected port %d, got %d", in.Ports[0].ContainerPort, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %d", in.Ports[0].ContainerPort, out.Ports[0].ContainerPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Ports: []current.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(0)}}} in = &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(0)}}}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolTCP { if out.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) { if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) {
t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Ports: []current.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromString("")}}} in = &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromString("")}}}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolTCP { if out.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) { if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) {
t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort)
@@ -306,33 +306,33 @@ func TestSetDefaultServicePort(t *testing.T) {
func TestSetDefaultMinionExternalID(t *testing.T) { func TestSetDefaultMinionExternalID(t *testing.T) {
name := "node0" name := "node0"
m := &current.Minion{} m := &versioned.Minion{}
m.ID = name m.ID = name
obj2 := roundTrip(t, runtime.Object(m)) obj2 := roundTrip(t, runtime.Object(m))
m2 := obj2.(*current.Minion) m2 := obj2.(*versioned.Minion)
if m2.ExternalID != name { if m2.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID) t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID)
} }
} }
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) { func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
s := current.ContainerManifest{ s := versioned.ContainerManifest{
Containers: []current.Container{ Containers: []versioned.Container{
{ {
Env: []current.EnvVar{ Env: []versioned.EnvVar{
{ {
ValueFrom: &current.EnvVarSource{ ValueFrom: &versioned.EnvVarSource{
FieldRef: &current.ObjectFieldSelector{}, FieldRef: &versioned.ObjectFieldSelector{},
}, },
}, },
}, },
}, },
}, },
} }
obj2 := roundTrip(t, runtime.Object(&current.ContainerManifestList{ obj2 := roundTrip(t, runtime.Object(&versioned.ContainerManifestList{
Items: []current.ContainerManifest{s}, Items: []versioned.ContainerManifest{s},
})) }))
sList2 := obj2.(*current.ContainerManifestList) sList2 := obj2.(*versioned.ContainerManifestList)
s2 := sList2.Items[0] s2 := sList2.Items[0]
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion
@@ -345,74 +345,74 @@ func TestSetDefaultSecurityContext(t *testing.T) {
priv := false priv := false
privTrue := true privTrue := true
testCases := map[string]struct { testCases := map[string]struct {
c current.Container c versioned.Container
}{ }{
"downward defaulting caps": { "downward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
}, },
"downward defaulting priv": { "downward defaulting priv": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
"upward defaulting caps": { "upward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"biz"}, Add: []versioned.Capability{"biz"},
Drop: []current.Capability{"baz"}, Drop: []versioned.Capability{"baz"},
}, },
}, },
}, },
}, },
"upward defaulting priv": { "upward defaulting priv": {
c: current.Container{ c: versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &privTrue, Privileged: &privTrue,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
DesiredState: current.PodState{ DesiredState: versioned.PodState{
Manifest: current.ContainerManifest{}, Manifest: versioned.ContainerManifest{},
}, },
} }
for k, v := range testCases { for k, v := range testCases {
pod.DesiredState.Manifest.Containers = []current.Container{v.c} pod.DesiredState.Manifest.Containers = []versioned.Container{v.c}
obj := roundTrip(t, runtime.Object(pod)) obj := roundTrip(t, runtime.Object(pod))
defaultedPod := obj.(*current.Pod) defaultedPod := obj.(*versioned.Pod)
c := defaultedPod.DesiredState.Manifest.Containers[0] c := defaultedPod.DesiredState.Manifest.Containers[0]
if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual { if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual {
t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues) t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues)
@@ -420,7 +420,7 @@ func TestSetDefaultSecurityContext(t *testing.T) {
} }
} }
func areSecurityContextAndContainerEqual(c *current.Container) (bool, []string) { func areSecurityContextAndContainerEqual(c *versioned.Container) (bool, []string) {
issues := make([]string, 0) issues := make([]string, 0)
equal := true equal := true

View File

@@ -22,7 +22,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@@ -30,34 +30,34 @@ import (
func addConversionFuncs() { func addConversionFuncs() {
// Our TypeMeta was split into two different structs. // Our TypeMeta was split into two different structs.
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.TypeMeta{}, "TypeMeta") api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.ObjectMeta{}, "ObjectMeta") api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ObjectMeta{}, "ObjectMeta")
newer.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", newer.ListMeta{}, "ListMeta") api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ListMeta{}, "ListMeta")
newer.Scheme.AddStructFieldConversion(newer.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta") api.Scheme.AddStructFieldConversion(api.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta") api.Scheme.AddStructFieldConversion(api.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta") api.Scheme.AddStructFieldConversion(api.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints") api.Scheme.AddStructFieldConversion(api.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below // TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
// newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition") // api.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
// newer.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status") // api.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status")
err := newer.Scheme.AddConversionFuncs( err := api.Scheme.AddConversionFuncs(
// TypeMeta must be split into two objects // TypeMeta must be split into two objects
func(in *newer.TypeMeta, out *TypeMeta, s conversion.Scope) error { func(in *api.TypeMeta, out *TypeMeta, s conversion.Scope) error {
out.Kind = in.Kind out.Kind = in.Kind
out.APIVersion = in.APIVersion out.APIVersion = in.APIVersion
return nil return nil
}, },
func(in *TypeMeta, out *newer.TypeMeta, s conversion.Scope) error { func(in *TypeMeta, out *api.TypeMeta, s conversion.Scope) error {
out.Kind = in.Kind out.Kind = in.Kind
out.APIVersion = in.APIVersion out.APIVersion = in.APIVersion
return nil return nil
}, },
// ListMeta must be converted to TypeMeta // ListMeta must be converted to TypeMeta
func(in *newer.ListMeta, out *TypeMeta, s conversion.Scope) error { func(in *api.ListMeta, out *TypeMeta, s conversion.Scope) error {
out.SelfLink = in.SelfLink out.SelfLink = in.SelfLink
if len(in.ResourceVersion) > 0 { if len(in.ResourceVersion) > 0 {
v, err := strconv.ParseUint(in.ResourceVersion, 10, 64) v, err := strconv.ParseUint(in.ResourceVersion, 10, 64)
@@ -68,7 +68,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *TypeMeta, out *newer.ListMeta, s conversion.Scope) error { func(in *TypeMeta, out *api.ListMeta, s conversion.Scope) error {
out.SelfLink = in.SelfLink out.SelfLink = in.SelfLink
if in.ResourceVersion != 0 { if in.ResourceVersion != 0 {
out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10) out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10)
@@ -79,7 +79,7 @@ func addConversionFuncs() {
}, },
// ObjectMeta must be converted to TypeMeta // ObjectMeta must be converted to TypeMeta
func(in *newer.ObjectMeta, out *TypeMeta, s conversion.Scope) error { func(in *api.ObjectMeta, out *TypeMeta, s conversion.Scope) error {
out.Namespace = in.Namespace out.Namespace = in.Namespace
out.ID = in.Name out.ID = in.Name
out.GenerateName = in.GenerateName out.GenerateName = in.GenerateName
@@ -96,7 +96,7 @@ func addConversionFuncs() {
} }
return s.Convert(&in.Annotations, &out.Annotations, 0) return s.Convert(&in.Annotations, &out.Annotations, 0)
}, },
func(in *TypeMeta, out *newer.ObjectMeta, s conversion.Scope) error { func(in *TypeMeta, out *api.ObjectMeta, s conversion.Scope) error {
out.Namespace = in.Namespace out.Namespace = in.Namespace
out.Name = in.ID out.Name = in.ID
out.GenerateName = in.GenerateName out.GenerateName = in.GenerateName
@@ -113,22 +113,22 @@ func addConversionFuncs() {
}, },
// Convert all to the new PodPhase constants // Convert all to the new PodPhase constants
func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error { func(in *api.PodPhase, out *PodStatus, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
case newer.PodPending: case api.PodPending:
*out = PodWaiting *out = PodWaiting
case newer.PodRunning: case api.PodRunning:
*out = PodRunning *out = PodRunning
case newer.PodSucceeded: case api.PodSucceeded:
*out = PodSucceeded *out = PodSucceeded
case newer.PodFailed: case api.PodFailed:
*out = PodTerminated *out = PodTerminated
case newer.PodUnknown: case api.PodUnknown:
*out = PodUnknown *out = PodUnknown
default: default:
return &newer.ConversionError{ return &api.ConversionError{
In: in, In: in,
Out: out, Out: out,
Message: "The string provided is not a valid PodPhase constant value", Message: "The string provided is not a valid PodPhase constant value",
@@ -138,23 +138,23 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error { func(in *PodStatus, out *api.PodPhase, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
case PodWaiting: case PodWaiting:
*out = newer.PodPending *out = api.PodPending
case PodRunning: case PodRunning:
*out = newer.PodRunning *out = api.PodRunning
case PodTerminated: case PodTerminated:
// Older API versions did not contain enough info to map to PodSucceeded // Older API versions did not contain enough info to map to PodSucceeded
*out = newer.PodFailed *out = api.PodFailed
case PodSucceeded: case PodSucceeded:
*out = newer.PodSucceeded *out = api.PodSucceeded
case PodUnknown: case PodUnknown:
*out = newer.PodUnknown *out = api.PodUnknown
default: default:
return &newer.ConversionError{ return &api.ConversionError{
In: in, In: in,
Out: out, Out: out,
Message: "The string provided is not a valid PodPhase constant value", Message: "The string provided is not a valid PodPhase constant value",
@@ -164,7 +164,7 @@ func addConversionFuncs() {
}, },
// Convert all the standard objects // Convert all the standard objects
func(in *newer.Pod, out *Pod, s conversion.Scope) error { func(in *api.Pod, out *Pod, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -189,7 +189,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *Pod, out *newer.Pod, s conversion.Scope) error { func(in *Pod, out *api.Pod, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -213,7 +213,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.ReplicationController, out *ReplicationController, s conversion.Scope) error { func(in *api.ReplicationController, out *ReplicationController, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -230,7 +230,7 @@ func addConversionFuncs() {
out.CurrentState.Replicas = in.Status.Replicas out.CurrentState.Replicas = in.Status.Replicas
return nil return nil
}, },
func(in *ReplicationController, out *newer.ReplicationController, s conversion.Scope) error { func(in *ReplicationController, out *api.ReplicationController, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -248,13 +248,13 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.ReplicationControllerSpec, out *ReplicationControllerState, s conversion.Scope) error { func(in *api.ReplicationControllerSpec, out *ReplicationControllerState, s conversion.Scope) error {
out.Replicas = in.Replicas out.Replicas = in.Replicas
if err := s.Convert(&in.Selector, &out.ReplicaSelector, 0); err != nil { if err := s.Convert(&in.Selector, &out.ReplicaSelector, 0); err != nil {
return err return err
} }
if in.TemplateRef != nil && in.Template == nil { if in.TemplateRef != nil && in.Template == nil {
return &newer.ConversionError{ return &api.ConversionError{
In: in, In: in,
Out: out, Out: out,
Message: "objects with a template ref cannot be converted to older objects, must populate template", Message: "objects with a template ref cannot be converted to older objects, must populate template",
@@ -267,19 +267,19 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *ReplicationControllerState, out *newer.ReplicationControllerSpec, s conversion.Scope) error { func(in *ReplicationControllerState, out *api.ReplicationControllerSpec, s conversion.Scope) error {
out.Replicas = in.Replicas out.Replicas = in.Replicas
if err := s.Convert(&in.ReplicaSelector, &out.Selector, 0); err != nil { if err := s.Convert(&in.ReplicaSelector, &out.Selector, 0); err != nil {
return err return err
} }
out.Template = &newer.PodTemplateSpec{} out.Template = &api.PodTemplateSpec{}
if err := s.Convert(&in.PodTemplate, out.Template, 0); err != nil { if err := s.Convert(&in.PodTemplate, out.Template, 0); err != nil {
return err return err
} }
return nil return nil
}, },
func(in *newer.PodTemplateSpec, out *PodTemplate, s conversion.Scope) error { func(in *api.PodTemplateSpec, out *PodTemplate, s conversion.Scope) error {
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil { if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
return err return err
} }
@@ -296,7 +296,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error { func(in *PodTemplate, out *api.PodTemplateSpec, s conversion.Scope) error {
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil { if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
return err return err
} }
@@ -316,7 +316,7 @@ func addConversionFuncs() {
// Converts internal Container to v1beta2.Container. // Converts internal Container to v1beta2.Container.
// Fields 'CPU' and 'Memory' are not present in the internal Container object. // Fields 'CPU' and 'Memory' are not present in the internal Container object.
// Hence the need for a custom conversion function. // Hence the need for a custom conversion function.
func(in *newer.Container, out *Container, s conversion.Scope) error { func(in *api.Container, out *Container, s conversion.Scope) error {
if err := s.Convert(&in.Name, &out.Name, 0); err != nil { if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
return err return err
} }
@@ -380,7 +380,7 @@ func addConversionFuncs() {
}, },
// Internal API does not support CPU to be specified via an explicit field. // Internal API does not support CPU to be specified via an explicit field.
// Hence it must be stored in Container.Resources. // Hence it must be stored in Container.Resources.
func(in *int, out *newer.ResourceList, s conversion.Scope) error { func(in *int, out *api.ResourceList, s conversion.Scope) error {
if *in == 0 { if *in == 0 {
return nil return nil
} }
@@ -388,13 +388,13 @@ func addConversionFuncs() {
if err := s.Convert(in, &quantity, 0); err != nil { if err := s.Convert(in, &quantity, 0); err != nil {
return err return err
} }
(*out)[newer.ResourceCPU] = quantity (*out)[api.ResourceCPU] = quantity
return nil return nil
}, },
// Internal API does not support Memory to be specified via an explicit field. // Internal API does not support Memory to be specified via an explicit field.
// Hence it must be stored in Container.Resources. // Hence it must be stored in Container.Resources.
func(in *int64, out *newer.ResourceList, s conversion.Scope) error { func(in *int64, out *api.ResourceList, s conversion.Scope) error {
if *in == 0 { if *in == 0 {
return nil return nil
} }
@@ -402,14 +402,14 @@ func addConversionFuncs() {
if err := s.Convert(in, &quantity, 0); err != nil { if err := s.Convert(in, &quantity, 0); err != nil {
return err return err
} }
(*out)[newer.ResourceMemory] = quantity (*out)[api.ResourceMemory] = quantity
return nil return nil
}, },
// Converts v1beta2.Container to internal newer.Container. // Converts v1beta2.Container to internal api.Container.
// Fields 'CPU' and 'Memory' are not present in the internal newer.Container object. // Fields 'CPU' and 'Memory' are not present in the internal api.Container object.
// Hence the need for a custom conversion function. // Hence the need for a custom conversion function.
func(in *Container, out *newer.Container, s conversion.Scope) error { func(in *Container, out *api.Container, s conversion.Scope) error {
if err := s.Convert(&in.Name, &out.Name, 0); err != nil { if err := s.Convert(&in.Name, &out.Name, 0); err != nil {
return err return err
} }
@@ -476,7 +476,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error { func(in *api.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil { if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err return err
} }
@@ -502,7 +502,7 @@ func addConversionFuncs() {
out.HostNetwork = in.HostNetwork out.HostNetwork = in.HostNetwork
return nil return nil
}, },
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error { func(in *ContainerManifest, out *api.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil { if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err return err
} }
@@ -523,12 +523,12 @@ func addConversionFuncs() {
out.ActiveDeadlineSeconds = new(int64) out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds *out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} }
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy) out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
out.HostNetwork = in.HostNetwork out.HostNetwork = in.HostNetwork
return nil return nil
}, },
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error { func(in *api.PodStatus, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in.Phase, &out.Status, 0); err != nil { if err := s.Convert(&in.Phase, &out.Status, 0); err != nil {
return err return err
} }
@@ -543,7 +543,7 @@ func addConversionFuncs() {
out.PodIP = in.PodIP out.PodIP = in.PodIP
return nil return nil
}, },
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error { func(in *PodState, out *api.PodStatus, s conversion.Scope) error {
if err := s.Convert(&in.Status, &out.Phase, 0); err != nil { if err := s.Convert(&in.Status, &out.Phase, 0); err != nil {
return err return err
} }
@@ -559,7 +559,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *[]newer.ContainerStatus, out *PodInfo, s conversion.Scope) error { func(in *[]api.ContainerStatus, out *PodInfo, s conversion.Scope) error {
*out = make(map[string]ContainerStatus) *out = make(map[string]ContainerStatus)
for _, st := range *in { for _, st := range *in {
v := ContainerStatus{} v := ContainerStatus{}
@@ -570,9 +570,9 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PodInfo, out *[]newer.ContainerStatus, s conversion.Scope) error { func(in *PodInfo, out *[]api.ContainerStatus, s conversion.Scope) error {
for k, v := range *in { for k, v := range *in {
st := newer.ContainerStatus{} st := api.ContainerStatus{}
if err := s.Convert(&v, &st, 0); err != nil { if err := s.Convert(&v, &st, 0); err != nil {
return err return err
} }
@@ -582,7 +582,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.ContainerStatus, out *ContainerStatus, s conversion.Scope) error { func(in *api.ContainerStatus, out *ContainerStatus, s conversion.Scope) error {
if err := s.Convert(&in.State, &out.State, 0); err != nil { if err := s.Convert(&in.State, &out.State, 0); err != nil {
return err return err
} }
@@ -606,7 +606,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *ContainerStatus, out *newer.ContainerStatus, s conversion.Scope) error { func(in *ContainerStatus, out *api.ContainerStatus, s conversion.Scope) error {
if err := s.Convert(&in.State, &out.State, 0); err != nil { if err := s.Convert(&in.State, &out.State, 0); err != nil {
return err return err
} }
@@ -631,7 +631,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.PodStatusResult, out *PodStatusResult, s conversion.Scope) error { func(in *api.PodStatusResult, out *PodStatusResult, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -643,7 +643,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PodStatusResult, out *newer.PodStatusResult, s conversion.Scope) error { func(in *PodStatusResult, out *api.PodStatusResult, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -656,21 +656,21 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.PodSpec, out *PodState, s conversion.Scope) error { func(in *api.PodSpec, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in, &out.Manifest, 0); err != nil { if err := s.Convert(&in, &out.Manifest, 0); err != nil {
return err return err
} }
out.Host = in.Host out.Host = in.Host
return nil return nil
}, },
func(in *PodState, out *newer.PodSpec, s conversion.Scope) error { func(in *PodState, out *api.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Manifest, &out, 0); err != nil { if err := s.Convert(&in.Manifest, &out, 0); err != nil {
return err return err
} }
out.Host = in.Host out.Host = in.Host
return nil return nil
}, },
func(in *newer.Service, out *Service, s conversion.Scope) error { func(in *api.Service, out *Service, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -711,7 +711,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *Service, out *newer.Service, s conversion.Scope) error { func(in *Service, out *api.Service, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -724,19 +724,19 @@ func addConversionFuncs() {
if len(in.Ports) == 0 && in.Port != 0 { if len(in.Ports) == 0 && in.Port != 0 {
// Use legacy fields to produce modern fields. // Use legacy fields to produce modern fields.
out.Spec.Ports = append(out.Spec.Ports, newer.ServicePort{ out.Spec.Ports = append(out.Spec.Ports, api.ServicePort{
Name: in.PortName, Name: in.PortName,
Port: in.Port, Port: in.Port,
Protocol: newer.Protocol(in.Protocol), Protocol: api.Protocol(in.Protocol),
TargetPort: in.ContainerPort, TargetPort: in.ContainerPort,
}) })
} else { } else {
// Use modern fields, ignore legacy. // Use modern fields, ignore legacy.
for i := range in.Ports { for i := range in.Ports {
out.Spec.Ports = append(out.Spec.Ports, newer.ServicePort{ out.Spec.Ports = append(out.Spec.Ports, api.ServicePort{
Name: in.Ports[i].Name, Name: in.Ports[i].Name,
Port: in.Ports[i].Port, Port: in.Ports[i].Port,
Protocol: newer.Protocol(in.Ports[i].Protocol), Protocol: api.Protocol(in.Ports[i].Protocol),
TargetPort: in.Ports[i].ContainerPort, TargetPort: in.Ports[i].ContainerPort,
}) })
} }
@@ -755,7 +755,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.Node, out *Minion, s conversion.Scope) error { func(in *api.Node, out *Minion, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -779,7 +779,7 @@ func addConversionFuncs() {
} }
for _, address := range in.Status.Addresses { for _, address := range in.Status.Addresses {
if address.Type == newer.NodeLegacyHostIP { if address.Type == api.NodeLegacyHostIP {
out.HostIP = address.Address out.HostIP = address.Address
} }
} }
@@ -788,7 +788,7 @@ func addConversionFuncs() {
out.Unschedulable = in.Spec.Unschedulable out.Unschedulable = in.Spec.Unschedulable
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0) return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
}, },
func(in *Minion, out *newer.Node, s conversion.Scope) error { func(in *Minion, out *api.Node, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -812,8 +812,8 @@ func addConversionFuncs() {
} }
if in.HostIP != "" { if in.HostIP != "" {
newer.AddToNodeAddresses(&out.Status.Addresses, api.AddToNodeAddresses(&out.Status.Addresses,
newer.NodeAddress{Type: newer.NodeLegacyHostIP, Address: in.HostIP}) api.NodeAddress{Type: api.NodeLegacyHostIP, Address: in.HostIP})
} }
out.Spec.PodCIDR = in.PodCIDR out.Spec.PodCIDR = in.PodCIDR
out.Spec.ExternalID = in.ExternalID out.Spec.ExternalID = in.ExternalID
@@ -821,7 +821,7 @@ func addConversionFuncs() {
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0) return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
}, },
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error { func(in *api.LimitRange, out *LimitRange, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -833,7 +833,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *LimitRange, out *newer.LimitRange, s conversion.Scope) error { func(in *LimitRange, out *api.LimitRange, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -846,7 +846,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *Namespace, out *newer.Namespace, s conversion.Scope) error { func(in *Namespace, out *api.Namespace, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -865,7 +865,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.LimitRangeSpec, out *LimitRangeSpec, s conversion.Scope) error { func(in *api.LimitRangeSpec, out *LimitRangeSpec, s conversion.Scope) error {
*out = LimitRangeSpec{} *out = LimitRangeSpec{}
out.Limits = make([]LimitRangeItem, len(in.Limits), len(in.Limits)) out.Limits = make([]LimitRangeItem, len(in.Limits), len(in.Limits))
for i := range in.Limits { for i := range in.Limits {
@@ -875,9 +875,9 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *LimitRangeSpec, out *newer.LimitRangeSpec, s conversion.Scope) error { func(in *LimitRangeSpec, out *api.LimitRangeSpec, s conversion.Scope) error {
*out = newer.LimitRangeSpec{} *out = api.LimitRangeSpec{}
out.Limits = make([]newer.LimitRangeItem, len(in.Limits), len(in.Limits)) out.Limits = make([]api.LimitRangeItem, len(in.Limits), len(in.Limits))
for i := range in.Limits { for i := range in.Limits {
if err := s.Convert(&in.Limits[i], &out.Limits[i], 0); err != nil { if err := s.Convert(&in.Limits[i], &out.Limits[i], 0); err != nil {
return err return err
@@ -886,7 +886,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.LimitRangeItem, out *LimitRangeItem, s conversion.Scope) error { func(in *api.LimitRangeItem, out *LimitRangeItem, s conversion.Scope) error {
*out = LimitRangeItem{} *out = LimitRangeItem{}
out.Type = LimitType(in.Type) out.Type = LimitType(in.Type)
if err := s.Convert(&in.Max, &out.Max, 0); err != nil { if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
@@ -900,9 +900,9 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *LimitRangeItem, out *newer.LimitRangeItem, s conversion.Scope) error { func(in *LimitRangeItem, out *api.LimitRangeItem, s conversion.Scope) error {
*out = newer.LimitRangeItem{} *out = api.LimitRangeItem{}
out.Type = newer.LimitType(in.Type) out.Type = api.LimitType(in.Type)
if err := s.Convert(&in.Max, &out.Max, 0); err != nil { if err := s.Convert(&in.Max, &out.Max, 0); err != nil {
return err return err
} }
@@ -915,7 +915,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.ResourceQuota, out *ResourceQuota, s conversion.Scope) error { func(in *api.ResourceQuota, out *ResourceQuota, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -933,7 +933,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *ResourceQuota, out *newer.ResourceQuota, s conversion.Scope) error { func(in *ResourceQuota, out *api.ResourceQuota, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -952,22 +952,22 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.ResourceQuotaSpec, out *ResourceQuotaSpec, s conversion.Scope) error { func(in *api.ResourceQuotaSpec, out *ResourceQuotaSpec, s conversion.Scope) error {
*out = ResourceQuotaSpec{} *out = ResourceQuotaSpec{}
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil { if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
return err return err
} }
return nil return nil
}, },
func(in *ResourceQuotaSpec, out *newer.ResourceQuotaSpec, s conversion.Scope) error { func(in *ResourceQuotaSpec, out *api.ResourceQuotaSpec, s conversion.Scope) error {
*out = newer.ResourceQuotaSpec{} *out = api.ResourceQuotaSpec{}
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil { if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
return err return err
} }
return nil return nil
}, },
func(in *newer.ResourceQuotaStatus, out *ResourceQuotaStatus, s conversion.Scope) error { func(in *api.ResourceQuotaStatus, out *ResourceQuotaStatus, s conversion.Scope) error {
*out = ResourceQuotaStatus{} *out = ResourceQuotaStatus{}
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil { if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
return err return err
@@ -977,8 +977,8 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *ResourceQuotaStatus, out *newer.ResourceQuotaStatus, s conversion.Scope) error { func(in *ResourceQuotaStatus, out *api.ResourceQuotaStatus, s conversion.Scope) error {
*out = newer.ResourceQuotaStatus{} *out = api.ResourceQuotaStatus{}
if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil { if err := s.Convert(&in.Hard, &out.Hard, 0); err != nil {
return err return err
} }
@@ -990,7 +990,7 @@ func addConversionFuncs() {
// Object ID <-> Name // Object ID <-> Name
// TODO: amend the conversion package to allow overriding specific fields. // TODO: amend the conversion package to allow overriding specific fields.
func(in *ObjectReference, out *newer.ObjectReference, s conversion.Scope) error { func(in *ObjectReference, out *api.ObjectReference, s conversion.Scope) error {
out.Kind = in.Kind out.Kind = in.Kind
out.Namespace = in.Namespace out.Namespace = in.Namespace
out.Name = in.ID out.Name = in.ID
@@ -1000,7 +1000,7 @@ func addConversionFuncs() {
out.FieldPath = in.FieldPath out.FieldPath = in.FieldPath
return nil return nil
}, },
func(in *newer.ObjectReference, out *ObjectReference, s conversion.Scope) error { func(in *api.ObjectReference, out *ObjectReference, s conversion.Scope) error {
out.Kind = in.Kind out.Kind = in.Kind
out.Namespace = in.Namespace out.Namespace = in.Namespace
out.ID = in.Name out.ID = in.Name
@@ -1015,7 +1015,7 @@ func addConversionFuncs() {
// Event Source <-> Source.Component // Event Source <-> Source.Component
// Event Host <-> Source.Host // Event Host <-> Source.Host
// TODO: remove this when it becomes possible to specify a field name conversion on a specific type // TODO: remove this when it becomes possible to specify a field name conversion on a specific type
func(in *newer.Event, out *Event, s conversion.Scope) error { func(in *api.Event, out *Event, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -1032,7 +1032,7 @@ func addConversionFuncs() {
out.Count = in.Count out.Count = in.Count
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0) return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
}, },
func(in *Event, out *newer.Event, s conversion.Scope) error { func(in *Event, out *api.Event, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -1081,28 +1081,28 @@ func addConversionFuncs() {
}, },
// Convert resource lists. // Convert resource lists.
func(in *ResourceList, out *newer.ResourceList, s conversion.Scope) error { func(in *ResourceList, out *api.ResourceList, s conversion.Scope) error {
*out = newer.ResourceList{} *out = api.ResourceList{}
for k, v := range *in { for k, v := range *in {
fv, err := strconv.ParseFloat(v.String(), 64) fv, err := strconv.ParseFloat(v.String(), 64)
if err != nil { if err != nil {
return &newer.ConversionError{ return &api.ConversionError{
In: in, Out: out, In: in, Out: out,
Message: fmt.Sprintf("value '%v' of '%v': %v", v, k, err), Message: fmt.Sprintf("value '%v' of '%v': %v", v, k, err),
} }
} }
if k == ResourceCPU { if k == ResourceCPU {
(*out)[newer.ResourceCPU] = *resource.NewMilliQuantity(int64(fv*1000), resource.DecimalSI) (*out)[api.ResourceCPU] = *resource.NewMilliQuantity(int64(fv*1000), resource.DecimalSI)
} else { } else {
(*out)[newer.ResourceName(k)] = *resource.NewQuantity(int64(fv), resource.BinarySI) (*out)[api.ResourceName(k)] = *resource.NewQuantity(int64(fv), resource.BinarySI)
} }
} }
return nil return nil
}, },
func(in *newer.ResourceList, out *ResourceList, s conversion.Scope) error { func(in *api.ResourceList, out *ResourceList, s conversion.Scope) error {
*out = ResourceList{} *out = ResourceList{}
for k, v := range *in { for k, v := range *in {
if k == newer.ResourceCPU { if k == api.ResourceCPU {
(*out)[ResourceCPU] = util.NewIntOrStringFromString(fmt.Sprintf("%v", float64(v.MilliValue())/1000)) (*out)[ResourceCPU] = util.NewIntOrStringFromString(fmt.Sprintf("%v", float64(v.MilliValue())/1000))
} else { } else {
(*out)[ResourceName(k)] = util.NewIntOrStringFromInt(int(v.Value())) (*out)[ResourceName(k)] = util.NewIntOrStringFromInt(int(v.Value()))
@@ -1111,14 +1111,14 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.Volume, out *Volume, s conversion.Scope) error { func(in *api.Volume, out *Volume, s conversion.Scope) error {
if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil { if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil {
return err return err
} }
out.Name = in.Name out.Name = in.Name
return nil return nil
}, },
func(in *Volume, out *newer.Volume, s conversion.Scope) error { func(in *Volume, out *api.Volume, s conversion.Scope) error {
if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil { if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil {
return err return err
} }
@@ -1126,7 +1126,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.VolumeSource, out *VolumeSource, s conversion.Scope) error { func(in *api.VolumeSource, out *VolumeSource, s conversion.Scope) error {
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil { if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
return err return err
} }
@@ -1159,7 +1159,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *VolumeSource, out *newer.VolumeSource, s conversion.Scope) error { func(in *VolumeSource, out *api.VolumeSource, s conversion.Scope) error {
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil { if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
return err return err
} }
@@ -1193,13 +1193,13 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.PullPolicy, out *PullPolicy, s conversion.Scope) error { func(in *api.PullPolicy, out *PullPolicy, s conversion.Scope) error {
switch *in { switch *in {
case newer.PullAlways: case api.PullAlways:
*out = PullAlways *out = PullAlways
case newer.PullNever: case api.PullNever:
*out = PullNever *out = PullNever
case newer.PullIfNotPresent: case api.PullIfNotPresent:
*out = PullIfNotPresent *out = PullIfNotPresent
case "": case "":
*out = "" *out = ""
@@ -1209,51 +1209,51 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PullPolicy, out *newer.PullPolicy, s conversion.Scope) error { func(in *PullPolicy, out *api.PullPolicy, s conversion.Scope) error {
switch *in { switch *in {
case PullAlways: case PullAlways:
*out = newer.PullAlways *out = api.PullAlways
case PullNever: case PullNever:
*out = newer.PullNever *out = api.PullNever
case PullIfNotPresent: case PullIfNotPresent:
*out = newer.PullIfNotPresent *out = api.PullIfNotPresent
case "": case "":
*out = "" *out = ""
default: default:
// Let unknown values through - they will get caught by validation // Let unknown values through - they will get caught by validation
*out = newer.PullPolicy(*in) *out = api.PullPolicy(*in)
} }
return nil return nil
}, },
func(in *newer.RestartPolicy, out *RestartPolicy, s conversion.Scope) error { func(in *api.RestartPolicy, out *RestartPolicy, s conversion.Scope) error {
switch *in { switch *in {
case newer.RestartPolicyAlways: case api.RestartPolicyAlways:
*out = RestartPolicy{Always: &RestartPolicyAlways{}} *out = RestartPolicy{Always: &RestartPolicyAlways{}}
case newer.RestartPolicyNever: case api.RestartPolicyNever:
*out = RestartPolicy{Never: &RestartPolicyNever{}} *out = RestartPolicy{Never: &RestartPolicyNever{}}
case newer.RestartPolicyOnFailure: case api.RestartPolicyOnFailure:
*out = RestartPolicy{OnFailure: &RestartPolicyOnFailure{}} *out = RestartPolicy{OnFailure: &RestartPolicyOnFailure{}}
default: default:
*out = RestartPolicy{} *out = RestartPolicy{}
} }
return nil return nil
}, },
func(in *RestartPolicy, out *newer.RestartPolicy, s conversion.Scope) error { func(in *RestartPolicy, out *api.RestartPolicy, s conversion.Scope) error {
switch { switch {
case in.Always != nil: case in.Always != nil:
*out = newer.RestartPolicyAlways *out = api.RestartPolicyAlways
case in.Never != nil: case in.Never != nil:
*out = newer.RestartPolicyNever *out = api.RestartPolicyNever
case in.OnFailure != nil: case in.OnFailure != nil:
*out = newer.RestartPolicyOnFailure *out = api.RestartPolicyOnFailure
default: default:
*out = "" *out = ""
} }
return nil return nil
}, },
func(in *newer.Probe, out *LivenessProbe, s conversion.Scope) error { func(in *api.Probe, out *LivenessProbe, s conversion.Scope) error {
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil { if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
return err return err
} }
@@ -1267,7 +1267,7 @@ func addConversionFuncs() {
out.TimeoutSeconds = in.TimeoutSeconds out.TimeoutSeconds = in.TimeoutSeconds
return nil return nil
}, },
func(in *LivenessProbe, out *newer.Probe, s conversion.Scope) error { func(in *LivenessProbe, out *api.Probe, s conversion.Scope) error {
if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil { if err := s.Convert(&in.Exec, &out.Exec, 0); err != nil {
return err return err
} }
@@ -1282,7 +1282,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.Endpoints, out *Endpoints, s conversion.Scope) error { func(in *api.Endpoints, out *Endpoints, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -1329,7 +1329,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *Endpoints, out *newer.Endpoints, s conversion.Scope) error { func(in *Endpoints, out *api.Endpoints, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err return err
} }
@@ -1343,7 +1343,7 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.NodeCondition, out *NodeCondition, s conversion.Scope) error { func(in *api.NodeCondition, out *NodeCondition, s conversion.Scope) error {
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil { if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
return err return err
} }
@@ -1364,7 +1364,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *NodeCondition, out *newer.NodeCondition, s conversion.Scope) error { func(in *NodeCondition, out *api.NodeCondition, s conversion.Scope) error {
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil { if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
return err return err
} }
@@ -1386,9 +1386,9 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.NodeConditionType, out *NodeConditionKind, s conversion.Scope) error { func(in *api.NodeConditionType, out *NodeConditionKind, s conversion.Scope) error {
switch *in { switch *in {
case newer.NodeReady: case api.NodeReady:
*out = NodeReady *out = NodeReady
break break
case "": case "":
@@ -1399,26 +1399,26 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *NodeConditionKind, out *newer.NodeConditionType, s conversion.Scope) error { func(in *NodeConditionKind, out *api.NodeConditionType, s conversion.Scope) error {
switch *in { switch *in {
case NodeReady: case NodeReady:
*out = newer.NodeReady *out = api.NodeReady
break break
case "": case "":
*out = "" *out = ""
default: default:
*out = newer.NodeConditionType(*in) *out = api.NodeConditionType(*in)
break break
} }
return nil return nil
}, },
func(in *newer.ConditionStatus, out *ConditionStatus, s conversion.Scope) error { func(in *api.ConditionStatus, out *ConditionStatus, s conversion.Scope) error {
switch *in { switch *in {
case newer.ConditionTrue: case api.ConditionTrue:
*out = ConditionFull *out = ConditionFull
break break
case newer.ConditionFalse: case api.ConditionFalse:
*out = ConditionNone *out = ConditionNone
break break
default: default:
@@ -1427,22 +1427,22 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *ConditionStatus, out *newer.ConditionStatus, s conversion.Scope) error { func(in *ConditionStatus, out *api.ConditionStatus, s conversion.Scope) error {
switch *in { switch *in {
case ConditionFull: case ConditionFull:
*out = newer.ConditionTrue *out = api.ConditionTrue
break break
case ConditionNone: case ConditionNone:
*out = newer.ConditionFalse *out = api.ConditionFalse
break break
default: default:
*out = newer.ConditionStatus(*in) *out = api.ConditionStatus(*in)
break break
} }
return nil return nil
}, },
func(in *newer.PodCondition, out *PodCondition, s conversion.Scope) error { func(in *api.PodCondition, out *PodCondition, s conversion.Scope) error {
if err := s.Convert(&in.Type, &out.Kind, 0); err != nil { if err := s.Convert(&in.Type, &out.Kind, 0); err != nil {
return err return err
} }
@@ -1451,7 +1451,7 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PodCondition, out *newer.PodCondition, s conversion.Scope) error { func(in *PodCondition, out *api.PodCondition, s conversion.Scope) error {
if err := s.Convert(&in.Kind, &out.Type, 0); err != nil { if err := s.Convert(&in.Kind, &out.Type, 0); err != nil {
return err return err
} }
@@ -1461,9 +1461,9 @@ func addConversionFuncs() {
return nil return nil
}, },
func(in *newer.PodConditionType, out *PodConditionKind, s conversion.Scope) error { func(in *api.PodConditionType, out *PodConditionKind, s conversion.Scope) error {
switch *in { switch *in {
case newer.PodReady: case api.PodReady:
*out = PodReady *out = PodReady
break break
case "": case "":
@@ -1474,31 +1474,31 @@ func addConversionFuncs() {
} }
return nil return nil
}, },
func(in *PodConditionKind, out *newer.PodConditionType, s conversion.Scope) error { func(in *PodConditionKind, out *api.PodConditionType, s conversion.Scope) error {
switch *in { switch *in {
case PodReady: case PodReady:
*out = newer.PodReady *out = api.PodReady
break break
case "": case "":
*out = "" *out = ""
default: default:
*out = newer.PodConditionType(*in) *out = api.PodConditionType(*in)
break break
} }
return nil return nil
}, },
func(in *Binding, out *newer.Binding, s conversion.Scope) error { func(in *Binding, out *api.Binding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil { if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err return err
} }
out.Target = newer.ObjectReference{ out.Target = api.ObjectReference{
Name: in.Host, Name: in.Host,
} }
out.Name = in.PodID out.Name = in.PodID
return nil return nil
}, },
func(in *newer.Binding, out *Binding, s conversion.Scope) error { func(in *api.Binding, out *Binding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil { if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err return err
} }
@@ -1506,11 +1506,11 @@ func addConversionFuncs() {
out.PodID = in.Name out.PodID = in.Name
return nil return nil
}, },
func(in *newer.SecretVolumeSource, out *SecretVolumeSource, s conversion.Scope) error { func(in *api.SecretVolumeSource, out *SecretVolumeSource, s conversion.Scope) error {
out.Target.ID = in.SecretName out.Target.ID = in.SecretName
return nil return nil
}, },
func(in *SecretVolumeSource, out *newer.SecretVolumeSource, s conversion.Scope) error { func(in *SecretVolumeSource, out *api.SecretVolumeSource, s conversion.Scope) error {
out.SecretName = in.Target.ID out.SecretName = in.Target.ID
return nil return nil
}, },
@@ -1521,7 +1521,7 @@ func addConversionFuncs() {
} }
// Add field conversion funcs. // Add field conversion funcs.
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Pod", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Pod",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "name":
@@ -1530,8 +1530,8 @@ func addConversionFuncs() {
return "spec.host", value, nil return "spec.host", value, nil
case "DesiredState.Status": case "DesiredState.Status":
podStatus := PodStatus(value) podStatus := PodStatus(value)
var internalValue newer.PodPhase var internalValue api.PodPhase
newer.Scheme.Convert(&podStatus, &internalValue) api.Scheme.Convert(&podStatus, &internalValue)
return "status.phase", string(internalValue), nil return "status.phase", string(internalValue), nil
default: default:
return "", "", fmt.Errorf("field label not supported: %s", label) return "", "", fmt.Errorf("field label not supported: %s", label)
@@ -1541,7 +1541,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Node", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Node",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "name":
@@ -1556,7 +1556,7 @@ func addConversionFuncs() {
// if one of the conversion functions is malformed, detect it immediately. // if one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "ReplicationController", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "ReplicationController",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "name":
@@ -1571,7 +1571,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Event", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Event",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "involvedObject.kind", case "involvedObject.kind",
@@ -1593,7 +1593,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Namespace", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Namespace",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "status.phase": case "status.phase":
@@ -1606,7 +1606,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "Secret", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "Secret",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "type": case "type":
@@ -1619,7 +1619,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "ServiceAccount", err = api.Scheme.AddFieldLabelConversionFunc("v1beta2", "ServiceAccount",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "name":

View File

@@ -21,39 +21,39 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
func TestServiceEmptySelector(t *testing.T) { func TestServiceEmptySelector(t *testing.T) {
// Nil map should be preserved // Nil map should be preserved
svc := &current.Service{Selector: nil} svc := &versioned.Service{Selector: nil}
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta2") data, err := api.Scheme.EncodeToVersion(svc, "v1beta2")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := newer.Scheme.Decode(data) obj, err := api.Scheme.Decode(data)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
selector := obj.(*newer.Service).Spec.Selector selector := obj.(*api.Service).Spec.Selector
if selector != nil { if selector != nil {
t.Errorf("unexpected selector: %#v", obj) t.Errorf("unexpected selector: %#v", obj)
} }
// Empty map should be preserved // Empty map should be preserved
svc2 := &current.Service{Selector: map[string]string{}} svc2 := &versioned.Service{Selector: map[string]string{}}
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta2") data, err = api.Scheme.EncodeToVersion(svc2, "v1beta2")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err = newer.Scheme.Decode(data) obj, err = api.Scheme.Decode(data)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
selector = obj.(*newer.Service).Spec.Selector selector = obj.(*api.Service).Spec.Selector
if selector == nil || len(selector) != 0 { if selector == nil || len(selector) != 0 {
t.Errorf("unexpected selector: %#v", obj) t.Errorf("unexpected selector: %#v", obj)
} }
@@ -61,160 +61,160 @@ func TestServiceEmptySelector(t *testing.T) {
func TestServicePorts(t *testing.T) { func TestServicePorts(t *testing.T) {
testCases := []struct { testCases := []struct {
given current.Service given versioned.Service
expected newer.Service expected api.Service
roundtrip current.Service roundtrip versioned.Service
}{ }{
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "legacy-with-defaults", ID: "legacy-with-defaults",
}, },
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Port: 111, Port: 111,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "legacy-full", ID: "legacy-full",
}, },
PortName: "p", PortName: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromString("p"), TargetPort: util.NewIntOrStringFromString("p"),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "both", ID: "both",
}, },
PortName: "p", PortName: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromString("p"), ContainerPort: util.NewIntOrStringFromString("p"),
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one", ID: "one",
}, },
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}}, }},
}, },
}, },
{ {
given: current.Service{ given: versioned.Service{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "two", ID: "two",
}, },
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromInt(76), ContainerPort: util.NewIntOrStringFromInt(76),
}}, }},
}, },
expected: newer.Service{ expected: api.Service{
Spec: newer.ServiceSpec{Ports: []newer.ServicePort{{ Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: newer.ProtocolUDP, Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(93), TargetPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: newer.ProtocolTCP, Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(76), TargetPort: util.NewIntOrStringFromInt(76),
}}}, }}},
}, },
roundtrip: current.Service{ roundtrip: versioned.Service{
Ports: []current.ServicePort{{ Ports: []versioned.ServicePort{{
Name: "p", Name: "p",
Port: 111, Port: 111,
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
ContainerPort: util.NewIntOrStringFromInt(93), ContainerPort: util.NewIntOrStringFromInt(93),
}, { }, {
Name: "q", Name: "q",
Port: 222, Port: 222,
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
ContainerPort: util.NewIntOrStringFromInt(76), ContainerPort: util.NewIntOrStringFromInt(76),
}}, }},
}, },
@@ -223,8 +223,8 @@ func TestServicePorts(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
// Convert versioned -> internal. // Convert versioned -> internal.
got := newer.Service{} got := api.Service{}
if err := newer.Scheme.Convert(&tc.given, &got); err != nil { if err := api.Scheme.Convert(&tc.given, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
@@ -233,8 +233,8 @@ func TestServicePorts(t *testing.T) {
} }
// Convert internal -> versioned. // Convert internal -> versioned.
got2 := current.Service{} got2 := versioned.Service{}
if err := newer.Scheme.Convert(&got, &got2); err != nil { if err := api.Scheme.Convert(&got, &got2); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
@@ -245,7 +245,7 @@ func TestServicePorts(t *testing.T) {
} }
func TestNodeConversion(t *testing.T) { func TestNodeConversion(t *testing.T) {
version, kind, err := newer.Scheme.ObjectVersionAndKind(&current.Minion{}) version, kind, err := api.Scheme.ObjectVersionAndKind(&versioned.Minion{})
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -253,30 +253,30 @@ func TestNodeConversion(t *testing.T) {
t.Errorf("unexpected version and kind: %s %s", version, kind) t.Errorf("unexpected version and kind: %s %s", version, kind)
} }
newer.Scheme.Log(t) api.Scheme.Log(t)
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`)) obj, err := versioned.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.Node); !ok { if _, ok := obj.(*api.Node); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta2"}`)) obj, err = versioned.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta2"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.NodeList); !ok { if _, ok := obj.(*api.NodeList); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj = &newer.Node{} obj = &api.Node{}
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`), obj); err != nil { if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta2"}`), obj); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj = &newer.Node{} obj = &api.Node{}
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -291,18 +291,18 @@ func TestNodeConversion(t *testing.T) {
func TestPullPolicyConversion(t *testing.T) { func TestPullPolicyConversion(t *testing.T) {
table := []struct { table := []struct {
versioned current.PullPolicy versioned versioned.PullPolicy
internal newer.PullPolicy internal api.PullPolicy
}{ }{
{ {
versioned: current.PullAlways, versioned: versioned.PullAlways,
internal: newer.PullAlways, internal: api.PullAlways,
}, { }, {
versioned: current.PullNever, versioned: versioned.PullNever,
internal: newer.PullNever, internal: api.PullNever,
}, { }, {
versioned: current.PullIfNotPresent, versioned: versioned.PullIfNotPresent,
internal: newer.PullIfNotPresent, internal: api.PullIfNotPresent,
}, { }, {
versioned: "", versioned: "",
internal: "", internal: "",
@@ -312,8 +312,8 @@ func TestPullPolicyConversion(t *testing.T) {
}, },
} }
for _, item := range table { for _, item := range table {
var got newer.PullPolicy var got api.PullPolicy
err := newer.Scheme.Convert(&item.versioned, &got) err := api.Scheme.Convert(&item.versioned, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
continue continue
@@ -323,8 +323,8 @@ func TestPullPolicyConversion(t *testing.T) {
} }
} }
for _, item := range table { for _, item := range table {
var got current.PullPolicy var got versioned.PullPolicy
err := newer.Scheme.Convert(&item.internal, &got) err := api.Scheme.Convert(&item.internal, &got)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
continue continue
@@ -335,14 +335,14 @@ func TestPullPolicyConversion(t *testing.T) {
} }
} }
func getResourceRequirements(cpu, memory resource.Quantity) current.ResourceRequirements { func getResourceRequirements(cpu, memory resource.Quantity) versioned.ResourceRequirements {
res := current.ResourceRequirements{} res := versioned.ResourceRequirements{}
res.Limits = current.ResourceList{} res.Limits = versioned.ResourceList{}
if cpu.Value() > 0 { if cpu.Value() > 0 {
res.Limits[current.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value())) res.Limits[versioned.ResourceCPU] = util.NewIntOrStringFromInt(int(cpu.Value()))
} }
if memory.Value() > 0 { if memory.Value() > 0 {
res.Limits[current.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value())) res.Limits[versioned.ResourceMemory] = util.NewIntOrStringFromInt(int(memory.Value()))
} }
return res return res
@@ -352,7 +352,7 @@ func TestContainerConversion(t *testing.T) {
cpuLimit := resource.MustParse("10") cpuLimit := resource.MustParse("10")
memoryLimit := resource.MustParse("10M") memoryLimit := resource.MustParse("10M")
null := resource.Quantity{} null := resource.Quantity{}
testCases := []current.Container{ testCases := []versioned.Container{
{ {
Name: "container", Name: "container",
Resources: getResourceRequirements(cpuLimit, memoryLimit), Resources: getResourceRequirements(cpuLimit, memoryLimit),
@@ -385,8 +385,8 @@ func TestContainerConversion(t *testing.T) {
} }
for i, tc := range testCases { for i, tc := range testCases {
got := newer.Container{} got := api.Container{}
if err := newer.Scheme.Convert(&tc, &got); err != nil { if err := api.Scheme.Convert(&tc, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
@@ -401,114 +401,114 @@ func TestContainerConversion(t *testing.T) {
func TestEndpointsConversion(t *testing.T) { func TestEndpointsConversion(t *testing.T) {
testCases := []struct { testCases := []struct {
given current.Endpoints given versioned.Endpoints
expected newer.Endpoints expected api.Endpoints
}{ }{
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "empty", ID: "empty",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{}, Endpoints: []string{},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{}, Subsets: []api.EndpointSubset{},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one legacy", ID: "one legacy",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{"1.2.3.4:88"}, Endpoints: []string{"1.2.3.4:88"},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{{ Subsets: []api.EndpointSubset{{
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "several legacy", ID: "several legacy",
}, },
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"}, Endpoints: []string{"1.2.3.4:88", "1.2.3.4:89", "1.2.3.4:90"},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{ Subsets: []api.EndpointSubset{
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 90, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 90, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}, },
}}, }},
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "one subset", ID: "one subset",
}, },
Protocol: current.ProtocolTCP, Protocol: versioned.ProtocolTCP,
Endpoints: []string{"1.2.3.4:88"}, Endpoints: []string{"1.2.3.4:88"},
Subsets: []current.EndpointSubset{{ Subsets: []versioned.EndpointSubset{{
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolTCP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolTCP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{{ Subsets: []api.EndpointSubset{{
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolTCP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolTCP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
}}, }},
}, },
}, },
{ {
given: current.Endpoints{ given: versioned.Endpoints{
TypeMeta: current.TypeMeta{ TypeMeta: versioned.TypeMeta{
ID: "several subset", ID: "several subset",
}, },
Protocol: current.ProtocolUDP, Protocol: versioned.ProtocolUDP,
Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"}, Endpoints: []string{"1.2.3.4:88", "5.6.7.8:88", "1.2.3.4:89", "5.6.7.8:89"},
Subsets: []current.EndpointSubset{ Subsets: []versioned.EndpointSubset{
{ {
Ports: []current.EndpointPort{{Name: "", Port: 88, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 88, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []current.EndpointPort{{Name: "", Port: 89, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "", Port: 89, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []current.EndpointPort{{Name: "named", Port: 90, Protocol: current.ProtocolUDP}}, Ports: []versioned.EndpointPort{{Name: "named", Port: 90, Protocol: versioned.ProtocolUDP}},
Addresses: []current.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
}, },
}, },
expected: newer.Endpoints{ expected: api.Endpoints{
Subsets: []newer.EndpointSubset{ Subsets: []api.EndpointSubset{
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 88, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 88, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "", Port: 89, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "", Port: 89, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
{ {
Ports: []newer.EndpointPort{{Name: "named", Port: 90, Protocol: newer.ProtocolUDP}}, Ports: []api.EndpointPort{{Name: "named", Port: 90, Protocol: api.ProtocolUDP}},
Addresses: []newer.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}}, Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}, {IP: "5.6.7.8"}},
}, },
}}, }},
}, },
@@ -516,48 +516,48 @@ func TestEndpointsConversion(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
// Convert versioned -> internal. // Convert versioned -> internal.
got := newer.Endpoints{} got := api.Endpoints{}
if err := newer.Scheme.Convert(&tc.given, &got); err != nil { if err := api.Scheme.Convert(&tc.given, &got); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
if !newer.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) { if !api.Semantic.DeepEqual(got.Subsets, tc.expected.Subsets) {
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets) t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.expected.Subsets, got.Subsets)
} }
// Convert internal -> versioned. // Convert internal -> versioned.
got2 := current.Endpoints{} got2 := versioned.Endpoints{}
if err := newer.Scheme.Convert(&got, &got2); err != nil { if err := api.Scheme.Convert(&got, &got2); err != nil {
t.Errorf("[Case: %d] Unexpected error: %v", i, err) t.Errorf("[Case: %d] Unexpected error: %v", i, err)
continue continue
} }
if got2.Protocol != tc.given.Protocol || !newer.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) { if got2.Protocol != tc.given.Protocol || !api.Semantic.DeepEqual(got2.Endpoints, tc.given.Endpoints) {
t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.given.Endpoints, got2.Endpoints) t.Errorf("[Case: %d] Expected %#v, got %#v", i, tc.given.Endpoints, got2.Endpoints)
} }
} }
} }
func TestSecretVolumeSourceConversion(t *testing.T) { func TestSecretVolumeSourceConversion(t *testing.T) {
given := current.SecretVolumeSource{ given := versioned.SecretVolumeSource{
Target: current.ObjectReference{ Target: versioned.ObjectReference{
ID: "foo", ID: "foo",
}, },
} }
expected := newer.SecretVolumeSource{ expected := api.SecretVolumeSource{
SecretName: "foo", SecretName: "foo",
} }
got := newer.SecretVolumeSource{} got := api.SecretVolumeSource{}
if err := newer.Scheme.Convert(&given, &got); err != nil { if err := api.Scheme.Convert(&given, &got); err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
if got.SecretName != expected.SecretName { if got.SecretName != expected.SecretName {
t.Errorf("Expected %v; got %v", expected, got) t.Errorf("Expected %v; got %v", expected, got)
} }
got2 := current.SecretVolumeSource{} got2 := versioned.SecretVolumeSource{}
if err := newer.Scheme.Convert(&got, &got2); err != nil { if err := api.Scheme.Convert(&got, &got2); err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
if got2.Target.ID != given.Target.ID { if got2.Target.ID != given.Target.ID {
@@ -568,42 +568,42 @@ func TestSecretVolumeSourceConversion(t *testing.T) {
func TestBadSecurityContextConversion(t *testing.T) { func TestBadSecurityContextConversion(t *testing.T) {
priv := false priv := false
testCases := map[string]struct { testCases := map[string]struct {
c *current.Container c *versioned.Container
err string err string
}{ }{
// this use case must use true for the container and false for the sc. Otherwise the defaulter // this use case must use true for the container and false for the sc. Otherwise the defaulter
// will assume privileged was left undefined (since it is the default value) and copy the // will assume privileged was left undefined (since it is the default value) and copy the
// sc setting upwards // sc setting upwards
"mismatched privileged": { "mismatched privileged": {
c: &current.Container{ c: &versioned.Container{
Privileged: true, Privileged: true,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
err: "container privileged settings do not match security context settings, cannot convert", err: "container privileged settings do not match security context settings, cannot convert",
}, },
"mismatched caps add": { "mismatched caps add": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"bar"}, Add: []versioned.Capability{"bar"},
}, },
}, },
}, },
err: "container capability settings do not match security context settings, cannot convert", err: "container capability settings do not match security context settings, cannot convert",
}, },
"mismatched caps drop": { "mismatched caps drop": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Drop: []current.Capability{"foo"}, Drop: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
@@ -612,8 +612,8 @@ func TestBadSecurityContextConversion(t *testing.T) {
} }
for k, v := range testCases { for k, v := range testCases {
got := newer.Container{} got := api.Container{}
err := newer.Scheme.Convert(v.c, &got) err := api.Scheme.Convert(v.c, &got)
if err == nil { if err == nil {
t.Errorf("expected error for case %s but got none", k) t.Errorf("expected error for case %s but got none", k)
} else { } else {

View File

@@ -20,25 +20,25 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Errorf("%v\n %#v", err, obj) t.Errorf("%v\n %#v", err, obj)
return nil return nil
} }
obj2, err := newer.Codec.Decode(data) obj2, err := api.Codec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj) t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil return nil
} }
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = newer.Scheme.Convert(obj2, obj3) err = api.Scheme.Convert(obj2, obj3)
if err != nil { if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2) t.Errorf("%v\nSource: %#v", err, obj2)
return nil return nil
@@ -48,14 +48,14 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultReplicationController(t *testing.T) { func TestSetDefaultReplicationController(t *testing.T) {
tests := []struct { tests := []struct {
rc *current.ReplicationController rc *versioned.ReplicationController
expectLabels bool expectLabels bool
expectSelector bool expectSelector bool
}{ }{
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -66,12 +66,12 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -82,15 +82,15 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
ReplicaSelector: map[string]string{ ReplicaSelector: map[string]string{
"some": "other", "some": "other",
}, },
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -101,12 +101,12 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: false, expectSelector: false,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
DesiredState: current.ReplicationControllerState{ DesiredState: versioned.ReplicationControllerState{
ReplicaSelector: map[string]string{ ReplicaSelector: map[string]string{
"some": "other", "some": "other",
}, },
PodTemplate: current.PodTemplate{ PodTemplate: versioned.PodTemplate{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -120,7 +120,7 @@ func TestSetDefaultReplicationController(t *testing.T) {
for _, test := range tests { for _, test := range tests {
rc := test.rc rc := test.rc
obj2 := roundTrip(t, runtime.Object(rc)) obj2 := roundTrip(t, runtime.Object(rc))
rc2, ok := obj2.(*current.ReplicationController) rc2, ok := obj2.(*versioned.ReplicationController)
if !ok { if !ok {
t.Errorf("unexpected object: %v", rc2) t.Errorf("unexpected object: %v", rc2)
t.FailNow() t.FailNow()
@@ -143,67 +143,67 @@ func TestSetDefaultReplicationController(t *testing.T) {
} }
func TestSetDefaultService(t *testing.T) { func TestSetDefaultService(t *testing.T) {
svc := &current.Service{} svc := &versioned.Service{}
obj2 := roundTrip(t, runtime.Object(svc)) obj2 := roundTrip(t, runtime.Object(svc))
svc2 := obj2.(*current.Service) svc2 := obj2.(*versioned.Service)
if svc2.Protocol != current.ProtocolTCP { if svc2.Protocol != versioned.ProtocolTCP {
t.Errorf("Expected default protocol :%s, got: %s", current.ProtocolTCP, svc2.Protocol) t.Errorf("Expected default protocol :%s, got: %s", versioned.ProtocolTCP, svc2.Protocol)
} }
if svc2.SessionAffinity != current.ServiceAffinityNone { if svc2.SessionAffinity != versioned.ServiceAffinityNone {
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.SessionAffinity) t.Errorf("Expected default sesseion affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.SessionAffinity)
} }
} }
func TestSetDefaultPersistentVolume(t *testing.T) { func TestSetDefaultPersistentVolume(t *testing.T) {
pv := &current.PersistentVolume{} pv := &versioned.PersistentVolume{}
obj2 := roundTrip(t, runtime.Object(pv)) obj2 := roundTrip(t, runtime.Object(pv))
pv2 := obj2.(*current.PersistentVolume) pv2 := obj2.(*versioned.PersistentVolume)
if pv2.Status.Phase != current.VolumePending { if pv2.Status.Phase != versioned.VolumePending {
t.Errorf("Expected volume phase %v, got %v", current.VolumePending, pv2.Status.Phase) t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
} }
} }
func TestSetDefaultPersistentVolumeClaim(t *testing.T) { func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
pvc := &current.PersistentVolumeClaim{} pvc := &versioned.PersistentVolumeClaim{}
obj2 := roundTrip(t, runtime.Object(pvc)) obj2 := roundTrip(t, runtime.Object(pvc))
pvc2 := obj2.(*current.PersistentVolumeClaim) pvc2 := obj2.(*versioned.PersistentVolumeClaim)
if pvc2.Status.Phase != current.ClaimPending { if pvc2.Status.Phase != versioned.ClaimPending {
t.Errorf("Expected claim phase %v, got %v", current.ClaimPending, pvc2.Status.Phase) t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
} }
} }
func TestSetDefaultSecret(t *testing.T) { func TestSetDefaultSecret(t *testing.T) {
s := &current.Secret{} s := &versioned.Secret{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Secret) s2 := obj2.(*versioned.Secret)
if s2.Type != current.SecretTypeOpaque { if s2.Type != versioned.SecretTypeOpaque {
t.Errorf("Expected secret type %v, got %v", current.SecretTypeOpaque, s2.Type) t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
} }
} }
func TestSetDefaulEndpointsLegacy(t *testing.T) { func TestSetDefaulEndpointsLegacy(t *testing.T) {
in := &current.Endpoints{ in := &versioned.Endpoints{
Protocol: "UDP", Protocol: "UDP",
Endpoints: []string{"1.2.3.4:93", "5.6.7.8:76"}, Endpoints: []string{"1.2.3.4:93", "5.6.7.8:76"},
TargetRefs: []current.EndpointObjectReference{{Endpoint: "1.2.3.4:93", ObjectReference: current.ObjectReference{ID: "foo"}}}, TargetRefs: []versioned.EndpointObjectReference{{Endpoint: "1.2.3.4:93", ObjectReference: versioned.ObjectReference{ID: "foo"}}},
} }
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
if len(out.Subsets) != 2 { if len(out.Subsets) != 2 {
t.Errorf("Expected 2 EndpointSubsets, got %d (%#v)", len(out.Subsets), out.Subsets) t.Errorf("Expected 2 EndpointSubsets, got %d (%#v)", len(out.Subsets), out.Subsets)
} }
expected := []current.EndpointSubset{ expected := []versioned.EndpointSubset{
{ {
Addresses: []current.EndpointAddress{{IP: "1.2.3.4", TargetRef: &current.ObjectReference{ID: "foo"}}}, Addresses: []versioned.EndpointAddress{{IP: "1.2.3.4", TargetRef: &versioned.ObjectReference{ID: "foo"}}},
Ports: []current.EndpointPort{{Protocol: current.ProtocolUDP, Port: 93}}, Ports: []versioned.EndpointPort{{Protocol: versioned.ProtocolUDP, Port: 93}},
}, },
{ {
Addresses: []current.EndpointAddress{{IP: "5.6.7.8"}}, Addresses: []versioned.EndpointAddress{{IP: "5.6.7.8"}},
Ports: []current.EndpointPort{{Protocol: current.ProtocolUDP, Port: 76}}, Ports: []versioned.EndpointPort{{Protocol: versioned.ProtocolUDP, Port: 76}},
}, },
} }
if !reflect.DeepEqual(out.Subsets, expected) { if !reflect.DeepEqual(out.Subsets, expected) {
@@ -212,20 +212,20 @@ func TestSetDefaulEndpointsLegacy(t *testing.T) {
} }
func TestSetDefaulEndpointsProtocol(t *testing.T) { func TestSetDefaulEndpointsProtocol(t *testing.T) {
in := &current.Endpoints{Subsets: []current.EndpointSubset{ in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
{Ports: []current.EndpointPort{{}, {Protocol: "UDP"}, {}}}, {Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
}} }}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
if out.Protocol != current.ProtocolTCP { if out.Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Protocol)
} }
for i := range out.Subsets { for i := range out.Subsets {
for j := range out.Subsets[i].Ports { for j := range out.Subsets[i].Ports {
if in.Subsets[i].Ports[j].Protocol == "" { if in.Subsets[i].Ports[j].Protocol == "" {
if out.Subsets[i].Ports[j].Protocol != current.ProtocolTCP { if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Subsets[i].Ports[j].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
} }
} else { } else {
if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol { if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol {
@@ -237,32 +237,32 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
} }
func TestSetDefaultNamespace(t *testing.T) { func TestSetDefaultNamespace(t *testing.T) {
s := &current.Namespace{} s := &versioned.Namespace{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Namespace) s2 := obj2.(*versioned.Namespace)
if s2.Status.Phase != current.NamespaceActive { if s2.Status.Phase != versioned.NamespaceActive {
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase) t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
} }
} }
func TestSetDefaultContainerManifestHostNetwork(t *testing.T) { func TestSetDefaultContainerManifestHostNetwork(t *testing.T) {
portNum := 8080 portNum := 8080
s := current.ContainerManifest{} s := versioned.ContainerManifest{}
s.HostNetwork = true s.HostNetwork = true
s.Containers = []current.Container{ s.Containers = []versioned.Container{
{ {
Ports: []current.ContainerPort{ Ports: []versioned.ContainerPort{
{ {
ContainerPort: portNum, ContainerPort: portNum,
}, },
}, },
}, },
} }
obj2 := roundTrip(t, runtime.Object(&current.ContainerManifestList{ obj2 := roundTrip(t, runtime.Object(&versioned.ContainerManifestList{
Items: []current.ContainerManifest{s}, Items: []versioned.ContainerManifest{s},
})) }))
sList2 := obj2.(*current.ContainerManifestList) sList2 := obj2.(*versioned.ContainerManifestList)
s2 := sList2.Items[0] s2 := sList2.Items[0]
hostPortNum := s2.Containers[0].Ports[0].HostPort hostPortNum := s2.Containers[0].Ports[0].HostPort
@@ -273,30 +273,30 @@ func TestSetDefaultContainerManifestHostNetwork(t *testing.T) {
func TestSetDefaultServicePort(t *testing.T) { func TestSetDefaultServicePort(t *testing.T) {
// Unchanged if set. // Unchanged if set.
in := &current.Service{Ports: []current.ServicePort{{Protocol: "UDP", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(118)}}} in := &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "UDP", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(118)}}}
out := roundTrip(t, runtime.Object(in)).(*current.Service) out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolUDP { if out.Ports[0].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != in.Ports[0].ContainerPort { if out.Ports[0].ContainerPort != in.Ports[0].ContainerPort {
t.Errorf("Expected port %d, got %d", in.Ports[0].ContainerPort, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %d", in.Ports[0].ContainerPort, out.Ports[0].ContainerPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Ports: []current.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(0)}}} in = &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromInt(0)}}}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolTCP { if out.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) { if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) {
t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Ports: []current.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromString("")}}} in = &versioned.Service{Ports: []versioned.ServicePort{{Protocol: "", Port: 9376, ContainerPort: util.NewIntOrStringFromString("")}}}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Ports[0].Protocol != current.ProtocolTCP { if out.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Ports[0].Protocol)
} }
if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) { if out.Ports[0].ContainerPort != util.NewIntOrStringFromInt(in.Ports[0].Port) {
t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort) t.Errorf("Expected port %d, got %v", in.Ports[0].Port, out.Ports[0].ContainerPort)
@@ -305,33 +305,33 @@ func TestSetDefaultServicePort(t *testing.T) {
func TestSetDefaultMinionExternalID(t *testing.T) { func TestSetDefaultMinionExternalID(t *testing.T) {
name := "node0" name := "node0"
m := &current.Minion{} m := &versioned.Minion{}
m.ID = name m.ID = name
obj2 := roundTrip(t, runtime.Object(m)) obj2 := roundTrip(t, runtime.Object(m))
m2 := obj2.(*current.Minion) m2 := obj2.(*versioned.Minion)
if m2.ExternalID != name { if m2.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID) t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID)
} }
} }
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) { func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
s := current.ContainerManifest{ s := versioned.ContainerManifest{
Containers: []current.Container{ Containers: []versioned.Container{
{ {
Env: []current.EnvVar{ Env: []versioned.EnvVar{
{ {
ValueFrom: &current.EnvVarSource{ ValueFrom: &versioned.EnvVarSource{
FieldRef: &current.ObjectFieldSelector{}, FieldRef: &versioned.ObjectFieldSelector{},
}, },
}, },
}, },
}, },
}, },
} }
obj2 := roundTrip(t, runtime.Object(&current.ContainerManifestList{ obj2 := roundTrip(t, runtime.Object(&versioned.ContainerManifestList{
Items: []current.ContainerManifest{s}, Items: []versioned.ContainerManifest{s},
})) }))
sList2 := obj2.(*current.ContainerManifestList) sList2 := obj2.(*versioned.ContainerManifestList)
s2 := sList2.Items[0] s2 := sList2.Items[0]
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion
@@ -344,74 +344,74 @@ func TestSetDefaultSecurityContext(t *testing.T) {
priv := false priv := false
privTrue := true privTrue := true
testCases := map[string]struct { testCases := map[string]struct {
c current.Container c versioned.Container
}{ }{
"downward defaulting caps": { "downward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
}, },
"downward defaulting priv": { "downward defaulting priv": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
"upward defaulting caps": { "upward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"biz"}, Add: []versioned.Capability{"biz"},
Drop: []current.Capability{"baz"}, Drop: []versioned.Capability{"baz"},
}, },
}, },
}, },
}, },
"upward defaulting priv": { "upward defaulting priv": {
c: current.Container{ c: versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &privTrue, Privileged: &privTrue,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
DesiredState: current.PodState{ DesiredState: versioned.PodState{
Manifest: current.ContainerManifest{}, Manifest: versioned.ContainerManifest{},
}, },
} }
for k, v := range testCases { for k, v := range testCases {
pod.DesiredState.Manifest.Containers = []current.Container{v.c} pod.DesiredState.Manifest.Containers = []versioned.Container{v.c}
obj := roundTrip(t, runtime.Object(pod)) obj := roundTrip(t, runtime.Object(pod))
defaultedPod := obj.(*current.Pod) defaultedPod := obj.(*versioned.Pod)
c := defaultedPod.DesiredState.Manifest.Containers[0] c := defaultedPod.DesiredState.Manifest.Containers[0]
if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual { if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual {
t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues) t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues)
@@ -419,7 +419,7 @@ func TestSetDefaultSecurityContext(t *testing.T) {
} }
} }
func areSecurityContextAndContainerEqual(c *current.Container) (bool, []string) { func areSecurityContextAndContainerEqual(c *versioned.Container) (bool, []string) {
issues := make([]string, 0) issues := make([]string, 0)
equal := true equal := true

View File

@@ -20,13 +20,13 @@ import (
"fmt" "fmt"
"reflect" "reflect"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
) )
func addConversionFuncs() { func addConversionFuncs() {
// Add non-generated conversion functions // Add non-generated conversion functions
err := newer.Scheme.AddConversionFuncs( err := api.Scheme.AddConversionFuncs(
convert_v1beta3_Container_To_api_Container, convert_v1beta3_Container_To_api_Container,
convert_api_Container_To_v1beta3_Container, convert_api_Container_To_v1beta3_Container,
) )
@@ -36,7 +36,7 @@ func addConversionFuncs() {
} }
// Add field conversion funcs. // Add field conversion funcs.
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name", case "metadata.name",
@@ -52,7 +52,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name": case "metadata.name":
@@ -67,7 +67,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name", case "metadata.name",
@@ -81,7 +81,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Event", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Event",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "involvedObject.kind", case "involvedObject.kind",
@@ -102,7 +102,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Namespace", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Namespace",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "status.phase": case "status.phase":
@@ -115,7 +115,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Secret", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Secret",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "type": case "type":
@@ -128,7 +128,7 @@ func addConversionFuncs() {
// If one of the conversion functions is malformed, detect it immediately. // If one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
} }
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ServiceAccount", err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ServiceAccount",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "metadata.name": case "metadata.name":
@@ -143,7 +143,7 @@ func addConversionFuncs() {
} }
} }
func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Container, s conversion.Scope) error { func convert_v1beta3_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*Container))(in) defaulting.(func(*Container))(in)
} }
@@ -163,7 +163,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
} }
out.WorkingDir = in.WorkingDir out.WorkingDir = in.WorkingDir
if in.Ports != nil { if in.Ports != nil {
out.Ports = make([]newer.ContainerPort, len(in.Ports)) out.Ports = make([]api.ContainerPort, len(in.Ports))
for i := range in.Ports { for i := range in.Ports {
if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil { if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
return err return err
@@ -171,7 +171,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
} }
} }
if in.Env != nil { if in.Env != nil {
out.Env = make([]newer.EnvVar, len(in.Env)) out.Env = make([]api.EnvVar, len(in.Env))
for i := range in.Env { for i := range in.Env {
if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil { if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
return err return err
@@ -182,7 +182,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
return err return err
} }
if in.VolumeMounts != nil { if in.VolumeMounts != nil {
out.VolumeMounts = make([]newer.VolumeMount, len(in.VolumeMounts)) out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts))
for i := range in.VolumeMounts { for i := range in.VolumeMounts {
if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil { if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
return err return err
@@ -190,7 +190,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
} }
} }
if in.LivenessProbe != nil { if in.LivenessProbe != nil {
out.LivenessProbe = new(newer.Probe) out.LivenessProbe = new(api.Probe)
if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil { if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
return err return err
} }
@@ -198,7 +198,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
out.LivenessProbe = nil out.LivenessProbe = nil
} }
if in.ReadinessProbe != nil { if in.ReadinessProbe != nil {
out.ReadinessProbe = new(newer.Probe) out.ReadinessProbe = new(api.Probe)
if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil { if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
return err return err
} }
@@ -206,7 +206,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
out.ReadinessProbe = nil out.ReadinessProbe = nil
} }
if in.Lifecycle != nil { if in.Lifecycle != nil {
out.Lifecycle = new(newer.Lifecycle) out.Lifecycle = new(api.Lifecycle)
if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil { if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
return err return err
} }
@@ -214,7 +214,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
out.Lifecycle = nil out.Lifecycle = nil
} }
out.TerminationMessagePath = in.TerminationMessagePath out.TerminationMessagePath = in.TerminationMessagePath
out.ImagePullPolicy = newer.PullPolicy(in.ImagePullPolicy) out.ImagePullPolicy = api.PullPolicy(in.ImagePullPolicy)
if in.SecurityContext != nil { if in.SecurityContext != nil {
if in.SecurityContext.Capabilities != nil { if in.SecurityContext.Capabilities != nil {
if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) || if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) ||
@@ -229,7 +229,7 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
} }
} }
if in.SecurityContext != nil { if in.SecurityContext != nil {
out.SecurityContext = new(newer.SecurityContext) out.SecurityContext = new(api.SecurityContext)
if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil { if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
return err return err
} }
@@ -239,9 +239,9 @@ func convert_v1beta3_Container_To_api_Container(in *Container, out *newer.Contai
return nil return nil
} }
func convert_api_Container_To_v1beta3_Container(in *newer.Container, out *Container, s conversion.Scope) error { func convert_api_Container_To_v1beta3_Container(in *api.Container, out *Container, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*newer.Container))(in) defaulting.(func(*api.Container))(in)
} }
out.Name = in.Name out.Name = in.Name
out.Image = in.Image out.Image = in.Image

File diff suppressed because it is too large Load Diff

View File

@@ -19,29 +19,29 @@ package v1beta3_test
import ( import (
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
) )
func TestNodeConversion(t *testing.T) { func TestNodeConversion(t *testing.T) {
obj, err := current.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`)) obj, err := versioned.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.Node); !ok { if _, ok := obj.(*api.Node); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj, err = current.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`)) obj, err = versioned.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, ok := obj.(*newer.NodeList); !ok { if _, ok := obj.(*api.NodeList); !ok {
t.Errorf("unexpected type: %#v", obj) t.Errorf("unexpected type: %#v", obj)
} }
obj = &newer.Node{} obj = &api.Node{}
if err := current.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil { if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
} }
@@ -49,42 +49,42 @@ func TestNodeConversion(t *testing.T) {
func TestBadSecurityContextConversion(t *testing.T) { func TestBadSecurityContextConversion(t *testing.T) {
priv := false priv := false
testCases := map[string]struct { testCases := map[string]struct {
c *current.Container c *versioned.Container
err string err string
}{ }{
// this use case must use true for the container and false for the sc. Otherwise the defaulter // this use case must use true for the container and false for the sc. Otherwise the defaulter
// will assume privileged was left undefined (since it is the default value) and copy the // will assume privileged was left undefined (since it is the default value) and copy the
// sc setting upwards // sc setting upwards
"mismatched privileged": { "mismatched privileged": {
c: &current.Container{ c: &versioned.Container{
Privileged: true, Privileged: true,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
err: "container privileged settings do not match security context settings, cannot convert", err: "container privileged settings do not match security context settings, cannot convert",
}, },
"mismatched caps add": { "mismatched caps add": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"bar"}, Add: []versioned.Capability{"bar"},
}, },
}, },
}, },
err: "container capability settings do not match security context settings, cannot convert", err: "container capability settings do not match security context settings, cannot convert",
}, },
"mismatched caps drop": { "mismatched caps drop": {
c: &current.Container{ c: &versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Drop: []current.Capability{"foo"}, Drop: []versioned.Capability{"foo"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
@@ -93,8 +93,8 @@ func TestBadSecurityContextConversion(t *testing.T) {
} }
for k, v := range testCases { for k, v := range testCases {
got := newer.Container{} got := api.Container{}
err := newer.Scheme.Convert(v.c, &got) err := api.Scheme.Convert(v.c, &got)
if err == nil { if err == nil {
t.Errorf("expected error for case %s but got none", k) t.Errorf("expected error for case %s but got none", k)
} else { } else {

View File

@@ -20,25 +20,25 @@ import (
"reflect" "reflect"
"testing" "testing"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3" versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := current.Codec.Encode(obj) data, err := versioned.Codec.Encode(obj)
if err != nil { if err != nil {
t.Errorf("%v\n %#v", err, obj) t.Errorf("%v\n %#v", err, obj)
return nil return nil
} }
obj2, err := newer.Codec.Decode(data) obj2, err := api.Codec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj) t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil return nil
} }
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = newer.Scheme.Convert(obj2, obj3) err = api.Scheme.Convert(obj2, obj3)
if err != nil { if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2) t.Errorf("%v\nSource: %#v", err, obj2)
return nil return nil
@@ -48,15 +48,15 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultReplicationController(t *testing.T) { func TestSetDefaultReplicationController(t *testing.T) {
tests := []struct { tests := []struct {
rc *current.ReplicationController rc *versioned.ReplicationController
expectLabels bool expectLabels bool
expectSelector bool expectSelector bool
}{ }{
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -68,15 +68,15 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
}, },
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -88,18 +88,18 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: true, expectSelector: true,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"bar": "foo", "bar": "foo",
}, },
}, },
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Selector: map[string]string{ Selector: map[string]string{
"some": "other", "some": "other",
}, },
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -111,13 +111,13 @@ func TestSetDefaultReplicationController(t *testing.T) {
expectSelector: false, expectSelector: false,
}, },
{ {
rc: &current.ReplicationController{ rc: &versioned.ReplicationController{
Spec: current.ReplicationControllerSpec{ Spec: versioned.ReplicationControllerSpec{
Selector: map[string]string{ Selector: map[string]string{
"some": "other", "some": "other",
}, },
Template: &current.PodTemplateSpec{ Template: &versioned.PodTemplateSpec{
ObjectMeta: current.ObjectMeta{ ObjectMeta: versioned.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@@ -133,7 +133,7 @@ func TestSetDefaultReplicationController(t *testing.T) {
for _, test := range tests { for _, test := range tests {
rc := test.rc rc := test.rc
obj2 := roundTrip(t, runtime.Object(rc)) obj2 := roundTrip(t, runtime.Object(rc))
rc2, ok := obj2.(*current.ReplicationController) rc2, ok := obj2.(*versioned.ReplicationController)
if !ok { if !ok {
t.Errorf("unexpected object: %v", rc2) t.Errorf("unexpected object: %v", rc2)
t.FailNow() t.FailNow()
@@ -156,56 +156,56 @@ func TestSetDefaultReplicationController(t *testing.T) {
} }
func TestSetDefaultService(t *testing.T) { func TestSetDefaultService(t *testing.T) {
svc := &current.Service{} svc := &versioned.Service{}
obj2 := roundTrip(t, runtime.Object(svc)) obj2 := roundTrip(t, runtime.Object(svc))
svc2 := obj2.(*current.Service) svc2 := obj2.(*versioned.Service)
if svc2.Spec.SessionAffinity != current.ServiceAffinityNone { if svc2.Spec.SessionAffinity != versioned.ServiceAffinityNone {
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.Spec.SessionAffinity) t.Errorf("Expected default sesseion affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.Spec.SessionAffinity)
} }
} }
func TestSetDefaultSecret(t *testing.T) { func TestSetDefaultSecret(t *testing.T) {
s := &current.Secret{} s := &versioned.Secret{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Secret) s2 := obj2.(*versioned.Secret)
if s2.Type != current.SecretTypeOpaque { if s2.Type != versioned.SecretTypeOpaque {
t.Errorf("Expected secret type %v, got %v", current.SecretTypeOpaque, s2.Type) t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
} }
} }
func TestSetDefaultPersistentVolume(t *testing.T) { func TestSetDefaultPersistentVolume(t *testing.T) {
pv := &current.PersistentVolume{} pv := &versioned.PersistentVolume{}
obj2 := roundTrip(t, runtime.Object(pv)) obj2 := roundTrip(t, runtime.Object(pv))
pv2 := obj2.(*current.PersistentVolume) pv2 := obj2.(*versioned.PersistentVolume)
if pv2.Status.Phase != current.VolumePending { if pv2.Status.Phase != versioned.VolumePending {
t.Errorf("Expected volume phase %v, got %v", current.VolumePending, pv2.Status.Phase) t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
} }
} }
func TestSetDefaultPersistentVolumeClaim(t *testing.T) { func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
pvc := &current.PersistentVolumeClaim{} pvc := &versioned.PersistentVolumeClaim{}
obj2 := roundTrip(t, runtime.Object(pvc)) obj2 := roundTrip(t, runtime.Object(pvc))
pvc2 := obj2.(*current.PersistentVolumeClaim) pvc2 := obj2.(*versioned.PersistentVolumeClaim)
if pvc2.Status.Phase != current.ClaimPending { if pvc2.Status.Phase != versioned.ClaimPending {
t.Errorf("Expected claim phase %v, got %v", current.ClaimPending, pvc2.Status.Phase) t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
} }
} }
func TestSetDefaulEndpointsProtocol(t *testing.T) { func TestSetDefaulEndpointsProtocol(t *testing.T) {
in := &current.Endpoints{Subsets: []current.EndpointSubset{ in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
{Ports: []current.EndpointPort{{}, {Protocol: "UDP"}, {}}}, {Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
}} }}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Endpoints) out := obj.(*versioned.Endpoints)
for i := range out.Subsets { for i := range out.Subsets {
for j := range out.Subsets[i].Ports { for j := range out.Subsets[i].Ports {
if in.Subsets[i].Ports[j].Protocol == "" { if in.Subsets[i].Ports[j].Protocol == "" {
if out.Subsets[i].Ports[j].Protocol != current.ProtocolTCP { if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Subsets[i].Ports[j].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
} }
} else { } else {
if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol { if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol {
@@ -217,16 +217,16 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
} }
func TestSetDefaulServiceTargetPort(t *testing.T) { func TestSetDefaulServiceTargetPort(t *testing.T) {
in := &current.Service{Spec: current.ServiceSpec{Ports: []current.ServicePort{{Port: 1234}}}} in := &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234}}}}
obj := roundTrip(t, runtime.Object(in)) obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Service) out := obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) {
t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.Ports[0].TargetPort) t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.Ports[0].TargetPort)
} }
in = &current.Service{Spec: current.ServiceSpec{Ports: []current.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}} in = &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}}
obj = roundTrip(t, runtime.Object(in)) obj = roundTrip(t, runtime.Object(in))
out = obj.(*current.Service) out = obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) {
t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.Ports[0].TargetPort) t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.Ports[0].TargetPort)
} }
@@ -234,42 +234,42 @@ func TestSetDefaulServiceTargetPort(t *testing.T) {
func TestSetDefaultServicePort(t *testing.T) { func TestSetDefaultServicePort(t *testing.T) {
// Unchanged if set. // Unchanged if set.
in := &current.Service{Spec: current.ServiceSpec{ in := &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []current.ServicePort{ Ports: []versioned.ServicePort{
{Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")}, {Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")},
{Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)}, {Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)},
}, },
}} }}
out := roundTrip(t, runtime.Object(in)).(*current.Service) out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != current.ProtocolUDP { if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
} }
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") {
t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort) t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
} }
if out.Spec.Ports[1].Protocol != current.ProtocolUDP { if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[1].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
} }
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) { if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) {
t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort) t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
} }
// Defaulted. // Defaulted.
in = &current.Service{Spec: current.ServiceSpec{ in = &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []current.ServicePort{ Ports: []versioned.ServicePort{
{Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")}, {Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")},
{Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)}, {Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)},
}, },
}} }}
out = roundTrip(t, runtime.Object(in)).(*current.Service) out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != current.ProtocolTCP { if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[0].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
} }
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) { if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) {
t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort) t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
} }
if out.Spec.Ports[1].Protocol != current.ProtocolTCP { if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[1].Protocol) t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
} }
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) { if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) {
t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort) t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
@@ -277,33 +277,33 @@ func TestSetDefaultServicePort(t *testing.T) {
} }
func TestSetDefaultNamespace(t *testing.T) { func TestSetDefaultNamespace(t *testing.T) {
s := &current.Namespace{} s := &versioned.Namespace{}
obj2 := roundTrip(t, runtime.Object(s)) obj2 := roundTrip(t, runtime.Object(s))
s2 := obj2.(*current.Namespace) s2 := obj2.(*versioned.Namespace)
if s2.Status.Phase != current.NamespaceActive { if s2.Status.Phase != versioned.NamespaceActive {
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase) t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
} }
} }
func TestSetDefaultPodSpecHostNetwork(t *testing.T) { func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
portNum := 8080 portNum := 8080
s := current.PodSpec{} s := versioned.PodSpec{}
s.HostNetwork = true s.HostNetwork = true
s.Containers = []current.Container{ s.Containers = []versioned.Container{
{ {
Ports: []current.ContainerPort{ Ports: []versioned.ContainerPort{
{ {
ContainerPort: portNum, ContainerPort: portNum,
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
Spec: s, Spec: s,
} }
obj2 := roundTrip(t, runtime.Object(pod)) obj2 := roundTrip(t, runtime.Object(pod))
pod2 := obj2.(*current.Pod) pod2 := obj2.(*versioned.Pod)
s2 := pod2.Spec s2 := pod2.Spec
hostPortNum := s2.Containers[0].Ports[0].HostPort hostPortNum := s2.Containers[0].Ports[0].HostPort
@@ -314,34 +314,34 @@ func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
func TestSetDefaultNodeExternalID(t *testing.T) { func TestSetDefaultNodeExternalID(t *testing.T) {
name := "node0" name := "node0"
n := &current.Node{} n := &versioned.Node{}
n.Name = name n.Name = name
obj2 := roundTrip(t, runtime.Object(n)) obj2 := roundTrip(t, runtime.Object(n))
n2 := obj2.(*current.Node) n2 := obj2.(*versioned.Node)
if n2.Spec.ExternalID != name { if n2.Spec.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID) t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
} }
} }
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) { func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
s := current.PodSpec{ s := versioned.PodSpec{
Containers: []current.Container{ Containers: []versioned.Container{
{ {
Env: []current.EnvVar{ Env: []versioned.EnvVar{
{ {
ValueFrom: &current.EnvVarSource{ ValueFrom: &versioned.EnvVarSource{
FieldRef: &current.ObjectFieldSelector{}, FieldRef: &versioned.ObjectFieldSelector{},
}, },
}, },
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
Spec: s, Spec: s,
} }
obj2 := roundTrip(t, runtime.Object(pod)) obj2 := roundTrip(t, runtime.Object(pod))
pod2 := obj2.(*current.Pod) pod2 := obj2.(*versioned.Pod)
s2 := pod2.Spec s2 := pod2.Spec
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion
@@ -354,72 +354,72 @@ func TestSetDefaultSecurityContext(t *testing.T) {
priv := false priv := false
privTrue := true privTrue := true
testCases := map[string]struct { testCases := map[string]struct {
c current.Container c versioned.Container
}{ }{
"downward defaulting caps": { "downward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
}, },
}, },
}, },
"downward defaulting priv": { "downward defaulting priv": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
"upward defaulting caps": { "upward defaulting caps": {
c: current.Container{ c: versioned.Container{
Privileged: false, Privileged: false,
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &priv, Privileged: &priv,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"biz"}, Add: []versioned.Capability{"biz"},
Drop: []current.Capability{"baz"}, Drop: []versioned.Capability{"baz"},
}, },
}, },
}, },
}, },
"upward defaulting priv": { "upward defaulting priv": {
c: current.Container{ c: versioned.Container{
Capabilities: current.Capabilities{ Capabilities: versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
SecurityContext: &current.SecurityContext{ SecurityContext: &versioned.SecurityContext{
Privileged: &privTrue, Privileged: &privTrue,
Capabilities: &current.Capabilities{ Capabilities: &versioned.Capabilities{
Add: []current.Capability{"foo"}, Add: []versioned.Capability{"foo"},
Drop: []current.Capability{"bar"}, Drop: []versioned.Capability{"bar"},
}, },
}, },
}, },
}, },
} }
pod := &current.Pod{ pod := &versioned.Pod{
Spec: current.PodSpec{}, Spec: versioned.PodSpec{},
} }
for k, v := range testCases { for k, v := range testCases {
pod.Spec.Containers = []current.Container{v.c} pod.Spec.Containers = []versioned.Container{v.c}
obj := roundTrip(t, runtime.Object(pod)) obj := roundTrip(t, runtime.Object(pod))
defaultedPod := obj.(*current.Pod) defaultedPod := obj.(*versioned.Pod)
c := defaultedPod.Spec.Containers[0] c := defaultedPod.Spec.Containers[0]
if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual { if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual {
t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues) t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues)
@@ -427,7 +427,7 @@ func TestSetDefaultSecurityContext(t *testing.T) {
} }
} }
func areSecurityContextAndContainerEqual(c *current.Container) (bool, []string) { func areSecurityContextAndContainerEqual(c *versioned.Container) (bool, []string) {
issues := make([]string, 0) issues := make([]string, 0)
equal := true equal := true

View File

@@ -19,53 +19,53 @@ package v1
import ( import (
"sort" "sort"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
) )
func init() { func init() {
err := newer.Scheme.AddConversionFuncs( err := api.Scheme.AddConversionFuncs(
func(in *Cluster, out *newer.Cluster, s conversion.Scope) error { func(in *Cluster, out *api.Cluster, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *newer.Cluster, out *Cluster, s conversion.Scope) error { func(in *api.Cluster, out *Cluster, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *Preferences, out *newer.Preferences, s conversion.Scope) error { func(in *Preferences, out *api.Preferences, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *newer.Preferences, out *Preferences, s conversion.Scope) error { func(in *api.Preferences, out *Preferences, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *AuthInfo, out *newer.AuthInfo, s conversion.Scope) error { func(in *AuthInfo, out *api.AuthInfo, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *newer.AuthInfo, out *AuthInfo, s conversion.Scope) error { func(in *api.AuthInfo, out *AuthInfo, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *Context, out *newer.Context, s conversion.Scope) error { func(in *Context, out *api.Context, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *newer.Context, out *Context, s conversion.Scope) error { func(in *api.Context, out *Context, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, },
func(in *Config, out *newer.Config, s conversion.Scope) error { func(in *Config, out *api.Config, s conversion.Scope) error {
out.CurrentContext = in.CurrentContext out.CurrentContext = in.CurrentContext
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil { if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
return err return err
} }
out.Clusters = make(map[string]newer.Cluster) out.Clusters = make(map[string]api.Cluster)
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil { if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
return err return err
} }
out.AuthInfos = make(map[string]newer.AuthInfo) out.AuthInfos = make(map[string]api.AuthInfo)
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil { if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
return err return err
} }
out.Contexts = make(map[string]newer.Context) out.Contexts = make(map[string]api.Context)
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil { if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
return err return err
} }
@@ -75,7 +75,7 @@ func init() {
} }
return nil return nil
}, },
func(in *newer.Config, out *Config, s conversion.Scope) error { func(in *api.Config, out *Config, s conversion.Scope) error {
out.CurrentContext = in.CurrentContext out.CurrentContext = in.CurrentContext
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil { if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
return err return err
@@ -99,9 +99,9 @@ func init() {
} }
return nil return nil
}, },
func(in *[]NamedCluster, out *map[string]newer.Cluster, s conversion.Scope) error { func(in *[]NamedCluster, out *map[string]api.Cluster, s conversion.Scope) error {
for _, curr := range *in { for _, curr := range *in {
newCluster := newer.NewCluster() newCluster := api.NewCluster()
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil { if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
return err return err
} }
@@ -110,7 +110,7 @@ func init() {
return nil return nil
}, },
func(in *map[string]newer.Cluster, out *[]NamedCluster, s conversion.Scope) error { func(in *map[string]api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in)) allKeys := make([]string, 0, len(*in))
for key := range *in { for key := range *in {
allKeys = append(allKeys, key) allKeys = append(allKeys, key)
@@ -130,9 +130,9 @@ func init() {
return nil return nil
}, },
func(in *[]NamedAuthInfo, out *map[string]newer.AuthInfo, s conversion.Scope) error { func(in *[]NamedAuthInfo, out *map[string]api.AuthInfo, s conversion.Scope) error {
for _, curr := range *in { for _, curr := range *in {
newAuthInfo := newer.NewAuthInfo() newAuthInfo := api.NewAuthInfo()
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil { if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
return err return err
} }
@@ -141,7 +141,7 @@ func init() {
return nil return nil
}, },
func(in *map[string]newer.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error { func(in *map[string]api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in)) allKeys := make([]string, 0, len(*in))
for key := range *in { for key := range *in {
allKeys = append(allKeys, key) allKeys = append(allKeys, key)
@@ -161,9 +161,9 @@ func init() {
return nil return nil
}, },
func(in *[]NamedContext, out *map[string]newer.Context, s conversion.Scope) error { func(in *[]NamedContext, out *map[string]api.Context, s conversion.Scope) error {
for _, curr := range *in { for _, curr := range *in {
newContext := newer.NewContext() newContext := api.NewContext()
if err := s.Convert(&curr.Context, newContext, 0); err != nil { if err := s.Convert(&curr.Context, newContext, 0); err != nil {
return err return err
} }
@@ -172,7 +172,7 @@ func init() {
return nil return nil
}, },
func(in *map[string]newer.Context, out *[]NamedContext, s conversion.Scope) error { func(in *map[string]api.Context, out *[]NamedContext, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in)) allKeys := make([]string, 0, len(*in))
for key := range *in { for key := range *in {
allKeys = append(allKeys, key) allKeys = append(allKeys, key)

View File

@@ -36,7 +36,6 @@ import (
func generateConversions(t *testing.T, version string) bytes.Buffer { func generateConversions(t *testing.T, version string) bytes.Buffer {
g := runtime.NewConversionGenerator(api.Scheme.Raw()) g := runtime.NewConversionGenerator(api.Scheme.Raw())
g.OverwritePackage(version, "") g.OverwritePackage(version, "")
g.OverwritePackage("api", "newer")
for _, knownType := range api.Scheme.KnownTypes(version) { for _, knownType := range api.Scheme.KnownTypes(version) {
if err := g.GenerateConversionsForType(version, knownType); err != nil { if err := g.GenerateConversionsForType(version, knownType); err != nil {
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err) glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
@@ -126,8 +125,8 @@ func compareBuffers(t *testing.T, generatedFile string, existing, generated byte
} }
if existingLine != generatedLine { if existingLine != generatedLine {
ok = false ok = false
diff := fmt.Sprintf("first difference: expected %s, got %s", generatedLine, existingLine) diff := fmt.Sprintf("\nexpected: %s\n got: %s", generatedLine, existingLine)
t.Errorf("please update conversion functions; generated: %s; diff: %s", generatedFile, diff) t.Errorf("please update conversion functions; generated: %s; first diff: %s", generatedFile, diff)
return ok return ok
} }
} }

View File

@@ -265,7 +265,7 @@ func (g *conversionGenerator) WriteConversionFunctions(w io.Writer) error {
func (g *conversionGenerator) writeRegisterHeader(b *buffer, indent int) { func (g *conversionGenerator) writeRegisterHeader(b *buffer, indent int) {
b.addLine("func init() {\n", indent) b.addLine("func init() {\n", indent)
b.addLine("err := newer.Scheme.AddGeneratedConversionFuncs(\n", indent+1) b.addLine("err := api.Scheme.AddGeneratedConversionFuncs(\n", indent+1)
} }
func (g *conversionGenerator) writeRegisterFooter(b *buffer, indent int) { func (g *conversionGenerator) writeRegisterFooter(b *buffer, indent int) {