From cd3546cb4546e972ab44e99bdaa7ba3618b99959 Mon Sep 17 00:00:00 2001 From: Volodymyr Stoiko Date: Wed, 16 Apr 2025 19:36:11 +0300 Subject: [PATCH] Add optional gitops mode --- config/configStructs/tapConfig.go | 5 +++++ helm-chart/README.md | 1 + helm-chart/templates/04-hub-deployment.yaml | 3 +++ helm-chart/templates/12-config-map.yaml | 2 +- helm-chart/templates/13-secret.yaml | 2 +- helm-chart/templates/18-cleanup-job.yaml | 4 +++- helm-chart/templates/_helpers.tpl | 12 ++++++++++++ helm-chart/values.yaml | 2 ++ manifests/complete.yaml | 4 ++-- 9 files changed, 30 insertions(+), 5 deletions(-) diff --git a/config/configStructs/tapConfig.go b/config/configStructs/tapConfig.go index 98f622589..43c3a75a4 100644 --- a/config/configStructs/tapConfig.go +++ b/config/configStructs/tapConfig.go @@ -227,6 +227,10 @@ type WatchdogConfig struct { Enabled bool `yaml:"enabled" json:"enabled" default:"true"` } +type GitopsConfig struct { + Enabled bool `yaml:"enabled" json:"enabled" default:"false"` +} + type CapabilitiesConfig struct { NetworkCapture []string `yaml:"networkCapture" json:"networkCapture" default:"[]"` ServiceMeshCapture []string `yaml:"serviceMeshCapture" json:"serviceMeshCapture" default:"[]"` @@ -330,6 +334,7 @@ type TapConfig struct { Telemetry TelemetryConfig `yaml:"telemetry" json:"telemetry"` ResourceGuard ResourceGuardConfig `yaml:"resourceGuard" json:"resourceGuard"` Watchdog WatchdogConfig `yaml:"watchdog" json:"watchdog"` + Gitops GitopsConfig `yaml:"gitops" json:"gitops"` Sentry SentryConfig `yaml:"sentry" json:"sentry"` DefaultFilter string `yaml:"defaultFilter" json:"defaultFilter" default:"!dns and !error"` LiveConfigMapChangesDisabled bool `yaml:"liveConfigMapChangesDisabled" json:"liveConfigMapChangesDisabled" default:"false"` diff --git a/helm-chart/README.md b/helm-chart/README.md index bfae9388a..043936d44 100644 --- a/helm-chart/README.md +++ b/helm-chart/README.md @@ -210,6 +210,7 @@ Example for overriding image names: | `tap.metrics.port` | Pod port used to expose Prometheus metrics | `49100` | | `tap.enabledDissectors` | This is an array of strings representing the list of supported protocols. Remove or comment out redundant protocols (e.g., dns).| The default list excludes: `udp` and `tcp` | | `tap.mountBpf` | BPF filesystem needs to be mounted for eBPF to work properly. This helm value determines whether Kubeshark will attempt to mount the filesystem. This option is not required if filesystem is already mounts. │ `true`| +| `tap.gitops.enabled` | Enable GitOps functionality. This will allow you to use GitOps to manage your Kubeshark configuration. | `false` | | `logs.file` | Logs dump path | `""` | | `pcapdump.enabled` | Enable recording of all traffic captured according to other parameters. Whatever Kubeshark captures, considering pod targeting rules, will be stored in pcap files ready to be viewed by tools | `true` | | `pcapdump.maxTime` | The time window into the past that will be stored. Older traffic will be discarded. | `2h` | diff --git a/helm-chart/templates/04-hub-deployment.yaml b/helm-chart/templates/04-hub-deployment.yaml index f2755eb04..29f4ed0e5 100644 --- a/helm-chart/templates/04-hub-deployment.yaml +++ b/helm-chart/templates/04-hub-deployment.yaml @@ -33,6 +33,9 @@ spec: - "8080" - -loglevel - '{{ .Values.logLevel | default "warning" }}' + {{- if .Values.tap.gitops.enabled }} + - -gitops + {{- end }} env: - name: POD_NAME valueFrom: diff --git a/helm-chart/templates/12-config-map.yaml b/helm-chart/templates/12-config-map.yaml index b356be53a..90bedb07e 100644 --- a/helm-chart/templates/12-config-map.yaml +++ b/helm-chart/templates/12-config-map.yaml @@ -1,7 +1,7 @@ kind: ConfigMap apiVersion: v1 metadata: - name: kubeshark-config-map-default + name: {{ include "kubeshark.configmapName" . }} namespace: {{ .Release.Namespace }} labels: app.kubeshark.co/app: hub diff --git a/helm-chart/templates/13-secret.yaml b/helm-chart/templates/13-secret.yaml index d5093d8c8..01f995cb5 100644 --- a/helm-chart/templates/13-secret.yaml +++ b/helm-chart/templates/13-secret.yaml @@ -1,7 +1,7 @@ kind: Secret apiVersion: v1 metadata: - name: kubeshark-secret-default + name: {{ include "kubeshark.secretName" . }} namespace: {{ .Release.Namespace }} labels: app.kubeshark.co/app: hub diff --git a/helm-chart/templates/18-cleanup-job.yaml b/helm-chart/templates/18-cleanup-job.yaml index 443c824ef..59a076299 100644 --- a/helm-chart/templates/18-cleanup-job.yaml +++ b/helm-chart/templates/18-cleanup-job.yaml @@ -1,3 +1,4 @@ +{{ if .Values.tap.gitops.enabled -}} apiVersion: batch/v1 kind: Job metadata: @@ -19,4 +20,5 @@ spec: {{ else }} image: '{{ .Values.tap.docker.registry }}/hub:{{ not (eq .Values.tap.docker.tag "") | ternary .Values.tap.docker.tag (include "kubeshark.defaultVersion" .) }}' {{- end }} - command: ["/app/cleanup"] \ No newline at end of file + command: ["/app/cleanup"] +{{ end -}} \ No newline at end of file diff --git a/helm-chart/templates/_helpers.tpl b/helm-chart/templates/_helpers.tpl index 0230d06f6..6285caeab 100644 --- a/helm-chart/templates/_helpers.tpl +++ b/helm-chart/templates/_helpers.tpl @@ -49,6 +49,18 @@ Create the name of the service account to use {{- printf "%s-service-account" .Release.Name }} {{- end }} +{{/* +Set configmap and secret names based on gitops.enabled +*/}} +{{- define "kubeshark.configmapName" -}} +kubeshark-config-map{{ if .Values.tap.gitops.enabled }}-default{{ end }} +{{- end -}} + +{{- define "kubeshark.secretName" -}} +kubeshark-secret{{ if .Values.tap.gitops.enabled }}-default{{ end }} +{{- end -}} + + {{/* Escape double quotes in a string */}} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 406cc63bc..9ce78a231 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -151,6 +151,8 @@ tap: enabled: false watchdog: enabled: true + gitops: + enabled: false sentry: enabled: false environment: production diff --git a/manifests/complete.yaml b/manifests/complete.yaml index 8adfc49ab..ccdbff2da 100644 --- a/manifests/complete.yaml +++ b/manifests/complete.yaml @@ -130,7 +130,7 @@ metadata: kind: Secret apiVersion: v1 metadata: - name: kubeshark-secret-default + name: kubeshark-secret namespace: default labels: app.kubeshark.co/app: hub @@ -244,7 +244,7 @@ data: kind: ConfigMap apiVersion: v1 metadata: - name: kubeshark-config-map-default + name: kubeshark-config-map namespace: default labels: app.kubeshark.co/app: hub