switch expose to externals

This commit is contained in:
David Eads 2018-08-02 08:36:22 -04:00
parent 608bf0de1f
commit 59d5298314
2 changed files with 89 additions and 92 deletions

View File

@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl" "k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@ -92,7 +91,6 @@ type ExposeServiceOptions struct {
Generators func(string) map[string]kubectl.Generator Generators func(string) map[string]kubectl.Generator
CanBeExposed polymorphichelpers.CanBeExposedFunc CanBeExposed polymorphichelpers.CanBeExposedFunc
ClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)
MapBasedSelectorForObject func(runtime.Object) (string, error) MapBasedSelectorForObject func(runtime.Object) (string, error)
PortsForObject polymorphichelpers.PortsForObjectFunc PortsForObject polymorphichelpers.PortsForObjectFunc
ProtocolsForObject func(runtime.Object) (map[string]string, error) ProtocolsForObject func(runtime.Object) (map[string]string, error)
@ -191,7 +189,6 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
o.Generators = cmdutil.GeneratorFn o.Generators = cmdutil.GeneratorFn
o.Builder = f.NewBuilder() o.Builder = f.NewBuilder()
o.CanBeExposed = polymorphichelpers.CanBeExposedFn o.CanBeExposed = polymorphichelpers.CanBeExposedFn
o.ClientForMapping = f.ClientForMapping
o.MapBasedSelectorForObject = polymorphichelpers.MapBasedSelectorForObjectFn o.MapBasedSelectorForObject = polymorphichelpers.MapBasedSelectorForObjectFn
o.ProtocolsForObject = polymorphichelpers.ProtocolsForObjectFn o.ProtocolsForObject = polymorphichelpers.ProtocolsForObjectFn
o.PortsForObject = polymorphichelpers.PortsForObjectFn o.PortsForObject = polymorphichelpers.PortsForObjectFn
@ -211,7 +208,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) error { func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) error {
r := o.Builder. r := o.Builder.
WithScheme(legacyscheme.Scheme). WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
ContinueOnError(). ContinueOnError().
NamespaceParam(o.Namespace).DefaultNamespace(). NamespaceParam(o.Namespace).DefaultNamespace().
FilenameParam(o.EnforceNamespace, &o.FilenameOptions). FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
@ -314,8 +311,7 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro
} }
if inline := cmdutil.GetFlagString(cmd, "overrides"); len(inline) > 0 { if inline := cmdutil.GetFlagString(cmd, "overrides"); len(inline) > 0 {
codec := runtime.NewCodec(cmdutil.InternalVersionJSONEncoder(), cmdutil.InternalVersionDecoder()) object, err = cmdutil.Merge(scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...), object, inline)
object, err = cmdutil.Merge(codec, object, inline)
if err != nil { if err != nil {
return err return err
} }
@ -333,7 +329,7 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro
} }
asUnstructured := &unstructured.Unstructured{} asUnstructured := &unstructured.Unstructured{}
if err := legacyscheme.Scheme.Convert(object, asUnstructured, nil); err != nil { if err := scheme.Scheme.Convert(object, asUnstructured, nil); err != nil {
return err return err
} }
gvks, _, err := unstructuredscheme.NewUnstructuredObjectTyper().ObjectKinds(asUnstructured) gvks, _, err := unstructuredscheme.NewUnstructuredObjectTyper().ObjectKinds(asUnstructured)

View File

