1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

hack: *: remove hacky shell scripts and move generate dir to scripts/

This commit is contained in:
paulfantom 2019-05-14 15:45:51 +02:00
parent cd4a9037c3
commit b602243f57
No known key found for this signature in database
GPG key ID: 12AE0185401674E7
16 changed files with 37 additions and 77 deletions

2
.gitignore vendored
View file

@ -16,4 +16,4 @@ tmp
# These are empty target files, created on every docker build. Their sole
# purpose is to track the last target execution time to evalualte, whether the
# container needds to be rebuild
hack/*-image
.hack-*-image

View file

@ -23,7 +23,7 @@ jobs:
# Build Prometheus Operator rule config map to rule file crds cli tool
- script: cd cmd/po-rule-migration && go install
# Ensure vendor folder matches vendor.json
- script: ./scripts/golang-mod.sh
- script: make --always-make vendor && git diff --exit-code vendor/
# Unit tests
- script: make test-unit
# E2e tests

View file

@ -4,6 +4,7 @@ GO_PKG=github.com/coreos/prometheus-operator
REPO?=quay.io/coreos/prometheus-operator
REPO_PROMETHEUS_CONFIG_RELOADER?=quay.io/coreos/prometheus-config-reloader
TAG?=$(shell git rev-parse --short HEAD)
VERSION?=$(shell cat VERSION | tr -d " \t\n\r")
FIRST_GOPATH:=$(firstword $(subst :, ,$(shell go env GOPATH)))
PO_CRDGEN_BINARY:=$(FIRST_GOPATH)/bin/po-crdgen
@ -24,14 +25,14 @@ K8S_GEN_DEPS+=$(TYPES_V1_TARGET)
K8S_GEN_DEPS+=$(foreach bin,$(K8S_GEN_BINARIES),$(FIRST_GOPATH)/bin/$(bin))
K8S_GEN_DEPS+=$(OPENAPI_GEN_BINARY)
GOLANG_FILES:=$(shell find . -name \*.go -print)
GO_BUILD_RECIPE=GOOS=linux CGO_ENABLED=0 go build -mod=vendor -ldflags="-s -X $(GO_PKG)/pkg/version.Version=$(VERSION)"
pkgs = $(shell go list ./... | grep -v /vendor/ | grep -v /test/ | grep -v /contrib/)
CONTAINER_CMD:=docker run --rm \
-u="$(shell id -u):$(shell id -g)" \
-v "$(shell go env GOCACHE):/.cache/go-build" \
-v "$(PWD):/go/src/github.com/coreos/prometheus-operator:Z" \
-w "/go/src/github.com/coreos/prometheus-operator" \
-v "$(PWD):/go/src/$(GO_PKG):Z" \
-w "/go/src/$(GO_PKG)" \
-e GO111MODULE=on \
quay.io/coreos/jsonnet-ci
@ -51,18 +52,12 @@ clean:
build: operator prometheus-config-reloader k8s-gen
.PHONY: operator
operator: $(GOLANG_FILES)
GOOS=linux CGO_ENABLED=0 go build \
-mod=vendor \
-ldflags "-X $(GO_PKG)/pkg/version.Version=$(shell cat VERSION)" \
-o $@ cmd/operator/main.go
operator:
$(GO_BUILD_RECIPE) -o $@ cmd/operator/main.go
.PHONY: prometheus-config-reloader
prometheus-config-reloader:
GOOS=linux CGO_ENABLED=0 go build \
-mod=vendor \
-ldflags "-X $(GO_PKG)/pkg/version.Version=$(shell cat VERSION)" \
-o $@ cmd/$@/main.go
$(GO_BUILD_RECIPE) -o $@ cmd/$@/main.go
DEEPCOPY_TARGET := pkg/apis/monitoring/v1/zz_generated.deepcopy.go
$(DEEPCOPY_TARGET): $(K8S_GEN_DEPS)
@ -106,23 +101,23 @@ $(OPENAPI_TARGET): $(K8S_GEN_DEPS)
.PHONY: k8s-gen
k8s-gen: \
$(DEEPCOPY_TARGET) \
$(CLIENT_TARGET) \
$(LISTER_TARGET) \
$(INFORMER_TARGET) \
$(OPENAPI_TARGET)
$(DEEPCOPY_TARGET) \
$(CLIENT_TARGET) \
$(LISTER_TARGET) \
$(INFORMER_TARGET) \
$(OPENAPI_TARGET)
.PHONY: image
image: hack/operator-image hack/prometheus-config-reloader-image
image: .hack-operator-image .hack-prometheus-config-reloader-image
hack/operator-image: Dockerfile operator
.hack-operator-image: Dockerfile operator
# Create empty target file, for the sole purpose of recording when this target
# was last executed via the last-modification timestamp on the file. See
# https://www.gnu.org/software/make/manual/make.html#Empty-Targets
docker build -t $(REPO):$(TAG) .
touch $@
hack/prometheus-config-reloader-image: cmd/prometheus-config-reloader/Dockerfile prometheus-config-reloader
.hack-prometheus-config-reloader-image: cmd/prometheus-config-reloader/Dockerfile prometheus-config-reloader
# Create empty target file, for the sole purpose of recording when this target
# was last executed via the last-modification timestamp on the file. See
# https://www.gnu.org/software/make/manual/make.html#Empty-Targets
@ -133,6 +128,9 @@ hack/prometheus-config-reloader-image: cmd/prometheus-config-reloader/Dockerfile
# Generating #
##############
vendor:
go mod vendor
.PHONY: generate
generate: $(DEEPCOPY_TARGET) $(OPENAPI_TARGET) $(shell find jsonnet/prometheus-operator/*-crd.libsonnet -type f) bundle.yaml $(shell find Documentation -type f)
@ -153,21 +151,21 @@ jsonnet/prometheus-operator/**-crd.libsonnet: $(shell find example/prometheus-op
cat example/prometheus-operator-crd/prometheusrule.crd.yaml | gojsontoyaml -yamltojson > jsonnet/prometheus-operator/prometheusrule-crd.libsonnet
bundle.yaml: $(shell find example/rbac/prometheus-operator/*.yaml -type f)
hack/generate-bundle.sh
scripts/generate-bundle.sh
hack/generate/vendor: $(JB_BINARY) $(shell find jsonnet/prometheus-operator -type f)
cd hack/generate; $(JB_BINARY) install;
scripts/generate/vendor: $(JB_BINARY) $(shell find jsonnet/prometheus-operator -type f)
cd scripts/generate; $(JB_BINARY) install;
example/non-rbac/prometheus-operator.yaml: hack/generate/vendor hack/generate/prometheus-operator-non-rbac.jsonnet $(shell find jsonnet -type f)
hack/generate/build-non-rbac-prometheus-operator.sh
example/non-rbac/prometheus-operator.yaml: scripts/generate/vendor scripts/generate/prometheus-operator-non-rbac.jsonnet $(shell find jsonnet -type f)
scripts/generate/build-non-rbac-prometheus-operator.sh
RBAC_MANIFESTS = example/rbac/prometheus-operator/prometheus-operator-cluster-role.yaml example/rbac/prometheus-operator/prometheus-operator-cluster-role-binding.yaml example/rbac/prometheus-operator/prometheus-operator-service-account.yaml example/rbac/prometheus-operator/prometheus-operator-deployment.yaml
$(RBAC_MANIFESTS): hack/generate/vendor hack/generate/prometheus-operator-rbac.jsonnet $(shell find jsonnet -type f)
hack/generate/build-rbac-prometheus-operator.sh
$(RBAC_MANIFESTS): scripts/generate/vendor scripts/generate/prometheus-operator-rbac.jsonnet $(shell find jsonnet -type f)
scripts/generate/build-rbac-prometheus-operator.sh
jsonnet/prometheus-operator/prometheus-operator.libsonnet: VERSION
sed -i \
"s/prometheusOperator: 'v.*',/prometheusOperator: 'v$(shell cat VERSION)',/" \
"s/prometheusOperator: 'v.*',/prometheusOperator: 'v$(VERSION)',/" \
jsonnet/prometheus-operator/prometheus-operator.libsonnet;
FULLY_GENERATED_DOCS = Documentation/api.md Documentation/compatibility.md
@ -212,7 +210,7 @@ test: test-unit test-e2e
.PHONY: test-unit
test-unit:
@go test -race $(TEST_RUN_ARGS) -short $(pkgs) -count=1
go test -race $(TEST_RUN_ARGS) -short $(pkgs) -count=1
.PHONY: test-e2e
test-e2e: KUBECONFIG?=$(HOME)/.kube/config

View file

@ -78,7 +78,7 @@ To run the Operator outside of a cluster:
```sh
make
hack/run-external.sh <kubectl cluster name>
scripts/run-external.sh <kubectl cluster name>
```
## Removal

View file

@ -1,12 +0,0 @@
#!/usr/bin/env bash
# exit immediately when a command fails
set -e
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail
# error on unset variables
set -u
# Concatenate all files with "---" because that's how to specify multiple
# Kubernetes manifests in one file. Because the first `awk` also adds "---" in
# the first line, we remove it with the second `awk` call.
awk 'FNR==1{print "---"}1' "$@" | awk '{if (NR!=1) {print}}'

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
# exit immediately when a command fails
set -e
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail
# error on unset variables
set -u
kubectl get pods --all-namespaces -l app="${1}" -ojsonpath="{.items[*].spec.containers[?(@.name==\"$1\")].image}"

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
# exit immediately when a command fails
set -e
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail
# error on unset variables
set -u
kubectl -n prometheus-operator-e2e-tests exec -it prometheus-test-0 -c prometheus '/bin/sh -c "cat /etc/prometheus/rules/rules-0/test.rules"'

View file

@ -6,5 +6,9 @@ set -o pipefail
# error on unset variables
set -u
function concat() {
awk 'FNR==1{print "---"}1' "$@" | awk '{if (NR!=1) {print}}'
}
# shellcheck disable=SC2046
hack/concat-kubernetes-manifests.sh $(find example/rbac/prometheus-operator -name '*.yaml' | sort | grep -v service-monitor) > bundle.yaml
concat $(find example/rbac/prometheus-operator -name '*.yaml' | sort | grep -v service-monitor) > bundle-new.yaml

View file

@ -6,4 +6,4 @@ set -o pipefail
# error on unset variables
set -u
jsonnet -J hack/generate/vendor hack/generate/prometheus-operator-non-rbac.jsonnet | gojsontoyaml > example/non-rbac/prometheus-operator.yaml
jsonnet -J scripts/generate/vendor scripts/generate/prometheus-operator-non-rbac.jsonnet | gojsontoyaml > example/non-rbac/prometheus-operator.yaml

View file

@ -8,7 +8,7 @@ set -u
rm -rf tmp
mkdir tmp
jsonnet -J hack/generate/vendor hack/generate/prometheus-operator-rbac.jsonnet > tmp/po.json
jsonnet -J scripts/generate/vendor scripts/generate/prometheus-operator-rbac.jsonnet > tmp/po.json
jq -r 'keys[]' tmp/po.json | while read -r file
do
jq -r ".[\"${file}\"]" tmp/po.json | gojsontoyaml > "example/rbac/prometheus-operator/${file}"

View file

@ -1,12 +0,0 @@
#!/usr/bin/env bash
# exit immediately when a command fails
set -e
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail
# error on unset variables
set -u
# print each command before executing it
set -x
go mod vendor
git diff --exit-code vendor/