Skip to content
Open
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
2 changes: 1 addition & 1 deletion cmd/atelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ func buildAteomWorkloadSpec(spec *ateletpb.WorkloadSpec, containerSpecs []*ateom
VolumeName: volName,
MountPath: vm.GetMountPath(),
})
case *ateletpb.Volume_External:
case *ateletpb.Volume_External, *ateletpb.Volume_EmptyDir:
csiMounts = append(csiMounts, &ateompb.VolumeMount{
VolumeName: volName,
MountPath: vm.GetMountPath(),
Expand Down
3 changes: 3 additions & 0 deletions cmd/atelet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ func TestBuildAteomWorkloadSpecForwardsDurableDirMounts(t *testing.T) {
{Name: "data", Source: &ateletpb.Volume_DurableDir{DurableDir: &ateletpb.DurableDirVolume{}}},
{Name: "cache", Source: &ateletpb.Volume_DurableDir{DurableDir: &ateletpb.DurableDirVolume{}}},
{Name: "scratch", Source: &ateletpb.Volume_External{External: &ateletpb.ExternalVolumeSource{}}},
{Name: "empty", Source: &ateletpb.Volume_EmptyDir{EmptyDir: &ateletpb.EmptyDirVolume{}}},
{Name: "system-info", Source: &ateletpb.Volume_SystemInfo{SystemInfo: &ateletpb.SystemInfoVolume{}}},
},
Containers: []*ateletpb.Container{
Expand All @@ -1031,6 +1032,7 @@ func TestBuildAteomWorkloadSpecForwardsDurableDirMounts(t *testing.T) {
{Name: "data", MountPath: "/home/counter"},
{Name: "cache", MountPath: "/var/cache"},
{Name: "scratch", MountPath: "/scratch"},
{Name: "empty", MountPath: "/empty"},
{Name: "system-info", MountPath: "/run/ate"},
},
},
Expand All @@ -1055,6 +1057,7 @@ func TestBuildAteomWorkloadSpecForwardsDurableDirMounts(t *testing.T) {
},
CsiVolumeMounts: []*ateompb.VolumeMount{
{VolumeName: "scratch", MountPath: "/scratch"},
{VolumeName: "empty", MountPath: "/empty"},
},
SystemInfoVolumeMounts: []*ateompb.SystemInfoVolumeMount{
{VolumeName: "system-info", MountPath: "/run/ate"},
Expand Down
18 changes: 17 additions & 1 deletion cmd/atelet/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ import (

func (s *AteomHerder) mountExternalVolumes(ctx context.Context, actorUID string, volumes []*ateletpb.Volume) error {
for _, vol := range volumes {
hostPath := ateletpath.VolumeHostPath(actorUID, vol.GetName())
if vol.GetEmptyDir() != nil {
if err := resetEmptyDir(hostPath); err != nil {
return err
}
continue
}
ext := vol.GetExternal()
if ext == nil {
continue
}
hostPath := ateletpath.VolumeHostPath(actorUID, vol.GetName())
if err := os.MkdirAll(hostPath, 0o750); err != nil {
return fmt.Errorf("failed to create mount point %q: %w", hostPath, err)
}
Expand All @@ -56,6 +62,16 @@ func (s *AteomHerder) mountExternalVolumes(ctx context.Context, actorUID string,
return nil
}

func resetEmptyDir(hostPath string) error {
if err := os.RemoveAll(hostPath); err != nil {
return fmt.Errorf("failed to clear empty dir %q: %w", hostPath, err)
}
if err := os.MkdirAll(hostPath, 0o750); err != nil {
return fmt.Errorf("failed to create empty dir %q: %w", hostPath, err)
}
return nil
}

func (s *AteomHerder) unmountExternalVolumes(ctx context.Context, actorUID string, volumes []*ateletpb.Volume) error {
var errs []error
for _, vol := range volumes {
Expand Down
20 changes: 20 additions & 0 deletions cmd/atelet/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,23 @@ func TestDirectCSIDriverConfigGetter(t *testing.T) {
t.Fatalf("expected error for missing driver, got nil")
}
}

func TestResetEmptyDirClearsPreviousContents(t *testing.T) {
dir := filepath.Join(t.TempDir(), "volumes", "shared")
if err := os.MkdirAll(dir, 0o750); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "stale"), []byte("x"), 0o600); err != nil {
t.Fatal(err)
}
if err := resetEmptyDir(dir); err != nil {
t.Fatalf("resetEmptyDir: %v", err)
}
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatalf("ReadDir: %v", err)
}
if len(entries) != 0 {
t.Fatalf("dir still has %d entries after reset", len(entries))
}
}
Loading
Loading