@ -22,6 +22,7 @@ import (
"strings" "strings"
"testing" "testing"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
@ -60,19 +61,19 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test"}, flags: map[string]string{"protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
@ -91,19 +92,19 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test"}, flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
@ -122,20 +123,20 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/default/services/mayor", "GET": "/namespaces/default/services/mayor",
"POST": "/namespaces/default/services", "POST": "/namespaces/default/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "default", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "default", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"run": "this"}, Selector: map[string]string{"run": "this"},
}, },
}, },
// No --name flag specified below. Service will use the rc's name passed via the 'default-name' parameter // No --name flag specified below. Service will use the rc's name passed via the 'default-name' parameter
flags: map[string]string{"selector": "run=this", "port": "80", "labels": "runas=amayor"}, flags: map[string]string{"selector": "run=this", "port": "80", "labels": "runas=amayor"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "", Labels: map[string]string{"runas": "amayor"}}, ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "", Labels: map[string]string{"runas": "amayor"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(80),
}, },
@ -154,25 +155,25 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "type": "LoadBalancer", "dry-run": "true"}, flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "type": "LoadBalancer", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
}, },
Selector: map[string]string{"func": "stream"}, Selector: map[string]string{"func": "stream"},
Type: api.ServiceTypeLoadBalancer, Type: corev1.ServiceTypeLoadBalancer,
}, },
}, },
status: 200, status: 200,
@ -185,26 +186,26 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "type": "LoadBalancer", "session-affinity": "ClientIP", "dry-run": "true"}, flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "type": "LoadBalancer", "session-affinity": "ClientIP", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
}, },
Selector: map[string]string{"func": "stream"}, Selector: map[string]string{"func": "stream"},
Type: api.ServiceTypeLoadBalancer, Type: corev1.ServiceTypeLoadBalancer,
SessionAffinity: api.ServiceAffinityClientIP, SessionAffinity: corev1.ServiceAffinityClientIP,
}, },
}, },
status: 200, status: 200,
@ -217,19 +218,19 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "10.10.10.10", "dry-run": "true"}, flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "10.10.10.10", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
@ -249,25 +250,25 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "None", "dry-run": "true"}, flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "None", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
}, },
Selector: map[string]string{"func": "stream"}, Selector: map[string]string{"func": "stream"},
ClusterIP: api.ClusterIPNone, ClusterIP: corev1.ClusterIPNone,
}, },
}, },
expected: "service/foo exposed", expected: "service/foo exposed",
@ -281,19 +282,19 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/baz", "GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"selector": "func=stream", "name": "foo", "labels": "svc=test", "cluster-ip": "None", "dry-run": "true"}, flags: map[string]string{"selector": "func=stream", "name": "foo", "labels": "svc=test", "cluster-ip": "None", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{}, Ports: []corev1.ServicePort{},
Selector: map[string]string{"func": "stream"}, Selector: map[string]string{"func": "stream"},
ClusterIP: api.ClusterIPNone, ClusterIP: corev1.ClusterIPNone,
}, },
}, },
expected: "service/foo exposed", expected: "service/foo exposed",
@ -307,19 +308,19 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/redis-master", "GET": "/namespaces/test/services/redis-master",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "redis-master", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "redis-master", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
flags: map[string]string{"filename": "../../../test/e2e/testing-manifests/guestbook/redis-master-service.yaml", "selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "dry-run": "true"}, flags: map[string]string{"filename": "../../../test/e2e/testing-manifests/guestbook/redis-master-service.yaml", "selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"svc": "test"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 14, Port: 14,
TargetPort: intstr.FromInt(14), TargetPort: intstr.FromInt(14),
}, },
@ -337,16 +338,16 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/pods/a-name-that-is-toooo-big-for-a-service-because-it-can-only-handle-63-characters", "GET": "/namespaces/test/pods/a-name-that-is-toooo-big-for-a-service-because-it-can-only-handle-63-characters",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Pod{ input: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"}, ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
}, },
flags: map[string]string{"selector": "svc=frompod", "port": "90", "labels": "svc=frompod", "generator": "service/v2"}, flags: map[string]string{"selector": "svc=frompod", "port": "90", "labels": "svc=frompod", "generator": "service/v2"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "a-name-that-is-toooo-big-for-a-service-because-it-can-only-handle-63-characters", Namespace: "", Labels: map[string]string{"svc": "frompod"}}, ObjectMeta: metav1.ObjectMeta{Name: "a-name-that-is-toooo-big-for-a-service-because-it-can-only-handle-63-characters", Namespace: "", Labels: map[string]string{"svc": "frompod"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 90, Port: 90,
TargetPort: intstr.FromInt(90), TargetPort: intstr.FromInt(90),
}, },
@ -365,17 +366,17 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/foo", "GET": "/namespaces/test/services/foo",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(80),
}, },
{ {
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 443, Port: 443,
TargetPort: intstr.FromInt(443), TargetPort: intstr.FromInt(443),
}, },
@ -383,19 +384,19 @@ func TestRunExposeService(t *testing.T) {
}, },
}, },
flags: map[string]string{"selector": "svc=fromfoo", "generator": "service/v2", "name": "fromfoo", "dry-run": "true"}, flags: map[string]string{"selector": "svc=fromfoo", "generator": "service/v2", "name": "fromfoo", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}}, ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Name: "port-1", Name: "port-1",
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(80),
}, },
{ {
Name: "port-2", Name: "port-2",
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 443, Port: 443,
TargetPort: intstr.FromInt(443), TargetPort: intstr.FromInt(443),
}, },
@ -413,22 +414,22 @@ func TestRunExposeService(t *testing.T) {
"GET": "/namespaces/test/services/foo", "GET": "/namespaces/test/services/foo",
"POST": "/namespaces/test/services", "POST": "/namespaces/test/services",
}, },
input: &api.Service{ input: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}}, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(80),
}, },
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 8080, Port: 8080,
TargetPort: intstr.FromInt(8080), TargetPort: intstr.FromInt(8080),
}, },
{ {
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 8081, Port: 8081,
TargetPort: intstr.FromInt(8081), TargetPort: intstr.FromInt(8081),
}, },
@ -436,25 +437,25 @@ func TestRunExposeService(t *testing.T) {
}, },
}, },
flags: map[string]string{"selector": "svc=fromfoo", "generator": "service/v2", "name": "fromfoo", "dry-run": "true"}, flags: map[string]string{"selector": "svc=fromfoo", "generator": "service/v2", "name": "fromfoo", "dry-run": "true"},
output: &api.Service{ output: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}}, ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{ Spec: corev1.ServiceSpec{
Ports: []api.ServicePort{ Ports: []corev1.ServicePort{
{ {
Name: "port-1", Name: "port-1",
Protocol: api.ProtocolTCP, Protocol: corev1.ProtocolTCP,
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(80),
}, },
{ {
Name: "port-2", Name: "port-2",
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 8080, Port: 8080,
TargetPort: intstr.FromInt(8080), TargetPort: intstr.FromInt(8080),
}, },
{ {
Name: "port-3", Name: "port-3",
Protocol: api.ProtocolUDP, Protocol: corev1.ProtocolUDP,
Port: 8081, Port: 8081,
TargetPort: intstr.FromInt(8081), TargetPort: intstr.FromInt(8081),
}, },