Skip to content

Commit 429f86b

Browse files
authored
Add warning to restore procedure about rancher-system-agent (#481)
Fixes #447 Signed-off-by: Michal Jura <mjura@suse.com> Signed-off-by: Michal Jura <mjura@suse.com>
1 parent 671a7cb commit 429f86b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

docs/restore.md

+29
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,32 @@ INFO[2022/10/31 06:34:50] Done restoring
4646
```
4747

4848
Continue with procedure from [Rancher documentation](https://docs.ranchermanager.rancher.io/how-to-guides/new-user-guides/backup-restore-and-disaster-recovery/migrate-rancher-to-new-cluster)
49+
50+
:::warning warning
51+
Try to not restart `rancher-system-agent` on elemental nodes, otherwise it can stuck in following error
52+
53+
`panic: error while connecting to Kubernetes cluster: the server has asked for the client to provide credentials`
54+
55+
If this problem occurs please go with procedure below.
56+
:::
57+
58+
Copy `/var/lib/rancher/agent/rancher2_connection_info.json` from elemental node to place where you have access to Kubernetes with Rancher UI
59+
60+
Download `rancher-agent-token-update.sh` script which from [Elemental repository](https://github.com/rancher/elemental)
61+
62+
```shell showLineNumbers
63+
wget -q https://raw.githubusercontent.com/rancher/elemental/main/scripts/rancher-agent-token-update && chmod +x rancher-agent-token-update
64+
```
65+
66+
Execute script without any additional commands
67+
68+
```shell showLineNumbers
69+
rancher-agent-token-update
70+
```
71+
72+
After it will finish successfully, copy back `rancher2_connection_info.json` to the elemental node
73+
`/var/lib/rancher/agent/rancher2_connection_info.json` and restart there `rancher-system-agent` service
74+
75+
```shell showLineNumbers
76+
systemctl restart rancher-system-agent
77+
```

scripts/rancher-agent-token-update

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
if [ "${DEBUG}" = 1 ]; then
4+
set -x
5+
fi
6+
7+
# Environment variables:
8+
# - DEBUG (default: 0)
9+
10+
RANCHER_AGENT_FILE="rancher2_connection_info.json"
11+
12+
info() {
13+
echo "[INFO] " "$@"
14+
}
15+
16+
error() {
17+
echo "[ERROR] " "$@" >&2
18+
}
19+
20+
21+
if [ ! -f $RANCHER_AGENT_FILE ]; then
22+
error "File $RANCHER_AGENT_FILE can't be found in current directory!"
23+
error "Copy it from the elemental node /var/lib/rancher/agent/rancher2_connection_info.json"
24+
exit 1
25+
fi
26+
27+
if ! $(kubectl get apiservice v1beta1.elemental.cattle.io > /dev/null 2>&1); then
28+
error "Provide kubeconfig for Kubernetes cluster with Rancher UI"
29+
exit 1
30+
fi
31+
32+
export NAMESPACE=$(cat rancher2_connection_info.json | jq -r '.namespace')
33+
export SECRET=$(cat rancher2_connection_info.json | jq -r '.secretName')
34+
35+
echo
36+
info "Getting $SECRET-token secret from $NAMESPACE namespace"
37+
export BEARER_TOKEN=$(kubectl get secret -n $NAMESPACE $SECRET-token -o jsonpath={.data.token} | base64 -d)
38+
39+
info "Updating $RANCHER_AGENT_FILE with new token value"
40+
echo
41+
sed -e 's/token: .*\\n/token: '"${BEARER_TOKEN}"'\\n/' $RANCHER_AGENT_FILE
42+
43+
echo
44+
info "File $RANCHER_AGENT_FILE was updated successfully !!!"
45+
info "Copy it to elemental node /var/lib/rancher/agent/rancher2_connection_info.json and"
46+
info "restart rancher-system-agent with command 'systemctl restart rancher-system-agent'"
47+
echo

0 commit comments

Comments
 (0)