From 4ab29795ed19f9c57679108c6381f3590da8304f Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Mon, 14 Aug 2023 13:56:25 +0200 Subject: [PATCH] CI: add annotation with prowjob name and id to ipclaims --- Makefile | 11 +++++++++++ hack/e2e.sh | 33 ++++++++++++++++++--------------- hack/ipclaim-template.yaml | 5 ++++- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index ec987775e7..a720692263 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,11 @@ CONVERSION_GEN_BIN := conversion-gen CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)) CONVERSION_GEN_PKG := k8s.io/code-generator/cmd/conversion-gen +ENVSUBST_BIN := envsubst +ENVSUBST_VER := $(call get_go_version,github.com/drone/envsubst/v2) +ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER)) +ENVSUBST_PKG := github.com/drone/envsubst/v2/cmd/envsubst + GO_APIDIFF_VER := v0.6.0 GO_APIDIFF_BIN := go-apidiff GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER)) @@ -695,6 +700,9 @@ $(GOTESTSUM_BIN): $(GOTESTSUM) ## Build a local copy of gotestsum. .PHONY: $(GO_APIDIFF_BIN) $(GO_APIDIFF_BIN): $(GO_APIDIFF) ## Build a local copy of go-apidiff +.PHONY: $(ENVSUBST_BIN) +$(ENVSUBST_BIN): $(ENVSUBST) ## Build a local copy of envsubst. + .PHONY: $(KUSTOMIZE_BIN) $(KUSTOMIZE_BIN): $(KUSTOMIZE) ## Build a local copy of kustomize. @@ -741,6 +749,9 @@ $(GOTESTSUM): # Build gotestsum from tools folder. $(GO_APIDIFF): # Build go-apidiff. GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER) +$(ENVSUBST): # Build envsubst. + GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(ENVSUBST_PKG) $(ENVSUBST_BIN) $(ENVSUBST_VER) + $(KUSTOMIZE): # Build kustomize. CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER) diff --git a/hack/e2e.sh b/hack/e2e.sh index 83609f2d0d..c26198c3b3 100755 --- a/hack/e2e.sh +++ b/hack/e2e.sh @@ -27,8 +27,8 @@ source "${REPO_ROOT}/hack/ensure-kubectl.sh" on_exit() { # release IPClaim echo "Releasing IP claims" - kubectl --kubeconfig="${KUBECONFIG}" delete "$(append_api_group ipclaim)" "${IPCLAIM_NAME}" || true - kubectl --kubeconfig="${KUBECONFIG}" delete "$(append_api_group ipclaim)" "${WORKLOAD_IPCLAIM_NAME}" || true + kubectl --kubeconfig="${KUBECONFIG}" delete "ipclaim.ipam.metal3.io" "${CONTROL_PLANE_IPCLAIM_NAME}" || true + kubectl --kubeconfig="${KUBECONFIG}" delete "ipclaim.ipam.metal3.io" "${WORKLOAD_IPCLAIM_NAME}" || true # kill the VPN docker kill vpn @@ -73,10 +73,6 @@ docker logs vpn # Sleep to allow vpn container to start running sleep 30 -function append_api_group() { - resource=$1 - echo "${resource}.ipam.metal3.io" -} function kubectl_get_jsonpath() { local OBJECT_KIND="${1}" @@ -84,7 +80,7 @@ function kubectl_get_jsonpath() { local JSON_PATH="${3}" local n=0 until [ $n -ge 30 ]; do - OUTPUT=$(kubectl --kubeconfig="${KUBECONFIG}" get "$(append_api_group "${OBJECT_KIND}")" "${OBJECT_NAME}" -o=jsonpath="${JSON_PATH}") + OUTPUT=$(kubectl --kubeconfig="${KUBECONFIG}" get "${OBJECT_KIND}.ipam.metal3.io" "${OBJECT_NAME}" -o=jsonpath="${JSON_PATH}") if [[ "${OUTPUT}" != "" ]]; then break fi @@ -101,20 +97,27 @@ function kubectl_get_jsonpath() { fi } +function claim_ip() { + IPCLAIM_NAME="$1" + export IPCLAIM_NAME + envsubst < "${REPO_ROOT}/hack/ipclaim-template.yaml" | kubectl --kubeconfig="${KUBECONFIG}" create -f - 1>&2 + IPADDRESS_NAME=$(kubectl_get_jsonpath ipclaim "${IPCLAIM_NAME}" '{@.status.address.name}') + kubectl --kubeconfig="${KUBECONFIG}" get "ipaddresses.ipam.metal3.io" "${IPADDRESS_NAME}" -o=jsonpath='{@.spec.address}' +} + +export KUBECONFIG="/root/ipam-conf/capv-services.conf" + +make envsubst + # Retrieve an IP to be used as the kube-vip IP -KUBECONFIG="/root/ipam-conf/capv-services.conf" -IPCLAIM_NAME="ip-claim-$(openssl rand -hex 20)" -sed "s/IPCLAIM_NAME/${IPCLAIM_NAME}/" "${REPO_ROOT}/hack/ipclaim-template.yaml" | kubectl --kubeconfig=${KUBECONFIG} create -f - -IPADDRESS_NAME=$(kubectl_get_jsonpath ipclaim "${IPCLAIM_NAME}" '{@.status.address.name}') -CONTROL_PLANE_ENDPOINT_IP=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipaddresses)" "${IPADDRESS_NAME}" -o=jsonpath='{@.spec.address}') +CONTROL_PLANE_IPCLAIM_NAME="ip-claim-$(openssl rand -hex 20)" +CONTROL_PLANE_ENDPOINT_IP=$(claim_ip "${CONTROL_PLANE_IPCLAIM_NAME}") export CONTROL_PLANE_ENDPOINT_IP echo "Acquired Control Plane IP: $CONTROL_PLANE_ENDPOINT_IP" # Retrieve an IP to be used for the workload cluster in v1a3/v1a4 -> v1b1 upgrade tests WORKLOAD_IPCLAIM_NAME="workload-ip-claim-$(openssl rand -hex 20)" -sed "s/IPCLAIM_NAME/${WORKLOAD_IPCLAIM_NAME}/" "${REPO_ROOT}/hack/ipclaim-template.yaml" | kubectl --kubeconfig=${KUBECONFIG} create -f - -WORKLOAD_IPADDRESS_NAME=$(kubectl_get_jsonpath ipclaim "${WORKLOAD_IPCLAIM_NAME}" '{@.status.address.name}') -WORKLOAD_CONTROL_PLANE_ENDPOINT_IP=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipaddresses)" "${WORKLOAD_IPADDRESS_NAME}" -o=jsonpath='{@.spec.address}') +WORKLOAD_CONTROL_PLANE_ENDPOINT_IP=$(claim_ip "${WORKLOAD_IPCLAIM_NAME}") export WORKLOAD_CONTROL_PLANE_ENDPOINT_IP echo "Acquired Workload Cluster Control Plane IP: $WORKLOAD_CONTROL_PLANE_ENDPOINT_IP" diff --git a/hack/ipclaim-template.yaml b/hack/ipclaim-template.yaml index c32cf66837..c3e872b5bf 100644 --- a/hack/ipclaim-template.yaml +++ b/hack/ipclaim-template.yaml @@ -1,7 +1,10 @@ apiVersion: ipam.metal3.io/v1alpha1 kind: IPClaim metadata: - name: IPCLAIM_NAME + name: ${IPCLAIM_NAME} + annotations: + prow.k8s.io/build-id: "${BUILD_ID}" + prow.k8s.io/job: "${JOB_NAME}" spec: pool: name: capv-e2e-ippool