Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Clean (#38)
Browse files Browse the repository at this point in the history
* clean unused code and renaming

* move cicd scripts

* update test stuff

* update makefile

* add/update license/owners/release_main_branch/security.md, also update master to main

* update dockerfile to make image include binaries with new/old name

* add deprecated opt back to be compatible with old version endpoint operator
  • Loading branch information
marcolan018 authored Mar 4, 2021
1 parent 3d99812 commit d830033
Show file tree
Hide file tree
Showing 140 changed files with 338 additions and 9,241 deletions.
2 changes: 0 additions & 2 deletions .errcheck_excludes.txt

This file was deleted.

8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/telemeter-benchmark
/telemeter-client
/telemeter-server
/authorization-server
/_output
telemeter-bench
/bin
/benchmark
benchmark.pdf
/docs/telemeter_query
/vendor

# These are empty target files, created on every docker build. Their sole
Expand Down
14 changes: 0 additions & 14 deletions .golangci.yml

This file was deleted.

16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ addons:

branches:
only:
- master
- main
- /^release-[0-9]+\..*$/

env:
Expand All @@ -28,11 +28,11 @@ env:
- COMPONENT_TAG_EXTENSION="-${TRAVIS_COMMIT}"

# Component Specific
- COMPONENT_DEPLOY_COMMAND=${TRAVIS_BUILD_DIR}/build/deploy-to-cluster.sh
- COMPONENT_INIT_COMMAND=${TRAVIS_BUILD_DIR}/build/install-dependencies.sh
- COMPONENT_BUILD_COMMAND=${TRAVIS_BUILD_DIR}/build/build.sh
- COMPONENT_UNIT_TEST_COMMAND=${TRAVIS_BUILD_DIR}/build/run-unit-tests.sh
- COMPONENT_E2E_TEST_COMMAND=${TRAVIS_BUILD_DIR}/build/run-e2e-tests.sh
- COMPONENT_DEPLOY_COMMAND=${TRAVIS_BUILD_DIR}/cicd-scripts/deploy-to-cluster.sh
- COMPONENT_INIT_COMMAND=${TRAVIS_BUILD_DIR}/cicd-scripts/install-dependencies.sh
- COMPONENT_BUILD_COMMAND=${TRAVIS_BUILD_DIR}/cicd-scripts/build.sh
- COMPONENT_UNIT_TEST_COMMAND=${TRAVIS_BUILD_DIR}/cicd-scripts/run-unit-tests.sh
- COMPONENT_E2E_TEST_COMMAND=${TRAVIS_BUILD_DIR}/cicd-scripts/run-e2e-tests.sh

- GO111MODULE=on

Expand Down Expand Up @@ -75,8 +75,8 @@ jobs:
- make component/pull
- make component/test/e2e
- stage: release-ff
name: "Push commits from master to branch defined in RELEASE_FF_BRANCH"
if: type = push AND branch =~ /^master$/
name: "Push commits from main to branch defined in RELEASE_FF_BRANCH"
if: type = push AND branch =~ /^main$/
script:
- make release-ff
- stage: publish
Expand Down
2 changes: 1 addition & 1 deletion COMPONENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.3.0
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM openshift/origin-release:golang-1.13 AS builder
ENV GOFLAGS="-mod=vendor"
COPY . /go/src/github.com/open-cluster-management/metrics-collector
RUN cd /go/src/github.com/open-cluster-management/metrics-collector && \
go build ./cmd/telemeter-client
go build ./cmd/metrics-collector

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

Expand Down Expand Up @@ -43,4 +43,5 @@ RUN microdnf update &&\
mkdir /licenses &&\
microdnf clean all

COPY --from=builder /go/src/github.com/open-cluster-management/metrics-collector/telemeter-client /usr/bin/
COPY --from=builder /go/src/github.com/open-cluster-management/metrics-collector/metrics-collector /usr/bin/
RUN cp /usr/bin/metrics-collector /usr/bin/telemeter-client
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
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.
limitations under the License.
254 changes: 11 additions & 243 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,256 +1,24 @@
# Copyright (c) 2020 Red Hat, Inc.

include build/Configfile
include ./cicd-scripts/Configfile

.PHONY: all build image check test-generate test-integration test-benchmark vendor dependencies manifests
SHELL=/usr/bin/env bash -o pipefail

# Bootstrap (pull) the build harness

# GITHUB_USER containing '@' char must be escaped with '%40'
export GITHUB_USER := $(shell echo $(GITHUB_USER) | sed 's/@/%40/g')
export GITHUB_TOKEN ?=
export UNIT_TEST=true

USE_VENDORIZED_BUILD_HARNESS ?=

ifndef USE_VENDORIZED_BUILD_HARNESS
-include $(shell curl -s -H 'Authorization: token ${GITHUB_TOKEN}' -H 'Accept: application/vnd.github.v4.raw' -L https://api.github.com/repos/open-cluster-management/build-harness-extensions/contents/templates/Makefile.build-harness-bootstrap -o .build-harness-bootstrap; echo .build-harness-bootstrap)
else
-include vbh/.build-harness-vendorized
endif

GO_PKG=github.com/open-cluster-management/metrics-collector
#REPO?=quay.io/openshift/telemeter
TAG?=$(shell git rev-parse --short HEAD)
-include $(shell curl -H 'Authorization: token ${GITHUB_TOKEN}' -H 'Accept: application/vnd.github.v4.raw' -L https://api.github.com/repos/open-cluster-management/build-harness-extensions/contents/templates/Makefile.build-harness-bootstrap -o .build-harness-bootstrap; echo .build-harness-bootstrap)

PKGS=$(shell go list ./... | grep -v '/vendor/|/test/(?!e2e)')
GOLANG_FILES:=$(shell find . -name \*.go -print)
FIRST_GOPATH:=$(firstword $(subst :, ,$(shell go env GOPATH)))
BIN_DIR?=$(shell pwd)/_output/bin
LIB_DIR?=./_output/lib
METRICS_JSON=./_output/metrics.json
GOLANGCI_LINT_BIN=$(BIN_DIR)/golangci-lint
GOLANGCI_LINT_VERSION=v1.18.0
EMBEDMD_BIN=$(BIN_DIR)/embedmd
THANOS_BIN=$(BIN_DIR)/thanos
UP_BIN=$(BIN_DIR)/up
MEMCACHED_BIN=$(BIN_DIR)/memcached
PROMETHEUS_BIN=$(BIN_DIR)/prometheus
GOJSONTOYAML_BIN=$(BIN_DIR)/gojsontoyaml
JSONNET_BIN?=$(BIN_DIR)/jsonnet
# We need jsonnet on CI; here we default to the user's installed jsonnet binary; if nothing is installed, then install go-jsonnet.
JSONNET_LOCAL_OR_INSTALLED=$(if $(shell which jsonnet 2>/dev/null),$(shell which jsonnet 2>/dev/null),$(JSONNET_BIN))
JB_BIN=$(BIN_DIR)/jb
JSONNET_SRC=$(shell find ./jsonnet -type f)
BENCHMARK_RESULTS=$(shell find ./benchmark -type f -name '*.json')
BENCHMARK_GOAL?=5000
JSONNET_VENDOR=jsonnet/jsonnetfile.lock.json jsonnet/vendor
DOCS=$(shell grep -rlF [embedmd] docs)

export PATH := $(BIN_DIR):$(PATH)

GO_BUILD_RECIPE=CGO_ENABLED=0 go build
CONTAINER_CMD:=docker run --rm \
-u="$(shell id -u):$(shell id -g)" \
-v "$(shell go env GOCACHE):/.cache/go-build" \
-v "$(PWD):/go/src/$(GO_PKG):Z" \
-w "/go/src/$(GO_PKG)" \
-e GO111MODULE=on \
quay.io/coreos/jsonnet-ci

.PHONY: all
all: build manifests $(DOCS)
copyright-check:
./cicd-scripts/copyright-check.sh $(TRAVIS_BRANCH)

.PHONY: clean
clean::
# Remove all files and directories ignored by git.
git clean -Xfd .

# Build harness cleanup
@rm -rf $(BUILD_DIR)/_output
@[ "$(BUILD_HARNESS_PATH)" == '/' ] || \
[ "$(BUILD_HARNESS_PATH)" == '.' ] || \
rm -rf $(BUILD_HARNESS_PATH)

############
# Building #
############
test-unit:
@echo "TODO: Run unit-tests"
go test -race -short $(PKGS) -count=1 -coverprofile cover.out

.PHONY: build-in-docker
build-in-docker:
$(CONTAINER_CMD) $(MAKE) $(MFLAGS) build
e2e-tests:
@echo "TODO: Run e2e-tests"

.PHONY: build
build:
go build ./cmd/telemeter-client
# go build ./cmd/telemeter-server
# go build ./cmd/authorization-server
# go build ./cmd/telemeter-benchmark

.PHONY: image
image:
docker build -t $(DOCKER_IMAGE_AND_TAG) .

#image: .hack-operator-image

.hack-operator-image: Dockerfile
# 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 $@

##############
# Generating #
##############
go build ./cmd/metrics-collector

vendor:
go mod vendor
go mod tidy
go mod verify

.PHONY: generate
generate: $(DOCS) manifests

.PHONY: generate-in-docker
generate-in-docker:
$(CONTAINER_CMD) $(MAKE) $(MFLAGS) generate

$(JSONNET_VENDOR): $(JB_BIN) jsonnet/jsonnetfile.json
cd jsonnet && $(JB_BIN) install

# Can't add test/timeseries.txt as a dependency, otherwise
# running make --always-make will try to regenerate the timeseries
# on CI, which will fail because there is no OpenShift cluster.
$(DOCS): $(JSONNET_SRC) $(EMBEDMD_BIN) docs/telemeter_query
$(EMBEDMD_BIN) -w $@

docs/telemeter_query: $(JSONNET_SRC)
query=""; \
for rule in $$(jsonnet metrics.json | jq -r '.[]'); do \
[ ! -z "$$query" ] && query="$$query or "; \
query="$$query$$rule"; \
done; \
echo "$$query" > $@

$(METRICS_JSON):
curl -L https://raw.githubusercontent.com/openshift/cluster-monitoring-operator/844e7afabfcfa4162c716ea18cd8e2d010789de1/manifests/0000_50_cluster_monitoring_operator_04-config.yaml | \
$(GOJSONTOYAML_BIN) --yamltojson | jq -r '.data."metrics.yaml"' | $(GOJSONTOYAML_BIN) --yamltojson | jq -r '.matches' > $@

manifests: $(JSONNET_LOCAL_OR_INSTALLED) $(JSONNET_SRC) $(JSONNET_VENDOR) $(GOJSONTOYAML_BIN) $(METRICS_JSON)
rm -rf manifests
mkdir -p manifests/{benchmark,client}
$(JSONNET_LOCAL_OR_INSTALLED) jsonnet/benchmark.jsonnet -J jsonnet/vendor -m manifests/benchmark --tla-code metrics="$$(cat $(METRICS_JSON))"
$(JSONNET_LOCAL_OR_INSTALLED) jsonnet/client.jsonnet -J jsonnet/vendor -m manifests/client
@for f in $$(find manifests -type f); do\
cat $$f | $(GOJSONTOYAML_BIN) > $$f.yaml && rm $$f;\
done

benchmark.pdf: $(BENCHMARK_RESULTS)
find ./benchmark -type f -name '*.json' -print0 | xargs -l -0 python3 test/plot.py && gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$@ benchmark/*.pdf


##############
# Formatting #
##############

.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
# Check .golangci.yml for configuration
$(GOLANGCI_LINT_BIN) run -c .golangci.yml

.PHONY: format
format: go-fmt shellcheck

.PHONY: go-fmt
go-fmt:
go fmt $(PKGS)

.PHONY: shellcheck
shellcheck:
docker run -v "${PWD}:/mnt" koalaman/shellcheck:stable $(shell find . -type f -name "*.sh" -not -path "*vendor*")

###########
# Testing #
###########

.PHONY: test
test: test-unit test-integration test-benchmark

.PHONY: test-unit
test-unit:
go test -race -short $(PKGS) -count=1 -coverprofile cover.out

# TODO(paulfantom): remove this target after removing it from Prow.
test-generate:
make --always-make && git diff --exit-code

test-integration: build | $(THANOS_BIN) $(UP_BIN) $(MEMCACHED_BIN) $(PROMETHEUS_BIN)
@echo "Running integration tests: V1"
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./test/integration.sh
@echo "Running integration tests: V2"
PATH=$$PATH:$$(pwd)/$(BIN_DIR) LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$$(pwd)/$(LIB_DIR) ./test/integration-v2.sh

test-benchmark: build $(GOJSONTOYAML_BIN)
# Allow the image to be overridden when running in CI.
if [ -n "$$IMAGE_FORMAT" ]; then \
f=$$(mktemp) && cat ./manifests/benchmark/statefulSetTelemeterServer.yaml | $(GOJSONTOYAML_BIN) --yamltojson | jq '.spec.template.spec.containers[].image="'"$${IMAGE_FORMAT//\$$\{component\}/telemeter}"'"' | $(GOJSONTOYAML_BIN) > $$f && mv $$f ./manifests/benchmark/statefulSetTelemeterServer.yaml; \
fi
./test/benchmark.sh "" "" $(BENCHMARK_GOAL) "" $(BENCHMARK_GOAL)

test/timeseries.txt:
oc port-forward -n openshift-monitoring prometheus-k8s-0 9090 > /dev/null & \
sleep 5 ; \
query="curl --fail --silent -G http://localhost:9090/federate"; \
for rule in $$(jsonnet metrics.json | jq -r '.[]'); do \
query="$$query $$(printf -- "--data-urlencode match[]=%s" $$rule)"; \
done; \
echo '# This file was generated using `make $@`.' > $@ ; \
$$query >> $@ ; \
jobs -p | xargs -r kill


############
# Binaries #
############

dependencies: $(JB_BIN) $(THANOS_BIN) $(UP_BIN) $(EMBEDMD_BIN) $(GOJSONTOYAML_BIN) | $(PROMETHEUS_BIN) $(GOLANGCI_LINT_BIN) $(MEMCACHED_BIN)

$(BIN_DIR):
mkdir -p $@

$(LIB_DIR):
mkdir -p $@

$(MEMCACHED_BIN): | $(BIN_DIR) $(LIB_DIR)
@echo "Downloading Memcached"
curl -L https://www.archlinux.org/packages/core/x86_64/libevent/download/ | tar -I $(LIB_DIR)/zstd --strip-components=2 -xf - -C $(LIB_DIR) usr/lib
curl -L https://www.archlinux.org/packages/extra/x86_64/memcached/download/ | tar -I $(LIB_DIR)/zstd --strip-components=2 -xf - -C $(BIN_DIR) usr/bin/memcached

$(PROMETHEUS_BIN): $(BIN_DIR)
@echo "Downloading Prometheus"
curl -L "https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.$$(go env GOOS)-$$(go env GOARCH).tar.gz" | tar --strip-components=1 -xzf - -C $(BIN_DIR)

$(GOLANGCI_LINT_BIN): $(BIN_DIR)
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
| sed -e '/install -d/d' \
| sh -s -- -b $(BIN_DIR) $(GOLANGCI_LINT_VERSION)

$(THANOS_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/thanos-io/thanos/cmd/thanos

$(UP_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/observatorium/up/cmd/up

$(EMBEDMD_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/campoy/embedmd

$(JSONNET_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/google/go-jsonnet/cmd/jsonnet

$(JB_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb

$(GOJSONTOYAML_BIN): $(BIN_DIR)
GOBIN=$(BIN_DIR) go install -mod=readonly -modfile=tools/go.mod github.com/brancz/gojsontoyaml
go mod verify
10 changes: 10 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
approvers:
- clyang82
- marcolan018
- bjoydeep
- songleo
reviewers:
- clyang82
- marcolan018
- bjoydeep
- songleo
Loading

0 comments on commit d830033

Please sign in to comment.