File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/bash
22
3+ set -o pipefail
4+ set -o errexit
5+ set -o nounset
6+ set -o errtrace
37set -x
48
59source /usr/local/bin/crc-systemd-common.sh
610export KUBECONFIG=" /opt/kubeconfig"
711
8- pub_key_path =" /opt/crc/id_rsa.pub"
12+ PUB_KEY_PATH =" /opt/crc/id_rsa.pub"
913
10- if [ ! -f " ${pub_key_path} " ]; then
14+ if [ ! -f " $PUB_KEY_PATH " ]; then
1115 echo " No pubkey file found"
1216 exit 1
1317fi
1418
19+ wait_for_resource_or_die machineconfig
20+
1521echo " Updating the public key resource for machine config operator"
16- pub_key=$( tr -d ' \n\r' < ${pub_key_path} )
17- wait_for_resource machineconfig
18- if ! oc patch machineconfig 99-master-ssh -p " {\" spec\" : {\" config\" : {\" passwd\" : {\" users\" : [{\" name\" : \" core\" , \" sshAuthorizedKeys\" : [\" ${pub_key} \" ]}]}}}}" --type merge;
19- then
20- echo " failed to update public key to machine config operator"
21- exit 1
22- fi
22+ pub_key=$( cat " ${PUB_KEY_PATH} " | tr -d ' \n\r' )
23+
24+ jq -n --arg key " ${pub_key} " '
25+ {
26+ "spec": {
27+ "config": {
28+ "passwd": {
29+ "users": [
30+ {
31+ "name": "core",
32+ "sshAuthorizedKeys": [ $key ]
33+ }
34+ ]
35+ }
36+ }
37+ }
38+ }' | oc patch machineconfig 99-master-ssh --type merge --patch-file=/dev/stdin
39+
40+ echo " All done"
41+
42+ exit 0
You can’t perform that action at this time.
0 commit comments