Skip to content

Commit

Permalink
prepare for first release (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Aug 27, 2021
1 parent 18dbb75 commit b1e2003
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# you may remove this if you don't use vgo
# - go mod download
# you may remove this if you don't need go generate
# - go generate ./...
builds:
-
# Path to main.go file or main package.
# Default is `.`.
main: ./cmd
# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`.
ldflags:
- "-s -w -X github.com/xcoulon/kubectl-terminate/cmd.BuildCommit={{.Commit}} github.com/xcoulon/kubectl-terminate/cmd.BuildTag={{.Version}} -X github.com/xcoulon/kubectl-terminate/cmd.BuildTime={{.Date}}"
env:
- CGO_ENABLED=0
archive:
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ image:https://github.com/xcoulon/kubectl-terminate/workflows/CI/badge.svg["CI",
image:https://codecov.io/gh/xcoulon/kubectl-terminate/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/xcoulon/kubectl-terminate"]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg["License", link="https://opensource.org/licenses/Apache-2.0"]

WARNING:: Use at your own risk!
WARNING:: *Use at your own risk!*

Sometimes you may find yourself with a namespace stuck in `Terminating` phase because one of its resource has a finalizer, but the operator (or controller) in charge of dealing with this finalizer is already gone (for example, it has been uninstalled). This is quite annoying and all the `--force`, `grace-period`, etc. flags won't help. The only way to get rid of the resource is to PATCH it to remove the finalizers, then delete it. Doing it with a good old `curl` command is possible, but let's admit it, it's a bit cumbersome 😬
Sometimes (hopefully on your dev cluster) you may find yourself with a namespace stuck in `Terminating` phase because one of its child resource has a finalizer, but the operator (or controller) in charge of dealing with this finalizer is already gone (for example, it has been uninstalled). This is quite annoying and sadly the `--force`, `grace-period`, etc. flags won't help. The only way to get rid of the resource is to PATCH it in order to remove the finalizers, then delete it. Doing it with a good old `curl` command is possible, but let's admit it, it's a bit cumbersome 😬

Say hello to `kubectl-terminate` 👋

Expand Down
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // required for GKE
)

var (
// BuildCommit lastest build commit (set by Makefile)
BuildCommit = ""
// BuildTag if the `BuildCommit` matches a tag
BuildTag = ""
// BuildTime set by build script (set by Makefile)
BuildTime = ""
)

func main() {
terminate.InitAndExecute()
}
26 changes: 21 additions & 5 deletions make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@ GO_PACKAGE_PATH ?= github.com/${GO_PACKAGE_ORG_NAME}/${GO_PACKAGE_REPO_NAME}
GO111MODULE?=on
export GO111MODULE

CUR_DIR=$(shell pwd)
INSTALL_PREFIX=$(CUR_DIR)/bin

ifeq ($(OS),Windows_NT)
BINARY_PATH=$(INSTALL_PREFIX)/kubectl-terminate.exe
else
BINARY_PATH=$(INSTALL_PREFIX)/kubectl-terminate
endif

.PHONY: build
## Build the operator
build:
@echo "building..."
@-CGO_ENABLED=0 \
go build \
-o $(OUT_DIR)/kubectl-terminate \
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))
$(eval BUILD_TAG:=$(shell git tag --contains $(BUILD_COMMIT)))
$(eval BUILD_TIME:=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ'))
@echo "building with commit:$(BUILD_COMMIT) / tag:$(BUILD_TAG) / time:$(BUILD_TIME)"
@CGO_ENABLED=0 \
go build -ldflags \
"-X github.com/xcoulon/kubectl-terminate/BuildCommit=$(BUILD_COMMIT) \
-X github.com/xcoulon/kubectl-terminate/main.BuildTag=$(BUILD_TAG) \
-X github.com/xcoulon/kubectl-terminate/main.BuildTime=$(BUILD_TIME)" \
-o $(BINARY_PATH) \
cmd/main.go
@echo "$(BINARY_PATH) is ready to use"

.PHONY: install
## Builds and installs the operator in $GOPATH/bin
install: build
@echo "installing..."
mv $(OUT_DIR)/kubectl-terminate $(GOPATH)/bin
mv $(BINARY_PATH) $(GOPATH)/bin

0 comments on commit b1e2003

Please sign in to comment.