Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 73f1010

Browse files
committed
add scripts
Signed-off-by: yxxhero <[email protected]>
1 parent aa495a2 commit 73f1010

File tree

3 files changed

+310
-3
lines changed

3 files changed

+310
-3
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Binaries for programs and plugins
32
*.exe
43
*.exe~
@@ -36,4 +35,8 @@ charts/harbor-operator/charts/*.tgz
3635

3736
## goreleaser
3837
dist/
39-
vendor/
38+
vendor/
39+
40+
## local development test files
41+
config/samples/harborcluster-standard-dev/
42+
config/samples/harborcluster-minimal-dev/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Use distroless as minimal base image to package the manager binary
22
# Refer to https://github.com/GoogleContainerTools/distroless for more details
3-
FROM gcr.io/distroless/static:nonroot
3+
FROM oamdev/gcr.io-distroless-static:nonroot
44
WORKDIR /
55
COPY manager .
66
USER nonroot:nonroot

scripts/harbor_operator_kind.sh

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
DEFAULT_DEV_HABOR_OPERATOR_IMAGE=harbor-operator:dev_test
8+
DEFAULT_KIND_VERSION=v0.12.0
9+
DEFAULT_CERT_MANGER_VERSION=1.3.3
10+
DEFAULT_INGRESS_VERSION=1.0.5
11+
DEFAULT_CLUSTER_NAME=harbor
12+
DEFAULT_NODE_IMAGE=kindest/node:v1.23.0
13+
DEFAULT_KUBECTL_VERSION=v1.23.0
14+
PROJECT_ROOT=$(dirname $(dirname $0))
15+
DEFAULT_CONFIG=$PROJECT_ROOT/.github/kind.yaml
16+
DEFAULT_RUNNER_TOOL_CACHE=/usr/local/harbor-operator
17+
DEFAULT_OPERATOR_NAMESPACE=harbor-operator-ns
18+
IP=$(hostname -I | awk '{print $1}')
19+
20+
show_help() {
21+
cat <<EOF
22+
Usage: $(basename "$0") <options>
23+
-h, --help Display help
24+
-v, --version The kind version to use (default: $DEFAULT_KIND_VERSION)"
25+
-c, --config The path to the kind config file"
26+
-i, --node-image The Docker image for the cluster nodes"
27+
-n, --cluster-name The name of the cluster to create (default: chart-testing)"
28+
-w, --wait The duration to wait for the control plane to become ready (default: 60s)"
29+
-l, --log-level The log level for kind [panic, fatal, error, warning, info, debug, trace] (default: warning)
30+
-k, --kubectl-version The kubectl version to use (default: $DEFAULT_KUBECTL_VERSION)"
31+
EOF
32+
}
33+
34+
main() {
35+
local RUNNER_TOOL_CACHE="$DEFAULT_RUNNER_TOOL_CACHE"
36+
local version="$DEFAULT_KIND_VERSION"
37+
local cluster_name="$DEFAULT_CLUSTER_NAME"
38+
local kubectl_version="$DEFAULT_KUBECTL_VERSION"
39+
local config="$DEFAULT_CONFIG"
40+
local node_image="$DEFAULT_NODE_IMAGE"
41+
local wait=60s
42+
local log_level=
43+
44+
parse_command_line "$@"
45+
46+
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
47+
mkdir -p $RUNNER_TOOL_CACHE
48+
fi
49+
50+
local arch
51+
arch=$(uname -m)
52+
local cache_dir="$RUNNER_TOOL_CACHE/tools/$version/$arch"
53+
54+
local kind_dir="$cache_dir/kind/bin"
55+
if [[ ! -x "$kind_dir/kind" ]]; then
56+
install_kind
57+
fi
58+
59+
local kubectl_dir="$cache_dir/kubectl/bin"
60+
if [[ ! -x "$kubectl_dir/kubectl" ]]; then
61+
install_kubectl
62+
fi
63+
64+
"$kind_dir/kind" version
65+
"$kubectl_dir/kubectl" version --client=true
66+
67+
mount_memory_etcd
68+
69+
create_kind_cluster
70+
71+
install_cert_manager
72+
73+
install_ingress
74+
75+
build_load_harbor_operator_image
76+
77+
install_harbor_operator
78+
79+
install_harbor
80+
81+
echo "kubectl location: $kubectl_dir/kubectl"
82+
echo "kind location: $kind_dir/kind"
83+
84+
echo "Access the harbor with: https://$IP, enjoy!"
85+
86+
}
87+
88+
parse_command_line() {
89+
while :; do
90+
case "${1:-}" in
91+
-h | --help)
92+
show_help
93+
exit
94+
;;
95+
-v | --version)
96+
if [[ -n "${2:-}" ]]; then
97+
version="$2"
98+
shift
99+
else
100+
echo "ERROR: '-v|--version' cannot be empty." >&2
101+
show_help
102+
exit 1
103+
fi
104+
;;
105+
-c | --config)
106+
if [[ -n "${2:-}" ]]; then
107+
config="$2"
108+
shift
109+
else
110+
echo "ERROR: '--config' cannot be empty." >&2
111+
show_help
112+
exit 1
113+
fi
114+
;;
115+
-i | --node-image)
116+
if [[ -n "${2:-}" ]]; then
117+
node_image="$2"
118+
shift
119+
else
120+
echo "ERROR: '-i|--node-image' cannot be empty." >&2
121+
show_help
122+
exit 1
123+
fi
124+
;;
125+
-n | --cluster-name)
126+
if [[ -n "${2:-}" ]]; then
127+
cluster_name="$2"
128+
shift
129+
else
130+
echo "ERROR: '-n|--cluster-name' cannot be empty." >&2
131+
show_help
132+
exit 1
133+
fi
134+
;;
135+
-w | --wait)
136+
if [[ -n "${2:-}" ]]; then
137+
wait="$2"
138+
shift
139+
else
140+
echo "ERROR: '--wait' cannot be empty." >&2
141+
show_help
142+
exit 1
143+
fi
144+
;;
145+
-l | --log-level)
146+
if [[ -n "${2:-}" ]]; then
147+
log_level="$2"
148+
shift
149+
else
150+
echo "ERROR: '--log-level' cannot be empty." >&2
151+
show_help
152+
exit 1
153+
fi
154+
;;
155+
-k | --kubectl-version)
156+
if [[ -n "${2:-}" ]]; then
157+
kubectl_version="$2"
158+
shift
159+
else
160+
echo "ERROR: '-k|--kubectl-version' cannot be empty." >&2
161+
show_help
162+
exit 1
163+
fi
164+
;;
165+
*)
166+
break
167+
;;
168+
esac
169+
170+
shift
171+
done
172+
}
173+
174+
install_kind() {
175+
echo 'Installing kind...'
176+
177+
mkdir -p "$kind_dir"
178+
179+
curl -sSLo "$kind_dir/kind" "https://github.com/kubernetes-sigs/kind/releases/download/$version/kind-linux-amd64"
180+
chmod +x "$kind_dir/kind"
181+
}
182+
183+
install_kubectl() {
184+
echo 'Installing kubectl...'
185+
186+
mkdir -p "$kubectl_dir"
187+
188+
curl -sSLo "$kubectl_dir/kubectl" "https://storage.googleapis.com/kubernetes-release/release/$kubectl_version/bin/linux/amd64/kubectl"
189+
chmod +x "$kubectl_dir/kubectl"
190+
}
191+
192+
create_kind_cluster() {
193+
if ! "$kind_dir/kind" get clusters | grep $DEFAULT_CLUSTER_NAME >/dev/null; then
194+
echo 'Creating kind cluster...'
195+
local args=(create cluster "--name=$cluster_name" "--wait=$wait")
196+
197+
if [[ -n "$node_image" ]]; then
198+
args+=("--image=$node_image")
199+
fi
200+
201+
if [[ -n "$config" ]]; then
202+
args+=("--config=$config")
203+
fi
204+
205+
if [[ -n "$log_level" ]]; then
206+
args+=("--loglevel=$log_level")
207+
fi
208+
209+
"$kind_dir/kind" "${args[@]}"
210+
else
211+
echo "kind cluster $DEFAULT_CLUSTER_NAME already exists"
212+
fi
213+
}
214+
215+
mount_memory_etcd() {
216+
echo 'Mounting memory etcd...'
217+
mkdir -p /tmp/lib/etcd
218+
if ! df -h | grep "^tmpfs.*/tmp/lib/etcd" &>/dev/null; then
219+
mount -t tmpfs tmpfs /tmp/lib/etcd
220+
fi
221+
}
222+
223+
install_cert_manager() {
224+
$kubectl_dir/kubectl apply -f "https://github.com/jetstack/cert-manager/releases/download/v$DEFAULT_CERT_MANGER_VERSION/cert-manager.yaml"
225+
sleep 5
226+
time $kubectl_dir/kubectl -n cert-manager wait --for=condition=Available deployment --all --timeout 300s
227+
}
228+
229+
install_ingress() {
230+
$kubectl_dir/kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v$DEFAULT_INGRESS_VERSION/deploy/static/provider/kind/deploy.yaml
231+
time $kubectl_dir/kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=300s
232+
}
233+
234+
build_load_harbor_operator_image() {
235+
echo 'Building and load harbor-operator image...'
236+
cd $PROJECT_ROOT
237+
make manifests docker-build IMG=$DEFAULT_DEV_HABOR_OPERATOR_IMAGE &> /dev/null
238+
cd - &>/dev/null
239+
$kind_dir/kind load docker-image $DEFAULT_DEV_HABOR_OPERATOR_IMAGE --name $DEFAULT_CLUSTER_NAME &> /dev/null
240+
}
241+
242+
install_harbor_operator() {
243+
echo 'Installing harbor-operator...'
244+
set -ex
245+
cd $PROJECT_ROOT
246+
make helm-install NAMESPACE=$DEFAULT_OPERATOR_NAMESPACE IMG=$DEFAULT_DEV_HABOR_OPERATOR_IMAGE
247+
$kubectl_dir/kubectl -n $DEFAULT_OPERATOR_NAMESPACE wait --for=condition=Available deployment --all --timeout 300s
248+
249+
if ! time $kubectl_dir/kubectl -n $DEFAULT_OPERATOR_NAMESPACE wait --for=condition=Available deployment --all --timeout 300s; then
250+
$kubectl_dir/kubectl get all -n $DEFAULT_OPERATOR_NAMESPACE
251+
exit 1
252+
fi
253+
cd - &>/dev/null
254+
}
255+
256+
install_harbor() {
257+
set -ex
258+
cd $PROJECT_ROOT
259+
CORE_HOST=core.$IP.nip.io
260+
NOTARY_HOST=notary.$IP.nip.io
261+
262+
# clean up
263+
rm -fr config/samples/harborcluster-standard-dev
264+
rm -fr config/samples/harborcluster-minimal-dev
265+
266+
cp -a config/samples/harborcluster-standard config/samples/harborcluster-standard-dev
267+
cp -a config/samples/harborcluster-minimal config/samples/harborcluster-minimal-dev
268+
269+
sed -i "s/core.harbor.domain/$CORE_HOST/g" config/samples/harborcluster-minimal-dev/*.yaml
270+
sed -i "s/notary.harbor.domain/$NOTARY_HOST/g" config/samples/harborcluster-minimal-dev/*.yaml
271+
sed -i "s/core.harbor.domain/$CORE_HOST/g" config/samples/harborcluster-standard-dev/*.yaml
272+
sed -i "s/notary.harbor.domain/$NOTARY_HOST/g" config/samples/harborcluster-standard-dev/*.yaml
273+
274+
sed -i "s/harborcluster-minimal/harborcluster-minimal-dev/g" config/samples/harborcluster-standard-dev/*.yaml
275+
276+
277+
make sample-harborcluster-standard-dev
278+
279+
for i in $(seq 1 7); do
280+
sleep 30
281+
echo $i
282+
$kubectl_dir/kubectl get all
283+
done
284+
if ! time $kubectl_dir/kubectl wait --for=condition=Ready -l job-type!=minio-init pod --all --timeout 600s && ! time kubectl wait --for=condition=Ready -l job-type!=minio-init pod --all --timeout 60s; then
285+
echo "install harbor failed"
286+
$kubectl_dir/kubectl get all
287+
288+
for n in $($kubectl_dir/kubectl get po | grep -v Running | grep -v NAME | awk '{print $1}'); do
289+
echo "describe $n"
290+
$kubectl_dir/kubectl describe pod $n
291+
echo "show log $n"
292+
$kubectl_dir/kubectl logs --tail 100 $n || true
293+
done
294+
$kubectl_dir/kubectl logs -l control-plane=harbor-operator -n ${operatorNamespace} --tail 100
295+
exit 1
296+
else
297+
$kubectl_dir/kubectl get all
298+
$kubectl_dir/kubectl get harbor -o wide
299+
$kubectl_dir/kubectl get harborcluster -o wide
300+
fi
301+
cd - &>/dev/null
302+
}
303+
304+
main "$@"

0 commit comments

Comments
 (0)