Skip to content

Commit

Permalink
Merge pull request #400 from cpanato/use-existing-images
Browse files Browse the repository at this point in the history
ci: use prebuilt node images for CAPG
  • Loading branch information
k8s-ci-robot authored Jul 22, 2021
2 parents 549b434 + 5ad5289 commit fa795c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
30 changes: 21 additions & 9 deletions hack/ci/e2e-conformance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,18 @@ create_cluster() {
# actually create the cluster
KIND_IS_UP=true

filter="name~cluster-api-ubuntu-1804-${KUBERNETES_VERSION//[.+]/-}"
image_id=$(gcloud compute images list --project "$GCP_PROJECT" \
--no-standard-images --filter="${filter}" --format="table[no-heading](name)")
if [[ -z "$image_id" ]]; then
echo "unable to find image using : $filter $GCP_PROJECT ... bailing out!"
exit 1
if [[ -n "${SKIP_INIT_IMAGE:-}" ]]; then
echo "Using prebuilt node image"
export IMAGE_TO_USE="projects/k8s-staging-cluster-api-gcp/global/images/cluster-api-ubuntu-1804-${KUBERNETES_VERSION//[.+]/-}-nightly"
else
filter="name~cluster-api-ubuntu-1804-${KUBERNETES_VERSION//[.+]/-}"
image_id=$(gcloud compute images list --project "$GCP_PROJECT" \
--no-standard-images --filter="${filter}" --format="table[no-heading](name)")
if [[ -z "$image_id" ]]; then
echo "unable to find image using : $filter $GCP_PROJECT ... bailing out!"
exit 1
fi
export IMAGE_TO_USE="projects/${GCP_PROJECT}/global/images/${image_id}"
fi

tracestate="$(shopt -po xtrace)"
Expand All @@ -291,7 +297,7 @@ create_cluster() {
GCP_B64ENCODED_CREDENTIALS=$(base64 -w0 "$GOOGLE_APPLICATION_CREDENTIALS") \
CLUSTER_NAME="${CLUSTER_NAME}" \
CI_VERSION=${CI_VERSION:-} \
IMAGE_ID="projects/${GCP_PROJECT}/global/images/${image_id}" \
IMAGE_ID="${IMAGE_TO_USE}" \
make create-cluster)

eval "$tracestate"
Expand Down Expand Up @@ -404,6 +410,10 @@ add_kustomize_patch() {

# setup kind, build kubernetes, create a cluster, run the e2es
main() {
# skip the build image by default for CI
# locally if want to build the image pass the flag --init-image
SKIP_INIT_IMAGE="1"

for arg in "$@"
do
if [[ "$arg" == "--verbose" ]]; then
Expand All @@ -415,9 +425,11 @@ main() {
fi
if [[ "$arg" == "--use-ci-artifacts" ]]; then
USE_CI_ARTIFACTS="1"
# when running the conformance that uses CI artifacts we need to build the node imade
unset SKIP_INIT_IMAGE
fi
if [[ "$arg" == "--skip-init-image" ]]; then
SKIP_INIT_IMAGE="1"
if [[ "$arg" == "--init-image" ]]; then
unset SKIP_INIT_IMAGE
fi
done

Expand Down
18 changes: 14 additions & 4 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export KUBERNETES_MAJOR_VERSION="1"
export KUBERNETES_MINOR_VERSION="19"
export KUBERNETES_PATCH_VERSION="10"
export KUBERNETES_VERSION="v${KUBERNETES_MAJOR_VERSION}.${KUBERNETES_MINOR_VERSION}.${KUBERNETES_PATCH_VERSION}"
# using prebuilt image from image-builder project the image is built everyday and the job is available here https://prow.k8s.io/?job=periodic-image-builder-gcp-all-nightly
export IMAGE_ID="projects/k8s-staging-cluster-api-gcp/global/images/cluster-api-ubuntu-1804-${KUBERNETES_VERSION//[.+]/-}-nightly"

init_image() {
if [[ "${REUSE_OLD_IMAGES:-false}" == "true" ]]; then
Expand Down Expand Up @@ -159,8 +161,12 @@ cleanup() {
--quiet "${GCP_NETWORK_NAME}" || true
fi

# removing the image created
gcloud compute images delete "${image_id}" --project "${GCP_PROJECT}" --quiet || true
if [[ -n "${SKIP_INIT_IMAGE:-}" ]]; then
echo "Skipping GCP image deletion..."
else
# removing the image created
gcloud compute images delete "${image_id}" --project "${GCP_PROJECT}" --quiet || true
fi

# stop boskos heartbeat
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" || true
Expand All @@ -174,13 +180,17 @@ exit-handler() {

# setup gcp network, build image run the e2es
main() {
# skip the build image by default for CI
# locally if want to build the image pass the flag --init-image
SKIP_INIT_IMAGE="1"

for arg in "$@"
do
if [[ "$arg" == "--verbose" ]]; then
set -o xtrace
fi
if [[ "$arg" == "--skip-init-image" ]]; then
SKIP_INIT_IMAGE="1"
if [[ "$arg" == "--init-image" ]]; then
unset SKIP_INIT_IMAGE
fi
if [[ "$arg" == "--build-image-only" ]]; then
BUILD_IMAGE_ONLY="1"
Expand Down
2 changes: 2 additions & 0 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
template:
spec:
instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}"
image: "${IMAGE_ID}"
---
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineDeployment
Expand Down Expand Up @@ -100,6 +101,7 @@ spec:
template:
spec:
instanceType: "${GCP_NODE_MACHINE_TYPE}"
image: "${IMAGE_ID}"
---
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha4
kind: KubeadmConfigTemplate
Expand Down

0 comments on commit fa795c8

Please sign in to comment.