-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ed417da
Showing
18 changed files
with
3,369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
/kubectl-dfi | ||
_output/ | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
env: | ||
- GO111MODULE=on | ||
before: | ||
hooks: | ||
- go mod download | ||
builds: | ||
- | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
main: cmd/kubectl-free/root.go | ||
binary: kubectl-free | ||
archives: | ||
- | ||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
amd64: x86_64 | ||
wrap_in_directory: true | ||
format: zip | ||
files: | ||
- LICENSE | ||
- README.md | ||
checksum: | ||
name_template: "{{ .ProjectName }}_checksums.txt" | ||
algorithm: sha256 | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
language: go | ||
|
||
go: | ||
- 1.12.6 | ||
|
||
env: | ||
- GO111MODULE=on | ||
|
||
install: true | ||
|
||
before_script: | ||
- go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
|
||
script: | ||
- golangci-lint run -E stylecheck -E gocritic | ||
- diff -u <(echo -n) <(gofmt -d .) | ||
- go test -v -race -coverprofile coverage.txt $(go list ./... | grep -v /constants | grep -v /cmd/kubectl-free) | ||
|
||
after_script: | ||
- bash <(curl -s https://codecov.io/bash) | ||
|
||
deploy: | ||
- provider: script | ||
skip_cleanup: true | ||
script: curl -sL https://git.io/goreleaser | bash | ||
on: | ||
tags: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 makocchi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
SHELL=/bin/bash -o pipefail | ||
|
||
GO ?= go | ||
GOLINT ?= golangci-lint | ||
|
||
COMMIT_HASH := $(shell git rev-parse --short HEAD 2> /dev/null || true) | ||
GIT_TAG := $(shell git describe --tags --dirty --always) | ||
|
||
LDFLAGS := -ldflags '-X main.commit=${COMMIT_HASH} -X main.date=$(shell date +%s) -X main.version=${GIT_TAG}' | ||
TESTPACKAGES := $(shell go list ./... | grep -v /constants | grep -v /cmd/) | ||
|
||
kubectl_free ?= _output/kubectl-free | ||
|
||
.PHONY: build | ||
build: clean ${kubectl_free} | ||
|
||
${kubectl_free}: | ||
GO111MODULE=on CGO_ENABLED=0 $(GO) build ${LDFLAGS} -o $@ ./cmd/kubectl-free/root.go | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -Rf _output | ||
|
||
.PHONY: test | ||
test: | ||
GO111MODULE=on $(GO) test -count=1 -v -race $(TESTPACKAGES) | ||
|
||
.PHONY: lint-install | ||
lint-install: | ||
GO111MODULE=on ${GO} install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
|
||
.PHONY: lint | ||
lint: | ||
GO111MODULE=on ${GOLINT} run -E stylecheck -E gocritic | ||
|
||
.PHONY: fmt | ||
fmt: | ||
${GO} fmt ./cmd/... ./pkg/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# kubectl free | ||
|
||
[![Build Status](https://travis-ci.org/makocchi-git/kubectl-free.svg?branch=master)](https://travis-ci.org/makocchi-git/kubectl-free) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/b92591d00becc95b11ca/maintainability)](https://codeclimate.com/github/makocchi-git/kubectl-free/maintainability) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/makocchi-git/kubectl-free)](https://goreportcard.com/report/github.com/makocchi-git/kubectl-free) | ||
[![codecov](https://codecov.io/gh/makocchi-git/kubectl-free/branch/master/graph/badge.svg)](https://codecov.io/gh/makocchi-git/kubectl-free) | ||
[![kubectl plugin](https://img.shields.io/badge/kubectl-plugin-blue.svg)](https://github.com/topics/kubectl-plugin) | ||
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) | ||
|
||
Print pod resources/limits usage on Kubernetes node(s) like a linux "free" command. | ||
|
||
```shell | ||
$ kubectl free | ||
NAME STATUS CPU/req CPU/alloc CPU/% MEM/req MEM/alloc MEM/% | ||
node1 Ready 350m 3600m 9% 73400K 5943865K 1% | ||
node2 Ready 553m 3600m 15% 216006K 5943865K 3% | ||
node3 Ready 455m 2 22% 52428K 3503149K 1% | ||
``` | ||
|
||
And list containers of pod on Kubernetes node(s). | ||
|
||
```shell | ||
$ kubectl free --list node1 | ||
NODE NAME POD POD IP POD STATUS NAMESPACE CONTAINER CPU/req CPU/lim MEM/req MEM/lim | ||
node1 calico-node-sml6z 10.8.2.87 Running kube-system calico-node 250m - - - | ||
node1 coredns-5695fb77c8-knc6d 10.112.1.3 Running kube-system coredns 100m - 73400K 178257K | ||
node1 kube-state-metrics-5f4459f5b8-7hrwz 10.112.1.42 Running kube-system kube-state-metrics 103m 103m 111149K 111149K | ||
node1 kube-state-metrics-5f4459f5b8-7hrwz 10.112.1.42 Running kube-system addon-resizer 100m 100m 31457K 31457K | ||
... | ||
``` | ||
|
||
## Install | ||
|
||
```shell | ||
$ make | ||
$ mv _output/kubectl-free /usr/local/bin/. | ||
|
||
# Happy free time! | ||
$ kubectl free | ||
``` | ||
|
||
## Usage | ||
|
||
```shell | ||
# Show pod resource usage of Kubernetes nodes. | ||
kubectl free | ||
|
||
# Show pod resource usage of Kubernetes nodes with number of pods and containers. | ||
kubectl free --pod | ||
|
||
# Using label selector. | ||
kubectl free -l key=value | ||
|
||
# Print raw(bytes) usage. | ||
kubectl free --bytes --without-unit | ||
|
||
# Using binary prefix unit (GiB, MiB, etc) | ||
kubectl free -g -B | ||
|
||
# List resources of containers in pods on nodes. | ||
kubectl free --list | ||
|
||
# List resources of containers in pods on nodes with image information. | ||
kubectl free --list --list-image | ||
|
||
# Print container even if that has no resources/limits. | ||
kubectl free --list --list-all | ||
|
||
# Do you like emoji? 😃 | ||
kubectl free --emoji | ||
kubectl free --list --emoji | ||
``` | ||
|
||
## License | ||
|
||
This software is released under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/makocchi-git/kubectl-free/pkg/cmd" | ||
"github.com/spf13/pflag" | ||
|
||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
) | ||
|
||
var ( | ||
// for goreleaser | ||
// https://goreleaser.com/customization/#Builds | ||
version = "master" | ||
commit = "unknown" | ||
date = "unknown" | ||
) | ||
|
||
func main() { | ||
flags := pflag.NewFlagSet("kubectl-free", pflag.ExitOnError) | ||
pflag.CommandLine = flags | ||
|
||
root := cmd.NewCmdFree( | ||
genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}, | ||
version, | ||
commit, | ||
date, | ||
) | ||
if err := root.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module github.com/makocchi-git/kubectl-free | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/gookit/color v1.1.7 | ||
github.com/spf13/cobra v0.0.2 | ||
github.com/spf13/pflag v1.0.1 | ||
k8s.io/api v0.0.0-20190531132109-d3f5f50bdd94 | ||
k8s.io/apimachinery v0.0.0-20190531131812-859a0ba5e71a | ||
k8s.io/cli-runtime v0.0.0-20190531135611-d60f41fb4dc3 | ||
k8s.io/client-go v11.0.0+incompatible | ||
k8s.io/kubernetes v1.14.3 | ||
) | ||
|
||
replace ( | ||
github.com/Sirupsen/logrus => github.com/sirupsen/logrus v1.4.2 | ||
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190607191414-238f8eaa31aa | ||
github.com/russross/blackfriday => github.com/russross/blackfriday v1.5.2 | ||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190531132438-d58e65e5f4b1 | ||
k8s.io/kubernetes => k8s.io/kubernetes v1.14.2 | ||
) |
Oops, something went wrong.