mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-27 16:50:02 +00:00
⚡ Template the Helm chart based on persistentstorage
value
This commit is contained in:
parent
a33a3467fc
commit
baf0e65337
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/kubeshark/kubeshark/config"
|
"github.com/kubeshark/kubeshark/config"
|
||||||
"github.com/kubeshark/kubeshark/kubernetes"
|
"github.com/kubeshark/kubeshark/kubernetes"
|
||||||
@ -257,6 +258,34 @@ func template(object interface{}, mappings map[string]interface{}) (template int
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlePVCManifest(manifest string) string {
|
||||||
|
return fmt.Sprintf("{{- if .Values.tap.persistentstorage }}\n%s{{- end }}", manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleDaemonSetManifest(manifest string) string {
|
||||||
|
lines := strings.Split(manifest, "\n")
|
||||||
|
|
||||||
|
for i, line := range lines {
|
||||||
|
if strings.TrimSpace(line) == "- mountPath: /app/data" {
|
||||||
|
lines[i] = fmt.Sprintf("{{- if .Values.tap.persistentstorage }}\n%s", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(line) == "name: kubeshark-persistent-volume" {
|
||||||
|
lines[i] = fmt.Sprintf("%s\n{{- end }}", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(line) == "- name: kubeshark-persistent-volume" {
|
||||||
|
lines[i] = fmt.Sprintf("{{- if .Values.tap.persistentstorage }}\n%s", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(line) == "claimName: kubeshark-persistent-volume-claim" {
|
||||||
|
lines[i] = fmt.Sprintf("%s\n{{- end }}", line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(lines, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
func dumpHelmChart(objects map[string]interface{}) error {
|
func dumpHelmChart(objects map[string]interface{}) error {
|
||||||
folder := filepath.Join(".", "helm-chart")
|
folder := filepath.Join(".", "helm-chart")
|
||||||
templatesFolder := filepath.Join(folder, "templates")
|
templatesFolder := filepath.Join(folder, "templates")
|
||||||
@ -285,6 +314,14 @@ func dumpHelmChart(objects map[string]interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filename == "08-persistent-volume-claim.yaml" {
|
||||||
|
manifest = handlePVCManifest(manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filename == "09-worker-daemon-set.yaml" {
|
||||||
|
manifest = handleDaemonSetManifest(manifest)
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(templatesFolder, filename)
|
path := filepath.Join(templatesFolder, filename)
|
||||||
err = os.WriteFile(path, []byte(manifestHeader+manifest), 0644)
|
err = os.WriteFile(path, []byte(manifestHeader+manifest), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,6 +104,8 @@ func generateManifests() (
|
|||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
config.Config.License = ""
|
config.Config.License = ""
|
||||||
|
persistentStorage := config.Config.Tap.PersistentStorage
|
||||||
|
config.Config.Tap.PersistentStorage = true
|
||||||
|
|
||||||
var kubernetesProvider *kubernetes.Provider
|
var kubernetesProvider *kubernetes.Provider
|
||||||
kubernetesProvider, err = getKubernetesProviderForCli(true, true)
|
kubernetesProvider, err = getKubernetesProviderForCli(true, true)
|
||||||
@ -171,6 +173,8 @@ func generateManifests() (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.Config.Tap.PersistentStorage = persistentStorage
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# THIS FILE IS AUTOMATICALLY GENERATED BY KUBESHARK CLI. DO NOT EDIT!
|
# THIS FILE IS AUTOMATICALLY GENERATED BY KUBESHARK CLI. DO NOT EDIT!
|
||||||
---
|
---
|
||||||
|
{{- if .Values.tap.persistentstorage }}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
metadata:
|
metadata:
|
||||||
@ -18,3 +19,4 @@ spec:
|
|||||||
storage: '{{ .Values.tap.storagelimit }}'
|
storage: '{{ .Values.tap.storagelimit }}'
|
||||||
storageClassName: '{{ .Values.tap.storageclass }}'
|
storageClassName: '{{ .Values.tap.storageclass }}'
|
||||||
status: {}
|
status: {}
|
||||||
|
{{- end }}
|
@ -67,6 +67,10 @@ spec:
|
|||||||
- mountPath: /sys
|
- mountPath: /sys
|
||||||
name: sys
|
name: sys
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
{{- if .Values.tap.persistentstorage }}
|
||||||
|
- mountPath: /app/data
|
||||||
|
name: kubeshark-persistent-volume
|
||||||
|
{{- end }}
|
||||||
dnsPolicy: ClusterFirstWithHostNet
|
dnsPolicy: ClusterFirstWithHostNet
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
serviceAccountName: kubeshark-service-account
|
serviceAccountName: kubeshark-service-account
|
||||||
@ -83,3 +87,8 @@ spec:
|
|||||||
- hostPath:
|
- hostPath:
|
||||||
path: /sys
|
path: /sys
|
||||||
name: sys
|
name: sys
|
||||||
|
{{- if .Values.tap.persistentstorage }}
|
||||||
|
- name: kubeshark-persistent-volume
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: kubeshark-persistent-volume-claim
|
||||||
|
{{- end }}
|
||||||
|
@ -67,6 +67,8 @@ spec:
|
|||||||
- mountPath: /sys
|
- mountPath: /sys
|
||||||
name: sys
|
name: sys
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
- mountPath: /app/data
|
||||||
|
name: kubeshark-persistent-volume
|
||||||
dnsPolicy: ClusterFirstWithHostNet
|
dnsPolicy: ClusterFirstWithHostNet
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
serviceAccountName: kubeshark-service-account
|
serviceAccountName: kubeshark-service-account
|
||||||
@ -83,3 +85,6 @@ spec:
|
|||||||
- hostPath:
|
- hostPath:
|
||||||
path: /sys
|
path: /sys
|
||||||
name: sys
|
name: sys
|
||||||
|
- name: kubeshark-persistent-volume
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: kubeshark-persistent-volume-claim
|
||||||
|
Loading…
Reference in New Issue
Block a user