From 863a97fe07d99394e522aca70e11adeacbc29318 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 8 Jul 2024 15:08:31 -0700 Subject: [PATCH] pre-create persistent directories --- internal/cmd/local/local/cmd.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/cmd/local/local/cmd.go b/internal/cmd/local/local/cmd.go index 8cc9dcf..c2bde65 100644 --- a/internal/cmd/local/local/cmd.go +++ b/internal/cmd/local/local/cmd.go @@ -244,6 +244,18 @@ const ( func (c *Command) persistentVolume(ctx context.Context, namespace, name string) error { if !c.k8s.PersistentVolumeExists(ctx, namespace, name) { c.spinner.UpdateText(fmt.Sprintf("Creating persistent volume '%s'", name)) + + // Pre-create the volume directory with 0755 permissions. K8s, when using HostPathDirectoryOrCreate will + // create the directory (if it doesn't exist) with 0755 permissions which causes issues when docker + // is running as root and our pods are not. + path := filepath.Join(paths.Data, name) + const perms = 0755 + pterm.Debug.Println(fmt.Sprintf("Creating directory '%s' with %d permissions", path, perms)) + if err := os.MkdirAll(path, perms); err != nil { + pterm.Error.Println(fmt.Sprintf("Could not create directory '%s'", name)) + return fmt.Errorf("could not create persistent volume '%s': %w", name, err) + } + if err := c.k8s.PersistentVolumeCreate(ctx, namespace, name); err != nil { pterm.Error.Println(fmt.Sprintf("Could not create persistent volume '%s'", name)) return fmt.Errorf("could not create persistent volume '%s': %w", name, err)