diff --git a/.travis.yml b/.travis.yml index 50db3e20..51f4b129 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,17 +23,20 @@ jobs: script: make unit-test name: Unit Tests after_success: bash <(curl -s https://codecov.io/bash) -v + - stage: Test + script: make helm-lint + name: Helm v2 and v3 Lint - stage: Test script: test/go-report-card-test/run-report-card-test.sh name: Go Report Card Test - stage: Test - script: make create-build-dir build-binaries + script: make build-binaries name: Build Binaries - stage: Test - script: make create-build-dir build-docker-images + script: make build-docker-images name: Build Docker Images - stage: Test - script: make create-build-dir generate-k8s-yaml + script: make generate-k8s-yaml name: Generate K8s yaml files - stage: Test if: type = push AND env(GITHUB_TOKEN) IS present diff --git a/Makefile b/Makefile index 2b8e1bbf..09e9aca4 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,12 @@ MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST)))) BUILD_DIR_PATH = ${MAKEFILE_PATH}/build SUPPORTED_PLATFORMS ?= "linux/amd64,linux/arm64,linux/arm" +$(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod) + compile: @echo ${MAKEFILE_PATH} go build -a -tags nth${GOOS} -o ${BUILD_DIR_PATH}/node-termination-handler ${MAKEFILE_PATH}/cmd/node-termination-handler.go -create-build-dir: - mkdir -p ${BUILD_DIR_PATH} - clean: rm -rf ${BUILD_DIR_PATH}/ @@ -65,6 +64,9 @@ helm-sync-test: helm-version-sync-test: ${MAKEFILE_PATH}/test/helm-sync-test/run-helm-version-sync-test +helm-lint: + ${MAKEFILE_PATH}/test/helm/helm-lint + build-binaries: ${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS} -v ${VERSION} @@ -77,17 +79,17 @@ generate-k8s-yaml: sync-readme-to-dockerhub: ${MAKEFILE_PATH}/scripts/sync-readme-to-dockerhub -unit-test: create-build-dir +unit-test: go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage.txt -covermode=atomic -outputdir=${BUILD_DIR_PATH} unit-test-linux: ${MAKEFILE_PATH}/scripts/run-unit-tests-in-docker -build: create-build-dir compile +build: compile -helm-tests: helm-sync-test helm-version-sync-test +helm-tests: helm-sync-test helm-version-sync-test helm-lint -release: create-build-dir build-binaries build-docker-images push-docker-images generate-k8s-yaml upload-resources-to-github +release: build-binaries build-docker-images push-docker-images generate-k8s-yaml upload-resources-to-github test: unit-test e2e-test compatibility-test license-test go-report-card-test helm-sync-test diff --git a/config/helm/aws-node-termination-handler/templates/_helpers.tpl b/config/helm/aws-node-termination-handler/templates/_helpers.tpl index 15acd5c6..7a1efdd4 100644 --- a/config/helm/aws-node-termination-handler/templates/_helpers.tpl +++ b/config/helm/aws-node-termination-handler/templates/_helpers.tpl @@ -71,7 +71,8 @@ In 1.14 "beta.kubernetes.io" was deprecated and is scheduled for removal in 1.18 See https://v1-14.docs.kubernetes.io/docs/setup/release/notes/#deprecations */}} {{- define "aws-node-termination-handler.defaultNodeSelectorTermsPrefix" -}} - {{- semverCompare "<1.14" .Capabilities.KubeVersion.Version | ternary "beta.kubernetes.io" "kubernetes.io" -}} + {{- $k8sVersion := printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor -}} + {{- semverCompare "<1.14" $k8sVersion | ternary "beta.kubernetes.io" "kubernetes.io" -}} {{- end -}} {{/* diff --git a/config/helm/ec2-metadata-test-proxy/templates/daemonset.yaml b/config/helm/ec2-metadata-test-proxy/templates/daemonset.yaml index be9b1254..bc4a0c46 100644 --- a/config/helm/ec2-metadata-test-proxy/templates/daemonset.yaml +++ b/config/helm/ec2-metadata-test-proxy/templates/daemonset.yaml @@ -1,6 +1,7 @@ {{- if .Values.ec2MetadataTestProxy.create -}} {{- $isWindows := (contains "windows" .Values.targetNodeOs) -}} -{{- $osSelector := (semverCompare "<1.14" .Capabilities.KubeVersion.Version | ternary "beta.kubernetes.io/os" "kubernetes.io/os") -}} +{{- $k8sVersion := printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor -}} +{{- $osSelector := (semverCompare "<1.14" $k8sVersion | ternary "beta.kubernetes.io/os" "kubernetes.io/os") -}} apiVersion: apps/v1 kind: DaemonSet metadata: diff --git a/config/helm/ec2-metadata-test-proxy/templates/regular-pod-test.yaml b/config/helm/ec2-metadata-test-proxy/templates/regular-pod-test.yaml index 18fe1dc5..c06aa412 100644 --- a/config/helm/ec2-metadata-test-proxy/templates/regular-pod-test.yaml +++ b/config/helm/ec2-metadata-test-proxy/templates/regular-pod-test.yaml @@ -1,6 +1,7 @@ {{- if .Values.regularPodTest.create -}} {{- $isWindows := (contains "windows" .Values.targetNodeOs) -}} -{{- $osSelector := (semverCompare "<1.14" .Capabilities.KubeVersion.Version | ternary "beta.kubernetes.io/os" "kubernetes.io/os") -}} +{{- $k8sVersion := printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor -}} +{{- $osSelector := (semverCompare "<1.14" $k8sVersion | ternary "beta.kubernetes.io/os" "kubernetes.io/os") -}} apiVersion: apps/v1 kind: Deployment metadata: diff --git a/scripts/generate-k8s-yaml b/scripts/generate-k8s-yaml index 0488a7f6..e2b2f57d 100755 --- a/scripts/generate-k8s-yaml +++ b/scripts/generate-k8s-yaml @@ -26,13 +26,16 @@ EOM ) # Process our input arguments -while getopts "n:" opt; do +while getopts "vn:" opt; do case ${opt} in n ) # K8s namespace NAMESPACE=$OPTARG ;; + v ) # Verbose + set -x + ;; \? ) - echoerr "$USAGE" 1>&2 + echo "$USAGE" 1>&2 exit ;; esac diff --git a/test/helm/helm-lint b/test/helm/helm-lint new file mode 100755 index 00000000..95a445dc --- /dev/null +++ b/test/helm/helm-lint @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" +TMP_DIR="$SCRIPTPATH/../../build" +PLATFORM=$(uname | tr '[:upper:]' '[:lower:]') +HELM3_VERSION="3.2.4" +HELM2_VERSION="2.16.9" + +mkdir -p $TMP_DIR + +if [ ! -x "$TMP_DIR/helm" ]; then + echo "🥑 Downloading the \"helm3\" binary" + curl -L https://get.helm.sh/helm-v$HELM3_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $TMP_DIR + mv $TMP_DIR/$PLATFORM-amd64/helm $TMP_DIR/. + chmod +x $TMP_DIR/helm + echo "👍 Downloaded the \"helm\" binary" +fi + +if [ ! -x "$TMP_DIR/helm2" ]; then + echo "🥑 Downloading the \"helm2\" binary" + curl -L https://get.helm.sh/helm-v$HELM2_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $TMP_DIR + mv $TMP_DIR/$PLATFORM-amd64/helm $TMP_DIR/helm2 + chmod +x $TMP_DIR/helm2 + echo "👍 Downloaded the \"helm2\" binary" +fi +export PATH=$TMP_DIR:$PATH + +echo "==============================================================================" +echo " Linting Helm Chart w/ Helm v3" +echo "==============================================================================" +helm lint $SCRIPTPATH/../../config/helm/aws-node-termination-handler/ + +echo "==============================================================================" +echo " Linting Helm Chart w/ Helm v2" +echo "==============================================================================" +helm2 lint $SCRIPTPATH/../../config/helm/aws-node-termination-handler/ + +echo "✅ Helm Linting for v2 and v3 have successfully completed!"