From 8547656a684c59188004c33935be0f93d23a4c29 Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Fri, 23 Oct 2020 20:13:31 +0000 Subject: [PATCH] Add document pull functionality to deploy job This change introduces airshipctl's document pull functionality to the Treasuremap gate runner job. This enables Treasuremap maintainers to pin to a version of airshipctl deployment scripts and manifests that are known to be compatible with Treasuremap's v2 branch. In order to ensure that the deployment scripts and manifests come from the same version of airshipctl, this change introduces a playbook that checks out the referenced version of airhsipctl after it is cloned by Zuul. It also checks out the known version a second time in the deployment scripts for operators invoking the scripts in a non-Zuul environment. To update the pinned version of Treasuremap using Zuul, change the Zuul variable airshipctl_ref. To update the pinned version in a non-Zuul environment, use the environment variable AIRSHIPCTL_REF. Change-Id: I300f545efcdd024b689a96ee99e502de7fdd1b83 Signed-off-by: Drew Walters --- .../function/clusterctl/clusterctl-patch.yaml | 13 -------- .../function/clusterctl/kustomization.yaml | 7 ---- .../airship-treasuremap-ensure-checkout.yaml | 25 ++++++++++++++ .../airship-treasuremap-gate-runner.yaml | 10 ++++-- tools/deployment/22_test_configs.sh | 33 ++++++++++++------- tools/deployment/23_pull_documents.sh | 23 +++++++++++++ zuul.d/jobs.yaml | 6 +++- 7 files changed, 82 insertions(+), 35 deletions(-) delete mode 100644 manifests/function/clusterctl/clusterctl-patch.yaml create mode 100644 playbooks/airship-treasuremap-ensure-checkout.yaml create mode 100755 tools/deployment/23_pull_documents.sh diff --git a/manifests/function/clusterctl/clusterctl-patch.yaml b/manifests/function/clusterctl/clusterctl-patch.yaml deleted file mode 100644 index 45bdf67e2..000000000 --- a/manifests/function/clusterctl/clusterctl-patch.yaml +++ /dev/null @@ -1,13 +0,0 @@ -- op: replace - path: /providers/0/versions/v0.3.2 - value: ../airshipctl/manifests/function/capm3/v0.3.2 -- op: replace - path: /providers/1/versions/v0.3.7 - value: ../airshipctl/manifests/function/cabpk/v0.3.7 -- op: replace - path: /providers/2/versions/v0.3.7 - value: ../airshipctl/manifests/function/capi/v0.3.7 -- op: replace - path: /providers/3/versions/v0.3.7 - value: ../airshipctl/manifests/function/cacpk/v0.3.7 - diff --git a/manifests/function/clusterctl/kustomization.yaml b/manifests/function/clusterctl/kustomization.yaml index 05417e8b0..ad4b0ed69 100644 --- a/manifests/function/clusterctl/kustomization.yaml +++ b/manifests/function/clusterctl/kustomization.yaml @@ -1,9 +1,2 @@ resources: - ../../../../airshipctl/manifests/function/clusterctl -patchesJson6902: - - target: - group: airshipit.org - version: v1alpha1 - kind: Clusterctl - name: clusterctl_init - path: clusterctl-patch.yaml diff --git a/playbooks/airship-treasuremap-ensure-checkout.yaml b/playbooks/airship-treasuremap-ensure-checkout.yaml new file mode 100644 index 000000000..af9e61001 --- /dev/null +++ b/playbooks/airship-treasuremap-ensure-checkout.yaml @@ -0,0 +1,25 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Ensure that Treasuremap uses the same airshipctl reference for setup scripts +# as well as the manifests cloned in document pull. +- hosts: primary + tasks: + - name: Checkout version + shell: git checkout "{{ airshipctl_ref | default('HEAD') }}" + args: + chdir: "{{ zuul.projects['opendev.org/airship/airshipctl'].src_dir }}" + + - name: Print version + shell: echo "Using airshipctl ref $(git rev-parse HEAD)" + args: + chdir: "{{ zuul.projects['opendev.org/airship/airshipctl'].src_dir }}" diff --git a/playbooks/airship-treasuremap-gate-runner.yaml b/playbooks/airship-treasuremap-gate-runner.yaml index fe95d0e4c..17bbc8ab2 100644 --- a/playbooks/airship-treasuremap-gate-runner.yaml +++ b/playbooks/airship-treasuremap-gate-runner.yaml @@ -25,8 +25,14 @@ - ./tools/deployment/30_deploy_controlplane.sh - name: "Run gate scripts" - include_role: - name: airshipctl-run-script + shell: | + {{ gate_script_path }} + args: + chdir: "{{ zuul.project.src_dir }}" + environment: + AIRSHIPCTL_REF: "{{ airshipctl_ref | default('') }}" + AIRSHIPCTL_REPO_URL: "https://opendev.org/airship/airshipctl.git" + TREASUREMAP_PROJECT: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" vars: gate_script_path: "{{ item }}" with_items: "{{ gate_scripts | default(gate_scripts_default) }}" diff --git a/tools/deployment/22_test_configs.sh b/tools/deployment/22_test_configs.sh index 6b01be156..45e522e75 100755 --- a/tools/deployment/22_test_configs.sh +++ b/tools/deployment/22_test_configs.sh @@ -17,22 +17,31 @@ set -xe : ${AIRSHIPCTL_PROJECT:="../airshipctl"} : ${TREASUREMAP_PROJECT:="$(pwd)"} -export AIRSHIPCTL_WS=${AIRSHIPCTL_WS:-$AIRSHIPCTL_PROJECT} -export AIRSHIP_CONFIG_MANIFEST_DIRECTORY=${AIRSHIP_CONFIG_MANIFEST_DIRECTORY:-$TREASUREMAP_PROJECT} -export AIRSHIP_SITE_NAME=${AIRSHIP_SITE_NAME:-"manifests/site/test-site"} +export AIRSHIP_SITE_NAME=${AIRSHIP_SITE_NAME:-"test-site"} +export AIRSHIP_CONFIG_METADATA_PATH=${AIRSHIP_CONFIG_METADATA_PATH:-"treasuremap/manifests/site/$AIRSHIP_SITE_NAME/metadata.yaml"} -export AIRSHIP_CONFIG_METADATA_PATH=${AIRSHIP_CONFIG_METADATA_PATH:-"$AIRSHIP_SITE_NAME/metadata.yaml"} +# Primary repo options +export AIRSHIP_CONFIG_PRIMARY_REPO_URL=${AIRSHIP_CONFIG_PRIMARY_REPO_URL:-"${TREASUREMAP_PROJECT}"} +export AIRSHIPCTL_REPO_URL=${AIRSHIPCTL_REPO_URL:-"https://opendev.org/airship/airshipctl.git"} +export TREASUREMAP_REF=${TREASUREMAP_REF:-"$(git rev-parse HEAD)"} cd ${AIRSHIPCTL_PROJECT} +# NOTE(drewwalters96): Override $AIRSHIPCTL_REF to pin airshipctl to a specific +# git commit. Defaults to cloned version. +export AIRSHIPCTL_REF=${AIRSHIPCTL_REF:-"$(git rev-parse HEAD)"} + ./tools/deployment/22_test_configs.sh -# TODO: may not need/want this since treasuremap repo is already present, -# and branch checkout seems not to be working anyway for some reason? +# Add the airshipctl manifest defintion +airshipctl config set-manifest treasuremap_ci \ + --repo airshipctl \ + --url "${AIRSHIPCTL_REPO_URL}" \ + --commithash "${AIRSHIPCTL_REF}" -# Add the manifest defintion for Treasuremap -#airshipctl config set-manifest dummy_manifest \ -# --repo treasuremap \ -# --url https://opendev.org/airship/treasuremap \ -# --branch v2 \ -# --primary +airshipctl config set-manifest treasuremap_ci \ + --repo primary \ + --url "${AIRSHIP_CONFIG_PRIMARY_REPO_URL}" \ + --commithash "${TREASUREMAP_REF}" \ +airshipctl config set-context ephemeral-cluster --manifest treasuremap_ci +airshipctl config set-context target-cluster --manifest treasuremap_ci diff --git a/tools/deployment/23_pull_documents.sh b/tools/deployment/23_pull_documents.sh new file mode 100755 index 000000000..ae60e5690 --- /dev/null +++ b/tools/deployment/23_pull_documents.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -xe + +# TODO(drewwalters96): The document pull command is not invoked from a script +# in airshipctl since it uses the -n (no checkout) option. This enables the +# Treasuremap repository to use a pinned version of airshipctl. +# +# When airshipctl removes the -n from its document pull script, that script can +# be invoked here. +airshipctl document pull --debug diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index a755cc376..495986e24 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -55,16 +55,21 @@ roles: - zuul: airship/airshipctl pre-run: + - playbooks/airship-treasuremap-ensure-checkout.yaml - playbooks/airship-treasuremap-deploy-docker.yaml - playbooks/airship-treasuremap-build-gate.yaml post-run: playbooks/airship-collect-logs.yaml run: playbooks/airship-treasuremap-gate-runner.yaml nodeset: airship-treasuremap-single-16GB-bionic-node vars: + # NOTE(drewwalters96): Set airshipctl_ref to a commit SHA in order to pin + # the cloned version of airshipctl to a known/compatible reference. + # airshipctl_ref: "" site_name: test-site gate_scripts: - ./tools/deployment/01_install_kubectl.sh - ./tools/deployment/22_test_configs.sh + - ./tools/deployment/23_pull_documents.sh - ./tools/deployment/24_build_ephemeral_iso.sh - ./tools/deployment/25_deploy_ephemeral_node.sh - ./tools/deployment/26_deploy_metal3_capi_ephemeral_node.sh @@ -74,7 +79,6 @@ - ./tools/deployment/33_cluster_move_target_node.sh - ./tools/deployment/34_deploy_worker_node.sh - ./tools/deployment/35_deploy_workload.sh - serve_dir: /srv/iso serve_port: 8099 voting: false