Skip to content

Commit

Permalink
dapr_scheduler: Adds scheduler-volume flag (#1422)
Browse files Browse the repository at this point in the history
* dapr_scheduler: pre-create data dir

Signed-off-by: joshvanl <[email protected]>

* Adds --scheduler-volume to specify volume for data directory

Signed-off-by: joshvanl <[email protected]>

---------

Signed-off-by: joshvanl <[email protected]>
  • Loading branch information
JoshVanL authored Jul 12, 2024
1 parent ed0d3af commit ad3442b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
8 changes: 7 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
fromDir string
containerRuntime string
imageVariant string
schedulerVolume string
)

var InitCmd = &cobra.Command{
Expand Down Expand Up @@ -170,7 +171,11 @@ dapr init --runtime-path <path-to-install-directory>
print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.")
os.Exit(1)
}
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath)
var schedVol *string
if cmd.Flags().Changed("scheduler-volume") {
schedVol = &schedulerVolume
}
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, schedVol)
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
os.Exit(1)
Expand Down Expand Up @@ -219,6 +224,7 @@ func init() {
InitCmd.Flags().String("network", "", "The Docker network on which to deploy the Dapr runtime")
InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation")
InitCmd.Flags().StringVarP(&imageVariant, "image-variant", "", "", "The image variant to use for the Dapr runtime, for example: mariner")
InitCmd.Flags().StringVarP(&schedulerVolume, "scheduler-volume", "", "", "Self-hosted only. Optionally specify a volume for the scheduler service data directory. By default, scheduler data is not persisted and not resilient to restarts without this flag.")
InitCmd.Flags().BoolP("help", "h", false, "Print this help message")
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL")
Expand Down
11 changes: 0 additions & 11 deletions pkg/standalone/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"os"
path_filepath "path/filepath"
"runtime"
"strconv"
"strings"
)

Expand Down Expand Up @@ -61,16 +60,6 @@ func getDaprBinPath(daprDir string) string {
return path_filepath.Join(daprDir, defaultDaprBinDirName)
}

// getSchedulerDataPath returns the data path of a given instance
// Receiving instanceID allows multiple instances of scheduler to run locally in the future.
func getSchedulerDataPath(daprDir string, instanceID int) string {
return path_filepath.Join(
daprDir,
defaultSchedulerDirName,
defaultSchedulerDataDirName,
strconv.Itoa(instanceID))
}

func binaryFilePathWithDir(binaryDir string, binaryFilePrefix string) string {
binaryPath := path_filepath.Join(binaryDir, binaryFilePrefix)
if runtime.GOOS == daprWindowsOS {
Expand Down
10 changes: 6 additions & 4 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type initInfo struct {
imageRegistryURL string
containerRuntime string
imageVariant string
schedulerVolume *string
}

type daprImageInfo struct {
Expand Down Expand Up @@ -184,7 +185,7 @@ func isSchedulerIncluded(runtimeVersion string) (bool, error) {
}

// Init installs Dapr on a local machine using the supplied runtimeVersion.
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string) error {
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string, schedulerVolume *string) error {
var err error
var bundleDet bundleDetails
containerRuntime = strings.TrimSpace(containerRuntime)
Expand Down Expand Up @@ -305,6 +306,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
imageRegistryURL: imageRegistryURL,
containerRuntime: containerRuntime,
imageVariant: imageVariant,
schedulerVolume: schedulerVolume,
}
for _, step := range initSteps {
// Run init on the configurations and containers.
Expand Down Expand Up @@ -633,15 +635,15 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
}
}

// instanceID is 0 because we run one instance only for now.
schedulerDataDir := getSchedulerDataPath(info.installDir, 0)
args := []string{
"run",
"--name", schedulerContainerName,
"--restart", "always",
"-d",
"--entrypoint", "./scheduler",
"--volume", fmt.Sprintf("%v:/data-default-dapr-scheduler-server-0", schedulerDataDir),
}
if info.schedulerVolume != nil {
args = append(args, "--volume", *info.schedulerVolume+":/data-default-dapr-scheduler-server-0")
}

if info.dockerNetwork != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestInitLogActualContainerRuntimeName(t *testing.T) {
t.Skip("Skipping test as container runtime is available")
}

err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "")
err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), test.containerRuntime)
})
Expand Down

0 comments on commit ad3442b

Please sign in to comment.