Skip to content

feat: Allow configuring the scheduler host on init #1520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025
Merged
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
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Runtime version: v1.0.0

#### Install with mariner images

You can install Dapr Runtime using mariner images using the `--image-variant` flag.
You can install Dapr Runtime using mariner images using the `--image-variant` flag.

```bash
# Installing Dapr with Mariner images
Expand All @@ -158,6 +158,17 @@ You can install Dapr runtime by pulling docker images from a given private regis
dapr init --image-registry example.io/<username>
```

#### Install with a custom scheduler host and port

You can install Dapr runtime with a custom scheduler host and port by using `--scheduler-override-broadcast-host-port` flag.

```bash
dapr init --scheduler-override-broadcast-host-port 192.168.42.42:50006
```

> Note: The default host is `localhost`.


#### Install in airgap environment

You can install Dapr runtime in airgap (offline) environment using a pre-downloaded [installer bundle](https://github.com/dapr/installer-bundle/releases). You need to download the archived bundle for your OS beforehand (e.g., daprbundle_linux_amd64.tar.gz,) and unpack it. Thereafter use the local Dapr CLI binary in the bundle with `--from-dir` flag in the init command to point to the extracted bundle location to initialize Dapr.
Expand All @@ -180,7 +191,7 @@ docker run --name "dapr_zipkin" --restart always -d -p 9411:9411 openzipkin/zipk
docker run --name "dapr_redis" --restart always -d -p 6379:6379 redis
```

Alternatively to the above, you can also have slim installation as well to install dapr without running any Docker containers in airgap mode.
Alternatively to the above, you can also have slim installation as well to install dapr without running any Docker containers in airgap mode.

```bash
./dapr init --slim --from-dir .
Expand Down Expand Up @@ -297,7 +308,7 @@ Output should look like as follows:
All available [Helm Chart values](https://github.com/dapr/dapr/tree/master/charts/dapr#configuration) can be set by using the `--set` flag:

```bash
dapr init -k --set global.tag=1.0.0 --set dapr_operator.logLevel=error
dapr init -k --set global.tag=1.0.0 --set dapr_operator.logLevel=error
```

#### Installing to a custom namespace
Expand Down Expand Up @@ -363,7 +374,7 @@ The example above shows how to upgrade from your current version to version `1.0
All available [Helm Chart values](https://github.com/dapr/dapr/tree/master/charts/dapr#configuration) can be set by using the `--set` flag:

```bash
dapr upgrade -k --runtime-version=1.0.0 --set global.tag=my-tag --set dapr_operator.logLevel=error
dapr upgrade -k --runtime-version=1.0.0 --set global.tag=my-tag --set dapr_operator.logLevel=error
```

*Note: do not use the `dapr upgrade` command if you're upgrading from 0.x versions of Dapr*
Expand Down
44 changes: 26 additions & 18 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,24 @@ import (
)

var (
kubernetesMode bool
wait bool
timeout uint
slimMode bool
devMode bool
runtimeVersion string
dashboardVersion string
allNamespaces bool
initNamespace string
resourceNamespace string
enableMTLS bool
enableHA bool
values []string
fromDir string
containerRuntime string
imageVariant string
schedulerVolume string
kubernetesMode bool
wait bool
timeout uint
slimMode bool
devMode bool
runtimeVersion string
dashboardVersion string
allNamespaces bool
initNamespace string
resourceNamespace string
enableMTLS bool
enableHA bool
values []string
fromDir string
containerRuntime string
imageVariant string
schedulerVolume string
schedulerOverrideBroadcastHostPort string
)

var InitCmd = &cobra.Command{
Expand Down Expand Up @@ -171,7 +172,13 @@ 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, &schedulerVolume)

schedulerHostPort := &schedulerOverrideBroadcastHostPort
if schedulerOverrideBroadcastHostPort == "" {
schedulerHostPort = nil
}

err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume, schedulerHostPort)
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
os.Exit(1)
Expand Down Expand Up @@ -221,6 +228,7 @@ func init() {
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", "", "dapr_scheduler", "Self-hosted only. Specify a volume for the scheduler service data directory.")
InitCmd.Flags().StringVarP(&schedulerOverrideBroadcastHostPort, "scheduler-override-broadcast-host-port", "", "", "Self-hosted only. Specify the scheduler broadcast host and port, for example: 192.168.42.42:50006. If not specified, it uses localhost:50006 (6060 for Windows).")
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
54 changes: 30 additions & 24 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ type componentMetadataItem struct {
}

type initInfo struct {
fromDir string
installDir string
bundleDet *bundleDetails
slimMode bool
runtimeVersion string
dashboardVersion string
dockerNetwork string
imageRegistryURL string
containerRuntime string
imageVariant string
schedulerVolume *string
fromDir string
installDir string
bundleDet *bundleDetails
slimMode bool
runtimeVersion string
dashboardVersion string
dockerNetwork string
imageRegistryURL string
containerRuntime string
imageVariant string
schedulerVolume *string
schedulerOverrideBroadcastHostPort *string
}

type daprImageInfo struct {
Expand Down Expand Up @@ -185,7 +186,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, schedulerVolume *string) error {
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string, schedulerVolume *string, schedulerOverrideBroadcastHostPort *string) error {
var err error
var bundleDet bundleDetails
containerRuntime = strings.TrimSpace(containerRuntime)
Expand Down Expand Up @@ -296,17 +297,18 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod

info := initInfo{
// values in bundleDet can be nil if fromDir is empty, so must be used in conjunction with fromDir.
bundleDet: &bundleDet,
fromDir: fromDir,
installDir: installDir,
slimMode: slimMode,
runtimeVersion: runtimeVersion,
dashboardVersion: dashboardVersion,
dockerNetwork: dockerNetwork,
imageRegistryURL: imageRegistryURL,
containerRuntime: containerRuntime,
imageVariant: imageVariant,
schedulerVolume: schedulerVolume,
bundleDet: &bundleDet,
fromDir: fromDir,
installDir: installDir,
slimMode: slimMode,
runtimeVersion: runtimeVersion,
dashboardVersion: dashboardVersion,
dockerNetwork: dockerNetwork,
imageRegistryURL: imageRegistryURL,
containerRuntime: containerRuntime,
imageVariant: imageVariant,
schedulerVolume: schedulerVolume,
schedulerOverrideBroadcastHostPort: schedulerOverrideBroadcastHostPort,
}
for _, step := range initSteps {
// Run init on the configurations and containers.
Expand Down Expand Up @@ -684,7 +686,11 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
}

if schedulerOverrideHostPort(info) {
args = append(args, fmt.Sprintf("--override-broadcast-host-port=localhost:%v", osPort))
if info.schedulerOverrideBroadcastHostPort != nil {
args = append(args, "--override-broadcast-host-port="+*info.schedulerOverrideBroadcastHostPort)
} else {
args = append(args, fmt.Sprintf("--override-broadcast-host-port=localhost:%v", osPort))
}
}

_, err = utils.RunCmdAndWait(runtimeCmd, args...)
Expand Down
3 changes: 2 additions & 1 deletion pkg/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/dapr/cli/utils"
"github.com/dapr/kit/ptr"
)

func TestStandaloneConfig(t *testing.T) {
Expand Down Expand Up @@ -325,7 +326,7 @@ func TestInitLogActualContainerRuntimeName(t *testing.T) {
t.Skip("Skipping test as container runtime is available")
}

err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil)
err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil, ptr.Of("localhost:50006"))
assert.Error(t, err)
assert.Contains(t, err.Error(), test.containerRuntime)
})
Expand Down
34 changes: 34 additions & 0 deletions tests/e2e/standalone/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ func TestStandaloneInit(t *testing.T) {
verifyTCPLocalhost(t, schedulerPort)
})

t.Run("init with custom scheduler host", func(t *testing.T) {
if isSlimMode() {
t.Skip("Skipping scheduler host test because of slim installation")
}

// Ensure a clean environment
must(t, cmdUninstall, "failed to uninstall Dapr")

customBroadcastHostPort := "192.168.42.42:50006"
args := []string{
"--scheduler-override-broadcast-host-port", customBroadcastHostPort,
}
output, err := cmdInit(args...)
t.Log(output)
require.NoError(t, err, "init failed")
assert.Contains(t, output, "Success! Dapr is up and running.")

verifySchedulerBroadcastHostPort(t, customBroadcastHostPort)
})

t.Run("init without runtime-version flag with mariner images", func(t *testing.T) {
// Ensure a clean environment
must(t, cmdUninstall, "failed to uninstall Dapr")
Expand Down Expand Up @@ -440,3 +460,17 @@ func verifyTCPLocalhost(t *testing.T, port int) {
}
}, time.Second*10, time.Millisecond*10)
}

// verifySchedulerBroadcastHostPort verifies that the scheduler container was started with the correct broadcast host and port.
func verifySchedulerBroadcastHostPort(t *testing.T, expectedBroadcastHostPort string) {
t.Helper()

cli, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv)
require.NoError(t, err)

containerInfo, err := cli.ContainerInspect(context.Background(), "dapr_scheduler")
require.NoError(t, err)

expectedArg := "--override-broadcast-host-port=" + expectedBroadcastHostPort
assert.Contains(t, containerInfo.Args, expectedArg, "Expected scheduler argument %s not found in container args: %v", expectedArg, containerInfo.Args)
}
Loading