Skip to content

Commit

Permalink
move initialization of SharedDirs to driver's CreatHost function
Browse files Browse the repository at this point in the history
options needed for the shared dirs such as the source path, target path
and types etc. differs between drivers and its best to configure  those
at the specific driver level

although currently both libvirt and vfkit have the same options for their
shared directories, hyperv will have different options to use smb instead
of virtiofs
  • Loading branch information
anjannath committed Oct 11, 2022
1 parent 6b62cdc commit 2785de0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
11 changes: 0 additions & 11 deletions pkg/crc/machine/config/driver.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package config

import (
"fmt"

"github.com/code-ready/machine/libmachine/drivers"
)

Expand All @@ -17,13 +15,4 @@ func InitVMDriverFromMachineConfig(machineConfig MachineConfig, driver *drivers.
driver.BundleName = machineConfig.BundleName
driver.ImageSourcePath = machineConfig.ImageSourcePath
driver.ImageFormat = machineConfig.ImageFormat

for i, dir := range machineConfig.SharedDirs {
sharedDir := drivers.SharedDir{
Source: dir,
Target: dir,
Tag: fmt.Sprintf("dir%d", i),
}
driver.SharedDirs = append(driver.SharedDirs, sharedDir)
}
}
19 changes: 19 additions & 0 deletions pkg/crc/machine/libvirt/driver_linux.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package libvirt

import (
"fmt"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/machine/config"
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/machine/drivers/libvirt"
"github.com/code-ready/machine/libmachine/drivers"
)

func CreateHost(machineConfig config.MachineConfig) *libvirt.Driver {
Expand All @@ -20,5 +23,21 @@ func CreateHost(machineConfig config.MachineConfig) *libvirt.Driver {
}

libvirtDriver.StoragePool = DefaultStoragePool
libvirtDriver.SharedDirs = configureShareDirs(machineConfig)

return libvirtDriver
}

func configureShareDirs(machineConfig config.MachineConfig) []drivers.SharedDir {
var sharedDirs []drivers.SharedDir
for i, dir := range machineConfig.SharedDirs {
sharedDir := drivers.SharedDir{
Source: dir,
Target: dir,
Tag: fmt.Sprintf("dir%d", i),
Type: "virtiofs",
}
sharedDirs = append(sharedDirs, sharedDir)
}
return sharedDirs
}
11 changes: 7 additions & 4 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,13 @@ func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error {
}
}
logging.Debugf("Mounting tag %s at %s", mount.Tag, mount.Target)
//FIXME: do not hardcode this
mount.Type = "virtiofs"
if _, _, err := sshRunner.RunPrivileged(fmt.Sprintf("Mounting %s", mount.Target), "mount", "-o", "context=\"system_u:object_r:container_file_t:s0\"", "-t", mount.Type, mount.Tag, mount.Target); err != nil {
return err
switch mount.Type {
case "virtiofs":
if _, _, err := sshRunner.RunPrivileged(fmt.Sprintf("Mounting %s", mount.Target), "mount", "-o", "context=\"system_u:object_r:container_file_t:s0\"", "-t", mount.Type, mount.Tag, mount.Target); err != nil {
return err
}
default:
return fmt.Errorf("Unknown Shared dir type requested: %s", mount.Type)
}
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/crc/machine/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package vfkit

import (
"fmt"
"path/filepath"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/machine/config"
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/crc/pkg/drivers/vfkit"
"github.com/code-ready/machine/libmachine/drivers"
)

func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
Expand All @@ -22,5 +24,21 @@ func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
vfDriver.VirtioNet = machineConfig.NetworkMode == network.SystemNetworkingMode
vfDriver.VsockPath = constants.TapSocketPath

vfDriver.SharedDirs = configureShareDirs(machineConfig)

return vfDriver
}

func configureShareDirs(machineConfig config.MachineConfig) []drivers.SharedDir {
var sharedDirs []drivers.SharedDir
for i, dir := range machineConfig.SharedDirs {
sharedDir := drivers.SharedDir{
Source: dir,
Target: dir,
Tag: fmt.Sprintf("dir%d", i),
Type: "virtiofs",
}
sharedDirs = append(sharedDirs, sharedDir)
}
return sharedDirs
}

0 comments on commit 2785de0

Please sign in to comment.