diff --git a/cmd/pcapDumpRunner.go b/cmd/pcapDumpRunner.go index 3fd515dab..fe32fdeff 100644 --- a/cmd/pcapDumpRunner.go +++ b/cmd/pcapDumpRunner.go @@ -22,9 +22,10 @@ import ( "k8s.io/client-go/tools/remotecommand" ) -const label = "app.kubeshark.co/app=worker" -const SELF_RESOURCES_PREFIX = "kubeshark-" -const SUFFIX_CONFIG_MAP = "config-map" +const ( + label = "app.kubeshark.co/app=worker" + srcDir = "pcapdump" +) // NamespaceFiles represents the namespace and the files found in that namespace. type NamespaceFiles struct { @@ -55,27 +56,13 @@ func listWorkerPods(ctx context.Context, clientset *clientk8s.Clientset, namespa } // listFilesInPodDir lists all files in the specified directory inside the pod across multiple namespaces -func listFilesInPodDir(ctx context.Context, clientset *clientk8s.Clientset, config *rest.Config, podName string, namespaces []string, configMapName, configMapKey string, cutoffTime *time.Time) ([]NamespaceFiles, error) { +func listFilesInPodDir(ctx context.Context, clientset *clientk8s.Clientset, config *rest.Config, podName string, namespaces []string, cutoffTime *time.Time) ([]NamespaceFiles, error) { var namespaceFilesList []NamespaceFiles for _, namespace := range namespaces { - // Attempt to get the ConfigMap in the current namespace - configMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(ctx, configMapName, metav1.GetOptions{}) - if err != nil { - continue - } - - // Check if the source directory exists in the ConfigMap - srcDir, ok := configMap.Data[configMapKey] - if !ok || srcDir == "" { - log.Error().Msgf("source directory not found in ConfigMap %s in namespace %s", configMapName, namespace) - continue - } - // Attempt to get the pod in the current namespace pod, err := clientset.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{}) if err != nil { - log.Error().Err(err).Msgf("failed to get pod %s in namespace %s", podName, namespace) continue } @@ -252,7 +239,7 @@ func mergePCAPs(outputFile string, inputFiles []string) error { // Read packet data data, ci, err := reader.ReadPacketData() if err != nil { - if errors.Is(err, io.EOF) { + if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) { break } log.Error().Err(err).Msgf("Error reading packet from file %s", inputFile) @@ -295,7 +282,7 @@ func copyPcapFiles(clientset *kubernetes.Clientset, config *rest.Config, destDir // Iterate over each pod to get the PCAP directory from config and copy files for _, pod := range workerPods { // Get the list of NamespaceFiles (files per namespace) and their source directories - namespaceFiles, err := listFilesInPodDir(context.Background(), clientset, config, pod.Name, targetNamespaces, SELF_RESOURCES_PREFIX+SUFFIX_CONFIG_MAP, "PCAP_SRC_DIR", cutoffTime) + namespaceFiles, err := listFilesInPodDir(context.Background(), clientset, config, pod.Name, targetNamespaces, cutoffTime) if err != nil { log.Error().Err(err).Msgf("Error listing files in pod %s", pod.Name) continue diff --git a/config/configStructs/tapConfig.go b/config/configStructs/tapConfig.go index 9edb77339..5e03072b7 100644 --- a/config/configStructs/tapConfig.go +++ b/config/configStructs/tapConfig.go @@ -220,7 +220,6 @@ type PcapDumpConfig struct { PcapTimeInterval string `yaml:"timeInterval" json:"timeInterval" default:"1m"` PcapMaxTime string `yaml:"maxTime" json:"maxTime" default:"1h"` PcapMaxSize string `yaml:"maxSize" json:"maxSize" default:"500MB"` - PcapSrcDir string `yaml:"pcapSrcDir" json:"pcapSrcDir" default:"pcapdump"` PcapTime string `yaml:"time" json:"time" default:"time"` } diff --git a/helm-chart/node-minikube-worker-1-20241211-193826.pcap b/helm-chart/node-minikube-worker-1-20241211-193826.pcap new file mode 100644 index 000000000..39c935c64 Binary files /dev/null and b/helm-chart/node-minikube-worker-1-20241211-193826.pcap differ diff --git a/helm-chart/templates/12-config-map.yaml b/helm-chart/templates/12-config-map.yaml index 48364b404..1f705c382 100644 --- a/helm-chart/templates/12-config-map.yaml +++ b/helm-chart/templates/12-config-map.yaml @@ -56,5 +56,4 @@ data: PCAP_DUMP_ENABLE: '{{ .Values.pcapdump.enabled }}' PCAP_TIME_INTERVAL: '{{ .Values.pcapdump.timeInterval }}' PCAP_MAX_TIME: '{{ .Values.pcapdump.maxTime }}' - PCAP_MAX_SIZE: '{{ .Values.pcapdump.maxSize }}' - PCAP_SRC_DIR: '{{ .Values.pcapdump.pcapSrcDir }}' + PCAP_MAX_SIZE: '{{ .Values.pcapdump.maxSize }}' \ No newline at end of file diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 737daf9ee..c7ab5665c 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -173,7 +173,6 @@ pcapdump: timeInterval: 1m maxTime: 1h maxSize: 500MB - pcapSrcDir: pcapdump time: time kube: configPath: ""