diff --git a/Makefile b/Makefile index fd969df70..c30513d7d 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,12 @@ GD_PORT ?= 8080 # Documentation location DOCS_DIR ?= docs +# document validation options +UNAME != uname +export KIND_URL ?= https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(UNAME)-amd64 +KUBECTL_VERSION ?= v1.16.2 +export KUBECTL_URL ?= https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl + .PHONY: depend depend: @go mod download @@ -206,3 +212,8 @@ add-copyright: .PHONY: check-copyright check-copyright: @./tools/check_copyright + +# Validate YAMLs for all sites +.PHONY: validate-docs +validate-docs: + @./tools/validate_docs diff --git a/playbooks/airship-airshipctl-validate-documents.yaml b/playbooks/airship-airshipctl-validate-documents.yaml new file mode 100644 index 000000000..9948a0f28 --- /dev/null +++ b/playbooks/airship-airshipctl-validate-documents.yaml @@ -0,0 +1,28 @@ +# 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. + +- hosts: primary + tasks: + + - name: Ensure kubectl is present + include_role: + name: install-kubectl + + - name: Ensure airshipctl is present + include_role: + name: airshipctl-systemwide-executable + + - name: Validating site documents + make: + target: validate-docs + chdir: "{{ zuul.project.src_dir }}" + diff --git a/tools/document/build_kustomize_plugin.sh b/tools/document/build_kustomize_plugin.sh new file mode 100755 index 000000000..de8a4787d --- /dev/null +++ b/tools/document/build_kustomize_plugin.sh @@ -0,0 +1,46 @@ +#!/bin/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. + +# Run this from the airshipctl project root +set -e + +# This script builds a version of kustomize that is able to acces +# the ReplacementTransformer plugin. +# It assumes a build airshipctl binary in bin/, or if not, +# somewhere on the path. +if [ -f "bin/airshipctl" ]; then + AIRSHIPCTL="bin/airshipctl" +else + AIRSHIPCTL="$(which airshipctl)" +fi + +: ${KUSTOMIZE_PLUGIN_HOME:="$HOME/.airship/kustomize-plugins"} +: ${AIRSHIP_TAG:="dev"} + +# purge any previous airship plugins +rm -rf ${KUSTOMIZE_PLUGIN_HOME}/airshipit.org + +# copy our plugin to the PLUGIN_ROOT, and give a kustomzie-friendly wrapper +PLUGIN_PATH=${KUSTOMIZE_PLUGIN_HOME}/airshipit.org/v1alpha1/replacementtransformer +mkdir -p ${PLUGIN_PATH} +cat > ${PLUGIN_PATH}/ReplacementTransformer < ${AIRSHIPCONFIG} +apiVersion: airshipit.org/v1alpha1 +bootstrapInfo: + default: + builder: + networkConfigFileName: network-config + outputMetadataFileName: output-metadata.yaml + userDataFileName: user-data + container: + containerRuntime: docker + image: quay.io/airshipit/isogen:latest-debian_stable + volume: /srv/iso:/config + remoteDirect: + isoUrl: http://localhost:8099/debian-custom.iso +clusters: + ${CONTEXT}_${cluster}: + clusterType: + ${cluster}: + bootstrapInfo: default + clusterKubeconf: ${CONTEXT}_${cluster} + managementConfiguration: default +contexts: + ${CONTEXT}_${cluster}: + contextKubeconf: ${CONTEXT}_${cluster} + manifest: ${CONTEXT}_${cluster} +currentContext: ${CONTEXT}_${cluster} +kind: Config +managementConfiguration: + default: + insecure: true + systemActionRetries: 30 + systemRebootDelay: 30 + type: redfish +manifests: + ${CONTEXT}_${cluster}: + primaryRepositoryName: primary + repositories: + primary: + checkout: + branch: master + commitHash: "" + force: false + tag: "" + url: https://opendev.org/airship/treasuremap + subPath: manifests/site/${SITE} + targetPath: . +users: + ${CONTEXT}_${cluster}: {} +EOL +} + +# Loop over all cluster types and phases for the given site +for cluster in ephemeral target; do + # Clear out any CRDs left from testing of a previous cluster + ${KUBECTL} --context ${CONTEXT} --kubeconfig ${KUBECONFIG} delete crd --all > /dev/null + + if [[ -d "manifests/site/${SITE}/${cluster}" ]]; then + # Since we'll be mucking with the kubeconfig - make a copy of it and muck with the copy + cp ${KUBECONFIG} ${AIRSHIPKUBECONFIG} + # This is a big hack to work around kubeconfig reconciliation + # change the cluster name (as well as context and user) to avoid kubeconfig reconciliation + sed -i "s/${CONTEXT}/${CONTEXT}_${cluster}/" ${AIRSHIPKUBECONFIG} + generate_airshipconf ${cluster} + + for phase in $(ls manifests/site/${SITE}/${cluster}| grep -v "\.yaml$"); do + echo -e "\n*** Rendering ${cluster}/${phase}" + + # step 1: actually apply all crds in the phase + # TODO: will need to loop through phases in order, eventually + # e.g., load CRDs from initinfra first, so they're present when validating later phases + ${ACTL} phase render ${phase} -k CustomResourceDefinition > ${TMP}/crds.yaml + if [ -s ${TMP}/crds.yaml ]; then + ${KUBECTL} --context ${CONTEXT} --kubeconfig ${KUBECONFIG} apply -f ${TMP}/crds.yaml + fi + + # step 2: dry-run the entire phase + ${ACTL} phase apply --dry-run ${phase} + done + fi +done diff --git a/tools/validate_docs b/tools/validate_docs new file mode 100755 index 000000000..1bddde295 --- /dev/null +++ b/tools/validate_docs @@ -0,0 +1,39 @@ +#!/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. + +# The makefile entrypoint driver for document validation +# Expected to be run from the project root +set -e + +# get kind +echo "Fetching kind from ${KIND_URL}..." +TMP=$(KIND_URL=${KIND_URL} ./tools/document/get_kind.sh) +export KIND=${TMP}/kind +export KUBECTL_URL + +function cleanup() { + ${KIND} delete cluster --name airship + rm -rf ${TMP} +} +trap cleanup EXIT + +./tools/document/build_kustomize_plugin.sh +./tools/document/start_kind.sh + +for site in $(ls manifests/site); do + echo -e "\nValidating site: ${site}\n****************" + SITE=${site} ./tools/document/validate_site_docs.sh + echo "Validation of site ${site} is succesful!" +done + diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 0a4ba07df..2da77cdc6 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -45,6 +45,13 @@ - ^.*\.md$ - ^docs/.*$ +- job: + name: airship-airshipctl-validate-site-docs + pre-run: + - playbooks/airship-airshipctl-deploy-docker.yaml + run: playbooks/airship-airshipctl-validate-documents.yaml + nodeset: airship-airshipctl-single-node + - job: name: airship-airshipctl-functional-existing-k8s pre-run: playbooks/airship-airshipctl-deploy-existing-k8s.yaml diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml index a865c1734..629882342 100644 --- a/zuul.d/projects.yaml +++ b/zuul.d/projects.yaml @@ -22,6 +22,7 @@ - airship-airshipctl-lint-unit - airship-airshipctl-golint - airship-airshipctl-build-image + - airship-airshipctl-validate-site-docs # - airship-airshipctl-functional-existing-k8s TODO: Enable this when functional tests exist, and a cluster is up - airship-airshipctl-gate-test - airship-airshipctl-32GB-gate-test @@ -31,6 +32,7 @@ - airship-airshipctl-lint-unit - airship-airshipctl-lint-unit - airship-airshipctl-build-image + - airship-airshipctl-validate-site-docs # - airship-airshipctl-functional-existing-k8s TODO: Enable this when functional tests exist, and a cluster is up - airship-airshipctl-gate-test post: