Repository: robscott/kube-capacity
Pull request #181: automate dev setup
Author: login: grosser
Created: 2025-01-29T01:00:29Z | Merged: 2025-03-24T03:18:41Z

@robscott 


Diff:
diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml
index 7a48173e..f2076fa7 100644
--- a/.github/workflows/golangci-lint.yaml
+++ b/.github/workflows/golangci-lint.yaml
@@ -18,13 +18,13 @@ jobs:
     steps:
       - uses: actions/setup-go@v5
         with:
-          go-version: 1.21
+          go-version: 1.23 # keep in sync with go.mod
       - uses: actions/checkout@v4
       - name: golangci-lint
         uses: golangci/golangci-lint-action@v6
         with:
           # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
-          version: v1.56.1
+          version: v1.61.0 # keep in sync with Makefile
 
           # Optional: working directory, useful for monorepos
           # working-directory: somedir
@@ -43,4 +43,4 @@ jobs:
           # skip-pkg-cache: true
 
           # Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
-          # skip-build-cache: true
\ No newline at end of file
+          # skip-build-cache: true
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 32ebd66c..26749f07 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -19,10 +19,10 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v5
         with:
-          go-version: 1.21
+          go-version: 1.23 # keep in sync with go.mod
 
       - name: Build
-        run: go build -v ./...
+        run: make build
 
       - name: Test
-        run: go test -v ./...
\ No newline at end of file
+        run: make test
diff --git a/.gitignore b/.gitignore
index fadcd22f..13231a9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,8 @@
 *.dylib
 main
 dist
+bin
+kubectl-resource_capacity
 
 # Test binary, built with `go test -c`
 *.test
@@ -14,4 +16,4 @@ dist
 *.out
 
 vendor
-.idea
\ No newline at end of file
+.idea
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..318af7cb
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+# default task since it's first
+.PHONY: all
+all: build lint test
+
+.PHONY: build
+build:
+	go build -o kubectl-resource_capacity main.go
+
+.PHONY: lint
+lint: golangci-lint
+	$(GOLANGCI_LINT) run --fix
+
+.PHONY: test
+test:
+	go test -v ./...
+
+## Location to install dependencies to
+LOCALBIN ?= $(shell pwd)/bin
+$(LOCALBIN):
+	mkdir -p $(LOCALBIN)
+
+# keep version in sync with .github/workflows/golangci-lint.yaml
+GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
+GOLANGCI_LINT_VERSION ?= 1.61.0
+
+.PHONY: golangci-lint
+golangci-lint: $(LOCALBIN) ## Download golangci-lint (replace existing if incorrect version). Should only be used locally, not in CI.
+	@(test -f $(GOLANGCI_LINT) && $(GOLANGCI_LINT) --version | grep " $(GOLANGCI_LINT_VERSION) " >/dev/null) || \
+	(rm -f $(GOLANGCI_LINT) && echo "Installing $(GOLANGCI_LINT) $(GOLANGCI_LINT_VERSION)" && \
+	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) -d v$(GOLANGCI_LINT_VERSION))
diff --git a/README.md b/README.md
index 373f5ae6..56dd91c4 100644
--- a/README.md
+++ b/README.md
@@ -210,6 +210,12 @@ There are already some great projects out there that have similar goals.
 - [kube-resource-report](https://github.com/hjacobs/kube-resource-report): generates HTML/CSS report for resource requests and limits across multiple clusters.
 - [kubetop](https://github.com/LeastAuthority/kubetop): a CLI similar to top for Kubernetes, focused on resource utilization (not requests and limits).
 
+## Development
+
+run `make` to run all tests
+
+see `Makefile` for more commands
+
 ## Contributors
 
 Although this project was originally developed by [robscott](https://github.com/robscott), there have been some great contributions from others:
diff --git a/go.mod b/go.mod
index 2e5e8a5f..0ea1ae99 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module github.com/robscott/kube-capacity
 
-go 1.21
+go 1.23 // keep in sync with .github/workflows/test.yaml and .github/workflows/golangci-lint.yaml
 
 require (
 	github.com/spf13/cobra v1.8.1
diff --git a/pkg/capacity/csv.go b/pkg/capacity/csv.go
index 211ac88f..ebe3cf18 100644
--- a/pkg/capacity/csv.go
+++ b/pkg/capacity/csv.go
@@ -120,7 +120,7 @@ func (cp *csvPrinter) printLine(cl *csvLine) {
 
 	lineItems := cp.getLineItems(cl)
 
-	_, _ = fmt.Fprint(cp.file, strings.Join(lineItems[:], separator)+"\n")
+	_, _ = fmt.Fprintln(cp.file, strings.Join(lineItems[:], separator))
 }
 
 func (cp *csvPrinter) getLineItems(cl *csvLine) []string {
diff --git a/pkg/capacity/table.go b/pkg/capacity/table.go
index 8e9a96c1..4e3ebd87 100644
--- a/pkg/capacity/table.go
+++ b/pkg/capacity/table.go
@@ -107,7 +107,7 @@ func (tp *tablePrinter) Print() {
 
 func (tp *tablePrinter) printLine(tl *tableLine) {
 	lineItems := tp.getLineItems(tl)
-	_, _ = fmt.Fprint(tp.w, strings.Join(lineItems[:], "\t ")+"\n")
+	_, _ = fmt.Fprintln(tp.w, strings.Join(lineItems[:], "\t "))
 }
 
 func (tp *tablePrinter) getLineItems(tl *tableLine) []string {


Reviews:
user: login: grosser
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T04:32:39Z
user: login: grosser
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T04:33:16Z

Review comments:
diff_hunk: @@ -19,10 +19,10 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v5
         with:
-          go-version: 1.21
+          go-version: 1.23 # keep in sync with go.mod
 
       - name: Build
-        run: go build -v ./...
path: .github/workflows/test.yaml
user: login: grosser
body: this did not produce the binary, so changed to `go build main.go` in Makefile
created_at: 2025-03-12T04:32:39Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,30 @@
+# default task since it's first
+.PHONY: all
+all: build lint test
+
+.PHONY: build
+build:
+	go build -o kubectl-resource_capacity main.go
path: Makefile
user: login: grosser
body: using this binary name because it can be added to users path and used locally which is great for dog-fooding a PR
created_at: 2025-03-12T04:33:16Z
author_association: CONTRIBUTOR

PR comments:
user: login: grosser
created_at: 2025-02-28T20:06:18Z
body: 👋 @robscott need another CI approval and a review 🙇 
author_association: CONTRIBUTOR
user: login: grosser
created_at: 2025-03-12T04:32:04Z
body: @robscott another CI run plz 😭 
author_association: CONTRIBUTOR
user: login: grosser
created_at: 2025-03-23T17:06:10Z
body: @robscott ready to merge ?
author_association: CONTRIBUTOR
user: login: robscott
created_at: 2025-03-24T03:18:38Z
body: Thanks @grosser!
author_association: OWNER