@@ -4,93 +4,104 @@ set -o errexit
4
4
set -o nounset
5
5
set -o pipefail
6
6
7
- readonly REPO_ROOT=" ${REPO_ROOT:- $(git rev-parse --show-toplevel)} "
7
+ readonly CT_VERSION=v2.2.0
8
+ readonly KIND_VERSION=0.1.0
9
+ readonly CLUSTER_NAME=chart-testing
10
+ readonly K8S_VERSION=v1.13.2
11
+
12
+ run_ct_container () {
13
+ echo ' Running ct container...'
14
+ docker run --rm --interactive --detach --network host --name ct \
15
+ --volume " $( pwd) /test/ct.yaml:/etc/ct/ct.yaml" \
16
+ --volume " $( pwd) :/workdir" \
17
+ --workdir /workdir \
18
+ " quay.io/helmpack/chart-testing:$CT_VERSION " \
19
+ cat
20
+ echo
21
+ }
22
+
23
+ cleanup () {
24
+ echo ' Removing ct container...'
25
+ docker kill ct > /dev/null 2>&1
26
+
27
+ echo ' Done!'
28
+ }
29
+
30
+ docker_exec () {
31
+ docker exec --interactive ct " $@ "
32
+ }
33
+
34
+ create_kind_cluster () {
35
+ echo ' Installing kind...'
36
+
37
+ curl -sSLo kind " https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION /kind-linux-amd64"
38
+ chmod +x kind
39
+ sudo mv kind /usr/local/bin/kind
8
40
9
- run_kind () {
41
+ kind create cluster --name " $CLUSTER_NAME " --config test/kind-config.yaml --image " kindest/node: $K8S_VERSION "
10
42
11
- echo " Download kind binary..."
12
- docker run --rm -it -v " $( pwd) " :/go/bin golang go get sigs.k8s.io/kind && sudo mv kind /usr/local/bin/
43
+ docker_exec mkdir -p /root/.kube
13
44
14
- echo " Download kubectl..."
15
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/" ${K8S_VERSION} " /bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
45
+ echo ' Copying kubeconfig to container...'
46
+ local kubeconfig
47
+ kubeconfig=" $( kind get kubeconfig-path --name " $CLUSTER_NAME " ) "
48
+ docker cp " $kubeconfig " ct:/root/.kube/config
49
+
50
+ docker_exec kubectl cluster-info
16
51
echo
17
52
18
- echo " Create Kubernetes cluster with kind..."
19
- kind create cluster --image=kindest/node:" $K8S_VERSION "
53
+ echo -n ' Waiting for cluster to be ready...'
54
+ until ! grep --quiet ' NotReady' <( docker_exec kubectl get nodes --no-headers) ; do
55
+ printf ' .'
56
+ sleep 1
57
+ done
20
58
21
- echo " Export kubeconfig..."
22
- # shellcheck disable=SC2155
23
- export KUBECONFIG=" $( kind get kubeconfig-path) "
59
+ echo ' ✔︎'
24
60
echo
25
61
26
- echo " Ensure the apiserver is responding..."
27
- kubectl cluster-info
62
+ docker_exec kubectl get nodes
28
63
echo
29
64
30
- echo " Wait for Kubernetes to be up and ready..."
31
- JSONPATH=' {range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' ; until kubectl get nodes -o jsonpath=" $JSONPATH " 2>&1 | grep -q " Ready=True" ; do sleep 1; done
65
+ echo ' Cluster ready!'
32
66
echo
33
67
}
34
68
35
69
install_tiller () {
36
- # Install Tiller with RBAC
37
- kubectl -n kube-system create sa tiller
38
- kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
39
- docker exec " $config_container_id " helm init --service-account tiller
40
- echo " Wait for Tiller to be up and ready..."
41
- until kubectl -n kube-system get pods 2>&1 | grep -w " tiller-deploy" | grep -w " 1/1" ; do sleep 1; done
70
+ echo ' Installing Tiller...'
71
+ docker_exec kubectl --namespace kube-system create sa tiller
72
+ docker_exec kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
73
+ docker_exec helm init --service-account tiller --upgrade --wait
42
74
echo
43
75
}
44
76
45
77
install_hostpath-provisioner () {
46
- # kind doesn't support Dynamic PVC provisioning yet, this one of ways to get it working
47
- # https://github.com/rimusz/charts/tree/master/stable/hostpath-provisioner
78
+ # kind doesn't support Dynamic PVC provisioning yet, this is one way to get it working
79
+ # https://github.com/rimusz/charts/tree/master/stable/hostpath-provisioner
48
80
49
- # delete the default storage class
50
- kubectl delete storageclass standard
81
+ echo ' Installing hostpath-provisioner...'
51
82
52
- echo " Install Hostpath Provisioner..."
53
- docker exec " $config_container_id " helm repo add rimusz https://charts.rimusz.net
54
- docker exec " $config_container_id " helm repo update
55
- docker exec " $config_container_id " helm upgrade --install hostpath-provisioner --namespace kube-system rimusz/hostpath-provisioner
56
- echo
57
- }
83
+ # Remove default storage class. Will be recreated by hostpath -provisioner
84
+ docker_exec kubectl delete storageclass standard
58
85
59
- main () {
60
-
61
- echo " Starting kind ... "
86
+ docker_exec helm repo add rimusz https://charts.rimusz.net
87
+ docker_exec helm repo update
88
+ docker_exec helm install rimusz/hostpath-provisioner --name hostpath-provisioner --namespace kube-system --wait
62
89
echo
63
- run_kind
64
-
65
- local config_container_id
66
- config_container_id=$( docker run -it -d -v " $REPO_ROOT :/workdir" --workdir /workdir " $CHART_TESTING_IMAGE :$CHART_TESTING_TAG " cat)
67
-
68
- # shellcheck disable=SC2064
69
- trap " docker rm -f $config_container_id > /dev/null" EXIT
70
-
71
- # Get kind container IP
72
- kind_container_ip=$( docker inspect -f ' {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kind-1-control-plane)
73
- # Copy kubeconfig file
74
- docker exec " $config_container_id " mkdir /root/.kube
75
- docker cp " $KUBECONFIG " " $config_container_id :/root/.kube/config"
76
- # Update in kubeconfig from localhost to kind container IP
77
- docker exec " $config_container_id " sed -i " s/localhost:.*/$kind_container_ip :6443/g" /root/.kube/config
90
+ }
78
91
79
- echo " Add git remote k8s ${CHARTS_REPO} "
80
- git remote add k8s " ${CHARTS_REPO} " & > /dev/null || true
81
- git fetch k8s master
92
+ install_charts () {
93
+ docker_exec ct install
82
94
echo
95
+ }
83
96
84
- # Install Tiller with RBAC
85
- install_tiller
97
+ main () {
98
+ run_ct_container
99
+ trap cleanup EXIT
86
100
87
- # Install hostpath-provisioner for Dynammic PVC provisioning
101
+ create_kind_cluster
102
+ install_tiller
88
103
install_hostpath-provisioner
89
-
90
- # shellcheck disable=SC2086
91
- docker exec " $config_container_id " ct install --config /workdir/test/ct.yaml
92
-
93
- echo " Done Testing!"
104
+ install_charts
94
105
}
95
106
96
107
main
0 commit comments