Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common,agent,node-analyzer,kspm-collector): support multi-level map in agent.tags #1351

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Sysdig Monitor and Secure agent
type: application

# currently matching sysdig 1.14.32
version: 1.13.8
version: 1.13.9

appVersion: 12.16.0

Expand Down Expand Up @@ -36,4 +36,4 @@ dependencies:
- name: common
# repository: https://charts.sysdig.com
repository: file://../common
version: ~1.2.0
version: ~1.2.1
3 changes: 0 additions & 3 deletions charts/agent/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ data:
enforce_leader_election: true
namespace: {{ include "agent.namespace" . }}
{{- end }}
{{- if .Values.global.sysdig.tags }}
tags: {{ include "agent.tags" . }}
{{- end }}
{{- if .Values.prometheus.file }}
prometheus.yaml: |
{{ toYaml .Values.prometheus.yaml | indent 4 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type: library
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.2.0
version: 1.2.1

maintainers:
- name: AlbertoBarba
Expand Down
34 changes: 25 additions & 9 deletions charts/common/templates/_agent_tags.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{{/*
Use global sysdig tags for agent
Flatten tags dict recursively
*/}}
{{- define "agent.tags" -}}
{{- if .Values.global.sysdig.tags -}}
{{- with .Values.global.sysdig.tags -}}
{{- $fields := list -}}
{{- range $k, $v := . -}}
{{- $fields = (printf "%s:%s" $k $v) | append $fields -}}
{{- end -}}
{{- join "," $fields -}}
{{- define "dict.flatten" -}}
{{- $map := first . -}}
{{- $label := last . -}}
{{- $fields := list -}}
{{- range $key, $val := $map -}}
{{- $sublabel := list $label $key | join "." -}}
{{- if $label | eq "" -}}
{{ $sublabel = $key }}
{{- end -}}
{{- if kindOf $val | eq "map" -}}
{{- $fields = (list $val $sublabel | include "dict.flatten") | append $fields }}
{{- else -}}
{{- $fields = (printf "%s:%s" $sublabel $val) | append $fields -}}
{{- end -}}
{{- end -}}
{{- join "," $fields -}}
{{- end -}}

{{/*
Use global sysdig tags for agent
*/}}
{{- define "agent.tags" -}}
{{- if .Values.global.sysdig.tags -}}
{{- $args := list .Values.global.sysdig.tags ""}}
{{- include "dict.flatten" $args }}
{{- end -}}
{{- end -}}
4 changes: 2 additions & 2 deletions charts/kspm-collector/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: kspm-collector
description: Sysdig KSPM collector

version: 0.8.0
version: 0.8.1
appVersion: 1.30.0

keywords:
Expand All @@ -24,4 +24,4 @@ dependencies:
- name: common
# repository: https://charts.sysdig.com
repository: file://../common
version: ~1.2.0
version: ~1.2.1
16 changes: 14 additions & 2 deletions charts/kspm-collector/tests/agent_tags_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ suite: Test kspm-collector Agent Tags
templates:
- deployment.yaml
tests:
- it: Check agent tags are set from global.settings.tags
- it: Check agent tags are set from global.sysdig.tags
set:
clusterName: "test-k8s"
sysdig:
Expand All @@ -12,12 +12,24 @@ tests:
sysdig:
tags:
tag: value
- it: Check nested agent tags are set from global.sysdig.tags
set:
clusterName: "test-k8s"
sysdig:
accessKey: standard-key
secureAPIToken: standard-token
global:
sysdig:
tags:
nested:
value:
level: two
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: TAGS
value: tag:value
value: nested.value.level:two
template: deployment.yaml
- it: Check agent tags are not set
set:
Expand Down
4 changes: 2 additions & 2 deletions charts/node-analyzer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: node-analyzer
description: Sysdig Node Analyzer

# currently matching Sysdig's appVersion 1.14.34
version: 1.17.0
version: 1.17.1
appVersion: 12.8.0
keywords:
- monitoring
Expand All @@ -26,4 +26,4 @@ dependencies:
- name: common
# repository: https://charts.sysdig.com
repository: file://../common
version: ~1.2.0
version: ~1.2.1
7 changes: 1 addition & 6 deletions charts/node-analyzer/templates/configmap-host-scanner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ data:
api_endpoint: https://{{ include "nodeAnalyzer.apiEndpoint" . }}
cluster_name: {{ required "A valid clusterName is required" (include "nodeAnalyzer.clusterName" . ) }}
{{- if hasKey .Values.global.sysdig "tags" }}
{{- $customTags := list -}}
{{ range $key, $val := .Values.global.sysdig.tags }}
{{- $entry := list $key $val | join ":" -}}
{{- $customTags = append $customTags $entry -}}
{{ end }}
custom_tags: {{ join "," $customTags | quote }}
custom_tags: {{ include "agent.tags" . }}
{{- end }}
{{- if hasKey .Values.nodeAnalyzer.hostScanner "scanOnStart" }}
scan_on_start: "{{ .Values.nodeAnalyzer.hostScanner.scanOnStart }}"
Expand Down
8 changes: 4 additions & 4 deletions charts/sysdig-deploy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: sysdig-deploy
description: A chart with various Sysdig components for Kubernetes
type: application
version: 1.22.4
version: 1.22.5
maintainers:
- name: AlbertoBarba
email: [email protected]
Expand All @@ -26,7 +26,7 @@ dependencies:
- name: agent
# repository: https://charts.sysdig.com
repository: file://../agent
version: ~1.13.8
version: ~1.13.9
alias: agent
condition: agent.enabled
- name: common
Expand All @@ -36,7 +36,7 @@ dependencies:
- name: node-analyzer
# repository: https://charts.sysdig.com
repository: file://../node-analyzer
version: ~1.17.0
version: ~1.17.1
alias: nodeAnalyzer
condition: nodeAnalyzer.enabled
- name: cluster-scanner
Expand All @@ -48,7 +48,7 @@ dependencies:
- name: kspm-collector
# repository: https://charts.sysdig.com
repository: file://../kspm-collector
version: ~0.8.0
version: ~0.8.1
alias: kspmCollector
condition: global.kspm.deploy
- name: rapid-response
Expand Down
Loading