-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparse-sysdig-helm-template-output.sh
More file actions
174 lines (157 loc) · 5.05 KB
/
parse-sysdig-helm-template-output.sh
File metadata and controls
174 lines (157 loc) · 5.05 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
#set -x #echo on
#===========================================================
# This script was written by Kendall Adkins to parse
# the template output from helm into individual manifest
# files when using the sysdig-deploy helm chart.
#
# Please direct any questions to kendall.adkins@sysdig.com
#
# Risk! In the event that the helm template output changes
# as a result of helm chart updates, this script could break.
#
# Date: June 27th, 2023
#
#===========================================================
function help {
echo ""
echo "Script: $(basename ${0})"
echo ""
echo "Description: This script will parse the template output from helm into individual"
echo " manifest files when using the sysdig-deploy helm chart."
echo ""
echo "Usage: $(basename ${0}) [ -f <helm template output file>] [ -p <prefix>] [ -h]"
echo ""
echo "options:"
echo " -f, --helm-template-file: the helm template file (required)"
echo " -p, --manifests-prefix: the prefix used in the manifest output file names (optional)"
echo " -h, --help: display this help message"
echo ""
}
function is_valid_value {
if [[ ${1} == -* ]] || [[ ${1} == --* ]] || [[ -z ${1} ]]; then
return 1
else
return 0
fi
}
function is_valid_file {
if [ ! -f ${1} ]; then
return 1
else
return 0
fi
}
#
# validate and load the arguments
#
HELM_VALUES_FILE=""
MANIFEST_PREFIX=""
if [[ ${#} -eq 0 ]]; then
help
exit 1
fi
while [[ ${#} > 0 ]]
do
case ${1} in
-f|--helm-template-file)
if is_valid_value "${2}"; then
if is_valid_file "${2}"; then
TEMPLATE_FILE=${2}
else
echo "ERROR: Helm template file does not exist"
echo "Use -h | --help for $(basename ${0}) usage."
exit 1
fi
else
echo "ERROR: Invalid argument for helm template file"
echo "Use -h | --help for $(basename ${0}) usage."
exit 1
fi
shift
;;
-p|--manifests-prefix)
if is_valid_value "${2}"; then
MANIFEST_PREFIX=${2}
else
echo "ERROR: Invalid argument for manifest prefix"
echo "Use -h | --help for $(basename ${0}) usage."
exit 1
fi
shift
;;
-h|--help)
help
exit 1
;;
*)
echo "ERROR: Invalid option: ${1}, use -h | --help for $(basename ${0}) usage."
exit 1
;;
esac
shift
done
if [[ "${TEMPLATE_FILE}" == "" ]]; then
echo "ERROR: Helm template file argument is required."
echo "Use -h | --help for $(basename ${0}) usage."
exit 1
fi
#
# Parse the helm output into individual files
#
echo "STATUS: Parsing helm template output file: ${TEMPLATE_FILE}"
input=${TEMPLATE_FILE}
found_seperator="false"
found_manifest_name="false"
while IFS= read -r line
do
if [ "$found_manifest_name" = "true" ] && [ "$line" != "---" ]; then
echo "$line" >> $manifest_name
fi
if [ "$found_seperator" = "true" ]; then
manifest_name="${line#*/}"
manifest_name="${manifest_name#charts\/}"
manifest_name="${manifest_name//templates\//}"
manifest_name="${manifest_name//\//-}"
found_seperator="false"
found_manifest_name="true"
fi
if [ "$line" = "---" ]; then
found_seperator="true"
found_manifest_name="false"
fi
done < $input
#
# Rename the raw helm template names using
# a standard manifest naming convention
#
echo "STATUS: Renaming parsed manifest files"
prefix=${MANIFEST_PREFIX}
mv agent-role.yaml ${prefix}sa-r.yaml 2> /dev/null
mv agent-rolebinding.yaml ${prefix}sa-rb.yaml 2> /dev/null
mv agent-clusterrole.yaml ${prefix}sa-cr.yaml 2> /dev/null
mv agent-clusterrolebinding.yaml ${prefix}sa-crb.yaml 2> /dev/null
mv agent-configmap.yaml ${prefix}sa-cm.yaml 2> /dev/null
mv agent-daemonset.yaml ${prefix}sa-ds.yaml 2> /dev/null
mv agent-psp.yaml ${prefix}sa-psp.yaml 2> /dev/null
mv agent-secrets.yaml ${prefix}sa-se.yaml 2> /dev/null
mv agent-serviceaccount.yaml ${prefix}sa-sa.yaml 2> /dev/null
mv nodeAnalyzer-clusterrole-node-analyzer.yaml ${prefix}sana-cr.yaml 2> /dev/null
mv nodeAnalyzer-clusterrolebinding-node-analyzer.yaml ${prefix}sana-crb.yaml 2> /dev/null
mv nodeAnalyzer-daemonset-node-analyzer.yaml ${prefix}sana-ds.yaml 2> /dev/null
mv nodeAnalyzer-psp.yaml ${prefix}sana-psp.yaml 2> /dev/null
mv nodeAnalyzer-runtimeScanner-runtime-scanner-configmap.yaml ${prefix}sana-rs-cm.yaml 2> /dev/null
mv nodeAnalyzer-secrets.yaml ${prefix}sana-se.yaml 2> /dev/null
mv nodeAnalyzer-serviceaccount-node-analyzer.yaml ${prefix}sana-sa.yaml 2> /dev/null
mv nodeAnalyzer-configmap-kspm-analyzer.yaml sana-kspm-cm.yaml 2> /dev/null
mv nodeAnalyzer-configmap-host-scanner.yaml sana-hs-cm.yaml 2> /dev/null
mv kspmCollector-clusterrole.yaml sa-kspm-cr.yaml 2> /dev/null
mv kspmCollector-clusterrolebinding.yaml sa-kspm-crb.yaml 2> /dev/null
mv kspmCollector-configmap.yaml sa-kspm-cm.yaml 2> /dev/null
mv kspmCollector-deployment.yaml sa-kspm-de.yaml 2> /dev/null
mv kspmCollector-secret.yaml sa-kspm-se.yaml 2> /dev/null
mv kspmCollector-serviceaccount.yaml sa-kspm-sa.yaml 2> /dev/null
#
# Done
#
echo "SUCCESS: Parsing of Sysdig helm template output file complete."