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:".*"`
Namespaces []string `yaml:"namespaces"`
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
PersistentStorage bool `yaml:"persistentstorage" default:"false"`
StorageLimit string `yaml:"storagelimit" default:"200Mi"`
StorageClass string `yaml:"storageclass" default:"standard"`
DryRun bool `yaml:"dryrun" default:"false"`

View File

@ -67,8 +67,6 @@ spec:
- mountPath: /sys
name: sys
readOnly: true
- mountPath: /app/data
name: kubeshark-persistent-volume
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
serviceAccountName: kubeshark-service-account
@ -85,6 +83,3 @@ spec:
- hostPath:
path: /sys
name: sys
- name: kubeshark-persistent-volume
persistentVolumeClaim:
claimName: kubeshark-persistent-volume-claim

View File

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

View File

@ -855,17 +855,22 @@ func (provider *Provider) BuildWorkerDaemonSet(
MountPath: PersistentVolumeHostPath,
}
// VolumeMount(s)
volumeMounts := []core.VolumeMount{
procfsVolumeMount,
sysfsVolumeMount,
}
if config.Config.Tap.PersistentStorage {
volumeMounts = append(volumeMounts, persistentVolumeMount)
}
// Containers
containers := []core.Container{
{
Name: podName,
Image: podImage,
ImagePullPolicy: imagePullPolicy,
VolumeMounts: []core.VolumeMount{
procfsVolumeMount,
sysfsVolumeMount,
persistentVolumeMount,
},
VolumeMounts: volumeMounts,
Command: command,
Resources: core.ResourceRequirements{
Limits: core.ResourceList{
@ -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 := DaemonSetPod{
ObjectMeta: metav1.ObjectMeta{
@ -900,11 +914,7 @@ func (provider *Provider) BuildWorkerDaemonSet(
ServiceAccountName: ServiceAccountName,
HostNetwork: true,
Containers: containers,
Volumes: []core.Volume{
procfsVolume,
sysfsVolume,
persistentVolume,
},
Volumes: volumes,
DNSPolicy: core.DNSClusterFirstWithHostNet,
TerminationGracePeriodSeconds: new(int64),
Tolerations: provider.BuildTolerations(),

View File

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

View File

@ -67,8 +67,6 @@ spec:
- mountPath: /sys
name: sys
readOnly: true
- mountPath: /app/data
name: kubeshark-persistent-volume
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
serviceAccountName: kubeshark-service-account
@ -85,6 +83,3 @@ spec:
- hostPath:
path: /sys
name: sys
- name: kubeshark-persistent-volume
persistentVolumeClaim:
claimName: kubeshark-persistent-volume-claim