mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #47694 from FengyunPan/display-service-type
Automatic merge from submit-queue (batch tested with PRs 47694, 47772, 47783, 47803, 47673) Output TYPE for getting service **What this PR does / why we need it**: Now service already supported 4 ServiceTypes, ServiceTypes is friendly to distinguish services, so outputing service type better when running 'kubectl get service'. **Release note**: ```release-note NONE ```
This commit is contained in:
commit
ae9ca46927
@ -594,6 +594,7 @@ func Example_printServiceWithNamespacesAndLabels() {
|
||||
"s": "magic",
|
||||
},
|
||||
ClusterIP: "10.1.1.1",
|
||||
Type: api.ServiceTypeClusterIP,
|
||||
},
|
||||
Status: api.ServiceStatus{},
|
||||
},
|
||||
@ -615,6 +616,7 @@ func Example_printServiceWithNamespacesAndLabels() {
|
||||
"s": "kazam",
|
||||
},
|
||||
ClusterIP: "10.1.1.2",
|
||||
Type: api.ServiceTypeClusterIP,
|
||||
},
|
||||
Status: api.ServiceStatus{},
|
||||
}},
|
||||
@ -627,9 +629,9 @@ func Example_printServiceWithNamespacesAndLabels() {
|
||||
fmt.Printf("Unexpected error: %v", err)
|
||||
}
|
||||
// Output:
|
||||
// |NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE L1|
|
||||
// |ns1 svc1 10.1.1.1 <unknown> 53/UDP,53/TCP 10y value|
|
||||
// |ns2 svc2 10.1.1.2 <unknown> 80/TCP,8080/TCP 10y dolla-bill-yall|
|
||||
// |NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE L1|
|
||||
// |ns1 svc1 ClusterIP 10.1.1.1 <none> 53/UDP,53/TCP 10y value|
|
||||
// |ns2 svc2 ClusterIP 10.1.1.2 <none> 80/TCP,8080/TCP 10y dolla-bill-yall|
|
||||
// ||
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ var (
|
||||
jobColumns = []string{"NAME", "DESIRED", "SUCCESSFUL", "AGE"}
|
||||
cronJobColumns = []string{"NAME", "SCHEDULE", "SUSPEND", "ACTIVE", "LAST-SCHEDULE"}
|
||||
batchJobWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
||||
serviceColumns = []string{"NAME", "CLUSTER-IP", "EXTERNAL-IP", "PORT(S)", "AGE"}
|
||||
serviceColumns = []string{"NAME", "TYPE", "CLUSTER-IP", "EXTERNAL-IP", "PORT(S)", "AGE"}
|
||||
serviceWideColumns = []string{"SELECTOR"}
|
||||
ingressColumns = []string{"NAME", "HOSTS", "ADDRESS", "PORTS", "AGE"}
|
||||
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
|
||||
@ -711,7 +711,7 @@ func getServiceExternalIP(svc *api.Service, wide bool) string {
|
||||
if len(svc.Spec.ExternalIPs) > 0 {
|
||||
return strings.Join(svc.Spec.ExternalIPs, ",")
|
||||
}
|
||||
return "<nodes>"
|
||||
return "<none>"
|
||||
case api.ServiceTypeLoadBalancer:
|
||||
lbIps := loadBalancerStatusStringer(svc.Status.LoadBalancer, wide)
|
||||
if len(svc.Spec.ExternalIPs) > 0 {
|
||||
@ -742,9 +742,8 @@ func makePortString(ports []api.ServicePort) string {
|
||||
|
||||
func printService(svc *api.Service, w io.Writer, options printers.PrintOptions) error {
|
||||
name := printers.FormatResourceName(options.Kind, svc.Name, options.WithKind)
|
||||
|
||||
namespace := svc.Namespace
|
||||
|
||||
svcType := svc.Spec.Type
|
||||
internalIP := svc.Spec.ClusterIP
|
||||
externalIP := getServiceExternalIP(svc, options.Wide)
|
||||
|
||||
@ -753,8 +752,9 @@ func printService(svc *api.Service, w io.Writer, options printers.PrintOptions)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s",
|
||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s",
|
||||
name,
|
||||
string(svcType),
|
||||
internalIP,
|
||||
externalIP,
|
||||
makePortString(svc.Spec.Ports),
|
||||
|
@ -2334,17 +2334,17 @@ func TestPrintService(t *testing.T) {
|
||||
{Protocol: "tcp",
|
||||
Port: 2233},
|
||||
},
|
||||
ClusterIP: "0.0.0.0",
|
||||
ClusterIP: "10.9.8.7",
|
||||
},
|
||||
},
|
||||
"test1\t0.0.0.0\t<none>\t2233/tcp\t<unknown>\n",
|
||||
"test1\tClusterIP\t10.9.8.7\t<none>\t2233/tcp\t<unknown>\n",
|
||||
},
|
||||
{
|
||||
// Test name, cluster ip, port:nodePort with protocol
|
||||
api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "test2"},
|
||||
Spec: api.ServiceSpec{
|
||||
Type: api.ServiceTypeClusterIP,
|
||||
Type: api.ServiceTypeNodePort,
|
||||
Ports: []api.ServicePort{
|
||||
{Protocol: "tcp",
|
||||
Port: 8888,
|
||||
@ -2354,7 +2354,7 @@ func TestPrintService(t *testing.T) {
|
||||
ClusterIP: "10.9.8.7",
|
||||
},
|
||||
},
|
||||
"test2\t10.9.8.7\t<none>\t8888:9999/tcp\t<unknown>\n",
|
||||
"test2\tNodePort\t10.9.8.7\t<none>\t8888:9999/tcp\t<unknown>\n",
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user