Skip to content

Commit

Permalink
pre-create persistent directories
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass committed Jul 8, 2024
1 parent 779145b commit 863a97f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/cmd/local/local/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 863a97f

Please sign in to comment.