add generate_external_config
generates a config based on the configmap and secrets in the cluster. this config is intended to be used to add an external node to the cluster.
This commit is contained in:
parent
89ede66f23
commit
441856198f
63
tools
63
tools
|
@ -79,6 +79,69 @@ generate_layout() {( # generates a sample layout, (args are included verbatim, e
|
|||
done
|
||||
)}
|
||||
|
||||
generate_external_config() {( # generate a config for an external node
|
||||
jq -rn \
|
||||
--argjson secret "$(kubectl -n "$GARAGE_NAMESPACE" get secret garage-secrets -o json)" \
|
||||
--argjson cm "$(kubectl -n "$GARAGE_NAMESPACE" get configmap garage-config -o json)" \
|
||||
--argjson peers "$(get_ids | jq -R | jq -s)" \
|
||||
'
|
||||
# FUNCTIONS
|
||||
|
||||
def prettyjson:
|
||||
if type != "array" then [tojson] else
|
||||
if length < 2 then [tojson] else
|
||||
[ (.[0] | "[\n \(tojson),\n")
|
||||
, (.[1:-1][] | " \(tojson),\n")
|
||||
, (.[-1] | " \(tojson)\n")
|
||||
, "]"
|
||||
]
|
||||
end
|
||||
end | add;
|
||||
|
||||
# gencfg: generates a toml line which will use a raw json value if possible or a string if not.
|
||||
# to guarantee a string, double encode it.
|
||||
def gencfg:
|
||||
( (.value | fromjson?) // .value) as $v
|
||||
| (if .key == "bootstrap_peers" then ($v + $peers) else ($v) end) as $v
|
||||
| "\(.key) = \($v | prettyjson)";
|
||||
|
||||
# secval: get the value of the $secret, base64 decoded.
|
||||
# will emit 0 items (not an empty list!) if no matching key is found.
|
||||
# try jq -n "[[][],1,[][]]" (and figure it out) for a more clear understanding.
|
||||
def secval($k): $secret.data | to_entries[] | select(.key == $k) | .value | @base64d;
|
||||
|
||||
# SETUP VARIABLES
|
||||
[ $cm | .data | to_entries[]
|
||||
, {"key": "rpc_secret", "value": secval("rpc-secret")}
|
||||
, {"key": "admin.admin_token", "value": secval("admin-token")}
|
||||
, {"key": "admin.metrics_token", "value": secval("metrics-token")}
|
||||
] | group_by(.key | test("[.]"))
|
||||
as $asec
|
||||
# data format now: [[{k,v},...],[{s.k,v},...]]
|
||||
| $asec[0]
|
||||
as $nsec
|
||||
| [$asec[1][] | (.key | split(".")) as $k | {"section": $k[0], "key": $k[1], "value": .value}]
|
||||
as $ysec
|
||||
| [$ysec[] | .section] | unique
|
||||
as $sections
|
||||
|
||||
| [][] # EMIT DATA -- [][] is to allow all outputs to start with ,
|
||||
|
||||
# emit unsectioned data
|
||||
,(
|
||||
$nsec[] |
|
||||
gencfg
|
||||
)
|
||||
# emit sectioned data
|
||||
,(
|
||||
$sections[] as $section | (
|
||||
"\n[\($section)]"
|
||||
, ($ysec[] | select(.section == $section) | gencfg)
|
||||
)
|
||||
)
|
||||
'
|
||||
)}
|
||||
|
||||
make_bucket() { # make a bucket along with metadata in a namespace
|
||||
TARGETBUCKET="$1"
|
||||
TARGETKEYNAME="${2-$TARGETBUCKET}-app-key"
|
||||
|
|
Loading…
Reference in New Issue
Block a user