Skip to content

Commit 5263b25

Browse files
committed
Rename field to make it clearer
Signed-off-by: Albert Callarisa <[email protected]>
1 parent 883180f commit 5263b25

File tree

5 files changed

+61
-61
lines changed

5 files changed

+61
-61
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ You can install Dapr runtime by pulling docker images from a given private regis
158158
dapr init --image-registry example.io/<username>
159159
```
160160

161-
#### Install with a custom scheduler host
161+
#### Install with a custom scheduler host and port
162162

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

165165
```bash
166-
dapr init --scheduler-host 192.168.42.42
166+
dapr init --scheduler-override-broadcast-host-port 192.168.42.42:50006
167167
```
168168

169169
> Note: The default host is `localhost`.

cmd/init.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ import (
2929
)
3030

3131
var (
32-
kubernetesMode bool
33-
wait bool
34-
timeout uint
35-
slimMode bool
36-
devMode bool
37-
runtimeVersion string
38-
dashboardVersion string
39-
allNamespaces bool
40-
initNamespace string
41-
resourceNamespace string
42-
enableMTLS bool
43-
enableHA bool
44-
values []string
45-
fromDir string
46-
containerRuntime string
47-
imageVariant string
48-
schedulerVolume string
49-
schedulerHost string
32+
kubernetesMode bool
33+
wait bool
34+
timeout uint
35+
slimMode bool
36+
devMode bool
37+
runtimeVersion string
38+
dashboardVersion string
39+
allNamespaces bool
40+
initNamespace string
41+
resourceNamespace string
42+
enableMTLS bool
43+
enableHA bool
44+
values []string
45+
fromDir string
46+
containerRuntime string
47+
imageVariant string
48+
schedulerVolume string
49+
schedulerOverrideBroadcastHostPort string
5050
)
5151

5252
var InitCmd = &cobra.Command{
@@ -172,7 +172,7 @@ dapr init --runtime-path <path-to-install-directory>
172172
print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.")
173173
os.Exit(1)
174174
}
175-
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume, schedulerHost)
175+
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume, schedulerOverrideBroadcastHostPort)
176176
if err != nil {
177177
print.FailureStatusEvent(os.Stderr, err.Error())
178178
os.Exit(1)
@@ -222,7 +222,7 @@ func init() {
222222
InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation")
223223
InitCmd.Flags().StringVarP(&imageVariant, "image-variant", "", "", "The image variant to use for the Dapr runtime, for example: mariner")
224224
InitCmd.Flags().StringVarP(&schedulerVolume, "scheduler-volume", "", "dapr_scheduler", "Self-hosted only. Specify a volume for the scheduler service data directory.")
225-
InitCmd.Flags().StringVarP(&schedulerHost, "scheduler-host", "", "localhost", "Self-hosted only. Specify the host address for the scheduler service. If not specified, it uses localhost.")
225+
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).")
226226
InitCmd.Flags().BoolP("help", "h", false, "Print this help message")
227227
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
228228
InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL")

pkg/standalone/standalone.go

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,18 @@ type componentMetadataItem struct {
133133
}
134134

135135
type initInfo struct {
136-
fromDir string
137-
installDir string
138-
bundleDet *bundleDetails
139-
slimMode bool
140-
runtimeVersion string
141-
dashboardVersion string
142-
dockerNetwork string
143-
imageRegistryURL string
144-
containerRuntime string
145-
imageVariant string
146-
schedulerVolume *string
147-
schedulerHost string
136+
fromDir string
137+
installDir string
138+
bundleDet *bundleDetails
139+
slimMode bool
140+
runtimeVersion string
141+
dashboardVersion string
142+
dockerNetwork string
143+
imageRegistryURL string
144+
containerRuntime string
145+
imageVariant string
146+
schedulerVolume *string
147+
schedulerOverrideBroadcastHostPort *string
148148
}
149149

150150
type daprImageInfo struct {
@@ -186,7 +186,7 @@ func isSchedulerIncluded(runtimeVersion string) (bool, error) {
186186
}
187187

188188
// Init installs Dapr on a local machine using the supplied runtimeVersion.
189-
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string, schedulerVolume *string, schedulerHost string) error {
189+
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string, schedulerVolume *string, schedulerOverrideBroadcastHostPort *string) error {
190190
var err error
191191
var bundleDet bundleDetails
192192
containerRuntime = strings.TrimSpace(containerRuntime)
@@ -297,18 +297,18 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
297297

298298
info := initInfo{
299299
// values in bundleDet can be nil if fromDir is empty, so must be used in conjunction with fromDir.
300-
bundleDet: &bundleDet,
301-
fromDir: fromDir,
302-
installDir: installDir,
303-
slimMode: slimMode,
304-
runtimeVersion: runtimeVersion,
305-
dashboardVersion: dashboardVersion,
306-
dockerNetwork: dockerNetwork,
307-
imageRegistryURL: imageRegistryURL,
308-
containerRuntime: containerRuntime,
309-
imageVariant: imageVariant,
310-
schedulerVolume: schedulerVolume,
311-
schedulerHost: schedulerHost,
300+
bundleDet: &bundleDet,
301+
fromDir: fromDir,
302+
installDir: installDir,
303+
slimMode: slimMode,
304+
runtimeVersion: runtimeVersion,
305+
dashboardVersion: dashboardVersion,
306+
dockerNetwork: dockerNetwork,
307+
imageRegistryURL: imageRegistryURL,
308+
containerRuntime: containerRuntime,
309+
imageVariant: imageVariant,
310+
schedulerVolume: schedulerVolume,
311+
schedulerOverrideBroadcastHostPort: schedulerOverrideBroadcastHostPort,
312312
}
313313
for _, step := range initSteps {
314314
// Run init on the configurations and containers.
@@ -686,7 +686,11 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
686686
}
687687

688688
if schedulerOverrideHostPort(info) {
689-
args = append(args, fmt.Sprintf("--override-broadcast-host-port=%s:%v", info.schedulerHost, osPort))
689+
if info.schedulerOverrideBroadcastHostPort != nil {
690+
args = append(args, fmt.Sprintf("--override-broadcast-host-port=%s", *info.schedulerOverrideBroadcastHostPort))
691+
} else {
692+
args = append(args, fmt.Sprintf("--override-broadcast-host-port=localhost:%v", osPort))
693+
}
690694
}
691695

692696
_, err = utils.RunCmdAndWait(runtimeCmd, args...)

pkg/standalone/standalone_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/stretchr/testify/assert"
2121

2222
"github.com/dapr/cli/utils"
23+
"github.com/dapr/kit/ptr"
2324
)
2425

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

328-
err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil, "localhost")
329+
err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil, ptr.Of("localhost:50006"))
329330
assert.Error(t, err)
330331
assert.Contains(t, err.Error(), test.containerRuntime)
331332
})

tests/e2e/standalone/init_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ func TestStandaloneInit(t *testing.T) {
218218
// Ensure a clean environment
219219
must(t, cmdUninstall, "failed to uninstall Dapr")
220220

221-
customHost := "192.168.42.42"
221+
customBroadcastHostPort := "192.168.42.42:50006"
222222
args := []string{
223-
"--scheduler-host", customHost,
223+
"--scheduler-override-broadcast-host-port", customBroadcastHostPort,
224224
}
225225
output, err := cmdInit(args...)
226226
t.Log(output)
227227
require.NoError(t, err, "init failed")
228228
assert.Contains(t, output, "Success! Dapr is up and running.")
229229

230-
verifySchedulerHost(t, customHost)
230+
verifySchedulerBroadcastHostPort(t, customBroadcastHostPort)
231231
})
232232

233233
t.Run("init without runtime-version flag with mariner images", func(t *testing.T) {
@@ -461,8 +461,8 @@ func verifyTCPLocalhost(t *testing.T, port int) {
461461
}, time.Second*10, time.Millisecond*10)
462462
}
463463

464-
// verifySchedulerHost verifies that the scheduler container was started with the correct host.
465-
func verifySchedulerHost(t *testing.T, expectedHost string) {
464+
// verifySchedulerBroadcastHostPort verifies that the scheduler container was started with the correct broadcast host and port.
465+
func verifySchedulerBroadcastHostPort(t *testing.T, expectedBroadcastHostPort string) {
466466
t.Helper()
467467

468468
cli, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv)
@@ -471,11 +471,6 @@ func verifySchedulerHost(t *testing.T, expectedHost string) {
471471
containerInfo, err := cli.ContainerInspect(context.Background(), "dapr_scheduler")
472472
require.NoError(t, err)
473473

474-
expectedPort := 50006
475-
if runtime.GOOS == "windows" {
476-
expectedPort = 6060
477-
}
478-
479-
expectedArg := "--override-broadcast-host-port=" + expectedHost + ":" + strconv.Itoa(expectedPort)
474+
expectedArg := "--override-broadcast-host-port=" + expectedBroadcastHostPort
480475
assert.Contains(t, containerInfo.Args, expectedArg, "Expected scheduler argument %s not found in container args: %v", expectedArg, containerInfo.Args)
481476
}

0 commit comments

Comments
 (0)