-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathdeploy-fleet.sh
More file actions
executable file
·90 lines (80 loc) · 3.12 KB
/
deploy-fleet.sh
File metadata and controls
executable file
·90 lines (80 loc) · 3.12 KB
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
#!/bin/bash
set -euxo pipefail
shards_json=${SHARDS-""}
node=${NODE-k3d-upstream-server-0}
function eventually {
for _ in $(seq 1 3); do
"$@" && return 0
done
return 1
}
# usage: ./deploy-fleet.sh ghcr.io/rancher/fleet:sha-49f6f81 ghcr.io/rancher/fleet-agent:1h
if [ $# -ge 2 ] && [ -n "$1" ] && [ -n "$2" ]; then
fleetRepo="${1%:*}"
fleetTag="${1#*:}"
agentRepo="${2%:*}"
agentTag="${2#*:}"
else
fleetRepo="rancher/fleet"
fleetTag="dev"
agentRepo="rancher/fleet-agent"
agentTag="dev"
fi
host=$(kubectl get node $node -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}')
ca=$( kubectl config view --flatten -o jsonpath='{.clusters[?(@.name == "k3d-upstream")].cluster.certificate-authority-data}' | base64 -d )
server="https://$host:6443"
# Constructing the shards settings dynamically
shards_settings=""
if [ -n "$shards_json" ]; then
index=0
for shard in $(echo "${shards_json}" | jq -c '.[]'); do
shard_id=$(echo "$shard" | jq -r '.id')
shards_settings="$shards_settings --set shards[$index].id=$shard_id"
node_selector=$(echo "$shard" | jq -r '.nodeSelector // empty')
if [ -n "$node_selector" ]; then
for key in $(echo "$node_selector" | jq -r 'keys[]'); do
value=$(echo "$node_selector" | jq -r --arg key "$key" '.[$key]')
escaped_key=$(echo "$key" | sed 's/\./\\./g')
shards_settings="$shards_settings --set shards[$index].nodeSelector.$escaped_key=$value"
done
fi
index=$((index + 1))
done
fi
eventually helm upgrade --install fleet-crd charts/fleet-crd \
--atomic \
-n cattle-fleet-system \
--create-namespace
eventually helm upgrade --install fleet charts/fleet \
--atomic \
-n cattle-fleet-system \
--timeout=10m \
--create-namespace \
--set image.repository="$fleetRepo" \
--set image.tag="$fleetTag" \
--set agentImage.repository="$agentRepo" \
--set agentImage.tag="$agentTag" \
--set agentImage.imagePullPolicy=IfNotPresent \
--set bootstrap.agentNamespace=cattle-fleet-local-system \
--set agentCheckinInterval=5s \
--set clusterMonitor.enabled=true \
--set clusterMonitor.threshold=20s \
--set clusterMonitor.interval=10s \
--set apiServerCA="$ca" \
--set apiServerURL="$server" \
$shards_settings \
--set garbageCollectionInterval=1s \
--set insecureSkipHostKeyChecks=false \
--set imagescan.enabled=true \
--set-string extraEnv[0].name=EXPERIMENTAL_SCHEDULES \
--set-string extraEnv[0].value=true \
--set-string extraEnv[1].name=EXPERIMENTAL_COPY_RESOURCES_DOWNSTREAM \
--set-string extraEnv[1].value=true \
--set debug=true --set debugLevel=1
# wait for controller and agent rollout
kubectl -n cattle-fleet-system rollout status deploy/fleet-controller
{ grep -E -q -m 1 "fleet-agent-local.*1/1"; kill $!; } < <(kubectl get bundles -n fleet-local -w)
kubectl wait --for=create ns/cattle-fleet-local-system --timeout=30s
kubectl -n cattle-fleet-local-system rollout status deployment/fleet-agent
# label local cluster
kubectl patch clusters.fleet.cattle.io -n fleet-local local --type=json -p '[{"op": "add", "path": "/metadata/labels/management.cattle.io~1cluster-display-name", "value": "local" }]'