-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path059-admin-settings-import.sh
More file actions
executable file
·63 lines (54 loc) · 2.95 KB
/
059-admin-settings-import.sh
File metadata and controls
executable file
·63 lines (54 loc) · 2.95 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
#!/bin/bash
# Resource: Settings (Under Administration)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DATA_DIR="$SCRIPT_DIR"/data/setting
scopes=("cluster" "clustergroup" "organization")
setting_json_template='{"type":{"kind":"Setting","version":"v1alpha1","package":"vmware.tanzu.manage.v1alpha1.cluster.setting.Setting"},"fullName":{"name":""},"spec":{}}'
if [ ! -d $DATA_DIR ]; then
echo "Nothing to do without directory $DATA_DIR, please backup data first"
exit 0
fi
echo "************************************************************************"
echo "* Importing Admin Settings into TMC SM ..."
echo "************************************************************************"
for scope in "${scopes[@]}"; do
settingList=$(cat $DATA_DIR/$scope/settings.yaml | yq eval -o=json - | jq -c '.effective[]')
while IFS= read -r setting; do
if [[ -z "$setting" ]]; then
echo "No any $scope level settings"
fi
if [[ -n "$setting" ]]; then
spec=$(echo "$setting" | jq ".spec.settingSpec // {}")
settingType=$(echo "$setting" | jq -r ".spec.settingType")
sourceRid=$(echo "$setting" | jq -r '.spec.source.rid // ""')
oldIFS=$IFS
IFS=':'
sourceRidParts=($sourceRid)
IFS=$oldIFS
if [[ "$scope" == "cluster" ]]; then
filename="${sourceRidParts[6]}--${sourceRidParts[5]}--${sourceRidParts[4]}--${sourceRidParts[3]}"
echo $setting_json_template | \
jq --argjson spec "$spec" '.spec = $spec' | \
jq --arg settingType "$settingType" '.fullName.name = $settingType' | \
jq --argjson managementClusterNameJson "{\"managementClusterName\": \"${sourceRidParts[3]}\"}" '.fullName += $managementClusterNameJson' | \
jq --argjson provisionerNameJson "{\"provisionerName\": \"${sourceRidParts[4]}\"}" '.fullName += $provisionerNameJson' | \
jq --argjson clusterNameJson "{\"clusterName\": \"${sourceRidParts[5]}\"}" '.fullName += $clusterNameJson' | \
yq eval -P - | tanzu tmc setting create --scope "$scope" --file -
elif [[ "$scope" == "clustergroup" ]]; then
filename="${sourceRidParts[4]}--${sourceRidParts[3]}"
echo $setting_json_template | \
jq --argjson spec "$spec" '.spec = $spec' | \
jq --arg settingType "$settingType" '.fullName.name = $settingType' | \
jq --argjson clusterGroupNameJson "{\"clusterGroupName\": \"${sourceRidParts[3]}\"}" '.fullName += $clusterGroupNameJson' | \
yq eval -P - | tanzu tmc setting create --scope "$scope" --file -
elif [[ "$scope" == "organization" ]]; then
filename=${settingType}
echo $setting_json_template | \
jq --argjson spec "$spec" '.spec = $spec' | \
jq --arg settingType "$settingType" '.fullName.name = $settingType' | \
yq eval -P - | tanzu tmc setting create --scope "$scope" --file -
fi
fi
done <<< "$settingList"
done
echo "Imported Admin Settings into TMC SM ..."