Skip to content

fix(shield): improve regions handling #2220

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion charts/shield/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ maintainers:
- name: mavimo
email: marcovito.moscaritolo@sysdig.com
type: application
version: 1.3.3
version: 1.3.4
appVersion: "1.0.0"
3 changes: 3 additions & 0 deletions charts/shield/templates/cluster/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
{{- if and .Values.sysdig_endpoint.collector.host .Values.sysdig_endpoint.collector.port -}}
{{- $_ := set $sysdigEndpointConfig "collector" (printf "%s:%d" .Values.sysdig_endpoint.collector.host (.Values.sysdig_endpoint.collector.port | int)) -}}
{{- end -}}
{{- if and (not .Values.sysdig_endpoint.api_url) (ne "custom" .Values.sysdig_endpoint.region) -}}
{{- $_ := unset $sysdigEndpointConfig "api_url" -}}
{{- end -}}
{{- $_ := set $config "sysdig_endpoint" $sysdigEndpointConfig -}}
{{- $_ := set $config "cluster_config" (dict "name" .Values.cluster_config.name) -}}
{{- $clusterConfig := dict "name" .Values.cluster_config.name -}}
Expand Down
12 changes: 6 additions & 6 deletions charts/shield/templates/common/_regions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@

{{- define "common.collector_endpoint" }}
{{- $regions := fromYaml (include "common.regions" .) }}
{{- if ne "custom" .Values.sysdig_endpoint.region }}
{{- get (get $regions .Values.sysdig_endpoint.region) "collector_endpoint" }}
{{- if not .Values.sysdig_endpoint.collector.host }}
{{- get (get $regions .Values.sysdig_endpoint.region) "collector_endpoint" }}
{{- else }}
{{- .Values.sysdig_endpoint.collector.host }}
{{- end }}
{{- end }}

{{- define "common.monitor_api_endpoint" }}
{{- $regions := fromYaml (include "common.regions" .) }}
{{- if hasKey $regions .Values.sysdig_endpoint.region }}
{{- if not .Values.sysdig_endpoint.api_url }}
{{- get (get $regions .Values.sysdig_endpoint.region) "monitor_api_endpoint" }}
{{- else }}
{{- .Values.sysdig_endpoint.api_url }}
Expand All @@ -198,7 +198,7 @@

{{- define "common.secure_api_endpoint" }}
{{- $regions := fromYaml (include "common.regions" .) }}
{{- if ne "custom" .Values.sysdig_endpoint.region }}
{{- if not .Values.sysdig_endpoint.api_url }}
{{- get (get $regions .Values.sysdig_endpoint.region) "secure_api_endpoint" }}
{{- else }}
{{- .Values.sysdig_endpoint.api_url }}
Expand All @@ -207,9 +207,9 @@

{{- define "common.secure_ui" }}
{{- $regions := fromYaml (include "common.regions" .) }}
{{- if ne "custom" .Values.sysdig_endpoint.region }}
{{- if not .Values.sysdig_endpoint.api_url }}
{{- get (get $regions .Values.sysdig_endpoint.region) "secure_ui" }}
{{- else }}
{{- .Values.sysdig_endpoint.api_url}}
{{- .Values.sysdig_endpoint.api_url }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/shield/tests/cluster/configmap_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,21 @@ tests:
enabled: true
asserts:
- notFailedTemplate: {}

- it: Doesn't set api_url when region is us2 and collector host and port are set
set:
cluster_config:
name: shield-cluster
sysdig_endpoint:
region: us2
api_url:
collector:
host: fake.collector.host
port: 6443
asserts:
- matchRegex:
path: data['cluster-shield.yaml']
pattern: |
sysdig_endpoint:
collector: fake.collector.host:6443
region: us2
42 changes: 41 additions & 1 deletion charts/shield/tests/common/regions_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,59 @@ tests:
set:
sysdig_endpoint:
region: "eu1"
api_url:
collector:
host:
port:
asserts:
- matchRegex:
path: data["dragent.yaml"]
pattern: |
collector: ingest-eu1.app.sysdig.com
collector_port: 6443

- it: API endpoint validation
set:
sysdig_endpoint:
region: "us1"
api_url:
collector:
host:
port:
asserts:
- matchRegex:
path: data["dragent.yaml"]
pattern: |
sysdig_api_endpoint: secure.sysdig.com

- it: Collector and API endpoint validation when collector host and port set, but region is not custom and api_url is not set.
set:
cluster_config:
name: test-cluster
sysdig_endpoint:
region: "us2"
collector:
host: ingest-alt-us2.app.sysdig.com
port: 443
api_url:
asserts:
- matchRegex:
path: data["dragent.yaml"]
pattern: |
collector: ingest-alt-us2.app.sysdig.com
collector_port: 443
- matchRegex:
path: data["dragent.yaml"]
pattern: |
sysdig_api_endpoint: us2.app.sysdig.com

- it: Collector host, port and API endpoint validation when region is custom.
asserts:
- matchRegex:
path: data["dragent.yaml"]
pattern: |
collector: example.com
collector_port: 6443
- matchRegex:
path: data["dragent.yaml"]
pattern: |
sysdig_api_endpoint: https://www.example.com
Loading