Skip to content

Commit

Permalink
Remove unnecessary port information after dropping port allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Jan 31, 2023
1 parent 0a47b01 commit 2ba2670
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 107 deletions.
81 changes: 1 addition & 80 deletions cmd/plugin/rpaasv2/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
"encoding/json"
"fmt"
"io"
"sort"
"strings"
"text/template"
"time"

sprig "github.com/Masterminds/sprig/v3"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/duration"

Expand Down Expand Up @@ -159,25 +157,15 @@ func writePodsOnTableFormat(pods []clientTypes.Pod) string {
return ""
}

portSet := map[string][]clientTypes.PodPort{}
var data [][]string
hasMetrics := false
for _, pod := range pods {
var ports []string
for _, p := range pod.Ports {
ports = append(ports, fmt.Sprintf("%#v", p))
}
sort.Strings(ports)
acc := strings.Join(ports, " ")
portSet[acc] = pod.Ports

if pod.Metrics != nil {
hasMetrics = true
}
}

differentPorts := len(portSet) > 1

for _, pod := range pods {
row := []string{
pod.Name,
Expand All @@ -199,14 +187,6 @@ func writePodsOnTableFormat(pods []clientTypes.Pod) string {
}
}

if differentPorts {
var ports []string
for _, p := range pod.Ports {
ports = append(ports, p.String())
}
p := strings.Join(ports, " ")
row = append(row, p)
}
data = append(data, row)
}

Expand All @@ -216,23 +196,14 @@ func writePodsOnTableFormat(pods []clientTypes.Pod) string {
if hasMetrics {
header = append(header, "CPU", "Memory")
}
if differentPorts {
header = append(header, "Ports")
}

table.SetHeader(header)
table.SetAutoWrapText(true)
table.SetAutoFormatHeaders(false)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.AppendBulk(data)
table.Render()

if !differentPorts {
for _, ports := range portSet {
writePortsTable(&buffer, ports)
break
}
}

return buffer.String()
}

Expand All @@ -255,56 +226,6 @@ func memoryValue(q string) string {
return memory
}

func writePortsTable(w io.Writer, ports []clientTypes.PodPort) {
fmt.Fprintf(w, "\nPorts:\n")
table := tablewriter.NewWriter(w)

table.SetAutoWrapText(true)
table.SetAutoFormatHeaders(false)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)

hasHostIP := false
hasHostPort := false

for _, port := range ports {
if port.HostIP != "" {
hasHostIP = true
}
if port.HostPort > 0 {
hasHostPort = true
}
}

for _, port := range ports {
if port.Protocol == "" {
port.Protocol = corev1.ProtocolTCP
}
row := []string{
port.Name,
fmt.Sprintf("%d", port.ContainerPort),
string(port.Protocol),
}

if hasHostIP {
row = append(row, port.HostIP)
}
if hasHostPort {
row = append(row, fmt.Sprintf("%d", port.HostPort))
}
table.Append(row)
}

headers := []string{"Name", "Container port", "Protocol"}
if hasHostIP {
headers = append(headers, "Host IP")
}
if hasHostPort {
headers = append(headers, "Host port")
}
table.SetHeader(headers)
table.Render()
}

func unifiedStatus(status string, ready bool) string {
if ready {
return "Ready"
Expand Down
33 changes: 6 additions & 27 deletions cmd/plugin/rpaasv2/cmd/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,6 @@ Pods: (current: 5)
| my-instance-123abc456f-bbbbb | 169.254.10.11 | Errored | 100 | 5m |
+------------------------------+---------------+---------+----------+-----+
Ports:
+---------------+----------------+----------+-----------+
| Name | Container port | Protocol | Host port |
+---------------+----------------+----------+-----------+
| http | 30000 | TCP | 30000 |
| https | 30001 | TCP | 30001 |
| nginx-metrics | 30002 | TCP | 30002 |
+---------------+----------------+----------+-----------+
Errors:
+--------------------+------------------------------+----------------------------------------------+
| Age | Pod | Message |
Expand Down Expand Up @@ -605,15 +596,6 @@ Pods: (current: 2 / desired: 3)
| my-instance-75c8bdc6b9-bcdef | 169.254.1.101 | Terminating | 0 | 12h | 200% | 3000Mi |
+------------------------------+---------------+-------------+----------+-----+------+--------+
Ports:
+---------------+----------------+----------+-----------+
| Name | Container port | Protocol | Host port |
+---------------+----------------+----------+-----------+
| http | 8001 | TCP | 80 |
| https | 8002 | TCP | 443 |
| nginx-metrics | 8003 | TCP | 30002 |
+---------------+----------------+----------+-----------+
`,
},

Expand Down Expand Up @@ -702,15 +684,12 @@ Flavors: flavor1, flavor2, flavor-N
Cluster: my-dedicated-cluster
Pods: (current: 2 / desired: 3)
+------------------------------+---------------+-------------+----------+-----+--------------------------------+
| Name | Host | Status | Restarts | Age | Ports |
+------------------------------+---------------+-------------+----------+-----+--------------------------------+
| my-instance-75c8bdc6b9-abcde | 169.254.1.100 | Ready | 2 | 12h | http(30000/TCP) |
| | | | | | https(30001/TCP) |
| | | | | | nginx-metrics(30002/TCP) |
| my-instance-75c8bdc6b9-bcdef | 169.254.1.101 | Terminating | 0 | 12h | http(80/TCP) https(443/TCP) |
| | | | | | nginx-metrics(30002/TCP) |
+------------------------------+---------------+-------------+----------+-----+--------------------------------+
+------------------------------+---------------+-------------+----------+-----+
| Name | Host | Status | Restarts | Age |
+------------------------------+---------------+-------------+----------+-----+
| my-instance-75c8bdc6b9-abcde | 169.254.1.100 | Ready | 2 | 12h |
| my-instance-75c8bdc6b9-bcdef | 169.254.1.101 | Terminating | 0 | 12h |
+------------------------------+---------------+-------------+----------+-----+
`,
},
Expand Down

0 comments on commit 2ba2670

Please sign in to comment.