Skip to content

Commit ad450aa

Browse files
committed
Use vSphere projects from Boskos
Signed-off-by: Stefan Büringer [email protected]
1 parent 8b7b506 commit ad450aa

File tree

1 file changed

+84
-12
lines changed

1 file changed

+84
-12
lines changed

images/capi/scripts/ci-ova.sh

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ cd "${CAPI_ROOT}" || exit 1
2424
export ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}"
2525
TARGETS=("ubuntu-2004" "ubuntu-2204" "photon-3" "photon-4" "photon-5" "rockylinux-8" "flatcar")
2626

27+
export BOSKOS_RESOURCE_OWNER=image-builder
28+
if [[ "${JOB_NAME}" != "" ]]; then
29+
export BOSKOS_RESOURCE_OWNER="${JOB_NAME}/${BUILD_ID}"
30+
fi
31+
export BOSKOS_RESOURCE_TYPE=vsphere-project-image-builder
32+
2733
on_exit() {
2834
#Cleanup VMs
2935
cleanup_build_vm
3036

37+
# Stop boskos heartbeat
38+
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}"
39+
40+
# If Boskos is being used then release the vsphere project.
41+
[ -z "${BOSKOS_HOST:-}" ] || docker run gcr.io/k8s-staging-capi-vsphere/extra/boskosctl:latest release --boskos-host="${BOSKOS_HOST}" --resource-owner="${BOSKOS_RESOURCE_OWNER}" --resource-name="${BOSKOS_RESOURCE_NAME}" --vsphere-username="${VSPHERE_USERNAME}" --vsphere-password="${VSPHERE_PASSWORD}" --vsphere-server="${VSPHERE_SERVER}" --vsphere-tls-thumbprint="${VSPHERE_TLS_THUMBPRINT}" --vsphere-folder="${BOSKOS_RESOURCE_FOLDER}" --vsphere-resource-pool="${BOSKOS_RESOURCE_POOL}"
42+
3143
# kill the VPN
3244
docker kill vpn
3345
}
@@ -50,16 +62,84 @@ cleanup_build_vm() {
5062

5163
trap on_exit EXIT
5264

65+
# For Boskos
66+
export VSPHERE_SERVER="${GOVC_URL:-}"
67+
export VSPHERE_USERNAME="${GOVC_USERNAME:-}"
68+
export VSPHERE_PASSWORD="${GOVC_PASSWORD:-}"
69+
5370
export PATH=${PWD}/.local/bin:$PATH
5471
export PATH=${PYTHON_BIN_DIR:-"/root/.local/bin"}:$PATH
5572
export GC_KIND="false"
5673
export TIMESTAMP="$(date -u '+%Y%m%dT%H%M%S')"
5774
export GOVC_DATACENTER="SDDC-Datacenter"
5875
export GOVC_INSECURE=true
59-
export FOLDER="Workloads/image-builder"
76+
77+
# FIXME(sbueringer) before merge this should be moved to the ProwJob config in test-infra (so we can move jobs incrementally to the new environment / boskos)
78+
export BOSKOS_HOST=http://192.168.6.138:32222
79+
80+
# Run the vpn client in container
81+
docker run --rm -d --name vpn -v "${HOME}/.openvpn/:${HOME}/.openvpn/" \
82+
-w "${HOME}/.openvpn/" --cap-add=NET_ADMIN --net=host --device=/dev/net/tun \
83+
gcr.io/k8s-staging-capi-vsphere/extra/openvpn:latest
84+
85+
# Tail the vpn logs
86+
docker logs vpn
87+
88+
# Wait until the VPN connection is active.
89+
function wait_for_vpn_up() {
90+
local n=0
91+
until [ $n -ge 30 ]; do
92+
curl "https://${VSPHERE_SERVER}" --connect-timeout 2 -k -v && RET=$? || RET=$?
93+
if [[ "$RET" -eq 0 ]]; then
94+
break
95+
fi
96+
n=$((n + 1))
97+
sleep 1
98+
done
99+
return "$RET"
100+
}
101+
wait_for_vpn_up
102+
103+
# If BOSKOS_HOST is set then acquire a vsphere-project from Boskos.
104+
if [ -n "${BOSKOS_HOST:-}" ]; then
105+
# Check out the account from Boskos and store the produced environment
106+
# variables in a temporary file.
107+
account_env_var_file="$(mktemp)"
108+
docker run gcr.io/k8s-staging-capi-vsphere/extra/boskosctl:latest acquire --boskos-host="${BOSKOS_HOST}" --resource-owner="${BOSKOS_RESOURCE_OWNER}" --resource-type="${BOSKOS_RESOURCE_TYPE}" 1>"${account_env_var_file}"
109+
checkout_account_status="${?}"
110+
111+
# If the checkout process was a success then load the account's
112+
# environment variables into this process.
113+
# shellcheck disable=SC1090
114+
[ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}"
115+
export BOSKOS_RESOURCE_NAME=${BOSKOS_RESOURCE_NAME}
116+
export VSPHERE_FOLDER=${BOSKOS_RESOURCE_FOLDER}
117+
export VSPHERE_RESOURCE_POOL=${BOSKOS_RESOURCE_POOL}
118+
119+
# Always remove the account environment variable file. It contains
120+
# sensitive information.
121+
rm -f "${account_env_var_file}"
122+
123+
if [ ! "${checkout_account_status}" = "0" ]; then
124+
echo "error getting vsphere project from Boskos" 1>&2
125+
exit "${checkout_account_status}"
126+
fi
127+
128+
# Run the heartbeat to tell boskos periodically that we are still
129+
# using the checked out account.
130+
docker run gcr.io/k8s-staging-capi-vsphere/extra/boskosctl:latest heartbeat --boskos-host="${BOSKOS_HOST}" --resource-owner="${BOSKOS_RESOURCE_OWNER}" --resource-name="${BOSKOS_RESOURCE_NAME}" >>"${ARTIFACTS}/boskos-heartbeat.log" 2>&1 &
131+
HEART_BEAT_PID=$!
132+
else
133+
echo "error getting vsphere project from Boskos, BOSKOS_HOST not set" 1>&2
134+
exit 1
135+
fi
60136

61137
echo "Running build with timestamp ${TIMESTAMP}"
62138

139+
echo "Using user: ${GOVC_USERNAME}"
140+
echo "Using folder: ${VSPHERE_FOLDER}"
141+
echo "Using resource pool: ${VSPHERE_RESOURCE_POOL}"
142+
63143
cat << EOF > packer/ova/vsphere.json
64144
{
65145
"vcenter_server":"${GOVC_URL}",
@@ -68,10 +148,10 @@ cat << EOF > packer/ova/vsphere.json
68148
"password":"${GOVC_PASSWORD}",
69149
"datastore":"WorkloadDatastore",
70150
"datacenter":"${GOVC_DATACENTER}",
71-
"resource_pool": "Compute-ResourcePool/image-builder",
151+
"resource_pool": "${VSPHERE_RESOURCE_POOL}",
72152
"cluster": "Cluster-1",
73-
"network": "sddc-cgw-network-8",
74-
"folder": "${FOLDER}"
153+
"network": "sddc-cgw-network-10",
154+
"folder": "${VSPHERE_FOLDER}"
75155
}
76156
EOF
77157

@@ -81,14 +161,6 @@ cat packer/ova/packer-node.json | jq 'del(.builders[] | select( .name == "vsphe
81161
cat packer/ova/packer-node.json | jq 'del(.builders[] | select( .name == "vsphere-clone" ).export)' > packer/ova/packer-node.json.tmp && mv packer/ova/packer-node.json.tmp packer/ova/packer-node.json
82162
cat packer/ova/packer-node.json | jq 'del(."post-processors"[])' > packer/ova/packer-node.json.tmp && mv packer/ova/packer-node.json.tmp packer/ova/packer-node.json
83163

84-
# Run the vpn client in container
85-
docker run --rm -d --name vpn -v "${HOME}/.openvpn/:${HOME}/.openvpn/" \
86-
-w "${HOME}/.openvpn/" --cap-add=NET_ADMIN --net=host --device=/dev/net/tun \
87-
gcr.io/k8s-staging-capi-vsphere/extra/openvpn:latest
88-
89-
# Tail the vpn logs
90-
docker logs vpn
91-
92164
# install deps and build all images
93165
make deps-ova
94166

0 commit comments

Comments
 (0)