From 0119e1dfa947d94df25781cd9a45b23069b0ba30 Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Thu, 28 Nov 2024 12:35:04 +0100 Subject: [PATCH] fix(helm): Fix UI DisruptionBudget and ServiceAccount templates (#606) Signed-off-by: Frank Jogeleit --- charts/policy-reporter/templates/_helpers.tpl | 8 ++++++++ charts/policy-reporter/templates/ui/_helpers.tpl | 16 ++++++++-------- pkg/target/elasticsearch/elasticsearch.go | 7 +++++++ pkg/target/factory/factory.go | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/charts/policy-reporter/templates/_helpers.tpl b/charts/policy-reporter/templates/_helpers.tpl index 665da407..1bc4361c 100644 --- a/charts/policy-reporter/templates/_helpers.tpl +++ b/charts/policy-reporter/templates/_helpers.tpl @@ -156,6 +156,10 @@ config: certificate: {{ .certificate | quote }} skipTLS: {{ .skipTLS }} path: {{ .path | quote }} + {{- with .headers }} + headers: + {{- toYaml . | nindent 4 }} + {{- end }} {{ include "target" . }} {{- end }} @@ -170,6 +174,10 @@ config: index: {{ .index| quote }} rotation: {{ .rotation | quote }} typelessApi: {{ .typelessApi | quote }} + {{- with .headers }} + headers: + {{- toYaml . | nindent 4 }} + {{- end }} {{ include "target" . }} {{- end }} diff --git a/charts/policy-reporter/templates/ui/_helpers.tpl b/charts/policy-reporter/templates/ui/_helpers.tpl index bd424b57..d8de3d52 100644 --- a/charts/policy-reporter/templates/ui/_helpers.tpl +++ b/charts/policy-reporter/templates/ui/_helpers.tpl @@ -48,21 +48,21 @@ app.kubernetes.io/instance: {{ .Release.Name }} Create the name of the service account to use */}} {{- define "ui.serviceAccountName" -}} -{{- if .Values.plugin.kyverno.serviceAccount.create }} -{{- default (include "ui.fullname" .) .Values.plugin.kyverno.serviceAccount.name }} +{{- if .Values.ui.serviceAccount.create }} +{{- default (include "ui.fullname" .) .Values.ui.serviceAccount.name }} {{- else }} -{{- default "default" .Values.plugin.kyverno.serviceAccount.name }} +{{- default "default" .Values.ui.serviceAccount.name }} {{- end }} {{- end }} {{- define "ui.podDisruptionBudget" -}} -{{- if and .Values.plugin.kyverno.ui.podDisruptionBudget.minAvailable .Values.plugin.kyverno.ui.podDisruptionBudget.maxUnavailable }} +{{- if and .Values.ui.podDisruptionBudget.minAvailable .Values.ui.podDisruptionBudget.maxUnavailable }} {{- fail "Cannot set both" -}} {{- end }} -{{- if not .Values.plugin.kyverno.ui.podDisruptionBudget.maxUnavailable }} -minAvailable: {{ default 1 .Values.plugin.kyverno.ui.podDisruptionBudget.minAvailable }} +{{- if not .Values.ui.podDisruptionBudget.maxUnavailable }} +minAvailable: {{ default 1 .Values.ui.podDisruptionBudget.minAvailable }} {{- end }} -{{- if .Values.plugin.kyverno.ui.podDisruptionBudget.maxUnavailable }} -maxUnavailable: {{ .Values.plugin.kyverno.ui.podDisruptionBudget.maxUnavailable }} +{{- if .Values.ui.podDisruptionBudget.maxUnavailable }} +maxUnavailable: {{ .Values.ui.podDisruptionBudget.maxUnavailable }} {{- end }} {{- end }} diff --git a/pkg/target/elasticsearch/elasticsearch.go b/pkg/target/elasticsearch/elasticsearch.go index 211f6626..89ef6e95 100644 --- a/pkg/target/elasticsearch/elasticsearch.go +++ b/pkg/target/elasticsearch/elasticsearch.go @@ -18,6 +18,7 @@ type Options struct { Index string Rotation string CustomFields map[string]string + Headers map[string]string HTTPClient http.Client // https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0 TypelessApi bool @@ -43,6 +44,7 @@ type client struct { apiKey string rotation Rotation customFields map[string]string + headers map[string]string client http.Client // https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0 typelessApi bool @@ -87,6 +89,10 @@ func (e *client) Send(result v1alpha2.PolicyReportResult) { return } + for k, v := range e.headers { + req.Header.Set(k, v) + } + if e.username != "" { req.SetBasicAuth(e.username, e.password) } else if e.apiKey != "" { @@ -112,6 +118,7 @@ func NewClient(options Options) target.Client { options.ApiKey, options.Rotation, options.CustomFields, + options.Headers, options.HTTPClient, options.TypelessApi, } diff --git a/pkg/target/factory/factory.go b/pkg/target/factory/factory.go index bb27bc4e..d398f1fd 100644 --- a/pkg/target/factory/factory.go +++ b/pkg/target/factory/factory.go @@ -247,6 +247,7 @@ func (f *TargetFactory) CreateElasticsearchTarget(config, parent *target.Config[ Index: config.Config.Index, TypelessApi: config.Config.TypelessAPI, CustomFields: config.CustomFields, + Headers: config.Config.Headers, HTTPClient: http.NewClient(config.Config.Certificate, config.Config.SkipTLS), }), }