From 5ad52896f3ac48032ca97931e0686415d0ae241b Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Wed, 21 Jul 2021 12:53:55 +0200 Subject: [PATCH] ci: use prebuilt node images for CAPG Signed-off-by: Carlos Panato --- hack/ci/e2e-conformance.sh | 30 +++++++++++++++++++++--------- scripts/ci-e2e.sh | 18 ++++++++++++++---- templates/cluster-template.yaml | 2 ++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/hack/ci/e2e-conformance.sh b/hack/ci/e2e-conformance.sh index 713b4103b..9bbf19e07 100755 --- a/hack/ci/e2e-conformance.sh +++ b/hack/ci/e2e-conformance.sh @@ -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)" @@ -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" @@ -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 @@ -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 diff --git a/scripts/ci-e2e.sh b/scripts/ci-e2e.sh index 61c6a0109..dde19abd6 100755 --- a/scripts/ci-e2e.sh +++ b/scripts/ci-e2e.sh @@ -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 @@ -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 @@ -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" diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml index a9d358adc..61692b0ba 100644 --- a/templates/cluster-template.yaml +++ b/templates/cluster-template.yaml @@ -67,6 +67,7 @@ spec: template: spec: instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}" + image: "${IMAGE_ID}" --- apiVersion: cluster.x-k8s.io/v1alpha4 kind: MachineDeployment @@ -100,6 +101,7 @@ spec: template: spec: instanceType: "${GCP_NODE_MACHINE_TYPE}" + image: "${IMAGE_ID}" --- apiVersion: bootstrap.cluster.x-k8s.io/v1alpha4 kind: KubeadmConfigTemplate