Skip to content

Commit

Permalink
Add test-helm-chart target to Makefile to lint/test Helm chart upgrades
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Torres <[email protected]>
  • Loading branch information
torredil committed Nov 22, 2022
1 parent d338fca commit 662cbf8
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 89 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ test-e2e-external-eks:
GINKGO_SKIP="\[Disruptive\]|\[Serial\]" \
./hack/e2e/run.sh

.PHONY: test-helm-chart
test-helm-chart:
AWS_REGION=us-west-2 \
AWS_AVAILABILITY_ZONES=us-west-2a,us-west-2b,us-west-2c \
EBS_INSTALL_SNAPSHOT="true" \
HELM_EXTRA_FLAGS='--set=controller.k8sTagClusterId=$$CLUSTER_NAME' \
HELM_TEST="true" \
./hack/e2e/run.sh

.PHONY: verify-vendor
test: verify-vendor
verify: verify-vendor
Expand Down
201 changes: 201 additions & 0 deletions charts/aws-ebs-csi-driver/templates/tests/helm-tester.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: helm-sa
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-role
rules:
- apiGroups: [ "" ]
resources:
- events
- nodes
- pods
- replicationcontrollers
- serviceaccounts
- configmaps
- persistentvolumes
- persistentvolumeclaims
verbs: [ "list" ]
- apiGroups: [ "" ]
resources:
- services
- nodes
- nodes/proxy
- persistentvolumes
- persistentvolumeclaims
- pods
- pods/log
verbs: [ "get" ]
- apiGroups: [ "" ]
resources:
- namespaces
- persistentvolumes
- persistentvolumeclaims
- pods
- pods/exec
verbs: [ "create" ]
- apiGroups: [ "" ]
resources:
- namespaces
- persistentvolumes
- persistentvolumeclaims
- pods
verbs: [ "delete" ]
- apiGroups: [ "" ]
resources:
- persistentvolumeclaims
verbs: [ "update" ]
- apiGroups: [ "" ]
resources:
- pods/ephemeralcontainers
verbs: [ "patch" ]
- apiGroups: [ "" ]
resources:
- serviceaccounts
- configmaps
verbs: [ "watch" ]
- apiGroups: [ "apps" ]
resources:
- replicasets
- daemonsets
verbs: [ "list" ]
- apiGroups: [ "storage.k8s.io" ]
resources:
- storageclasses
verbs: [ "create" ]
- apiGroups: [ "storage.k8s.io" ]
resources:
- storageclasses
- csinodes
verbs: [ "get" ]
- apiGroups: [ "storage.k8s.io" ]
resources:
- storageclasses
verbs: [ "delete" ]
- apiGroups: [ "snapshot.storage.k8s.io" ]
resources:
- volumesnapshots
- volumesnapshotclasses
- volumesnapshotcontents
verbs: [ "create" ]
- apiGroups: [ "snapshot.storage.k8s.io" ]
resources:
- volumesnapshots
- volumesnapshotclasses
- volumesnapshotcontents
verbs: [ "get" ]
- apiGroups: [ "snapshot.storage.k8s.io" ]
resources:
- volumesnapshotcontents
verbs: [ "update" ]
- apiGroups: [ "snapshot.storage.k8s.io" ]
resources:
- volumesnapshots
- volumesnapshotclasses
- volumesnapshotcontents
verbs: [ "delete" ]
- apiGroups: [ "authorization.k8s.io" ]
resources:
- clusterroles
verbs: [ "list" ]
- apiGroups: [ "authorization.k8s.io" ]
resources:
- subjectaccessreviews
verbs: [ "create" ]
- apiGroups: [ "rbac.authorization.k8s.io" ]
resources:
- clusterroles
verbs: [ "list" ]
- apiGroups: [ "rbac.authorization.k8s.io" ]
resources:
- clusterrolebindings
verbs: [ "create" ]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-role-binding
subjects:
- kind: ServiceAccount
name: helm-sa
namespace: kube-system
roleRef:
kind: ClusterRole
name: test-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ConfigMap
data:
manifests.yaml: |
ShortName: ebs
StorageClass:
FromFile: storageclass.yaml
SnapshotClass:
FromName: true
DriverInfo:
Name: ebs.csi.aws.com
SupportedSizeRange:
Min: 1Gi
Max: 16Ti
SupportedFsType:
xfs: {}
ext4: {}
SupportedMountOption:
dirsync: {}
TopologyKeys: ["topology.ebs.csi.aws.com/zone"]
Capabilities:
persistence: true
fsGroup: true
block: true
exec: true
snapshotDataSource: true
pvcDataSource: false
multipods: true
controllerExpansion: true
nodeExpansion: true
volumeLimits: true
topology: true
storageclass.yaml: |
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs.csi.aws.com
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
metadata:
name: manifest-config
---
apiVersion: v1
kind: Pod
metadata:
name: helm-test
annotations:
"helm.sh/hook": test
spec:
containers:
- name: helm-test
image: gcr.io/k8s-staging-test-infra/kubekins-e2e:v20220624-1a63fdd9f2-master
command: [ "/bin/sh", "-c" ]
args:
- |
cp /etc/config/storageclass.yaml /workspace/storageclass.yaml
go install sigs.k8s.io/kubetest2/...@latest
kubectl config set-cluster cluster --server=https://kubernetes.default --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
kubectl config set-context kubetest2 --cluster=cluster
kubectl config set-credentials sa --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
kubectl config set-context kubetest2 --user=sa
kubectl config use-context kubetest2
kubetest2 noop --run-id='e2e-kubernetes' --test=ginkgo -- --test-package-version=$(curl https://storage.googleapis.com/kubernetes-release/release/stable-1.25.txt) --skip-regex='\[Disruptive\]|\[Serial\]' --focus-regex='External.Storage' --parallel=25 --test-args='-storage.testdriver=/etc/config/manifests.yaml'
volumeMounts:
- name: config-vol
mountPath: /etc/config
serviceAccountName: helm-sa
volumes:
- name: config-vol
configMap:
name: manifest-config
restartPolicy: Never
5 changes: 3 additions & 2 deletions charts/aws-ebs-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ controller:
# cpu: 100m
# memory: 128Mi
serviceAccount:
create: true # A service account will be created for you if set to true. Set to false if you want to use your own.
name: ebs-csi-controller-sa # Name of the service-account to be used/created.
# A service account will be created for you if set to true. Set to false if you want to use your own.
create: true
name: ebs-csi-controller-sa
annotations: {}
tolerations:
- key: CriticalAddonsOnly
Expand Down
37 changes: 37 additions & 0 deletions charts/chart_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: str()
home: str(required=False)
version: str()
apiVersion: str()
appVersion: any(str(), num(), required=False)
description: str(required=False)
keywords: list(str(), required=False)
sources: list(str(), required=False)
maintainers: list(include('maintainer'), required=False)
dependencies: list(include('dependency'), required=False)
icon: str(required=False)
engine: str(required=False)
condition: str(required=False)
tags: str(required=False)
deprecated: bool(required=False)
kubeVersion: str(required=False)
annotations: map(str(), str(), required=False)
type: str(required=False)
---
maintainer:
name: str()
email: str(required=False)
url: str(required=False)
---
dependency:
name: str()
version: str()
repository: str(required=False)
condition: str(required=False)
tags: list(str(), required=False)
enabled: bool(required=False)
import-values: any(list(str()), list(include('import-value')), required=False)
alias: str(required=False)
---
import-value:
child: str()
parent: str()
19 changes: 19 additions & 0 deletions charts/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
remote: origin
since: HEAD~1
github-instance: https://github.com
lint-conf: charts/lintconf.yaml
chart-yaml-schema: charts/chart_schema.yaml
validate-chart-schema: true
validate-yaml: true
check-version-increment: false
charts:
- charts/aws-ebs-csi-driver
helm-extra-args: "--timeout 1000s"
upgrade: true
skip-missing-values: true
namespace: kube-system
release-label: release
kubectl-timeout: 1000s
skip-clean-up: false
print-logs: true
debug: true
42 changes: 42 additions & 0 deletions charts/lintconf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
rules:
braces:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
max-spaces-before: 0
max-spaces-after: 1
commas:
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
require-starting-space: true
min-spaces-from-content: 2
document-end: disable
document-start: disable # No --- to start a file
empty-lines:
max: 2
max-start: 0
max-end: 0
hyphens:
max-spaces-after: 1
indentation:
spaces: consistent
indent-sequences: whatever # - list indentation will handle both indentation and without
check-multi-line-strings: false
key-duplicates: enable
line-length: disable # Lines can be any length
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: enable
truthy:
level: warning
17 changes: 17 additions & 0 deletions hack/e2e/chart-testing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -uo pipefail

function ct_install() {
INSTALL_PATH=${1}
CHART_TESTING_VERSION=${2}
if [[ ! -e ${INSTALL_PATH}/chart-testing ]]; then
CHART_TESTING_DOWNLOAD_URL="https://github.com/helm/chart-testing/releases/download/v${CHART_TESTING_VERSION}/chart-testing_${CHART_TESTING_VERSION}_linux_amd64.tar.gz"
curl --silent --location "${CHART_TESTING_DOWNLOAD_URL}" | tar xz -C "${INSTALL_PATH}"
chmod +x "${INSTALL_PATH}"/ct
fi

export PATH=/root/.local/bin:$PATH
python3 -m pip install --upgrade pip
python3 -m pip install --user yamllint yamale
}
Loading

0 comments on commit 662cbf8

Please sign in to comment.