From e9d62111a8fe281f1a04947d242cb35ec0108927 Mon Sep 17 00:00:00 2001 From: Logan Ballard Date: Fri, 11 Oct 2024 13:04:41 -0400 Subject: [PATCH 1/2] Adding a count of each node type to the nodepool list --- main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 5539b9e..46f2560 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,7 @@ func main() { cmd.AddCommand(listCmd()) cmd.AddCommand(nodesCmd()) - ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT) err := cmd.ExecuteContext(ctx) cancel() @@ -145,7 +145,7 @@ func instanceType(node corev1.Node) string { type nodepool struct { Name string - Types map[string]bool + Types map[string]int Nodes uint } @@ -177,13 +177,13 @@ func listCmd() *cobra.Command { names = append(names, npName) np = &nodepool{ Name: npName, - Types: map[string]bool{ - instanceType(n): true, + Types: map[string]int{ + instanceType(n): 1, }, } nps[npName] = np } else { - np.Types[instanceType(n)] = true + np.Types[instanceType(n)]++ } np.Nodes += 1 } @@ -205,8 +205,9 @@ func listCmd() *cobra.Command { fmt.Fprintln(w, np.Name) } else { typeList := make([]string, 0, len(np.Types)) - for k := range np.Types { - typeList = append(typeList, k) + for k, v := range np.Types { + typeWithCount := fmt.Sprintf("%s (%d)", k, v) + typeList = append(typeList, typeWithCount) } sort.Strings(typeList) fmt.Fprintf(w, "%s\t%5d\t%s\n", np.Name, np.Nodes, strings.Join(typeList, ", ")) From fdc57acff0a260f14cfe8894e13036da654b16b8 Mon Sep 17 00:00:00 2001 From: Logan Ballard Date: Fri, 11 Oct 2024 13:15:25 -0400 Subject: [PATCH 2/2] updating go version --- Makefile | 4 ++-- go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b43ca0e..764fd5a 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ PKG ?= ./... checks: go vet $(PKG) - go run honnef.co/go/tools/cmd/staticcheck@latest $(PKG) - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run $(PKG) + go run honnef.co/go/tools/cmd/staticcheck@v0.4.7 $(PKG) + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run $(PKG) test: go test $(PKG) diff --git a/go.mod b/go.mod index c570181..ac3f432 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/grafana/kubectl-nodepools -go 1.19 +go 1.21 require ( github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index 9badbd1..b2cd7c5 100644 --- a/go.sum +++ b/go.sum @@ -174,7 +174,9 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= +github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo= github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= +github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -185,6 +187,7 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -192,6 +195,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=