From 2c3cbde9c3ff67e5db4d1ec9f4ecba415ab3e6e3 Mon Sep 17 00:00:00 2001 From: Daniel Fox Date: Thu, 22 Feb 2024 14:48:17 -0800 Subject: [PATCH 1/2] Fix yq, var requirements --- hack/postrelease/Dockerfile | 9 ++++--- hack/postrelease/Makefile | 40 +++++++++++++++++++++++++++---- hack/postrelease/requirements.txt | 4 ---- hack/postrelease/variables.mk | 16 ++++++++----- 4 files changed, 51 insertions(+), 18 deletions(-) delete mode 100755 hack/postrelease/requirements.txt diff --git a/hack/postrelease/Dockerfile b/hack/postrelease/Dockerfile index e89b163e0c6..1f093009b18 100644 --- a/hack/postrelease/Dockerfile +++ b/hack/postrelease/Dockerfile @@ -15,15 +15,18 @@ RUN --mount=type=tmpfs,target=/var/cache/apk apk add --no-cache \ python3 \ python3-dev \ py3-pip \ + py3-yaml \ + py3-pytest \ + py3-requests \ + py3-rich \ py-setuptools \ openssl-dev \ curl \ - jq + jq \ + yq RUN mkdir -p /root/.docker /code COPY config.json /root/.docker/ -COPY requirements.txt /requirements.txt -RUN pip install --no-cache-dir -r /requirements.txt # The container is used by mounting the code-under-test to /code WORKDIR /code/ diff --git a/hack/postrelease/Makefile b/hack/postrelease/Makefile index 6ba3846d855..6b6b577826a 100644 --- a/hack/postrelease/Makefile +++ b/hack/postrelease/Makefile @@ -1,5 +1,32 @@ include variables.mk +### Binaries we need + +bin/yq: + $(info Downloading YQ from $(YQ4_URL)) + @mkdir -p bin + @curl -fsSL $(YQ4_URL) -o $(YQ4) + @chmod +x $(YQ4) + +### Utility! + +define set_variable_error_with_message +$(warning The variable $(1) is required but is not defined) +$(eval REQUIRED_VARIABLES_FAILED=1) +endef + +require_var = $(if \ + $(filter-out undefined,$(origin $(1))),\ + ,\ + $(call set_variable_error_with_message,$1) \ + ) + +require-vars-%: + $(foreach var,$(subst -, ,$*),$(call require_var,$(var))) + ifeq ($(REQUIRED_VARIABLES_FAILED),1) + $(error Please correct missing variables and retry) + endif + ### Actual rules below here! .PHONY: create_docker_container clean @@ -10,7 +37,7 @@ all: create_docker_container run_pytests_docker clean_docker_container create_docker_container: .docker_container.stamp -.docker_container.stamp: Dockerfile requirements.txt config.json +.docker_container.stamp: bin/yq Dockerfile config.json $(info +++ Building docker container with Calico $(CALICO_VERSION), Operator $(OPERATOR_VERSION), Flannel $(FLANNEL_VERSION)) docker buildx build \ -t $(CALICO_POSTRELEASE_TEST_IMAGE) \ @@ -22,9 +49,9 @@ create_docker_container: .docker_container.stamp ## Execution -run_pytests_docker: create_docker_container +run_pytests_docker: create_docker_container require-vars-QUAY_TOKEN $(info +++ Running postrelease tests) - @docker run -it --rm \ + @docker run -it --rm \ -v .:/code \ -v /run/docker.sock:/run/docker.sock \ -e QUAY_TOKEN \ @@ -35,12 +62,15 @@ run_pytests_docker: create_docker_container # `clean` is meant to be run manually, as it also runs clean_xunit, which # deletes the xunit file. We actually want that file to exist in e.g. semaphore. -clean: clean_docker_container clean_xunit +clean: clean_docker_container clean_xunit clean_bin clean_xunit: $(RM) xunit.xml -clean_docker_container: +clean_bin: + $(RM) -r bin + +clean_docker_container: bin/yq $(info +++ Cleaning docker container) @docker rmi $(CALICO_POSTRELEASE_TEST_IMAGE) 2> /dev/null || true $(RM) .docker_container.stamp diff --git a/hack/postrelease/requirements.txt b/hack/postrelease/requirements.txt deleted file mode 100755 index fd4bff6829f..00000000000 --- a/hack/postrelease/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest>=7.2,<8 -pyyaml>=6.0,<6.1 -requests>=2.31,<2.40 -rich>=13,<14 diff --git a/hack/postrelease/variables.mk b/hack/postrelease/variables.mk index 6d5791f7f37..19494c67149 100644 --- a/hack/postrelease/variables.mk +++ b/hack/postrelease/variables.mk @@ -1,5 +1,9 @@ -# Paths to override -YQ ?= yq +# Binaries we need + +YQ4_VERSION := v4.40.3 +YQ4_BINARY := yq_linux_amd64 +YQ4_URL := https://github.com/mikefarah/yq/releases/download/$(YQ4_VERSION)/$(YQ4_BINARY) +YQ4 := bin/yq # Override implicit RM command quietly RM := @$(RM) @@ -9,16 +13,16 @@ CHARTS_TIGERAOPERATOR_VALUES = ../../charts/tigera-operator/values.yaml CHART_CALICO_VALUES = ../../charts/calico/values.yaml # Versions (extracted from the charts files) -CALICO_VERSION := $(shell $(YQ) '.calicoctl.tag' < $(CHARTS_TIGERAOPERATOR_VALUES)) -OPERATOR_VERSION := $(shell $(YQ) '.tigeraOperator.version' < $(CHARTS_TIGERAOPERATOR_VALUES)) -FLANNEL_VERSION := $(shell $(YQ) '.flannel.tag' < $(CHART_CALICO_VALUES)) +CALICO_VERSION = $(shell $(YQ4) '.calicoctl.tag' < $(CHARTS_TIGERAOPERATOR_VALUES)) +OPERATOR_VERSION = $(shell $(YQ4) '.tigeraOperator.version' < $(CHARTS_TIGERAOPERATOR_VALUES)) +FLANNEL_VERSION = $(shell $(YQ4) '.flannel.tag' < $(CHART_CALICO_VALUES)) # The docker image that we build to run the tests in CALICO_POSTRELEASE_TEST_IMAGE = calico_postrelease_tests:$(CALICO_VERSION) .PHONY: show-variables -show-variables: +show-variables: bin/yq $(info # Chart locations) $(info CHARTS_TIGERAOPERATOR_VALUES = $(CHARTS_TIGERAOPERATOR_VALUES)) $(info CHART_CALICO_VALUES = $(CHART_CALICO_VALUES)) From 4612512048cf96daa29d1be52b9159906b5bec0e Mon Sep 17 00:00:00 2001 From: Daniel Fox Date: Thu, 22 Feb 2024 14:56:36 -0800 Subject: [PATCH 2/2] Fix buggy var-require code --- hack/postrelease/Makefile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/hack/postrelease/Makefile b/hack/postrelease/Makefile index 6b6b577826a..87ceff89464 100644 --- a/hack/postrelease/Makefile +++ b/hack/postrelease/Makefile @@ -10,22 +10,14 @@ bin/yq: ### Utility! -define set_variable_error_with_message -$(warning The variable $(1) is required but is not defined) -$(eval REQUIRED_VARIABLES_FAILED=1) -endef - require_var = $(if \ $(filter-out undefined,$(origin $(1))),\ ,\ - $(call set_variable_error_with_message,$1) \ + $(error The variable $(1) is required but is not defined) \ ) require-vars-%: $(foreach var,$(subst -, ,$*),$(call require_var,$(var))) - ifeq ($(REQUIRED_VARIABLES_FAILED),1) - $(error Please correct missing variables and retry) - endif ### Actual rules below here!