From 5652d19bfe3441eb5d31fd17c6c381cb1a895f10 Mon Sep 17 00:00:00 2001 From: ishaansehgal99 Date: Thu, 4 Apr 2024 14:23:39 -0700 Subject: [PATCH] fix: config host path --- pkg/tuning/preset-tuning.go | 7 ++++--- pkg/utils/common-preset.go | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/tuning/preset-tuning.go b/pkg/tuning/preset-tuning.go index 0a81585a7..c836727ec 100644 --- a/pkg/tuning/preset-tuning.go +++ b/pkg/tuning/preset-tuning.go @@ -129,7 +129,7 @@ func handleImageDataSource(ctx context.Context, workspaceObj *kaitov1alpha1.Work }, }) - volumes, volumeMounts := utils.ConfigDataVolume() + volumes, volumeMounts := utils.ConfigDataVolume("") return initContainers, volumes, volumeMounts } @@ -153,13 +153,14 @@ func handleURLDataSource(ctx context.Context, workspaceObj *kaitov1alpha1.Worksp }, }, }) - volumes, volumeMounts := utils.ConfigDataVolume() + volumes, volumeMounts := utils.ConfigDataVolume("") return initContainers, volumes, volumeMounts } func handleHostPathDataSource(ctx context.Context, workspaceObj *kaitov1alpha1.Workspace) ([]corev1.Container, []corev1.Volume, []corev1.VolumeMount) { var initContainers []corev1.Container - volumes, volumeMounts := utils.ConfigDataVolume() + hostPath := workspaceObj.Tuning.Input.HostPath + volumes, volumeMounts := utils.ConfigDataVolume(hostPath) return initContainers, volumes, volumeMounts } diff --git a/pkg/utils/common-preset.go b/pkg/utils/common-preset.go index 46410cb21..a1a514413 100644 --- a/pkg/utils/common-preset.go +++ b/pkg/utils/common-preset.go @@ -39,14 +39,24 @@ func ConfigSHMVolume(wObj *kaitov1alpha1.Workspace) (corev1.Volume, corev1.Volum return volume, volumeMount } -func ConfigDataVolume() ([]corev1.Volume, []corev1.VolumeMount) { +func ConfigDataVolume(hostPath string) ([]corev1.Volume, []corev1.VolumeMount) { var volumes []corev1.Volume var volumeMounts []corev1.VolumeMount - volumes = append(volumes, corev1.Volume{ - Name: "data-volume", - VolumeSource: corev1.VolumeSource{ + var volumeSource corev1.VolumeSource + if hostPath != "" { + volumeSource = corev1.VolumeSource{ + HostPath: &corev1.HostPathVolumeSource{ + Path: hostPath, + }, + } + } else { + volumeSource = corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, + } + } + volumes = append(volumes, corev1.Volume{ + Name: "data-volume", + VolumeSource: volumeSource, }) volumeMounts = append(volumeMounts, corev1.VolumeMount{