From d6b539d2ef89ac8408cf3c005493b2badcf599aa Mon Sep 17 00:00:00 2001 From: Ankur Kothiwal Date: Wed, 18 Oct 2023 21:07:14 +0530 Subject: [PATCH] remove summary, discover as they depend on an external tool Signed-off-by: Ankur Kothiwal --- README.md | 2 - cmd/discover.go | 36 ------- cmd/summary.go | 39 -------- discover/discover.go | 195 -------------------------------------- go.mod | 3 +- go.sum | 2 - summary/summary.go | 140 --------------------------- summary/table.go | 221 ------------------------------------------- 8 files changed, 1 insertion(+), 637 deletions(-) delete mode 100644 cmd/discover.go delete mode 100644 cmd/summary.go delete mode 100644 discover/discover.go delete mode 100644 summary/summary.go delete mode 100644 summary/table.go diff --git a/README.md b/README.md index e126b2fc..8b291149 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ Usage: Available Commands: completion Generate the autocompletion script for the specified shell - discover Discover applicable policies help Help about any command install Install KubeArmor in a Kubernetes Cluster logs Observe Logs from KubeArmor @@ -44,7 +43,6 @@ Available Commands: recommend Recommend Policies rotate-tls Rotate webhook controller tls certificates selfupdate selfupdate this cli tool - summary Observability from discovery engine sysdump Collect system dump information for troubleshooting and error report uninstall Uninstall KubeArmor from a Kubernetes Cluster version Display version information diff --git a/cmd/discover.go b/cmd/discover.go deleted file mode 100644 index f7552d1d..00000000 --- a/cmd/discover.go +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -package cmd - -import ( - "github.com/kubearmor/kubearmor-client/discover" - "github.com/spf13/cobra" -) - -var discoverOptions discover.Options - -// discoverCmd represents the discover command -var discoverCmd = &cobra.Command{ - Use: "discover", - Short: "Discover applicable policies", - Long: `Discover applicable policies`, - RunE: func(cmd *cobra.Command, args []string) error { - if err := discover.Policy(client, discoverOptions); err != nil { - return err - } - return nil - }, -} - -func init() { - rootCmd.AddCommand(discoverCmd) - discoverCmd.Flags().StringVar(&discoverOptions.GRPC, "gRPC", "", "gRPC server information") - discoverCmd.Flags().StringVarP(&discoverOptions.Format, "format", "f", "yaml", "Format: json or yaml") - discoverCmd.Flags().StringVarP(&discoverOptions.Policy, "policy", "p", "KubearmorSecurityPolicy", "Type of policies to be discovered: KubearmorSecurityPolicy|CiliumNetworkPolicy|NetworkPolicy") - discoverCmd.Flags().StringVarP(&discoverOptions.Namespace, "namespace", "n", "", "Filter by Namespace") - discoverCmd.Flags().StringVarP(&discoverOptions.Clustername, "clustername", "c", "", "Filter by Clustername") - discoverCmd.Flags().StringVarP(&discoverOptions.Labels, "labels", "l", "", "Filter by policy Label") - discoverCmd.Flags().StringVarP(&discoverOptions.Fromsource, "fromsource", "s", "", "Filter by policy FromSource") - discoverCmd.Flags().BoolVar(&discoverOptions.IncludeNetwork, "network", false, "Include network rules in system policies") -} diff --git a/cmd/summary.go b/cmd/summary.go deleted file mode 100644 index 70cc8111..00000000 --- a/cmd/summary.go +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -package cmd - -import ( - "github.com/kubearmor/kubearmor-client/summary" - "github.com/spf13/cobra" -) - -var summaryOptions summary.Options - -// summaryCmd represents the summary command -var summaryCmd = &cobra.Command{ - Use: "summary", - Short: "Observability from discovery engine", - Long: `Discovery engine keeps the telemetry information from the policy enforcement engines and the karmor connects to it to provide this as observability data`, - RunE: func(cmd *cobra.Command, args []string) error { - if err := summary.Summary(client, summaryOptions); err != nil { - return err - } - return nil - }, -} - -func init() { - rootCmd.AddCommand(summaryCmd) - - summaryCmd.Flags().StringVar(&summaryOptions.GRPC, "gRPC", "", "gRPC server information") - summaryCmd.Flags().StringVarP(&summaryOptions.Labels, "labels", "l", "", "Labels") - summaryCmd.Flags().StringVarP(&summaryOptions.Namespace, "namespace", "n", "", "Namespace") - summaryCmd.Flags().StringVarP(&summaryOptions.PodName, "pod", "p", "", "PodName") - summaryCmd.Flags().StringVarP(&summaryOptions.Type, "type", "t", summary.DefaultReqType, "Summary filter type : process|file|network ") - summaryCmd.Flags().StringVar(&summaryOptions.ClusterName, "cluster", "", "Cluster name") - summaryCmd.Flags().StringVar(&summaryOptions.ContainerName, "container", "", "Container name") - summaryCmd.Flags().StringVarP(&summaryOptions.Output, "output", "o", "", "Export Summary Data in JSON (karmor summary -o json)") - summaryCmd.Flags().BoolVar(&summaryOptions.RevDNSLookup, "rev-dns-lookup", false, "Reverse DNS Lookup") - summaryCmd.Flags().BoolVar(&summaryOptions.Aggregation, "agg", false, "Aggregate destination files/folder path") -} diff --git a/discover/discover.go b/discover/discover.go deleted file mode 100644 index 341aa431..00000000 --- a/discover/discover.go +++ /dev/null @@ -1,195 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -// Package discover fetches policies from discovery engine -package discover - -import ( - "context" - "errors" - "fmt" - "os" - "strconv" - - "github.com/clarketm/json" - "github.com/kubearmor/kubearmor-client/k8s" - "github.com/kubearmor/kubearmor-client/utils" - "github.com/rs/zerolog/log" - "sigs.k8s.io/yaml" - - nv1 "k8s.io/api/networking/v1" - - wpb "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/worker" - "github.com/accuknox/auto-policy-discovery/src/types" - "google.golang.org/grpc" -) - -// Options Structure -type Options struct { - GRPC string - Format string - Policy string - Namespace string - Clustername string - Labels string - Fromsource string - IncludeNetwork bool -} - -var matchLabels = map[string]string{"app": "discovery-engine"} -var port int64 = 9089 - -// ConvertPolicy converts the knoxautopolicies to KubeArmor and Cilium policies -func ConvertPolicy(c *k8s.Client, o Options) ([]string, error) { - var str []string - gRPC := "" - targetSvc := "discovery-engine" - - if o.GRPC != "" { - gRPC = o.GRPC - } else { - if val, ok := os.LookupEnv("DISCOVERY_SERVICE"); ok { - gRPC = val - } else { - pf, err := utils.InitiatePortForward(c, port, port, matchLabels, targetSvc) - if err != nil { - return nil, err - } - gRPC = "localhost:" + strconv.FormatInt(pf.LocalPort, 10) - } - } - - data := &wpb.WorkerRequest{ - Policytype: o.Policy, - Namespace: o.Namespace, - Clustername: o.Clustername, - Labels: o.Labels, - Fromsource: o.Fromsource, - Includenetwork: o.IncludeNetwork, - } - - // create a client - conn, err := grpc.Dial(gRPC, grpc.WithInsecure()) - if err != nil { - return nil, err - } - defer conn.Close() - - client := wpb.NewWorkerClient(conn) - - var response *wpb.WorkerResponse - response, err = client.Convert(context.Background(), data) - if err != nil { - return nil, errors.New("could not connect to the server. Possible troubleshooting:\n- Check if discovery engine is running\n- kubectl get po -n accuknox-agents") - } - - if o.Policy == "CiliumNetworkPolicy" { - - if len(response.Ciliumpolicy) > 0 { - for _, val := range response.Ciliumpolicy { - policy := types.CiliumNetworkPolicy{} - - err = json.Unmarshal(val.Data, &policy) - if err != nil { - log.Error().Msg(err.Error()) - return nil, err - } - - if o.Format == "json" { - arr, _ := json.MarshalIndent(policy, "", " ") - pstr := fmt.Sprintf("%s\n", string(arr)) - str = append(str, pstr) - } else if o.Format == "yaml" { - arr, _ := json.Marshal(policy) - yamlarr, _ := yaml.JSONToYAML(arr) - pstr := fmt.Sprintf("%s", string(yamlarr)) - str = append(str, pstr) - } else { - log.Printf("Currently supported formats are json and yaml\n") - break - } - } - return str, err - } - } else if o.Policy == "KubearmorSecurityPolicy" { - - if len(response.Kubearmorpolicy) > 0 { - for _, val := range response.Kubearmorpolicy { - policy := types.KubeArmorPolicy{} - - err = json.Unmarshal(val.Data, &policy) - if err != nil { - log.Error().Msg(err.Error()) - return nil, err - } - - if o.Format == "json" { - arr, _ := json.MarshalIndent(policy, "", " ") - pstr := fmt.Sprintf("%s\n", string(arr)) - str = append(str, pstr) - } else if o.Format == "yaml" { - arr, _ := json.Marshal(policy) - yamlarr, _ := yaml.JSONToYAML(arr) - pstr := fmt.Sprintf("%s", string(yamlarr)) - str = append(str, pstr) - } else { - fmt.Printf("Currently supported formats are json and yaml\n") - break - } - } - return str, err - } - } else if o.Policy == "NetworkPolicy" { - - if len(response.K8SNetworkpolicy) > 0 { - for _, val := range response.K8SNetworkpolicy { - policy := nv1.NetworkPolicy{} - - err = json.Unmarshal(val.Data, &policy) - if err != nil { - log.Error().Msg(err.Error()) - return nil, err - } - - if o.Format == "json" { - arr, _ := json.MarshalIndent(policy, "", " ") - pstr := fmt.Sprintf("%s\n", string(arr)) - str = append(str, pstr) - } else if o.Format == "yaml" { - arr, _ := json.Marshal(policy) - yamlarr, _ := yaml.JSONToYAML(arr) - pstr := fmt.Sprintf("%s", string(yamlarr)) - str = append(str, pstr) - } else { - fmt.Printf("Currently supported formats are json and yaml\n") - break - } - } - return str, err - } - } - - return str, err -} - -// Policy discovers Cilium or KubeArmor policies -func Policy(c *k8s.Client, o Options) error { - var str []string - var err error - if o.Policy != "CiliumNetworkPolicy" && o.Policy != "NetworkPolicy" && o.Policy != "KubearmorSecurityPolicy" { - log.Error().Msgf("Policy type not recognized.\nCurrently supported policies are cilium, kubearmor and k8snetpol\n") - } - - if str, err = ConvertPolicy(c, o); err != nil { - return err - } - for _, policy := range str { - if o.Format == "yaml" { - fmt.Printf("%s---\n", policy) - } - if o.Format == "json" { - fmt.Printf("%s", policy) - } - } - return nil -} diff --git a/go.mod b/go.mod index d78010a0..e439a1cb 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( require ( github.com/accuknox/auto-policy-discovery/src v0.0.0-20230707054448-845969c25277 - github.com/accuknox/auto-policy-discovery/src/protobuf v0.0.0-20230707054448-845969c25277 github.com/charmbracelet/bubbles v0.15.0 github.com/charmbracelet/bubbletea v0.23.2 github.com/charmbracelet/lipgloss v0.7.1 @@ -55,7 +54,6 @@ require ( github.com/kubearmor/KubeArmor/KubeArmor v0.0.0-20230918061249-1d5b51c449bd github.com/kubearmor/KubeArmor/deployments v0.0.0-20230918135729-00395f443fa0 github.com/kubearmor/KubeArmor/pkg/KubeArmorController v0.0.0-20230626060245-4f5b8ac4f298 - github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d github.com/onsi/ginkgo/v2 v2.9.5 github.com/onsi/gomega v1.27.7 k8s.io/api v0.27.3 @@ -87,6 +85,7 @@ require ( github.com/OneOfOne/xxhash v1.2.8 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230426101702-58e86b294756 // indirect github.com/ThalesIgnite/crypto11 v1.2.5 // indirect + github.com/accuknox/auto-policy-discovery/src/protobuf v0.0.0-20230707054448-845969c25277 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect github.com/alibabacloud-go/cr-20160607 v1.0.1 // indirect diff --git a/go.sum b/go.sum index 5d3ccdf2..25405192 100644 --- a/go.sum +++ b/go.sum @@ -1030,8 +1030,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfr github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc= github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= github.com/mgechev/revive v1.0.6/go.mod h1:Lj5gIVxjBlH8REa3icEOkdfchwYc291nShzZ4QYWyMo= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo= github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= diff --git a/summary/summary.go b/summary/summary.go deleted file mode 100644 index 2ea47a2b..00000000 --- a/summary/summary.go +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -// Package summary shows observability data from discovery engine -package summary - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "os" - "strconv" - - opb "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/observability" - "github.com/kubearmor/kubearmor-client/k8s" - "github.com/kubearmor/kubearmor-client/utils" - - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" -) - -// DefaultReqType : default option for request type -var DefaultReqType = "process,file,network" -var matchLabels = map[string]string{"app": "discovery-engine"} -var port int64 = 9089 - -// Options Structure -type Options struct { - GRPC string - Labels string - Namespace string - PodName string - ClusterName string - ContainerName string - Type string - Output string - RevDNSLookup bool - Aggregation bool -} - -// GetSummary on pods -func GetSummary(c *k8s.Client, o Options) ([]*opb.Response, error) { - var jsonObs []*opb.Response - gRPC := "" - targetSvc := "discovery-engine" - - if o.GRPC != "" { - gRPC = o.GRPC - } else { - if val, ok := os.LookupEnv("DISCOVERY_SERVICE"); ok { - gRPC = val - } else { - pf, err := utils.InitiatePortForward(c, port, port, matchLabels, targetSvc) - if err != nil { - return nil, err - } - gRPC = "localhost:" + strconv.FormatInt(pf.LocalPort, 10) - } - } - - data := &opb.Request{ - Label: o.Labels, - NameSpace: o.Namespace, - PodName: o.PodName, - ClusterName: o.ClusterName, - ContainerName: o.ContainerName, - Aggregate: o.Aggregation, - Type: o.Type, - } - - // create a client - conn, err := grpc.Dial(gRPC, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - return nil, errors.New("could not connect to the server. Possible troubleshooting:\n- Check if discovery engine is running\n- kubectl get po -n accuknox-agents") - } - defer conn.Close() - - client := opb.NewObservabilityClient(conn) - - if data.PodName != "" { - sumResp, err := client.Summary(context.Background(), data) - if err != nil { - return nil, err - } - if o.Output == "" { - DisplaySummaryOutput(sumResp, o.RevDNSLookup, o.Type) - } - - if o.Output == "json" { - jsonObs = append(jsonObs, sumResp) - return jsonObs, nil - } - - } else { - //Fetch Summary Logs - podNameResp, err := client.GetPodNames(context.Background(), data) - if err != nil { - return nil, err - } - - for _, podname := range podNameResp.PodName { - if podname == "" { - continue - } - data.PodName = podname - sumResp, err := client.Summary(context.Background(), data) - if err != nil { - return nil, err - } - if o.Output == "" { - DisplaySummaryOutput(sumResp, o.RevDNSLookup, o.Type) - } - - if o.Output == "json" { - jsonObs = append(jsonObs, sumResp) - } - } - if o.Output == "json" { - return jsonObs, nil - } - } - return jsonObs, nil -} - -// Summary - printing the summary output -func Summary(c *k8s.Client, o Options) error { - summary, err := GetSummary(c, o) - if err != nil { - return err - } - if o.Output == "json" { - summaryJson, err := json.MarshalIndent(summary, "", " ") - if err != nil { - return err - } - fmt.Printf("%s", string(summaryJson)) - } - return nil -} diff --git a/summary/table.go b/summary/table.go deleted file mode 100644 index a1c627f1..00000000 --- a/summary/table.go +++ /dev/null @@ -1,221 +0,0 @@ -package summary - -import ( - "fmt" - "net" - "os" - "sort" - "strings" - - opb "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/observability" - "github.com/mgutz/ansi" - - "github.com/olekukonko/tablewriter" -) - -var ( - // SysProcHeader variable contains source process, destination process path, count, timestamp and status - SysProcHeader = []string{"Src Process", "Destination Process Path", "Count", "Last Updated Time", "Status"} - // SysFileHeader variable contains source process, destination file path, count, timestamp and status - SysFileHeader = []string{"Src Process", "Destination File Path", "Count", "Last Updated Time", "Status"} - // SysNwHeader variable contains protocol, command, POD/SVC/IP, Port, Namespace, and Labels - SysNwHeader = []string{"Protocol", "Command", "POD/SVC/IP", "Port", "Namespace", "Labels", "Count", "Last Updated Time"} - // SysBindNwHeader variable contains protocol, command, Bind Port, Bind Address, count and timestamp - SysBindNwHeader = []string{"Protocol", "Command", "Bind Port", "Bind Address", "Count", "Last Updated Time"} -) - -// DisplaySummaryOutput function -func DisplaySummaryOutput(resp *opb.Response, revDNSLookup bool, requestType string) { - - if len(resp.ProcessData) <= 0 && len(resp.FileData) <= 0 && len(resp.IngressConnection) <= 0 && len(resp.EgressConnection) <= 0 { - return - } - - writePodInfoToTable(resp.PodName, resp.Namespace, resp.ClusterName, resp.ContainerName, resp.Label) - - // Colored Status for Allow and Deny - agc := ansi.ColorFunc("green") - arc := ansi.ColorFunc("red") - ayc := ansi.ColorFunc("yellow") - - if strings.Contains(requestType, "process") { - if len(resp.ProcessData) > 0 { - procRowData := [][]string{} - // Display process data - fmt.Printf("\nProcess Data\n") - for _, procData := range resp.ProcessData { - procStrSlice := []string{} - procStrSlice = append(procStrSlice, procData.Source) - procStrSlice = append(procStrSlice, procData.Destination) - procStrSlice = append(procStrSlice, procData.Count) - procStrSlice = append(procStrSlice, procData.UpdatedTime) - if procData.Status == "Allow" { - procStrSlice = append(procStrSlice, agc(procData.Status)) - } else if procData.Status == "Audit" { - procStrSlice = append(procStrSlice, ayc(procData.Status)) - } else { - procStrSlice = append(procStrSlice, arc(procData.Status)) - } - procRowData = append(procRowData, procStrSlice) - } - sort.Slice(procRowData[:], func(i, j int) bool { - for x := range procRowData[i] { - if procRowData[i][x] == procRowData[j][x] { - continue - } - return procRowData[i][x] < procRowData[j][x] - } - return false - }) - WriteTable(SysProcHeader, procRowData) - fmt.Printf("\n") - } - } - - if strings.Contains(requestType, "file") { - if len(resp.FileData) > 0 { - fmt.Printf("\nFile Data\n") - // Display file data - fileRowData := [][]string{} - for _, fileData := range resp.FileData { - fileStrSlice := []string{} - fileStrSlice = append(fileStrSlice, fileData.Source) - fileStrSlice = append(fileStrSlice, fileData.Destination) - fileStrSlice = append(fileStrSlice, fileData.Count) - fileStrSlice = append(fileStrSlice, fileData.UpdatedTime) - if fileData.Status == "Allow" { - fileStrSlice = append(fileStrSlice, agc(fileData.Status)) - } else if fileData.Status == "Audit" { - fileStrSlice = append(fileStrSlice, ayc(fileData.Status)) - } else { - fileStrSlice = append(fileStrSlice, arc(fileData.Status)) - } - fileRowData = append(fileRowData, fileStrSlice) - } - sort.Slice(fileRowData[:], func(i, j int) bool { - for x := range fileRowData[i] { - if fileRowData[i][x] == fileRowData[j][x] { - continue - } - return fileRowData[i][x] < fileRowData[j][x] - } - return false - }) - WriteTable(SysFileHeader, fileRowData) - fmt.Printf("\n") - } - } - - if strings.Contains(requestType, "network") { - if len(resp.IngressConnection) > 0 { - fmt.Printf("\nIngress connections\n") - // Display server conn data - inNwRowData := [][]string{} - for _, ingressConnection := range resp.IngressConnection { - inNwStrSlice := []string{} - domainName := dnsLookup(ingressConnection.IP, revDNSLookup) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Protocol) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Command) - inNwStrSlice = append(inNwStrSlice, domainName) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Port) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Namespace) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Labels) - inNwStrSlice = append(inNwStrSlice, ingressConnection.Count) - inNwStrSlice = append(inNwStrSlice, ingressConnection.UpdatedTime) - inNwRowData = append(inNwRowData, inNwStrSlice) - } - WriteTable(SysNwHeader, inNwRowData) - fmt.Printf("\n") - } - - if len(resp.EgressConnection) > 0 { - fmt.Printf("\nEgress connections\n") - // Display server conn data - outNwRowData := [][]string{} - for _, egressConnection := range resp.EgressConnection { - outNwStrSlice := []string{} - domainName := dnsLookup(egressConnection.IP, revDNSLookup) - outNwStrSlice = append(outNwStrSlice, egressConnection.Protocol) - outNwStrSlice = append(outNwStrSlice, egressConnection.Command) - outNwStrSlice = append(outNwStrSlice, domainName) - outNwStrSlice = append(outNwStrSlice, egressConnection.Port) - outNwStrSlice = append(outNwStrSlice, egressConnection.Namespace) - outNwStrSlice = append(outNwStrSlice, egressConnection.Labels) - outNwStrSlice = append(outNwStrSlice, egressConnection.Count) - outNwStrSlice = append(outNwStrSlice, egressConnection.UpdatedTime) - outNwRowData = append(outNwRowData, outNwStrSlice) - } - WriteTable(SysNwHeader, outNwRowData) - fmt.Printf("\n") - } - - if len(resp.BindConnection) > 0 { - fmt.Printf("\nBind Points\n") - // Display bind connections details - bindNwRowData := [][]string{} - for _, bindConnection := range resp.BindConnection { - bindNwStrSlice := []string{} - bindNwStrSlice = append(bindNwStrSlice, bindConnection.Protocol) - bindNwStrSlice = append(bindNwStrSlice, bindConnection.Command) - bindNwStrSlice = append(bindNwStrSlice, bindConnection.BindPort) - bindNwStrSlice = append(bindNwStrSlice, bindConnection.BindAddress) - bindNwStrSlice = append(bindNwStrSlice, bindConnection.Count) - bindNwStrSlice = append(bindNwStrSlice, bindConnection.UpdatedTime) - bindNwRowData = append(bindNwRowData, bindNwStrSlice) - } - WriteTable(SysBindNwHeader, bindNwRowData) - fmt.Printf("\n") - } - } -} - -func dnsLookup(ip string, revDNSLookup bool) string { - if revDNSLookup { - if strings.Contains(ip, "svc") || strings.Contains(ip, "pod") { - return ip - } - dns, err := net.LookupAddr(ip) - if err != nil { - return ip - } - if dns[0] != "" { - return dns[0] - } - } - return ip -} - -// WriteTable function -func WriteTable(header []string, data [][]string) { - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(header) - table.SetAlignment(tablewriter.ALIGN_LEFT) - for _, v := range data { - table.Append(v) - } - table.Render() -} - -func writePodInfoToTable(podname, namespace, clustername, containername, labels string) { - - fmt.Printf("\n") - - podinfo := [][]string{ - {"Pod Name", podname}, - {"Namespace Name", namespace}, - {"Cluster Name", clustername}, - {"Container Name", containername}, - {"Labels", labels}, - } - table := tablewriter.NewWriter(os.Stdout) - table.SetBorder(false) - table.SetTablePadding("\t") - table.SetCenterSeparator("") - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetAlignment(tablewriter.ALIGN_LEFT) - for _, v := range podinfo { - table.Append(v) - } - table.Render() -}