diff --git a/internal/common/tasks/scratch_volumes_test.go b/internal/common/tasks/scratch_volumes_test.go index 269c8313..c48ad379 100644 --- a/internal/common/tasks/scratch_volumes_test.go +++ b/internal/common/tasks/scratch_volumes_test.go @@ -22,10 +22,10 @@ var pvcScratchMountPaths = map[string]bool{ // allScratchVolumeNames includes container-storage for memory volume tests var allScratchVolumeNames = map[string]bool{ - "build-dir": true, - "output-dir": true, - "run-dir": true, - "container-storage": true, + "build-dir": true, + "output-dir": true, + "run-dir": true, + volumeNameContainerStorage: true, } func TestPVCScratchVolumes_RemovesEmptyDirVolumes(t *testing.T) { @@ -47,7 +47,7 @@ func TestPVCScratchVolumes_KeepsContainerStorage(t *testing.T) { found := false for _, vol := range task.Spec.Volumes { - if vol.Name == "container-storage" { + if vol.Name == volumeNameContainerStorage { found = true if vol.EmptyDir == nil { t.Fatal("container-storage should remain as emptyDir") @@ -169,6 +169,20 @@ func TestPVCScratchVolumes_TakesPrecedenceOverMemory(t *testing.T) { } } + // container-storage should still be present and get memory medium + found := false + for _, vol := range task.Spec.Volumes { + if vol.Name == volumeNameContainerStorage { + found = true + if vol.EmptyDir == nil || vol.EmptyDir.Medium != corev1.StorageMediumMemory { + t.Fatal("container-storage should have memory medium when useMemoryVolumes is true") + } + } + } + if !found { + t.Fatal("container-storage volume should be preserved when both useMemoryVolumes and usePVCScratchVolumes are true") + } + // Steps that had scratch mounts should now reference workspace volume totalFound := 0 for _, step := range task.Spec.Steps { diff --git a/internal/common/tasks/tasks.go b/internal/common/tasks/tasks.go index c2f419fb..75bfdd01 100644 --- a/internal/common/tasks/tasks.go +++ b/internal/common/tasks/tasks.go @@ -12,7 +12,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - "sigs.k8s.io/controller-runtime/pkg/log" ) // BuildConfig defines configuration options for build operations @@ -592,15 +591,16 @@ func GenerateBuildAutomotiveImageTask(namespace string, buildConfig *BuildConfig }, } - if buildConfig != nil && buildConfig.UseMemoryVolumes && buildConfig.UsePVCScratchVolumes { - log.Log.Info("WARNING: useMemoryVolumes and usePVCScratchVolumes are both enabled; usePVCScratchVolumes takes precedence") - } - - if buildConfig != nil && buildConfig.UseMemoryVolumes && !buildConfig.UsePVCScratchVolumes { + if buildConfig != nil && buildConfig.UseMemoryVolumes { for i := range task.Spec.Volumes { vol := &task.Spec.Volumes[i] - if vol.Name == "build-dir" || vol.Name == "run-dir" || vol.Name == volumeNameContainerStorage || vol.Name == "output-dir" { + isContainerStorage := vol.Name == volumeNameContainerStorage + isScratch := vol.Name == "build-dir" || vol.Name == "run-dir" || vol.Name == "output-dir" + + // When PVC scratch is on, only container-storage remains as emptyDir; + // the other scratch volumes get redirected to the workspace PVC below. + if isContainerStorage || (!buildConfig.UsePVCScratchVolumes && isScratch) { vol.EmptyDir = &corev1.EmptyDirVolumeSource{ Medium: corev1.StorageMediumMemory, } diff --git a/internal/controller/imagebuild/controller.go b/internal/controller/imagebuild/controller.go index cf543e52..58a72afe 100644 --- a/internal/controller/imagebuild/controller.go +++ b/internal/controller/imagebuild/controller.go @@ -2051,7 +2051,7 @@ func (r *ImageBuildReconciler) getOrCreateWorkspacePVC( "old-pvc", imageBuild.Status.PVCName) } - // Fetch OperatorConfig to get PVC size configuration + // Fetch OperatorConfig to get PVC size and storage class configuration operatorConfig := &automotivev1alpha1.OperatorConfig{} err := r.Get(ctx, types.NamespacedName{Name: "config", Namespace: OperatorNamespace}, operatorConfig) @@ -2097,6 +2097,8 @@ func (r *ImageBuildReconciler) getOrCreateWorkspacePVC( if imageBuild.Spec.StorageClass != "" { pvc.Spec.StorageClassName = &imageBuild.Spec.StorageClass + } else if err == nil && operatorConfig.Spec.OSBuilds != nil && operatorConfig.Spec.OSBuilds.StorageClass != "" { + pvc.Spec.StorageClassName = &operatorConfig.Spec.OSBuilds.StorageClass } if err := r.Create(ctx, pvc); err != nil {