-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
92 lines (76 loc) · 3.92 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
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE.txt file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
VERSION ?= $(shell cat VERSION)
REGISTRY ?= docker.elastic.co
NAMESPACE ?= elasticsearch-k8s-metrics-adapter
IMAGE ?= elasticsearch-metrics-adapter
TEMP_DIR := $(shell mktemp -d)
ARCH ?= amd64
SHA1 ?= $(shell git rev-parse --short=12 --verify HEAD)
GO_LD_FLAGS := -X main.serviceVersion=$(SHA1)
.PHONY: all docker-build build-elasticsearch-k8s-metrics-adapter test test-adapter-container go-run
all: build-elasticsearch-k8s-metrics-adapter check-license-header
build-elasticsearch-k8s-metrics-adapter: check-license-header generated/openapi/zz_generated.openapi.go
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -ldflags "$(GO_LD_FLAGS)" -o elasticsearch-k8s-metrics-adapter github.com/elastic/elasticsearch-k8s-metrics-adapter
tidy:
go mod tidy
test:
CGO_ENABLED=0 go test -coverprofile=./coverage.out ./pkg/...
test-kind:
kind load docker-image $(REGISTRY)/$(NAMESPACE)/$(IMAGE)-$(ARCH):$(VERSION)
kubectl apply -f deploy/elasticsearch-k8s-metrics-adapter.yaml
kubectl rollout restart -n custom-metrics deployment/custom-metrics-apiserver
check-license-header:
@ hack/check/check-license-header.sh
generate-notice-file:
go install go.elastic.co/[email protected]
go list -mod=mod -m -json all | go-licence-detector -noticeOut=NOTICE.txt -noticeTemplate=hack/notice/NOTICE.txt.tmpl -includeIndirect -overrides=hack/notice/overrides/overrides.json -rules=hack/notice/rules.json
generated/openapi/zz_generated.openapi.go: go.mod go.sum
go run k8s.io/kube-openapi/cmd/openapi-gen --logtostderr \
--go-header-file ./hack/boilerplate.go.txt \
--output-dir ./ \
--output-pkg github.com/elastic/elasticsearch-k8s-metrics-adapter/generated/openapi \
--output-file zz_generated.openapi \
--report-filename /dev/null \
k8s.io/metrics/pkg/apis/custom_metrics k8s.io/metrics/pkg/apis/custom_metrics/v1beta1 k8s.io/metrics/pkg/apis/custom_metrics/v1beta2 k8s.io/metrics/pkg/apis/external_metrics k8s.io/metrics/pkg/apis/external_metrics/v1beta1 k8s.io/apimachinery/pkg/apis/meta/v1 k8s.io/apimachinery/pkg/api/resource k8s.io/apimachinery/pkg/version k8s.io/api/core/v1 \
docker-build: generated/openapi/zz_generated.openapi.go generate-notice-file check-license-header
docker build . \
--progress=plain \
--build-arg VERSION='$(VERSION)' \
--build-arg SOURCE_COMMIT='$(SHA1)' \
-t $(REGISTRY)/$(NAMESPACE)/$(IMAGE)-$(ARCH):$(VERSION)
go-run: ## Run the adapter program locally for development purposes.
go run -ldflags "$(GO_LD_FLAGS)" main.go \
--lister-kubeconfig ${HOME}/.kube/config \
--authentication-kubeconfig ${HOME}/.kube/config \
--authorization-kubeconfig ${HOME}/.kube/config \
--secure-port=6443 \
--v=2 \
--insecure ## Allow unauthenticated calls
BUILD_PLATFORM ?= "linux/amd64,linux/arm64"
docker-multiarch-build: generated/openapi/zz_generated.openapi.go generate-notice-file check-license-header
docker buildx build . \
--progress=plain \
--build-arg VERSION='$(VERSION)' \
--build-arg SOURCE_COMMIT='$(SHA1)' \
--platform $(BUILD_PLATFORM) \
-t $(REGISTRY)/$(NAMESPACE)/$(IMAGE):$(VERSION) \
--push
##@ Helm
.PHONY: validate-helm
validate-helm:
helm lint helm && helm template helm