Skip to content

Commit

Permalink
move to subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 30, 2023
1 parent 0d37b8f commit b5e8e6f
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 443 deletions.
36 changes: 9 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
OS ?= $(shell uname -s | tr A-Z a-z)
ALL_ARCH = amd64 arm arm64 ppc64le s390x
PKG = github.com/prometheus/common
PROMETHEUS_VERSION = 2.45.0
GO_VERSION = 1.20.6
PROMETHEUS_VERSION = 2.37.0
GO_VERSION = 1.19.2
IMAGE = $(REGISTRY)/kube-state-metrics
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
USER ?= $(shell id -u -n)
Expand All @@ -43,11 +43,6 @@ licensecheck:

lint: shellcheck licensecheck
golangci-lint run
cd exp/metric-gen && golangci-lint run

lint-fix:
golangci-lint run --fix -v
cd exp/metric-gen && golangci-lint run --fix -v

doccheck: generate
@echo "- Checking if the generated documentation is up to date..."
Expand All @@ -65,18 +60,10 @@ doccheck: generate
build-local:
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Version=${TAG} -X ${PKG}/version.Revision=${GIT_COMMIT} -X ${PKG}/version.Branch=${BRANCH} -X ${PKG}/version.BuildUser=${USER}@${HOST} -X ${PKG}/version.BuildDate=${BUILD_DATE}" -o kube-state-metrics

build-metric-gen-local:
cd exp/metric-gen && GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Version=${TAG} -X ${PKG}/version.Revision=${GIT_COMMIT} -X ${PKG}/version.Branch=${BRANCH} -X ${PKG}/version.BuildUser=${USER}@${HOST} -X ${PKG}/version.BuildDate=${BUILD_DATE}" -o ../../metric-gen

build: kube-state-metrics metric-gen
build: kube-state-metrics

kube-state-metrics:
# Need to update git setting to prevent failing builds due to https://github.com/docker-library/golang/issues/452
${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} git config --global --add safe.directory "*" && make build-local

metric-gen:
# Need to update git setting to prevent failing builds due to https://github.com/docker-library/golang/issues/452
${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} git config --global --add safe.directory "*" && make build-metric-gen-local
${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} make build-local

test-unit:
GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) $(TESTENVVAR) go test --race $(FLAGS) $(PKGS)
Expand All @@ -91,7 +78,7 @@ shellcheck:
# the two.
test-benchmark-compare:
@git fetch
./tests/compare_benchmarks.sh main
./tests/compare_benchmarks.sh master
./tests/compare_benchmarks.sh ${LATEST_RELEASE_BRANCH}

all: all-container
Expand Down Expand Up @@ -123,7 +110,7 @@ push-multi-arch:
${DOCKER_CLI} manifest push --purge $(IMAGE):$(TAG)

clean:
rm -f kube-state-metrics metric-gen
rm -f kube-state-metrics
git clean -Xfd .

e2e:
Expand All @@ -143,7 +130,7 @@ examples/prometheus-alerting-rules/alerts.yaml: jsonnet $(shell find jsonnet | g
mkdir -p examples/prometheus-alerting-rules
jsonnet -J scripts/vendor scripts/mixin.jsonnet | gojsontoyaml > examples/prometheus-alerting-rules/alerts.yaml

examples: examples/standard examples/autosharding examples/daemonsetsharding mixin
examples: examples/standard examples/autosharding mixin

examples/standard: jsonnet $(shell find jsonnet | grep ".libsonnet") scripts/standard.jsonnet scripts/vendor VERSION
mkdir -p examples/standard
Expand All @@ -155,21 +142,16 @@ examples/autosharding: jsonnet $(shell find jsonnet | grep ".libsonnet") scripts
jsonnet -J scripts/vendor -m examples/autosharding --ext-str version="$(VERSION)" scripts/autosharding.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > `echo {} | sed "s/\(.\)\([A-Z]\)/\1-\2/g" | tr "[:upper:]" "[:lower:]"`.yaml' -- {}
find examples -type f ! -name '*.yaml' -delete

examples/daemonsetsharding: jsonnet $(shell find jsonnet | grep ".libsonnet") scripts/daemonsetsharding.jsonnet scripts/vendor VERSION
mkdir -p examples/daemonsetsharding
jsonnet -J scripts/vendor -m examples/daemonsetsharding --ext-str version="$(VERSION)" scripts/daemonsetsharding.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > `echo {} | sed "s/\(.\)\([A-Z]\)/\1-\2/g" | tr "[:upper:]" "[:lower:]"`.yaml' -- {}
find examples -type f ! -name '*.yaml' -delete

scripts/vendor: scripts/jsonnetfile.json scripts/jsonnetfile.lock.json
cd scripts && jb install

install-tools:
@echo Installing tools from tools.go
grep '^\s*_' tools/tools.go | awk '{print $$2}' | xargs -tI % go install -mod=readonly -modfile=tools/go.mod %
@cat tools/tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %

install-promtool:
@echo Installing promtool
@wget -qO- "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.${OS}-${ARCH}.tar.gz" |\
tar xvz --strip-components=1 prometheus-${PROMETHEUS_VERSION}.${OS}-${ARCH}/promtool

.PHONY: all build build-local all-push all-container container container-* do-push-* sub-push-* push push-multi-arch test-unit test-rules test-benchmark-compare clean e2e validate-modules shellcheck licensecheck lint lint-fix generate embedmd
.PHONY: all build build-local all-push all-container container container-* do-push-* sub-push-* push push-multi-arch test-unit test-rules test-benchmark-compare clean e2e validate-modules shellcheck licensecheck lint generate embedmd
74 changes: 0 additions & 74 deletions exp/metric-gen/go.mod

This file was deleted.

Loading

0 comments on commit b5e8e6f

Please sign in to comment.