Add persistentstorage option

This commit is contained in:
M. Mert Yildiran 2023-05-08 00:50:56 +03:00
parent a9b598bc41
commit a33a3467fc
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
6 changed files with 39 additions and 34 deletions

View File

@ -82,6 +82,7 @@ type TapConfig struct {
PodRegexStr string `yaml:"regex" default:".*"` PodRegexStr string `yaml:"regex" default:".*"`
Namespaces []string `yaml:"namespaces"` Namespaces []string `yaml:"namespaces"`
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"` SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
PersistentStorage bool `yaml:"persistentstorage" default:"false"`
StorageLimit string `yaml:"storagelimit" default:"200Mi"` StorageLimit string `yaml:"storagelimit" default:"200Mi"`
StorageClass string `yaml:"storageclass" default:"standard"` StorageClass string `yaml:"storageclass" default:"standard"`
DryRun bool `yaml:"dryrun" default:"false"` DryRun bool `yaml:"dryrun" default:"false"`

View File

@ -67,8 +67,6 @@ 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
@ -85,6 +83,3 @@ spec:
- hostPath: - hostPath:
path: /sys path: /sys
name: sys name: sys
- name: kubeshark-persistent-volume
persistentVolumeClaim:
claimName: kubeshark-persistent-volume-claim

View File

@ -18,6 +18,7 @@ tap:
regex: .* regex: .*
namespaces: [] namespaces: []
selfnamespace: kubeshark selfnamespace: kubeshark
persistentstorage: false
storagelimit: 200Mi storagelimit: 200Mi
storageclass: standard storageclass: standard
dryrun: false dryrun: false

View File

@ -855,18 +855,23 @@ func (provider *Provider) BuildWorkerDaemonSet(
MountPath: PersistentVolumeHostPath, MountPath: PersistentVolumeHostPath,
} }
// VolumeMount(s)
volumeMounts := []core.VolumeMount{
procfsVolumeMount,
sysfsVolumeMount,
}
if config.Config.Tap.PersistentStorage {
volumeMounts = append(volumeMounts, persistentVolumeMount)
}
// Containers // Containers
containers := []core.Container{ containers := []core.Container{
{ {
Name: podName, Name: podName,
Image: podImage, Image: podImage,
ImagePullPolicy: imagePullPolicy, ImagePullPolicy: imagePullPolicy,
VolumeMounts: []core.VolumeMount{ VolumeMounts: volumeMounts,
procfsVolumeMount, Command: command,
sysfsVolumeMount,
persistentVolumeMount,
},
Command: command,
Resources: core.ResourceRequirements{ Resources: core.ResourceRequirements{
Limits: core.ResourceList{ Limits: core.ResourceList{
"cpu": cpuLimit, "cpu": cpuLimit,
@ -887,6 +892,15 @@ func (provider *Provider) BuildWorkerDaemonSet(
}, },
} }
// Volume(s)
volumes := []core.Volume{
procfsVolume,
sysfsVolume,
}
if config.Config.Tap.PersistentStorage {
volumes = append(volumes, persistentVolume)
}
// Pod // Pod
pod := DaemonSetPod{ pod := DaemonSetPod{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -897,14 +911,10 @@ func (provider *Provider) BuildWorkerDaemonSet(
}, provider), }, provider),
}, },
Spec: core.PodSpec{ Spec: core.PodSpec{
ServiceAccountName: ServiceAccountName, ServiceAccountName: ServiceAccountName,
HostNetwork: true, HostNetwork: true,
Containers: containers, Containers: containers,
Volumes: []core.Volume{ Volumes: volumes,
procfsVolume,
sysfsVolume,
persistentVolume,
},
DNSPolicy: core.DNSClusterFirstWithHostNet, DNSPolicy: core.DNSClusterFirstWithHostNet,
TerminationGracePeriodSeconds: new(int64), TerminationGracePeriodSeconds: new(int64),
Tolerations: provider.BuildTolerations(), Tolerations: provider.BuildTolerations(),

View File

@ -3,6 +3,7 @@ package kubernetes
import ( import (
"context" "context"
"github.com/kubeshark/kubeshark/config"
"github.com/kubeshark/kubeshark/config/configStructs" "github.com/kubeshark/kubeshark/config/configStructs"
"github.com/kubeshark/kubeshark/docker" "github.com/kubeshark/kubeshark/docker"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -21,17 +22,19 @@ func CreateWorkers(
tls bool, tls bool,
debug bool, debug bool,
) error { ) error {
persistentVolumeClaim, err := kubernetesProvider.BuildPersistentVolumeClaim() if config.Config.Tap.PersistentStorage {
if err != nil { persistentVolumeClaim, err := kubernetesProvider.BuildPersistentVolumeClaim()
return err if err != nil {
} return err
}
if _, err = kubernetesProvider.CreatePersistentVolumeClaim( if _, err = kubernetesProvider.CreatePersistentVolumeClaim(
ctx, ctx,
namespace, namespace,
persistentVolumeClaim, persistentVolumeClaim,
); err != nil { ); err != nil {
return err return err
}
} }
image := docker.GetWorkerImage() image := docker.GetWorkerImage()

View File

@ -67,8 +67,6 @@ 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
@ -85,6 +83,3 @@ spec:
- hostPath: - hostPath:
path: /sys path: /sys
name: sys name: sys
- name: kubeshark-persistent-volume
persistentVolumeClaim:
claimName: kubeshark-persistent-volume-claim