From acc3ed6628f819ac6152718d7a8ff47e85d93d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=85=E7=B1=B3=20=E6=8B=93=E9=A6=AC?= Date: Sat, 5 Aug 2023 15:59:39 +0900 Subject: [PATCH] portName is renamed to svcPort and port number will be supported in addition to port name in the future --- pkg/cmd/open-svc.go | 11 +++++++---- pkg/cmd/open-svc_test.go | 16 ++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/open-svc.go b/pkg/cmd/open-svc.go index 1c89912..4cb938b 100644 --- a/pkg/cmd/open-svc.go +++ b/pkg/cmd/open-svc.go @@ -47,6 +47,9 @@ var ( # Open service/kubernetes-dashboard in namespace/kube-system kubectl open-svc kubernetes-dashboard -n kube-system + # Open http-monitoring port name of service/istiod in namespace/istio-system + kubectl open-svc istiod -n istio-system --svc-port http-monitoring + # Use "https" scheme with --scheme option for connections between the apiserver # and service/rook-ceph-mgr-dashboard in namespace/rook-ceph kubectl open-svc rook-ceph-mgr-dashboard -n rook-ceph --scheme https @@ -60,7 +63,7 @@ type OpenServiceOptions struct { args []string port int - portName string + svcPort string address string keepalive time.Duration scheme string @@ -233,7 +236,7 @@ func (o *OpenServiceOptions) getServiceProxyPath(svc *v1.Service) (string, error var port v1.ServicePort - if len(o.portName) == 0 { + if len(o.svcPort) == 0 { port = svc.Spec.Ports[0] if l > 1 { @@ -241,14 +244,14 @@ func (o *OpenServiceOptions) getServiceProxyPath(svc *v1.Service) (string, error } } else { for _, p := range svc.Spec.Ports { - if p.Name == o.portName { + if p.Name == o.svcPort { port = p break } } if len(port.Name) == 0 { - return "", fmt.Errorf("port %s not found for service/%s", o.portName, svc.GetName()) + return "", fmt.Errorf("port %s not found in service/%s", o.svcPort, svc.GetName()) } } diff --git a/pkg/cmd/open-svc_test.go b/pkg/cmd/open-svc_test.go index 9ae932c..8a7a56e 100644 --- a/pkg/cmd/open-svc_test.go +++ b/pkg/cmd/open-svc_test.go @@ -211,10 +211,10 @@ func TestOpenServiceOptionsGetServiceProxyPath(t *testing.T) { "Looks like service/nginx is a headless service", }, { - "no ports by portName", + "no ports by service port name", &OpenServiceOptions{ IOStreams: genericclioptions.NewTestIOStreamsDiscard(), - portName: "noport", + svcPort: "noport", }, &v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -230,13 +230,13 @@ func TestOpenServiceOptionsGetServiceProxyPath(t *testing.T) { }, }, "", - "port noport not found for service/nginx", + "port noport not found in service/nginx", }, { - "not specified scheme by portName", + "not specified scheme by service port name", &OpenServiceOptions{ IOStreams: genericclioptions.NewTestIOStreamsDiscard(), - portName: "metrics", + svcPort: "metrics", }, &v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -260,10 +260,10 @@ func TestOpenServiceOptionsGetServiceProxyPath(t *testing.T) { "", }, { - "specified scheme by portName", + "specified scheme by service port name", &OpenServiceOptions{ IOStreams: genericclioptions.NewTestIOStreamsDiscard(), - portName: "https", + svcPort: "https", }, &v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -283,7 +283,7 @@ func TestOpenServiceOptionsGetServiceProxyPath(t *testing.T) { }, }, }, - "/api/v1/namespaces/default/services/nginx:https:https/proxy", + "/api/v1/namespaces/default/services/https:nginx:https/proxy", "", }, }