Skip to content

Commit ecffb19

Browse files
Merge pull request #17 from voldemortensen/fix-deployments-nodes-services
fix deployments, nodes, and services commands, update deps
2 parents e83202b + 9a1c2e7 commit ecffb19

File tree

6 files changed

+781
-204
lines changed

6 files changed

+781
-204
lines changed

cmd/deployment.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/canopytax/ckube/util"
77
"github.com/manifoldco/promptui"
88
"github.com/spf13/cobra"
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
109
"strings"
1110
"time"
1211
)
@@ -72,12 +71,7 @@ func printDeploymentView() {
7271
}
7372

7473
func deploymentInfo() []DeploymentInfo {
75-
clientset := util.GetClientset(kubeconfig)
76-
77-
depList, err := clientset.AppsV1beta2().Deployments(namespace).List(metav1.ListOptions{})
78-
if err != nil {
79-
panic(fmt.Errorf("error listing deployments: %v", err))
80-
}
74+
depList := util.GetDeploymentList(namespace, context, labels)
8175

8276
var deploymentInfos []DeploymentInfo
8377
for _, deployment := range depList.Items {

cmd/nodes.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/fatih/color"
1111
"github.com/spf13/cobra"
1212
"k8s.io/api/core/v1"
13-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1413
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1514
)
1615

@@ -28,7 +27,6 @@ var nodesCmd = &cobra.Command{
2827
func printNodeView() {
2928
nodeMap := nodeMap()
3029
for _, nodePodInfo := range nodeMap {
31-
//fmt.Println(node)
3230
printNodeInfo(nodePodInfo.Node)
3331
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.StripEscape)
3432
headerLine := fmt.Sprintf("\t%v\t%v\t%v\t%v\t%v\t", "NAME", "READY", "STATUS", "RESTARTS", "AGE")
@@ -81,17 +79,7 @@ func NewPodStatus(pod v1.Pod) PodStatus {
8179
}
8280

8381
func nodeMap() map[string]NodePodInfo {
84-
clientset := util.GetClientset(kubeconfig)
85-
86-
podList, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{})
87-
if err != nil {
88-
panic(fmt.Errorf("error listing pods: %v", err))
89-
}
90-
91-
nodeList, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
92-
if err != nil {
93-
panic(fmt.Errorf("error listing pods: %v", err))
94-
}
82+
podList := util.GetPodList(namespace, context, labels)
9583

9684
nodeMap := make(map[string][]v1.Pod)
9785
for _, pod := range podList.Items {
@@ -102,6 +90,8 @@ func nodeMap() map[string]NodePodInfo {
10290
}
10391
}
10492

93+
nodeList := util.GetNodeList(context, labels)
94+
10595
nodePodMap := make(map[string]NodePodInfo)
10696
for _, node := range nodeList.Items {
10797
nodePodMap[node.Name] = NodePodInfo{Node: node, Pods: nodeMap[node.Name]}

cmd/service.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/manifoldco/promptui"
88
"github.com/spf13/cobra"
99
"k8s.io/api/core/v1"
10-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1211
)
1312

@@ -18,9 +17,6 @@ var serviceCmd = &cobra.Command{
1817
Short: "Interactive view of your services",
1918
Long: `Shows an interactive view of your services`,
2019
Run: func(cmd *cobra.Command, args []string) {
21-
if namespace == "" {
22-
namespace = "default"
23-
}
2420
showServiceView()
2521
},
2622
}
@@ -53,22 +49,14 @@ func showServiceView() {
5349
}
5450

5551
func getServiceInfo() []ServiceInfo {
56-
clientset := util.GetClientset(kubeconfig)
57-
58-
serviceList, err := clientset.CoreV1().Services(namespace).List(metav1.ListOptions{})
59-
if err != nil {
60-
panic(fmt.Errorf("error listing services: %v", err))
61-
}
52+
serviceList := util.GetServiceList(namespace, context, labels)
6253

6354
var serviceInfos []ServiceInfo
6455
for _, service := range serviceList.Items {
6556
selector := service.Spec.Selector
6657
if len(selector) > 0 {
58+
podList := util.GetPodList(namespace, context, util.KeysString(selector))
6759

68-
podList, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: util.KeysString(selector)})
69-
if err != nil {
70-
panic(fmt.Errorf("error listing pods: %v", err))
71-
}
7260
var podDetails []PodDetails
7361
for _, pod := range podList.Items {
7462
podDetails = append(podDetails, NewPodDetails(pod))

go.mod

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,11 @@ module github.com/canopytax/ckube
33
go 1.16
44

55
require (
6-
cloud.google.com/go v0.18.0 // indirect
7-
github.com/BurntSushi/toml v0.4.1 // indirect
8-
github.com/PuerkitoBio/purell v1.1.0 // indirect
9-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
10-
github.com/chzyer/logex v1.1.10 // indirect
11-
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3 // indirect
12-
github.com/chzyer/test v0.0.0-20210722231415-061457976a23 // indirect
13-
github.com/davecgh/go-spew v1.1.1 // indirect
14-
github.com/emicklei/go-restful v2.4.0+incompatible // indirect
15-
github.com/fatih/color v1.5.0
16-
github.com/fsnotify/fsnotify v1.4.2 // indirect
17-
github.com/ghodss/yaml v1.0.0 // indirect
18-
github.com/go-openapi/jsonpointer v0.0.0-20170102174223-779f45308c19 // indirect
19-
github.com/go-openapi/jsonreference v0.0.0-20161105162150-36d33bfe519e // indirect
20-
github.com/go-openapi/spec v0.0.0-20171206193454-01738944bdee // indirect
21-
github.com/go-openapi/swag v0.0.0-20171111214437-cf0bdb963811 // indirect
22-
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415 // indirect
23-
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
24-
github.com/golang/protobuf v0.0.0-20171113180720-1e59b77b52bf // indirect
25-
github.com/google/btree v0.0.0-20161217183710-316fb6d3f031 // indirect
26-
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
27-
github.com/googleapis/gnostic v0.1.0 // indirect
28-
github.com/gregjones/httpcache v0.0.0-20171119193500-2bcd89a1743f // indirect
29-
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect
30-
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
31-
github.com/imdario/mergo v0.0.0-20171009183408-7fe0c75c13ab // indirect
32-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
33-
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede // indirect
34-
github.com/juju/ansiterm v0.0.0-20161107204639-35c59b9e0fe2 // indirect
35-
github.com/juju/ratelimit v1.0.1 // indirect
36-
github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626 // indirect
37-
github.com/magiconair/properties v1.7.3 // indirect
38-
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect
39-
github.com/manifoldco/promptui v0.2.2-0.20171212205406-abacd3cb3a43
40-
github.com/mattn/go-colorable v0.0.9 // indirect
41-
github.com/mattn/go-isatty v0.0.3 // indirect
42-
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
43-
github.com/mitchellh/mapstructure v0.0.0-20171017171808-06020f85339e // indirect
44-
github.com/pelletier/go-toml v1.0.1 // indirect
45-
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
46-
github.com/spf13/afero v1.0.0 // indirect
47-
github.com/spf13/cast v1.1.0 // indirect
48-
github.com/spf13/cobra v0.0.1
49-
github.com/spf13/jwalterweatherman v0.0.0-20170901151539-12bd96e66386 // indirect
50-
github.com/spf13/pflag v1.0.0 // indirect
51-
github.com/spf13/viper v1.0.0
52-
github.com/stretchr/testify v1.7.0 // indirect
53-
golang.org/x/crypto v0.0.0-20171128194009-94eea52f7b74 // indirect
54-
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce // indirect
55-
golang.org/x/oauth2 v0.0.0-20180118004544-b28fcf2b08a1 // indirect
56-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
57-
golang.org/x/sys v0.0.0-20171214072955-1d2aa6dbdea4 // indirect
58-
golang.org/x/text v0.3.0 // indirect
59-
google.golang.org/appengine v1.0.0 // indirect
60-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
61-
gopkg.in/inf.v0 v0.9.0 // indirect
62-
gopkg.in/yaml.v2 v2.0.0-20171116090243-287cf08546ab // indirect
63-
k8s.io/api v0.0.0-20171214073027-400667919eb0
64-
k8s.io/apimachinery v0.0.0-20171207040628-a04e753f5223
65-
k8s.io/client-go v0.0.0-20171214154143-87887458218a
66-
k8s.io/kube-openapi v0.0.0-20171212221656-b16ebc07f5ca // indirect
6+
github.com/fatih/color v1.12.0
7+
github.com/manifoldco/promptui v0.8.0
8+
github.com/mitchellh/go-homedir v1.1.0
9+
github.com/spf13/cobra v1.2.1
10+
github.com/spf13/viper v1.8.1
11+
k8s.io/api v0.20.10
12+
k8s.io/client-go v0.20.10
6713
)

0 commit comments

Comments
 (0)