mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #66912 from deads2k/kubectl-03-externalpoly
Automatic merge from submit-queue (batch tested with PRs 66850, 66902, 66779, 66864, 66912). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. update polymorphichelpers for external types and updates expose to externals as proof @kubernetes/sig-cli-maintainers /assign @soltysh @juanvallejo ```release-note NONE ```
This commit is contained in:
commit
a54c0974e3
@ -29,7 +29,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
@ -92,7 +91,6 @@ type ExposeServiceOptions struct {
|
||||
|
||||
Generators func(string) map[string]kubectl.Generator
|
||||
CanBeExposed polymorphichelpers.CanBeExposedFunc
|
||||
ClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)
|
||||
MapBasedSelectorForObject func(runtime.Object) (string, error)
|
||||
PortsForObject polymorphichelpers.PortsForObjectFunc
|
||||
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.Builder = f.NewBuilder()
|
||||
o.CanBeExposed = polymorphichelpers.CanBeExposedFn
|
||||
o.ClientForMapping = f.ClientForMapping
|
||||
o.MapBasedSelectorForObject = polymorphichelpers.MapBasedSelectorForObjectFn
|
||||
o.ProtocolsForObject = polymorphichelpers.ProtocolsForObjectFn
|
||||
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 {
|
||||
r := o.Builder.
|
||||
WithScheme(legacyscheme.Scheme).
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
ContinueOnError().
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
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 {
|
||||
codec := runtime.NewCodec(cmdutil.InternalVersionJSONEncoder(), cmdutil.InternalVersionDecoder())
|
||||
object, err = cmdutil.Merge(codec, object, inline)
|
||||
object, err = cmdutil.Merge(scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...), object, inline)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -333,7 +329,7 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
gvks, _, err := unstructuredscheme.NewUnstructuredObjectTyper().ObjectKinds(asUnstructured)
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@ -60,19 +61,19 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Selector: map[string]string{"app": "go"},
|
||||
},
|
||||
},
|
||||
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"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
@ -91,19 +92,19 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Selector: map[string]string{"app": "go"},
|
||||
},
|
||||
},
|
||||
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"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
@ -122,20 +123,20 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/default/services/mayor",
|
||||
"POST": "/namespaces/default/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "default", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Selector: map[string]string{"run": "this"},
|
||||
},
|
||||
},
|
||||
// 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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "mayor", Namespace: "", Labels: map[string]string{"runas": "amayor"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
@ -154,25 +155,25 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{"func": "stream"},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
Type: corev1.ServiceTypeLoadBalancer,
|
||||
},
|
||||
},
|
||||
status: 200,
|
||||
@ -185,26 +186,26 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{"func": "stream"},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
SessionAffinity: api.ServiceAffinityClientIP,
|
||||
Type: corev1.ServiceTypeLoadBalancer,
|
||||
SessionAffinity: corev1.ServiceAffinityClientIP,
|
||||
},
|
||||
},
|
||||
status: 200,
|
||||
@ -217,19 +218,19 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
@ -249,25 +250,25 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 14,
|
||||
TargetPort: intstr.FromInt(14),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{"func": "stream"},
|
||||
ClusterIP: api.ClusterIPNone,
|
||||
ClusterIP: corev1.ClusterIPNone,
|
||||
},
|
||||
},
|
||||
expected: "service/foo exposed",
|
||||
@ -281,19 +282,19 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/baz",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Selector: map[string]string{"app": "go"},
|
||||
},
|
||||
},
|
||||
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"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{},
|
||||
Selector: map[string]string{"func": "stream"},
|
||||
ClusterIP: api.ClusterIPNone,
|
||||
ClusterIP: corev1.ClusterIPNone,
|
||||
},
|
||||
},
|
||||
expected: "service/foo exposed",
|
||||
@ -307,19 +308,19 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/redis-master",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "redis-master", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"svc": "test"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 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",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Pod{
|
||||
input: &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
},
|
||||
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"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 90,
|
||||
TargetPort: intstr.FromInt(90),
|
||||
},
|
||||
@ -365,17 +366,17 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/foo",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Name: "port-1",
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
{
|
||||
Name: "port-2",
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 443,
|
||||
TargetPort: intstr.FromInt(443),
|
||||
},
|
||||
@ -413,22 +414,22 @@ func TestRunExposeService(t *testing.T) {
|
||||
"GET": "/namespaces/test/services/foo",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
input: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 8080,
|
||||
TargetPort: intstr.FromInt(8080),
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 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"},
|
||||
output: &api.Service{
|
||||
output: &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Name: "port-1",
|
||||
Protocol: api.ProtocolTCP,
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
{
|
||||
Name: "port-2",
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 8080,
|
||||
TargetPort: intstr.FromInt(8080),
|
||||
},
|
||||
{
|
||||
Name: "port-3",
|
||||
Protocol: api.ProtocolUDP,
|
||||
Protocol: corev1.ProtocolUDP,
|
||||
Port: 8081,
|
||||
TargetPort: intstr.FromInt(8081),
|
||||
},
|
||||
|
@ -31,6 +31,7 @@ go_library(
|
||||
"//pkg/controller:go_default_library",
|
||||
"//pkg/kubectl:go_default_library",
|
||||
"//pkg/kubectl/genericclioptions:go_default_library",
|
||||
"//pkg/kubectl/scheme:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1beta2:go_default_library",
|
||||
|
@ -19,6 +19,11 @@ package polymorphichelpers
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1beta2 "k8s.io/api/apps/v1beta2"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
@ -33,16 +38,31 @@ func mapBasedSelectorForObject(object runtime.Object) (string, error) {
|
||||
switch t := object.(type) {
|
||||
case *api.ReplicationController:
|
||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
||||
case *corev1.ReplicationController:
|
||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
||||
|
||||
case *api.Pod:
|
||||
if len(t.Labels) == 0 {
|
||||
return "", fmt.Errorf("the pod has no labels and cannot be exposed")
|
||||
}
|
||||
return kubectl.MakeLabels(t.Labels), nil
|
||||
case *corev1.Pod:
|
||||
if len(t.Labels) == 0 {
|
||||
return "", fmt.Errorf("the pod has no labels and cannot be exposed")
|
||||
}
|
||||
return kubectl.MakeLabels(t.Labels), nil
|
||||
|
||||
case *api.Service:
|
||||
if t.Spec.Selector == nil {
|
||||
return "", fmt.Errorf("the service has no pod selector set")
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
||||
case *corev1.Service:
|
||||
if t.Spec.Selector == nil {
|
||||
return "", fmt.Errorf("the service has no pod selector set")
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
||||
|
||||
case *extensions.Deployment:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
@ -50,6 +70,35 @@ func mapBasedSelectorForObject(object runtime.Object) (string, error) {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *extensionsv1beta1.Deployment:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *appsv1.Deployment:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *appsv1beta2.Deployment:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *appsv1beta1.Deployment:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
|
||||
case *extensions.ReplicaSet:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
@ -57,6 +106,28 @@ func mapBasedSelectorForObject(object runtime.Object) (string, error) {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *extensionsv1beta1.ReplicaSet:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *appsv1.ReplicaSet:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
case *appsv1beta2.ReplicaSet:
|
||||
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
|
||||
// operator, DoubleEquals operator and In operator with only one element in the set.
|
||||
if len(t.Spec.Selector.MatchExpressions) > 0 {
|
||||
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
|
||||
}
|
||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf("cannot extract pod selector from %T", object)
|
||||
}
|
||||
|
@ -20,10 +20,15 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1beta2 "k8s.io/api/apps/v1beta2"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
)
|
||||
|
||||
// Currently only supports Deployments.
|
||||
@ -35,6 +40,35 @@ func defaultObjectPauser(obj runtime.Object) ([]byte, error) {
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(internalVersionJSONEncoder(), obj)
|
||||
|
||||
case *extensionsv1beta1.Deployment:
|
||||
if obj.Spec.Paused {
|
||||
return nil, errors.New("is already paused")
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(extensionsv1beta1.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1.Deployment:
|
||||
if obj.Spec.Paused {
|
||||
return nil, errors.New("is already paused")
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1beta2.Deployment:
|
||||
if obj.Spec.Paused {
|
||||
return nil, errors.New("is already paused")
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1beta2.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1beta1.Deployment:
|
||||
if obj.Spec.Paused {
|
||||
return nil, errors.New("is already paused")
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1beta1.SchemeGroupVersion), obj)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("pausing is not supported")
|
||||
}
|
||||
|
@ -20,8 +20,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1beta2 "k8s.io/api/apps/v1beta2"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
)
|
||||
|
||||
func defaultObjectResumer(obj runtime.Object) ([]byte, error) {
|
||||
@ -32,6 +37,35 @@ func defaultObjectResumer(obj runtime.Object) ([]byte, error) {
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(internalVersionJSONEncoder(), obj)
|
||||
|
||||
case *extensionsv1beta1.Deployment:
|
||||
if !obj.Spec.Paused {
|
||||
return nil, errors.New("is not paused")
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(extensionsv1beta1.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1.Deployment:
|
||||
if !obj.Spec.Paused {
|
||||
return nil, errors.New("is not paused")
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1beta2.Deployment:
|
||||
if !obj.Spec.Paused {
|
||||
return nil, errors.New("is not paused")
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1beta2.SchemeGroupVersion), obj)
|
||||
|
||||
case *appsv1beta1.Deployment:
|
||||
if !obj.Spec.Paused {
|
||||
return nil, errors.New("is not paused")
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(scheme.Codecs.LegacyCodec(appsv1beta1.SchemeGroupVersion), obj)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("resuming is not supported")
|
||||
}
|
||||
|
@ -20,6 +20,11 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1beta2 "k8s.io/api/apps/v1beta2"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
@ -28,21 +33,45 @@ import (
|
||||
func portsForObject(object runtime.Object) ([]string, error) {
|
||||
switch t := object.(type) {
|
||||
case *api.ReplicationController:
|
||||
return getPortsInternal(t.Spec.Template.Spec), nil
|
||||
case *corev1.ReplicationController:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
|
||||
case *api.Pod:
|
||||
return getPortsInternal(t.Spec), nil
|
||||
case *corev1.Pod:
|
||||
return getPorts(t.Spec), nil
|
||||
|
||||
case *api.Service:
|
||||
return getServicePortsInternal(t.Spec), nil
|
||||
case *corev1.Service:
|
||||
return getServicePorts(t.Spec), nil
|
||||
|
||||
case *extensions.Deployment:
|
||||
return getPortsInternal(t.Spec.Template.Spec), nil
|
||||
case *extensionsv1beta1.Deployment:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *appsv1.Deployment:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta2.Deployment:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta1.Deployment:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
|
||||
case *extensions.ReplicaSet:
|
||||
return getPortsInternal(t.Spec.Template.Spec), nil
|
||||
case *extensionsv1beta1.ReplicaSet:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *appsv1.ReplicaSet:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta2.ReplicaSet:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot extract ports from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
func getPorts(spec api.PodSpec) []string {
|
||||
func getPortsInternal(spec api.PodSpec) []string {
|
||||
result := []string{}
|
||||
for _, container := range spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
@ -53,7 +82,25 @@ func getPorts(spec api.PodSpec) []string {
|
||||
}
|
||||
|
||||
// Extracts the ports exposed by a service from the given service spec.
|
||||
func getServicePorts(spec api.ServiceSpec) []string {
|
||||
func getServicePortsInternal(spec api.ServiceSpec) []string {
|
||||
result := []string{}
|
||||
for _, servicePort := range spec.Ports {
|
||||
result = append(result, strconv.Itoa(int(servicePort.Port)))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getPorts(spec corev1.PodSpec) []string {
|
||||
result := []string{}
|
||||
for _, container := range spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
result = append(result, strconv.Itoa(int(port.ContainerPort)))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getServicePorts(spec corev1.ServiceSpec) []string {
|
||||
result := []string{}
|
||||
for _, servicePort := range spec.Ports {
|
||||
result = append(result, strconv.Itoa(int(servicePort.Port)))
|
||||
|
@ -20,6 +20,11 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1beta2 "k8s.io/api/apps/v1beta2"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
@ -29,21 +34,46 @@ func protocolsForObject(object runtime.Object) (map[string]string, error) {
|
||||
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
||||
switch t := object.(type) {
|
||||
case *api.ReplicationController:
|
||||
return getProtocolsInternal(t.Spec.Template.Spec), nil
|
||||
case *corev1.ReplicationController:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
|
||||
case *api.Pod:
|
||||
return getProtocolsInternal(t.Spec), nil
|
||||
case *corev1.Pod:
|
||||
return getProtocols(t.Spec), nil
|
||||
|
||||
case *api.Service:
|
||||
return getServiceProtocolsInternal(t.Spec), nil
|
||||
case *corev1.Service:
|
||||
return getServiceProtocols(t.Spec), nil
|
||||
|
||||
case *extensions.Deployment:
|
||||
return getProtocolsInternal(t.Spec.Template.Spec), nil
|
||||
case *extensionsv1beta1.Deployment:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
case *appsv1.Deployment:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta2.Deployment:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta1.Deployment:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
|
||||
case *extensions.ReplicaSet:
|
||||
return getProtocolsInternal(t.Spec.Template.Spec), nil
|
||||
case *extensionsv1beta1.ReplicaSet:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
case *appsv1.ReplicaSet:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
case *appsv1beta2.ReplicaSet:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot extract protocols from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
func getProtocols(spec api.PodSpec) map[string]string {
|
||||
func getProtocolsInternal(spec api.PodSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, container := range spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
@ -54,7 +84,26 @@ func getProtocols(spec api.PodSpec) map[string]string {
|
||||
}
|
||||
|
||||
// Extracts the protocols exposed by a service from the given service spec.
|
||||
func getServiceProtocols(spec api.ServiceSpec) map[string]string {
|
||||
func getServiceProtocolsInternal(spec api.ServiceSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, servicePort := range spec.Ports {
|
||||
result[strconv.Itoa(int(servicePort.Port))] = string(servicePort.Protocol)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getProtocols(spec corev1.PodSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, container := range spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
result[strconv.Itoa(int(port.ContainerPort))] = string(port.Protocol)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Extracts the protocols exposed by a service from the given service spec.
|
||||
func getServiceProtocols(spec corev1.ServiceSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, servicePort := range spec.Ports {
|
||||
result[strconv.Itoa(int(servicePort.Port))] = string(servicePort.Protocol)
|
||||
|
Loading…
Reference in New Issue
Block a user