Skip to content

Commit 1235337

Browse files
aalubinlwolf
authored andcommitted
Feautre/makefile (#10)
* new and improved Makefile that supports Quay.io and remove redundant check * travis changes
1 parent 1f91079 commit 1235337

File tree

4 files changed

+65
-22
lines changed

4 files changed

+65
-22
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ install:
66
- make install_deps
77

88
script:
9-
- make bin/linux/kube-cleanup-operator
10-
- make bin/darwin/kube-cleanup-operator
9+
- NAME=GOOS=linux GOARCH=amd64 go build -o bin/kube-cleanup-operator-linux-amd64 ./cmd
10+
- NAME=GOOS=darwin GOARCH=amd64 go build -o bin/kube-cleanup-operator-darwin-amd64 ./cmd
1111
- mkdir bin/release
12-
- mv bin/linux/kube-cleanup-operator bin/release/kube-cleanup-operator-linux
13-
- mv bin/darwin/kube-cleanup-operator bin/release/kube-cleanup-operator-darwin
12+
- mv bin/kube-cleanup-operator-linux-amd64 bin/release/kube-cleanup-operator-linux-amd64
13+
- mv bin/kube-cleanup-operator-darwin-amd64 bin/release/kube-cleanup-operator-darwin-amd64
1414

1515
deploy:
1616
provider: releases

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ RUN addgroup -S kube-operator && adduser -S -g kube-operator kube-operator
55

66
USER kube-operator
77

8-
COPY bin/linux/kube-cleanup-operator .
8+
COPY bin/kube-cleanup-operator .
99

1010
ENTRYPOINT ["./kube-cleanup-operator"]

Makefile

+59-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,66 @@
1-
OPERATOR_NAME := kube-cleanup-operator
2-
VERSION := $(shell date +%Y%m%d%H%M)
3-
IMAGE := lwolf/$(OPERATOR_NAME)
1+
NAME:= kube-cleanup-operator
2+
AUTHOR=lwolf
3+
VERSION=0.3
4+
REGISTRY := quay.io
5+
GIT_SHA=$(shell git --no-pager describe --always --dirty)
6+
BUILD_TIME=$(shell date '+%s')
7+
LFLAGS ?= -X main.gitsha=${GIT_SHA} -X main.compiled=${BUILD_TIME}
8+
ROOT_DIR=${PWD}
9+
GOVERSION ?= 1.9.2
10+
HARDWARE=$(shell uname -m)
411

5-
.PHONY: install_deps build build-image
12+
.PHONY: authors changelog build docker static release install_deps
13+
14+
default: build
15+
16+
golang:
17+
@echo "--> Go Version"
18+
@go version
619

720
install_deps:
821
dep ensure
922

10-
build:
11-
rm -rf bin/%/$(OPERATOR_NAME)
12-
go build -v -i -o bin/$(OPERATOR_NAME) ./cmd
23+
build: golang
24+
@echo "--> Compiling the project"
25+
@mkdir -p bin
26+
go build -ldflags "${LFLAGS}" -o bin/$(NAME) ./cmd
27+
28+
static: golang
29+
@echo "--> Compiling the static binary"
30+
@mkdir -p bin
31+
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -tags netgo -ldflags "-w ${LFLAGS}" -o bin/${NAME} ./cmd
32+
33+
docker-build:
34+
@echo "--> Compiling the project"
35+
docker run --rm \
36+
-v ${ROOT_DIR}:/go/src/github.com/${AUTHOR}/${NAME} \
37+
-w /go/src/github.com/${AUTHOR}/${NAME} \
38+
-e GOOS=linux golang:${GOVERSION} \
39+
make static
40+
41+
docker-release:
42+
@echo "--> Building a release image"
43+
@$(MAKE) static
44+
@$(MAKE) docker
45+
@docker push ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION}
46+
47+
docker:
48+
@echo "--> Building the docker image"
49+
docker build -t ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION} .
50+
51+
release: static
52+
mkdir -p release
53+
gzip -c bin/${NAME} > release/${NAME}_${VERSION}_linux_${HARDWARE}.gz
54+
rm -f release/${NAME}
55+
56+
clean:
57+
rm -rf ./bin 2>/dev/null
58+
rm -rf ./release 2>/dev/null
1359

14-
bin/%/$(OPERATOR_NAME):
15-
rm -rf bin/%/$(OPERATOR_NAME)
16-
GOOS=$* GOARCH=amd64 go build -v -i -o bin/$*/$(OPERATOR_NAME) ./cmd
60+
authors:
61+
@echo "--> Updating the AUTHORS"
62+
git log --format='%aN <%aE>' | sort -u > AUTHORS
1763

18-
build-image: bin/linux/$(OPERATOR_NAME)
19-
docker build . -t $(IMAGE):$(VERSION)
64+
format:
65+
@echo "--> Running go fmt"
66+
@gofmt -s -w ./

pkg/controller/controller.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func NewPodController(kclient *kubernetes.Clientset, opts map[string]string) *Po
4949
return kclient.CoreV1().Pods(opts["namespace"]).List(options)
5050
},
5151
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
52+
5253
return kclient.CoreV1().Pods(opts["namespace"]).Watch(options)
5354
},
5455
},
@@ -97,11 +98,6 @@ func (c *PodController) doTheMagic(cur interface{}, keepSuccessHours int, keepFa
9798
if createdMeta.Reference.Kind != "Job" {
9899
return
99100
}
100-
// if restartCount is not 0, do not delete
101-
restartCounts := podObj.Status.ContainerStatuses[0].RestartCount
102-
if restartCounts != 0 {
103-
return
104-
}
105101

106102
executionTimeHours := c.getExecutionTimeHours(podObj)
107103
log.Printf("Checking pod %s with %s status that was executed %f hours ago", podObj.Name, podObj.Status.Phase, executionTimeHours)

0 commit comments

Comments
 (0)