Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#2223 from k8s-infra-cherrypick-rob…
Browse files Browse the repository at this point in the history
…ot/cherry-pick-2210-to-release-1.6

[release-1.6] 🌱 CI: add annotation with prowjob name and id to ipclaims
  • Loading branch information
k8s-ci-robot committed Aug 15, 2023
2 parents 5e0d5e8 + 4ab2979 commit b9c175d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand Down
33 changes: 18 additions & 15 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,18 +73,14 @@ 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}"
local OBJECT_NAME="${2}"
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
Expand All @@ -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"

Expand Down
5 changes: 4 additions & 1 deletion hack/ipclaim-template.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b9c175d

Please sign in to comment.