-
Notifications
You must be signed in to change notification settings - Fork 102
/
Makefile
205 lines (165 loc) · 5.59 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright © 2018 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2-Clause
IMAGE ?= vmware/kube-fluentd-operator
TAG ?= latest
TARGETARCH ?= $(shell go env GOARCH)
TARGETOS ?= linux
VERSION ?= $(shell git describe --tags --always --dirty)
BUILD_FLAGS := -v
LDFLAGS := -X github.com/vmware/kube-fluentd-operator/config-reloader/config.Version=$(VERSION) -w -s
SHELL = bash
PKG = vmware/kube-fluentd-operator
GO_OPTS = GO111MODULE=on GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GOBIN=$(GOBIN)
GO = $(GO_OPTS) go
CURRENT_DIR = $(shell pwd)
DEV_ENV_IMAGE := vmwaresaas.jfrog.io/vdp-public/go-dev:latest-1.21-amd64
DEV_ENV_WORK_DIR := /go/src/${PKG}
DEV_ENV_CMD := docker run --rm -v ${CURRENT_DIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
.DEFAULT_GOAL := build-image
all: test build
.PHONY: test-image
dev:
${DEV_ENV_CMD} bash
vendor:
cd config-reloader && ${GO} mod vendor
install:
${GO} install -v .
tidy:
${GO} mod tidy -v
test: lint test-unit
lint: vendor
${DEV_ENV_CMD} lint
test-unit: vendor
${DEV_ENV_CMD} go test --cover --race -v ./...
in-docker-test:
go test --cover --race -v ./...
test-cover: vendor
${DEV_ENV_CMD} test-cover.sh
report-cover: test-cover
${DEV_ENV_CMD} report-cover.sh
test-clean:
rm -rf coverage.*
build:
${GO} build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .
dep:
which dep > /dev/null || (echo "Install dep first: go get -u github.com/golang/dep/cmd/dep" && exit 1)
dep ensure
guess-tag:
@echo "TAG=`git describe --tags --always`"
clean:
rm -fr config-reloader pkg > /dev/null
build-image:
DOCKER_BUILDKIT=1 docker build --platform $(TARGETOS)/$(TARGETARCH) --build-arg VERSION=$(VERSION) -t $(IMAGE):$(TAG) .
push-image: build-image
docker push $(IMAGE):$(TAG)
buildx-image:
docker buildx create --use --name=multiarch --node=multiarch
docker run --rm --privileged tonistiigi/binfmt:latest --install all
# due to a limitation of docker buildx exporter/docker we can only build one without pushing
# https://github.com/docker/buildx/issues/59
docker buildx build \
--platform=linux/$(TARGETARCH) \
--build-arg VERSION=$(VERSION) \
--load \
-t $(IMAGE):$(TAG) .
pushx-image:
docker buildx create --use --name=multiarch --node=multiarch
docker run --rm --privileged tonistiigi/binfmt:latest --install all
docker buildx build \
--platform=linux/arm64,linux/amd64 \
--build-arg VERSION=$(VERSION) \
--push=true \
--tag $(IMAGE):$(TAG) \
--tag $(IMAGE):latest .
create-test-ns:
HUMIO_KEY=$(HUMIO_KEY) LOGZ_TOKEN=$(LOGZ_TOKEN) envsubst '$$LOGZ_TOKEN:$$HUMIO_KEY' < examples/manifests/kfo-test.yaml | kubectl apply -f -
delete-test-ns:
kubectl delete -f examples/manifests/kfo-test.yaml
run-loop-fs: build
rm -fr tmp
./config-reloader \
--interval 5 \
--log-level=debug \
--output-dir=tmp \
--meta-key=prefix \
--meta-values=aws_region=us-west-2,csp_cluster=mon \
--templates-dir=templates \
--datasource=fs \
--fs-dir=examples \
--fluentd-binary "fluentd/fake-fluentd.sh -p /plugins"
run-once-fs: build
rm -fr tmp
./config-reloader \
--interval 0 \
--log-level=debug \
--fluentd-loglevel=debug \
--buffer-mount-folder="" \
--output-dir=tmp \
--meta-key=prefix2 \
--meta-values=aws_region=us-west-2,csp_cluster=mon \
--templates-dir=templates \
--datasource=fs \
--fs-dir=examples \
--fluentd-binary "fluentd/fake-fluentd.sh -p /plugins"
run-once: build
rm -fr tmp
./config-reloader \
--interval 0 \
--log-level=debug \
--fluentd-loglevel=debug \
--buffer-mount-folder="" \
--output-dir=tmp \
--templates-dir=templates \
--meta-key=run-once \
--meta-values=aws_region=us-west-2,csp_cluster=mon \
--fluentd-binary "fluentd/fake-fluentd.sh -p /plugins"
run-loop: build
rm -fr tmp
./config-reloader \
--interval 5 \
--log-level=debug \
--fluentd-loglevel=debug \
--buffer-mount-folder="" \
--output-dir=tmp \
--meta-key=prefix3 \
--meta-values=aws_region=us-west-2,csp_cluster=mon \
--templates-dir=templates
run-fluentd:
docker run --entrypoint=fluentd \
-ti --rm -v `pwd`:/workspace --net=host \
$(IMAGE):$(TAG) \
-p /fluentd/plugins -v -c /workspace/local-fluent.conf
dep-graph:
godepgraph -s \
-l 4 \
-p github.com/alecthomas/units,github.com/alecthomas/template,github.com/spf13,github.com/jackc,k8s.io/kubernetes,k8s.io/apimachinery,github.com/palantir,github.com/sirupsen,github.com/prometheus,golang.org,gopkg.in \
github.com/vmware/kube-fluentd-operator/config-reloader \
| sed 's|github.com/vmware/kube-fluentd-operator/config-reloader/||g'\
| dot -Tpng -o godepgraph.png
validate-config:
docker run --entrypoint=fluentd \
-ti --rm -v `pwd`:/workspace --net=host \
$(IMAGE):$(TAG) \
--dry-run -p /fluentd/plugins -v -c /workspace/tmp/fluent.conf
shell:
docker run --entrypoint=/bin/bash \
-ti --rm -v `pwd`:/workspace --net=host \
$(IMAGE):$(TAG)
test-image: build-image
docker run -t --rm \
--net=host \
-v `pwd`:/workspace \
-v `pwd`/image/test/containers:/var/log/containers \
-v `pwd`/image/test/input.conf:/fluentd/etc/input.conf \
-v `pwd`/image/test/local.conf:/fluentd/etc/fluent.conf \
-e FLUENTD_OPT="--no-supervisor" \
$(IMAGE):$(TAG)
list-gems:
@docker run -ti --rm \
--net=host --entrypoint /bin/bash \
$(IMAGE):$(TAG) \
-c 'fluent-gem list' | \
grep '^fluent' | sed 's/^/* /'
build-test-ci: build-image
cd image && TEST_IMAGE_NAME=$(IMAGE) TEST_IMAGE_TAG=$(TAG) go test -mod=readonly -v -count=1 --race ./...
cd config-reloader && go test -mod=readonly -v -count=1 --race ./...