-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathkind.sh
executable file
·196 lines (171 loc) · 6.21 KB
/
kind.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
# Copyright The Helm Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
DEFAULT_KIND_VERSION=v0.5.1
DEFAULT_CLUSTER_NAME=chart-testing
show_help() {
cat << EOF
Usage: $(basename "$0") <options>
-h, --help Display help
-v, --version The kind version to use (default: v0.5.1)"
-c, --config The path to the kind config file"
-i, --node-image The Docker image for the cluster nodes"
-n, --cluster-name The name of the cluster to create (default: chart-testing)"
-w, --wait The duration to wait for the control plane to become ready (default: 60s)"
-l, --log-level The log level for kind [panic, fatal, error, warning, info, debug, trace] (default: warning)
-p, --install-local-path-provisioner If true, Rancher's local-path provisioner is installed which supports
dynamic volume provisioning on multi-node clusters. The newly created
local-path StorageClass is made the default.
EOF
}
main() {
local version="$DEFAULT_KIND_VERSION"
local config=
local node_image=
local cluster_name="$DEFAULT_CLUSTER_NAME"
local wait=60s
local log_level=
local install_local_path_provisioner=
parse_command_line "$@"
install_kind
install_kubectl
create_kind_cluster
set_kubeconfig
if [[ -n "$install_local_path_provisioner" ]]; then
install_local_path_provisioner
fi
}
parse_command_line() {
while :; do
case "${1:-}" in
-h|--help)
show_help
exit
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
version="$2"
shift
else
echo "ERROR: '-v|--version' cannot be empty." >&2
show_help
exit 1
fi
;;
-c|--config)
if [[ -n "${2:-}" ]]; then
config="$2"
shift
else
echo "ERROR: '--config' cannot be empty." >&2
show_help
exit 1
fi
;;
-i|--node_image)
if [[ -n "${2:-}" ]]; then
node_image="$2"
shift
else
echo "ERROR: '-i|--node-image' cannot be empty." >&2
show_help
exit 1
fi
;;
-n|--cluster_name)
if [[ -n "${2:-}" ]]; then
cluster_name="$2"
shift
else
echo "ERROR: '-n|--cluster-name' cannot be empty." >&2
show_help
exit 1
fi
;;
-w|--wait)
if [[ -n "${2:-}" ]]; then
wait="$2"
shift
else
echo "ERROR: '--wait' cannot be empty." >&2
show_help
exit 1
fi
;;
-l|--log-level)
if [[ -n "${2:-}" ]]; then
log_level="$2"
shift
else
echo "ERROR: '--log-level' cannot be empty." >&2
show_help
exit 1
fi
;;
-p|--install-local-pasth-provisioner)
install_local_path_provisioner=true
;;
*)
break
;;
esac
shift
done
}
install_kind() {
echo 'Installing kind...'
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$version/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind
}
install_kubectl() {
echo 'Installing kubectl...'
curl -sSLO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
}
create_kind_cluster() {
echo 'Creating kind cluster...'
local args=(create cluster "--name=$cluster_name" "--wait=$wait")
if [[ -n "$node_image" ]]; then
args+=("--image=$node_image")
fi
if [[ -n "$config" ]]; then
args+=("--config=$config")
fi
if [[ -n "$log_level" ]]; then
args+=("--loglevel=$log_level")
fi
kind "${args[@]}"
}
set_kubeconfig() {
local kubeconfig_path
kubeconfig_path=$(kind get kubeconfig-path "--name=$cluster_name")
mv "$kubeconfig_path" "$HOME/.kube/config"
}
install_local_path_provisioner() {
echo 'Installing local-path provisioner...'
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
echo 'Changing default StorageClass...'
kubectl patch storageclass standard --patch '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "false"}}}'
kubectl patch storageclass standard --patch '{"metadata": {"annotations": {"storageclass.beta.kubernetes.io/is-default-class": "false"}}}'
kubectl patch storageclass local-path --patch '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'
kubectl patch storageclass local-path --patch '{"metadata": {"annotations": {"storageclass.beta.kubernetes.io/is-default-class": "true"}}}'
echo 'Available StorageClasses:'
kubectl get storageclasses
}
main "$@"