|
13 | 13 | (dict "kubernetes_metadata" (dig "kubernetes_metadata" nil .Values.features )) |
14 | 14 | (dict "monitor" (pick $monitorFeature "kube_state_metrics" "kubernetes_events")) |
15 | 15 | (dict "investigations" (pick $investigationsFeature "investigations" "network_security")) |
16 | | - (dict "respond" (pick $respondFeature "response_actions")) |
17 | 16 | -}} |
18 | 17 | {{- $featuresConfig := dict -}} |
19 | 18 | {{- range $feature := $features }} |
|
22 | 21 | {{- end -}} |
23 | 22 | {{- end }} |
24 | 23 | {{- $_ := set $featuresConfig.container_vulnerability_management "in_use" .Values.features.vulnerability_management.in_use -}} |
25 | | - {{- $_ := set $featuresConfig.respond "response_actions" (pick $featuresConfig.respond.response_actions "enabled" "queue_length" "timeout" "cluster") -}} |
| 24 | + {{- $respond := (include "cluster.configmap.respond" .) | fromYaml }} |
| 25 | + {{- $_ := set $featuresConfig "respond" $respond -}} |
| 26 | + |
26 | 27 | {{- $additionalFeaturesSettings := (dig "features" (dict) .Values.cluster.additional_settings) -}} |
27 | 28 | {{- (mergeOverwrite $featuresConfig $additionalFeaturesSettings) | toYaml -}} |
28 | 29 | {{- end }} |
|
207 | 208 | {{- end -}} |
208 | 209 | {{- end }} |
209 | 210 |
|
| 211 | +{{/* |
| 212 | +Generic helper: checks if .Values.features.respond.response_actions.<action>.trigger == "all" |
| 213 | +Usage: {{ include "cluster.response_actions.is_enabled" (dict "Action" "delete_pod" "Context" .) }} |
| 214 | +*/}} |
| 215 | +{{- define "cluster.response_actions.is_enabled" -}} |
| 216 | + {{- $action := .Action }} |
| 217 | + {{- $ctx := .Context }} |
| 218 | + {{- with $ctx.Values.features.respond.response_actions -}} |
| 219 | + {{- $entry := index . $action }} |
| 220 | + {{- if and $entry (eq $entry.trigger "none") -}} |
| 221 | + false |
| 222 | + {{- else -}} |
| 223 | + true |
| 224 | + {{- end -}} |
| 225 | + {{- else -}} |
| 226 | + true |
| 227 | + {{- end -}} |
| 228 | +{{- end -}} |
| 229 | + |
210 | 230 | {{/* |
211 | 231 | Response Actions: Cluster actions |
212 | 232 | In the future we will have more complex logic to determine if the action is enabled or not. |
213 | 233 | */}} |
214 | 234 | {{- define "cluster.response_actions.rollout_restart.enabled" }} |
215 | | - {{- include "cluster.response_actions_enabled" . }} |
| 235 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "rollout_restart" "Context" .) }} |
216 | 236 | {{- end}} |
217 | 237 | {{- define "cluster.response_actions.delete_pod.enabled" }} |
218 | | - {{- include "cluster.response_actions_enabled" . }} |
| 238 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "delete_pod" "Context" .) }} |
219 | 239 | {{- end}} |
220 | 240 | {{- define "cluster.response_actions.isolate_network.enabled" }} |
221 | | - {{- include "cluster.response_actions_enabled" . }} |
| 241 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "isolate_network" "Context" .) }} |
222 | 242 | {{- end}} |
223 | 243 | {{- define "cluster.response_actions.delete_network_policy.enabled" }} |
224 | | - {{- include "cluster.response_actions_enabled" . }} |
| 244 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "delete_network_policy" "Context" .) }} |
225 | 245 | {{- end}} |
226 | 246 | {{- define "cluster.response_actions.get_logs.enabled" }} |
227 | | - {{- include "cluster.response_actions_enabled" . }} |
| 247 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "get_logs" "Context" .) }} |
228 | 248 | {{- end}} |
229 | 249 | {{- define "cluster.response_actions.volume_snapshot.enabled" }} |
230 | | - {{- include "cluster.response_actions_enabled" . }} |
| 250 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "volume_snapshot" "Context" .) }} |
231 | 251 | {{- end}} |
232 | | -{{- define "cluster.response_actions.delete_volume_snapshot.enabled" }} |
233 | | - {{- include "cluster.response_actions_enabled" . }} |
| 252 | +{{- define "cluster.response_actions.delete_volume_snapshot.enabled" -}} |
| 253 | + {{- include "cluster.response_actions.is_enabled" (dict "Action" "delete_volume_snapshot" "Context" .) -}} |
234 | 254 | {{- end}} |
| 255 | + |
| 256 | + |
| 257 | +{{- define "cluster.configmap.respond" }} |
| 258 | +{{- $response_actions_feature := (dig "respond" "response_actions" nil .Values.features) }} |
| 259 | +{{- $fields := list "enabled" "queue_length" "timeout" "cluster" }} |
| 260 | +{{- $actions := list |
| 261 | + "rollout_restart" |
| 262 | + "delete_pod" |
| 263 | + "isolate_network" |
| 264 | + "delete_network_policy" |
| 265 | + "get_logs" |
| 266 | + "volume_snapshot" |
| 267 | + "delete_volume_snapshot" |
| 268 | +}} |
| 269 | +{{- if and (include "common.semver.is_valid" .Values.cluster.image.tag) (semverCompare ">= 1.14.0" .Values.cluster.image.tag) }} |
| 270 | + {{- $fields = (concat $fields $actions) }} |
| 271 | +{{- end }} |
| 272 | +{{- $response_actions := dict }} |
| 273 | +{{- range $field := $fields }} |
| 274 | + {{- if hasKey $response_actions_feature $field}} |
| 275 | + {{- $response_actions := set $response_actions $field (index $response_actions_feature $field) }} |
| 276 | + {{- end}} |
| 277 | +{{- end }} |
| 278 | + |
| 279 | +{{- if (include "common.semver.is_valid" (.Values.on_prem_version | default "")) -}} |
| 280 | +{{- if semverCompare ">= 7.3.0" .Values.on_prem_version -}} |
| 281 | + {{- dict "response_actions" $response_actions | toYaml -}} |
| 282 | +{{- end -}} |
| 283 | +{{- else -}} |
| 284 | +{{- dict "response_actions" $response_actions | toYaml -}} |
| 285 | +{{- end -}} |
| 286 | + |
| 287 | +{{- end }} |
0 commit comments