From b448f013357b118c1db1b796c1a501ac764cf19b Mon Sep 17 00:00:00 2001 From: John Starich Date: Tue, 22 Sep 2020 15:46:05 -0500 Subject: [PATCH] Add kubeval for validation of kube yaml in PRs (#214) --- .travis.yml | 4 ++-- Makefile | 23 ++++++++++++++++++++++- config/manager/kustomization.yaml | 2 +- config/manager/manager.yaml | 2 +- internal/cmd/genolm/maintainer.go | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6bbb3350..4ab0a17c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,8 @@ jobs: if: (branch = master AND type = push) OR type = pull_request # Don't run int tests too much on the same account in parallel, risks service name conflict failures - name: Test End-to-end script: make test-e2e - - name: Docker Build - script: make docker-build + - name: Release Validation + script: make validate-release RELEASE_VERSION=0.3.0 # Fake version, just used for quick validation - name: Release stage: release script: make -e RELEASE_VERSION="${TRAVIS_TAG/v}" release diff --git a/Makefile b/Makefile index 00f59648..c469e478 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ export KUBEBUILDER_ASSETS = ${PWD}/cache/kubebuilder_${KUBEBUILDER_VERSION}/bin CONTROLLER_GEN_VERSION = 0.2.5 CONTROLLER_GEN=${PWD}/cache/controller-gen_${CONTROLLER_GEN_VERSION}/controller-gen LINT_VERSION = 1.28.3 +KUBEVAL_VERSION= 0.15.0 +KUBEVAL_KUBE_VERSION=1.18.1 # Set PATH to pick up cached tools. The additional 'sed' is required for cross-platform support of quoting the args to 'env' SHELL := /usr/bin/env PATH=$(shell echo ${PWD}/cache/bin:${KUBEBUILDER_ASSETS}:${PATH} | sed 's/ /\\ /g') bash @@ -62,7 +64,12 @@ cache/bin/kustomize: cache/bin @rm -f cache/bin/kustomize cd cache/bin && \ set -o pipefail && \ - curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + for (( i = 0; i < 5; i++ )); do \ + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash; \ + if [[ "$$(which kustomize)" =~ cache/bin/kustomize ]]; then \ + break; \ + fi \ + done [[ "$$(which kustomize)" =~ cache/bin/kustomize ]] .PHONY: test-fast @@ -177,6 +184,12 @@ release-prep: kustomize manifests out .PHONY: release release: release-prep docker-push +# Validates release artifacts. +# TODO add validation for operator-courier. Currently hitting WAY too many issues with Travis CI and Python deps. +.PHONY: validate-release +validate-release: kubeval release-prep docker-build + kubeval -d out --kubernetes-version "${KUBEVAL_KUBE_VERSION}" --ignored-filename-patterns package.yaml --ignore-missing-schemas + .PHONY: operator-courier operator-courier: @if ! which operator-courier; then \ @@ -189,6 +202,7 @@ verify-operator-meta: release-prep operator-courier curl -sL https://github.com/IBM/cloud-operators/releases/download/v0.1.11/001_ibmcloud_v1alpha1_binding.yaml > out/0.1.11_ibmcloud_v1alpha1_binding.yaml curl -sL https://github.com/IBM/cloud-operators/releases/download/v0.1.11/002_ibmcloud_v1alpha1_service.yaml > out/0.1.11_ibmcloud_v1alpha1_service.yaml curl -sL https://github.com/IBM/cloud-operators/releases/download/v0.1.11/ibmcloud_operator.v0.1.11.clusterserviceversion.yaml > out/ibmcloud_operator.v0.1.11.clusterserviceversion.yaml + ls out operator-courier verify --ui_validate_io out/ .PHONY: operator-push-test @@ -210,3 +224,10 @@ operator-push-test: verify-operator-meta docker-build docker login -u="${QUAY_USER}" -p="${QUAY_TOKEN}" quay.io docker push "${IMG}" operator-courier push ./out "${QUAY_NAMESPACE}" "${QUAY_APP}" "${RELEASE_VERSION}" "Basic $$(printf "${QUAY_USER}:${QUAY_TOKEN}" | base64)" + +.PHONY: kubeval +kubeval: cache/bin + @if [[ ! -f cache/bin/kubeval ]]; then \ + set -ex -o pipefail; \ + curl -sL https://github.com/instrumenta/kubeval/releases/download/${KUBEVAL_VERSION}/kubeval-$$(uname)-amd64.tar.gz | tar -xz -C cache/bin; \ + fi diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 7e787cb9..a5eab3e0 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: cloudoperators/ibmcloud-operator - newTag: 0.2.1 + newTag: 0.2.0 diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 70b05722..2bb8b033 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -33,7 +33,7 @@ spec: fieldRef: fieldPath: metadata.namespace - name: MAX_CONCURRENT_RECONCILES - value: 1 + value: "1" image: controller:latest name: manager resources: diff --git a/internal/cmd/genolm/maintainer.go b/internal/cmd/genolm/maintainer.go index db630048..f0ca0782 100644 --- a/internal/cmd/genolm/maintainer.go +++ b/internal/cmd/genolm/maintainer.go @@ -40,7 +40,7 @@ func getMaintainers(repoRoot string) ([]Maintainer, error) { } var commits []*object.Commit - const maxCommits = 200 + const maxCommits = 100 for i := 0; i < maxCommits; i++ { commit, err := commitIter.Next() if err == io.EOF {