-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path063-base-policy-assignments-import.sh
More file actions
executable file
·80 lines (63 loc) · 2.32 KB
/
063-base-policy-assignments-import.sh
File metadata and controls
executable file
·80 lines (63 loc) · 2.32 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/bash
source utils/log.sh
source utils/policy-helper.sh
register_last_words "Import policy assignments"
DATA_DIR="data"
SRC_DIR="$PWD/$DATA_DIR/policies/assignments"
TEMP_DIR="$SRC_DIR/$(date +%s)"
INTERVAL=2
import_org_policies() {
scope="organization"
policies_temp="$TEMP_DIR/$scope"
mkdir -p $policies_temp
pushd $policies_temp > /dev/null
yq '.policies[]' -s '.fullName.name' $SRC_DIR/$scope/policies.yaml
for p_file in $(ls *.yml)
do
yq -i 'del(.fullName.orgId)' $p_file
tanzu mission-control policy create -s organization -f $p_file
sleep $INTERVAL
done
popd > /dev/null
}
import_clustergroup_policies() {
scope="clustergroups"
policies_temp="$TEMP_DIR/$scope"
mkdir -p $policies_temp
generate_policy_spec "$scope" "$policies_temp"
pushd $policies_temp > /dev/null
for p_file in $(ls *.yaml)
do
IFS='_' read -r cg_name policy_name <<< $(echo "$p_file" | sed 's/.yaml$//g')
yq e -i ".fullName.clusterGroupName = \"$cg_name\"" $p_file
log info "Importing policies on clustergroup ${cg_name} ..."
tanzu mission-control policy create -s clustergroup -f $p_file
sleep $INTERVAL
done
popd > /dev/null
}
import_workspace_policies() {
scope="workspaces"
policies_temp="$TEMP_DIR/$scope"
mkdir -p $policies_temp
generate_policy_spec "$scope" "$policies_temp"
pushd $policies_temp > /dev/null
for p_file in $(ls *.yaml)
do
IFS='_' read -r ws_name policy_name <<< $(echo "$p_file" | sed 's/.yaml$//g')
yq e -i ".fullName.workspaceName = \"$ws_name\"" $p_file
log info "Importing policies on workspace ${ws_name} ..."
tanzu mission-control policy create -s workspace -f $p_file
sleep $INTERVAL
done
popd > /dev/null
}
log "************************************************************************"
log "* Import Policy Assignments to TMC SM ..."
log "************************************************************************"
log info "Importing policies on organization ..."
import_org_policies
log info "Importing policies on clustergroups ..."
import_clustergroup_policies
log info "Importing policies on workspaces ..."
import_workspace_policies