Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions internal/common/tasks/scratch_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions internal/common/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/imagebuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
Loading