mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Rename versioned pkg imports in defaults tests
This commit is contained in:
@@ -20,25 +20,25 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
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 {
|
||||
t.Errorf("%v\n %#v", err, obj)
|
||||
return nil
|
||||
}
|
||||
obj2, err := newer.Codec.Decode(data)
|
||||
obj2, err := api.Codec.Decode(data)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||
return nil
|
||||
}
|
||||
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 {
|
||||
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||
return nil
|
||||
@@ -48,15 +48,15 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
|
||||
func TestSetDefaultReplicationController(t *testing.T) {
|
||||
tests := []struct {
|
||||
rc *current.ReplicationController
|
||||
rc *versioned.ReplicationController
|
||||
expectLabels bool
|
||||
expectSelector bool
|
||||
}{
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
rc: &versioned.ReplicationController{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
@@ -68,15 +68,15 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
rc: &versioned.ReplicationController{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
@@ -88,18 +88,18 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
rc: &versioned.ReplicationController{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
@@ -111,13 +111,13 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
||||
expectSelector: false,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
rc: &versioned.ReplicationController{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
@@ -133,7 +133,7 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
rc := test.rc
|
||||
obj2 := roundTrip(t, runtime.Object(rc))
|
||||
rc2, ok := obj2.(*current.ReplicationController)
|
||||
rc2, ok := obj2.(*versioned.ReplicationController)
|
||||
if !ok {
|
||||
t.Errorf("unexpected object: %v", rc2)
|
||||
t.FailNow()
|
||||
@@ -156,56 +156,56 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetDefaultService(t *testing.T) {
|
||||
svc := ¤t.Service{}
|
||||
svc := &versioned.Service{}
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
svc2 := obj2.(*current.Service)
|
||||
if svc2.Spec.SessionAffinity != current.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.Spec.SessionAffinity)
|
||||
svc2 := obj2.(*versioned.Service)
|
||||
if svc2.Spec.SessionAffinity != versioned.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.Spec.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecret(t *testing.T) {
|
||||
s := ¤t.Secret{}
|
||||
s := &versioned.Secret{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
s2 := obj2.(*current.Secret)
|
||||
s2 := obj2.(*versioned.Secret)
|
||||
|
||||
if s2.Type != current.SecretTypeOpaque {
|
||||
t.Errorf("Expected secret type %v, got %v", current.SecretTypeOpaque, s2.Type)
|
||||
if s2.Type != versioned.SecretTypeOpaque {
|
||||
t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPersistentVolume(t *testing.T) {
|
||||
pv := ¤t.PersistentVolume{}
|
||||
pv := &versioned.PersistentVolume{}
|
||||
obj2 := roundTrip(t, runtime.Object(pv))
|
||||
pv2 := obj2.(*current.PersistentVolume)
|
||||
pv2 := obj2.(*versioned.PersistentVolume)
|
||||
|
||||
if pv2.Status.Phase != current.VolumePending {
|
||||
t.Errorf("Expected volume phase %v, got %v", current.VolumePending, pv2.Status.Phase)
|
||||
if pv2.Status.Phase != versioned.VolumePending {
|
||||
t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
|
||||
pvc := ¤t.PersistentVolumeClaim{}
|
||||
pvc := &versioned.PersistentVolumeClaim{}
|
||||
obj2 := roundTrip(t, runtime.Object(pvc))
|
||||
pvc2 := obj2.(*current.PersistentVolumeClaim)
|
||||
pvc2 := obj2.(*versioned.PersistentVolumeClaim)
|
||||
|
||||
if pvc2.Status.Phase != current.ClaimPending {
|
||||
t.Errorf("Expected claim phase %v, got %v", current.ClaimPending, pvc2.Status.Phase)
|
||||
if pvc2.Status.Phase != versioned.ClaimPending {
|
||||
t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulEndpointsProtocol(t *testing.T) {
|
||||
in := ¤t.Endpoints{Subsets: []current.EndpointSubset{
|
||||
{Ports: []current.EndpointPort{{}, {Protocol: "UDP"}, {}}},
|
||||
in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
|
||||
{Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
|
||||
}}
|
||||
obj := roundTrip(t, runtime.Object(in))
|
||||
out := obj.(*current.Endpoints)
|
||||
out := obj.(*versioned.Endpoints)
|
||||
|
||||
for i := range out.Subsets {
|
||||
for j := range out.Subsets[i].Ports {
|
||||
if in.Subsets[i].Ports[j].Protocol == "" {
|
||||
if out.Subsets[i].Ports[j].Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
|
||||
if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
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))
|
||||
out := obj.(*current.Service)
|
||||
out := obj.(*versioned.Service)
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) {
|
||||
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))
|
||||
out = obj.(*current.Service)
|
||||
out = obj.(*versioned.Service)
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) {
|
||||
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) {
|
||||
// Unchanged if set.
|
||||
in := ¤t.Service{Spec: current.ServiceSpec{
|
||||
Ports: []current.ServicePort{
|
||||
in := &versioned.Service{Spec: versioned.ServiceSpec{
|
||||
Ports: []versioned.ServicePort{
|
||||
{Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")},
|
||||
{Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)},
|
||||
},
|
||||
}}
|
||||
out := roundTrip(t, runtime.Object(in)).(*current.Service)
|
||||
if out.Spec.Ports[0].Protocol != current.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[0].Protocol)
|
||||
out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
|
||||
if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
|
||||
}
|
||||
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)
|
||||
}
|
||||
if out.Spec.Ports[1].Protocol != current.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", current.ProtocolUDP, out.Spec.Ports[1].Protocol)
|
||||
if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// Defaulted.
|
||||
in = ¤t.Service{Spec: current.ServiceSpec{
|
||||
Ports: []current.ServicePort{
|
||||
in = &versioned.Service{Spec: versioned.ServiceSpec{
|
||||
Ports: []versioned.ServicePort{
|
||||
{Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")},
|
||||
{Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)},
|
||||
},
|
||||
}}
|
||||
out = roundTrip(t, runtime.Object(in)).(*current.Service)
|
||||
if out.Spec.Ports[0].Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[0].Protocol)
|
||||
out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
|
||||
if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
|
||||
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) {
|
||||
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 {
|
||||
t.Errorf("Expected protocol %s, got %s", current.ProtocolTCP, out.Spec.Ports[1].Protocol)
|
||||
if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
|
||||
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) {
|
||||
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) {
|
||||
s := ¤t.Namespace{}
|
||||
s := &versioned.Namespace{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
s2 := obj2.(*current.Namespace)
|
||||
s2 := obj2.(*versioned.Namespace)
|
||||
|
||||
if s2.Status.Phase != current.NamespaceActive {
|
||||
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase)
|
||||
if s2.Status.Phase != versioned.NamespaceActive {
|
||||
t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
|
||||
portNum := 8080
|
||||
s := current.PodSpec{}
|
||||
s := versioned.PodSpec{}
|
||||
s.HostNetwork = true
|
||||
s.Containers = []current.Container{
|
||||
s.Containers = []versioned.Container{
|
||||
{
|
||||
Ports: []current.ContainerPort{
|
||||
Ports: []versioned.ContainerPort{
|
||||
{
|
||||
ContainerPort: portNum,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pod := ¤t.Pod{
|
||||
pod := &versioned.Pod{
|
||||
Spec: s,
|
||||
}
|
||||
obj2 := roundTrip(t, runtime.Object(pod))
|
||||
pod2 := obj2.(*current.Pod)
|
||||
pod2 := obj2.(*versioned.Pod)
|
||||
s2 := pod2.Spec
|
||||
|
||||
hostPortNum := s2.Containers[0].Ports[0].HostPort
|
||||
@@ -314,34 +314,34 @@ func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
|
||||
|
||||
func TestSetDefaultNodeExternalID(t *testing.T) {
|
||||
name := "node0"
|
||||
n := ¤t.Node{}
|
||||
n := &versioned.Node{}
|
||||
n.Name = name
|
||||
obj2 := roundTrip(t, runtime.Object(n))
|
||||
n2 := obj2.(*current.Node)
|
||||
n2 := obj2.(*versioned.Node)
|
||||
if n2.Spec.ExternalID != name {
|
||||
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
|
||||
s := current.PodSpec{
|
||||
Containers: []current.Container{
|
||||
s := versioned.PodSpec{
|
||||
Containers: []versioned.Container{
|
||||
{
|
||||
Env: []current.EnvVar{
|
||||
Env: []versioned.EnvVar{
|
||||
{
|
||||
ValueFrom: ¤t.EnvVarSource{
|
||||
FieldRef: ¤t.ObjectFieldSelector{},
|
||||
ValueFrom: &versioned.EnvVarSource{
|
||||
FieldRef: &versioned.ObjectFieldSelector{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pod := ¤t.Pod{
|
||||
pod := &versioned.Pod{
|
||||
Spec: s,
|
||||
}
|
||||
obj2 := roundTrip(t, runtime.Object(pod))
|
||||
pod2 := obj2.(*current.Pod)
|
||||
pod2 := obj2.(*versioned.Pod)
|
||||
s2 := pod2.Spec
|
||||
|
||||
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion
|
||||
|
||||
Reference in New Issue
Block a user