Skip to content

Commit

Permalink
Kube version helm (#190)
Browse files Browse the repository at this point in the history
* fix kube version retrieval in helm template helpers

* add helm lint test

* change kube-version retrieval on emtp
  • Loading branch information
bwagner5 authored Jul 7, 2020
1 parent b6cbb2a commit e16065c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 15 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}/

Expand Down Expand Up @@ -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}

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

{{/*
Expand Down
3 changes: 2 additions & 1 deletion config/helm/ec2-metadata-test-proxy/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 5 additions & 2 deletions scripts/generate-k8s-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/helm/helm-lint
Original file line number Diff line number Diff line change
@@ -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!"

0 comments on commit e16065c

Please sign in to comment.