Skip to content

Commit 08a465c

Browse files
authored
[tooling] Automatic release artefacts: Cluster configuration (#1495)
1 parent e978e3b commit 08a465c

2 files changed

Lines changed: 121 additions & 1 deletion

File tree

‎release/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ A parallel terraform apply is then run.
2525

2626
After this step, Kubernetes clusters are ready.
2727

28-
#### Configure clusters (TODO)
28+
#### Configure clusters
2929
* `./release/scripts/configure-clusters.sh`
3030

31+
Fetch the Kubernetes configuration for clusters, generate certificates (trusted between clusters), and apply certificates configuration.
32+
33+
After this step, services are ready to be deployed.
34+
3135
#### Deploy services (TODO)
3236
* `./release/scripts/deploy-services.sh`
3337

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
# shellcheck source=release/scripts/common.sh
7+
source "$SCRIPT_DIR/common.sh"
8+
9+
CRDB_CERT_DIRS=(ca_certs_dir node_certs_dir client_certs_dir prometheus_certs_dir)
10+
11+
# === 1. Resolve workspace dirs from terraform output ===
12+
section "Resolving workspaces"
13+
declare -A WS=()
14+
for name in "${CLUSTERS[@]}"; do
15+
[[ -d "$PERSONAL_DIR/$name" ]] \
16+
|| die "missing personal config $PERSONAL_DIR/$name - run spawn-clusters.sh first"
17+
ws=$(terraform -chdir="$PERSONAL_DIR/$name" output -raw workspace_location)
18+
WS[$name]="$ws"
19+
printf ' %s•%s %-32s → %s\n' "$DIM" "$RESET" "$name" "$ws"
20+
done
21+
22+
# === 2. Get credentials ===
23+
section "Getting credentials"
24+
for name in "${CLUSTERS[@]}"; do
25+
printf ' %s→%s %-32s ' "$BLUE" "$RESET" "$name"
26+
if ( cd "${WS[$name]}" && ./get-credentials.sh ) >"$LOG_DIR/$name.creds.log" 2>&1; then
27+
printf '%s✓%s\n' "$GREEN" "$RESET"
28+
else
29+
printf '%s✗%s see %s\n' "$RED" "$RESET" "$LOG_DIR/$name.creds.log"
30+
exit 1
31+
fi
32+
done
33+
34+
# === 3. Group clusters by datastore type and apply per-type cert ritual ===
35+
# Cluster names follow: release-{cloud}-dss-{datastore}
36+
declare -A CLUSTER_AWS=() CLUSTER_GOOGLE=() ALL_DATASTORES=()
37+
for name in "${CLUSTERS[@]}"; do
38+
cloud=$(cloud_of "$name") || { warn "$name: unknown cloud, skipping"; continue; }
39+
ds="${name##*-}"
40+
ALL_DATASTORES[$ds]=1
41+
case "$cloud" in
42+
aws) CLUSTER_AWS[$ds]="$name" ;;
43+
google) CLUSTER_GOOGLE[$ds]="$name" ;;
44+
esac
45+
done
46+
47+
mapfile -t datastores < <(printf '%s\n' "${!ALL_DATASTORES[@]}" | sort)
48+
for ds in "${datastores[@]}"; do
49+
aws_name="${CLUSTER_AWS[$ds]:-}"
50+
goo_name="${CLUSTER_GOOGLE[$ds]:-}"
51+
if [[ -z "$aws_name" || -z "$goo_name" ]]; then
52+
section "$ds certs"
53+
info "skipping (incomplete pair: aws=${aws_name:-—}, google=${goo_name:-—})"
54+
continue
55+
fi
56+
aws_ws="${WS[$aws_name]}"
57+
goo_ws="${WS[$goo_name]}"
58+
aws_log="$LOG_DIR/$aws_name.certs.log"
59+
goo_log="$LOG_DIR/$goo_name.certs.log"
60+
61+
case "$ds" in
62+
ybdb)
63+
section "Yugabyte certs ($aws_name ↔ $goo_name)"
64+
( cd "$aws_ws" && ./dss-certs.sh init ) >"$aws_log" 2>&1
65+
ok "init $aws_name"
66+
( cd "$goo_ws" && ./dss-certs.sh init ) >"$goo_log" 2>&1
67+
ok "init $goo_name"
68+
69+
( cd "$goo_ws" && ./dss-certs.sh get-ca ) \
70+
| ( cd "$aws_ws" && ./dss-certs.sh add-pool-ca ) >>"$aws_log" 2>&1
71+
ok "$aws_name trusts $goo_name"
72+
73+
( cd "$aws_ws" && ./dss-certs.sh get-ca ) \
74+
| ( cd "$goo_ws" && ./dss-certs.sh add-pool-ca ) >>"$goo_log" 2>&1
75+
ok "$goo_name trusts $aws_name"
76+
77+
( cd "$aws_ws" && ./dss-certs.sh apply ) >>"$aws_log" 2>&1
78+
ok "apply $aws_name"
79+
( cd "$goo_ws" && ./dss-certs.sh apply ) >>"$goo_log" 2>&1
80+
ok "apply $goo_name"
81+
;;
82+
crdb)
83+
section "CockroachDB certs ($aws_name ↔ $goo_name)"
84+
( cd "$aws_ws" && ./make-certs.sh ) >"$aws_log" 2>&1
85+
ok "make-certs $aws_name"
86+
( cd "$goo_ws" && ./make-certs.sh "$aws_ws/ca_certs_dir/ca.crt" ) >"$goo_log" 2>&1
87+
ok "make-certs $goo_name"
88+
89+
# Snapshot fresh per-cluster CAs before cross-cat, else we'd append into the source.
90+
aws_ca=$(mktemp); goo_ca=$(mktemp)
91+
cp "$aws_ws/ca_certs_dir/ca.crt" "$aws_ca"
92+
cp "$goo_ws/ca_certs_dir/ca.crt" "$goo_ca"
93+
94+
# apply-certs.sh creates k8s secrets from these dirs, so patch ca.crt in all
95+
# of them so the cockroachdb.{ca.crt,node,client.root,...} secrets carry both CAs.
96+
for d in "${CRDB_CERT_DIRS[@]}"; do
97+
cat "$goo_ca" >> "$aws_ws/$d/ca.crt"
98+
cat "$aws_ca" >> "$goo_ws/$d/ca.crt"
99+
done
100+
rm -f "$aws_ca" "$goo_ca"
101+
ok "appended foreign CA into ${CRDB_CERT_DIRS[*]} on both sides"
102+
103+
( cd "$aws_ws" && ./apply-certs.sh ) >>"$aws_log" 2>&1
104+
ok "apply-certs $aws_name"
105+
( cd "$goo_ws" && ./apply-certs.sh ) >>"$goo_log" 2>&1
106+
ok "apply-certs $goo_name"
107+
;;
108+
*)
109+
section "$ds certs"
110+
warn "unknown datastore type - no cert ritual defined"
111+
;;
112+
esac
113+
done
114+
115+
section "All ${#CLUSTERS[@]} clusters prepared"
116+
info "kubeconfig + certs ready."

0 commit comments

Comments
 (0)