mirror of https://github.com/dapr/cli.git
Merge pull request #1520 from acroca/set-scheduler-binding-address-on-init
feat: Allow configuring the scheduler host on init
This commit is contained in:
parent
22536a9640
commit
edb70cf461
19
README.md
19
README.md
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
|
@ -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 .
|
||||
|
|
@ -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
|
||||
|
|
@ -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*
|
||||
|
|
|
|||
44
cmd/init.go
44
cmd/init.go
|
|
@ -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{
|
||||
|
|
@ -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)
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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)
|
||||
|
|
@ -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.
|
||||
|
|
@ -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...)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
@ -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…
Reference in New Issue