2018-10-08 13:17:05 +02:00
|
|
|
.PHONY: clean test check build.local build.linux build.osx build.docker build.push
|
|
|
|
|
|
|
|
BINARY ?= kube-metrics-adapter
|
|
|
|
VERSION ?= $(shell git describe --tags --always --dirty)
|
2018-10-14 11:37:58 +02:00
|
|
|
IMAGE ?= registry-write.opensource.zalan.do/teapot/$(BINARY)
|
2018-10-08 13:17:05 +02:00
|
|
|
TAG ?= $(VERSION)
|
|
|
|
SOURCES = $(shell find . -name '*.go')
|
|
|
|
DOCKERFILE ?= Dockerfile
|
|
|
|
GOPKGS = $(shell go list ./...)
|
|
|
|
BUILD_FLAGS ?= -v
|
2020-10-27 10:25:40 +01:00
|
|
|
OPENAPI ?= pkg/api/generated/openapi/zz_generated.openapi.go
|
2018-10-08 13:17:05 +02:00
|
|
|
LDFLAGS ?= -X main.version=$(VERSION) -w -s
|
2021-03-19 19:33:38 +01:00
|
|
|
CRD_SOURCES = $(shell find pkg/apis/zalando.org -name '*.go')
|
|
|
|
CRD_TYPE_SOURCE = pkg/apis/zalando.org/v1/types.go
|
|
|
|
GENERATED_CRDS = docs/scaling_schedules_crd.yaml
|
|
|
|
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
|
2018-10-08 13:17:05 +02:00
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
|
2018-10-08 13:17:05 +02:00
|
|
|
default: build.local
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf build
|
2020-10-27 10:25:40 +01:00
|
|
|
rm -rf $(OPENAPI)
|
2018-10-08 13:17:05 +02:00
|
|
|
|
2021-03-19 19:33:38 +01:00
|
|
|
test: $(GENERATED)
|
2021-02-19 10:31:20 +01:00
|
|
|
go test -v -coverprofile=profile.cov $(GOPKGS)
|
2018-10-08 13:17:05 +02:00
|
|
|
|
2021-03-19 19:33:38 +01:00
|
|
|
check: $(GENERATED)
|
2019-11-25 10:55:38 +01:00
|
|
|
go mod download
|
|
|
|
golangci-lint run --timeout=2m ./...
|
2018-10-08 13:17:05 +02:00
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
|
2021-03-19 19:33:38 +01:00
|
|
|
$(GENERATED): go.mod $(CRD_TYPE_SOURCE)
|
|
|
|
./hack/update-codegen.sh
|
|
|
|
|
|
|
|
$(GENERATED_CRDS): $(GENERATED) $(CRD_SOURCES)
|
|
|
|
go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:crdVersions=v1 paths=./pkg/apis/... output:crd:dir=docs || /bin/true || true
|
|
|
|
mv docs/zalando.org_clusterscalingschedules.yaml docs/cluster_scaling_schedules_crd.yaml
|
|
|
|
mv docs/zalando.org_scalingschedules.yaml docs/scaling_schedules_crd.yaml
|
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
$(OPENAPI): go.mod
|
|
|
|
go run k8s.io/kube-openapi/cmd/openapi-gen \
|
|
|
|
--go-header-file hack/boilerplate.go.txt \
|
|
|
|
--logtostderr \
|
|
|
|
-i 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/metrics/pkg/apis/metrics,k8s.io/metrics/pkg/apis/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 \
|
|
|
|
-p pkg/api/generated/openapi \
|
|
|
|
-o . \
|
|
|
|
-O zz_generated.openapi \
|
|
|
|
-r /dev/null
|
|
|
|
|
2018-10-08 13:17:05 +02:00
|
|
|
build.local: build/$(BINARY)
|
|
|
|
build.linux: build/linux/$(BINARY)
|
|
|
|
build.osx: build/osx/$(BINARY)
|
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
build/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
|
2018-10-08 13:17:05 +02:00
|
|
|
CGO_ENABLED=0 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .
|
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
build/linux/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
|
2018-10-08 13:17:05 +02:00
|
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/$(BINARY) -ldflags "$(LDFLAGS)" .
|
|
|
|
|
2020-10-27 10:25:40 +01:00
|
|
|
build/osx/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
|
2018-10-08 13:17:05 +02:00
|
|
|
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/osx/$(BINARY) -ldflags "$(LDFLAGS)" .
|
|
|
|
|
|
|
|
build.docker: build.linux
|
|
|
|
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) .
|
|
|
|
|
|
|
|
build.push: build.docker
|
|
|
|
docker push "$(IMAGE):$(TAG)"
|