mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Rename versioned pkg imports in defaults tests
This commit is contained in:
parent
441f69f34e
commit
d689ba9b01
@ -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: ¤t.ReplicationController{
|
rc: &versioned.ReplicationController{
|
||||||
Spec: current.ReplicationControllerSpec{
|
Spec: versioned.ReplicationControllerSpec{
|
||||||
Template: ¤t.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: ¤t.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: ¤t.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: ¤t.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: ¤t.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: ¤t.ReplicationController{
|
rc: &versioned.ReplicationController{
|
||||||
Spec: current.ReplicationControllerSpec{
|
Spec: versioned.ReplicationControllerSpec{
|
||||||
Selector: map[string]string{
|
Selector: map[string]string{
|
||||||
"some": "other",
|
"some": "other",
|
||||||
},
|
},
|
||||||
Template: ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 = ¤t.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 := ¤t.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 = ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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: ¤t.EnvVarSource{
|
ValueFrom: &versioned.EnvVarSource{
|
||||||
FieldRef: ¤t.ObjectFieldSelector{},
|
FieldRef: &versioned.ObjectFieldSelector{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pod := ¤t.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
|
||||||
|
@ -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: ¤t.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: ¤t.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: ¤t.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: ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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: ¤t.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 := ¤t.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 := ¤t.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(¤t.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 := ¤t.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 = ¤t.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 = ¤t.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 := ¤t.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: ¤t.EnvVarSource{
|
ValueFrom: &versioned.EnvVarSource{
|
||||||
FieldRef: ¤t.ObjectFieldSelector{},
|
FieldRef: &versioned.ObjectFieldSelector{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj2 := roundTrip(t, runtime.Object(¤t.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: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &privTrue,
|
Privileged: &privTrue,
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := ¤t.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
|
||||||
|
|
||||||
|
@ -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: ¤t.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: ¤t.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: ¤t.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: ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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: ¤t.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 := ¤t.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 := ¤t.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(¤t.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 := ¤t.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 = ¤t.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 = ¤t.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 := ¤t.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: ¤t.EnvVarSource{
|
ValueFrom: &versioned.EnvVarSource{
|
||||||
FieldRef: ¤t.ObjectFieldSelector{},
|
FieldRef: &versioned.ObjectFieldSelector{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj2 := roundTrip(t, runtime.Object(¤t.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: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &privTrue,
|
Privileged: &privTrue,
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := ¤t.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
|
||||||
|
|
||||||
|
@ -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: ¤t.ReplicationController{
|
rc: &versioned.ReplicationController{
|
||||||
Spec: current.ReplicationControllerSpec{
|
Spec: versioned.ReplicationControllerSpec{
|
||||||
Template: ¤t.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: ¤t.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: ¤t.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: ¤t.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: ¤t.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: ¤t.ReplicationController{
|
rc: &versioned.ReplicationController{
|
||||||
Spec: current.ReplicationControllerSpec{
|
Spec: versioned.ReplicationControllerSpec{
|
||||||
Selector: map[string]string{
|
Selector: map[string]string{
|
||||||
"some": "other",
|
"some": "other",
|
||||||
},
|
},
|
||||||
Template: ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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 = ¤t.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 := ¤t.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 = ¤t.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 := ¤t.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 := ¤t.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 := ¤t.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: ¤t.EnvVarSource{
|
ValueFrom: &versioned.EnvVarSource{
|
||||||
FieldRef: ¤t.ObjectFieldSelector{},
|
FieldRef: &versioned.ObjectFieldSelector{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pod := ¤t.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: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &priv,
|
Privileged: &priv,
|
||||||
Capabilities: ¤t.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: ¤t.SecurityContext{
|
SecurityContext: &versioned.SecurityContext{
|
||||||
Privileged: &privTrue,
|
Privileged: &privTrue,
|
||||||
Capabilities: ¤t.Capabilities{
|
Capabilities: &versioned.Capabilities{
|
||||||
Add: []current.Capability{"foo"},
|
Add: []versioned.Capability{"foo"},
|
||||||
Drop: []current.Capability{"bar"},
|
Drop: []versioned.Capability{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := ¤t.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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user