Skip to content

Commit edfc94b

Browse files
committed
fix: move scheduler and placement flags to pointer-aware
Signed-off-by: inishchith <[email protected]>
1 parent cf872e7 commit edfc94b

File tree

3 files changed

+108
-54
lines changed

3 files changed

+108
-54
lines changed

cmd/run.go

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,42 @@ dapr run --run-file /path/to/directory -k
189189
}
190190

191191
sharedRunConfig := &standalone.SharedRunConfig{
192-
ConfigFile: configFile,
193-
EnableProfiling: enableProfiling,
194-
LogLevel: logLevel,
195-
MaxConcurrency: maxConcurrency,
196-
AppProtocol: protocol,
197-
PlacementHostAddr: viper.GetString("placement-host-address"),
198-
ComponentsPath: componentsPath,
199-
ResourcesPaths: resourcesPaths,
200-
AppSSL: appSSL,
201-
MaxRequestBodySize: maxRequestBodySize,
202-
HTTPReadBufferSize: readBufferSize,
203-
EnableAppHealth: enableAppHealth,
204-
AppHealthPath: appHealthPath,
205-
AppHealthInterval: appHealthInterval,
206-
AppHealthTimeout: appHealthTimeout,
207-
AppHealthThreshold: appHealthThreshold,
208-
EnableAPILogging: enableAPILogging,
209-
APIListenAddresses: apiListenAddresses,
210-
SchedulerHostAddress: schedulerHostAddress,
211-
DaprdInstallPath: daprRuntimePath,
192+
ConfigFile: configFile,
193+
EnableProfiling: enableProfiling,
194+
LogLevel: logLevel,
195+
MaxConcurrency: maxConcurrency,
196+
AppProtocol: protocol,
197+
ComponentsPath: componentsPath,
198+
ResourcesPaths: resourcesPaths,
199+
AppSSL: appSSL,
200+
MaxRequestBodySize: maxRequestBodySize,
201+
HTTPReadBufferSize: readBufferSize,
202+
EnableAppHealth: enableAppHealth,
203+
AppHealthPath: appHealthPath,
204+
AppHealthInterval: appHealthInterval,
205+
AppHealthTimeout: appHealthTimeout,
206+
AppHealthThreshold: appHealthThreshold,
207+
EnableAPILogging: enableAPILogging,
208+
APIListenAddresses: apiListenAddresses,
209+
DaprdInstallPath: daprRuntimePath,
210+
}
211+
212+
// placement-host-address flag handling: only set pointer if flag was explicitly changed
213+
if cmd.Flags().Changed("placement-host-address") {
214+
val := viper.GetString("placement-host-address")
215+
sharedRunConfig.PlacementHostAddr = &val // may be empty => disable
216+
}
217+
218+
// scheduler-host-address defaulting/handling
219+
if cmd.Flags().Changed("scheduler-host-address") {
220+
val := schedulerHostAddress
221+
sharedRunConfig.SchedulerHostAddress = &val // may be empty => disable
222+
} else {
223+
// Apply version-based defaulting used previously
224+
addr := validateSchedulerHostAddress(daprVer.RuntimeVersion, schedulerHostAddress)
225+
if addr != "" {
226+
sharedRunConfig.SchedulerHostAddress = &addr
227+
}
212228
}
213229
output, err := runExec.NewOutput(&standalone.RunConfig{
214230
AppID: appID,
@@ -529,7 +545,15 @@ func executeRun(runTemplateName, runFilePath string, apps []runfileconfig.App) (
529545
// Set defaults if zero value provided in config yaml.
530546
app.RunConfig.SetDefaultFromSchema()
531547

532-
app.RunConfig.SchedulerHostAddress = validateSchedulerHostAddress(daprVer.RuntimeVersion, app.RunConfig.SchedulerHostAddress)
548+
// Adjust scheduler host address defaults for run-file apps (pointer-aware)
549+
var schedIn string
550+
if app.RunConfig.SchedulerHostAddress != nil {
551+
schedIn = *app.RunConfig.SchedulerHostAddress
552+
}
553+
schedOut := validateSchedulerHostAddress(daprVer.RuntimeVersion, schedIn)
554+
if schedOut != "" {
555+
app.RunConfig.SchedulerHostAddress = &schedOut
556+
}
533557

534558
// Validate validates the configs and modifies the ports to free ports, appId etc.
535559
err := app.RunConfig.Validate()
@@ -1012,7 +1036,7 @@ func putAppProcessIDInMeta(runE *runExec.RunExec) {
10121036
func putAppCommandInMeta(runConfig standalone.RunConfig, runE *runExec.RunExec) {
10131037
appCommand := strings.Join(runConfig.Command, " ")
10141038
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogInfo, "Updating metadata for app command: %s", appCommand)
1015-
err := metadata.Put(runE.DaprHTTPPort, "appCommand", appCommand, runE.AppID, runConfig.UnixDomainSocket)
1039+
err := metadata.Put(runE.DaprHTTPPort, "appCommand", appCommand, runE.AppID, unixDomainSocket)
10161040
if err != nil {
10171041
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for appCommand: %s", err.Error())
10181042
return

pkg/standalone/run.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ type SharedRunConfig struct {
7272
LogLevel string `arg:"log-level" annotation:"dapr.io.log-level" yaml:"logLevel"`
7373
MaxConcurrency int `arg:"app-max-concurrency" annotation:"dapr.io/app-max-concurrerncy" yaml:"appMaxConcurrency" default:"-1"`
7474
// Speicifcally omitted from annotations similar to config file path above.
75-
PlacementHostAddr string `arg:"placement-host-address" yaml:"placementHostAddress"`
75+
// Pointer string to distinguish omitted (nil) vs explicitly empty (disable) vs value provided
76+
PlacementHostAddr *string `arg:"placement-host-address" yaml:"placementHostAddress"`
7677
// Speicifcally omitted from annotations similar to config file path above.
7778
ComponentsPath string `arg:"components-path"` // Deprecated in run template file: use ResourcesPaths instead.
7879
// Speicifcally omitted from annotations similar to config file path above.
@@ -90,11 +91,12 @@ type SharedRunConfig struct {
9091
AppHealthThreshold int `arg:"app-health-threshold" annotation:"dapr.io/app-health-threshold" ifneq:"0" yaml:"appHealthThreshold"`
9192
EnableAPILogging bool `arg:"enable-api-logging" annotation:"dapr.io/enable-api-logging" yaml:"enableApiLogging"`
9293
// Specifically omitted from annotations see https://github.com/dapr/cli/issues/1324 .
93-
DaprdInstallPath string `yaml:"runtimePath"`
94-
Env map[string]string `yaml:"env"`
95-
DaprdLogDestination LogDestType `yaml:"daprdLogDestination"`
96-
AppLogDestination LogDestType `yaml:"appLogDestination"`
97-
SchedulerHostAddress string `arg:"scheduler-host-address" yaml:"schedulerHostAddress"`
94+
DaprdInstallPath string `yaml:"runtimePath"`
95+
Env map[string]string `yaml:"env"`
96+
DaprdLogDestination LogDestType `yaml:"daprdLogDestination"`
97+
AppLogDestination LogDestType `yaml:"appLogDestination"`
98+
// Pointer string to distinguish omitted (nil) vs explicitly empty (disable) vs value provided
99+
SchedulerHostAddress *string `arg:"scheduler-host-address" yaml:"schedulerHostAddress"`
98100
}
99101

100102
func (meta *DaprMeta) newAppID() string {
@@ -125,9 +127,21 @@ func (config *RunConfig) validateResourcesPaths() error {
125127
}
126128

127129
func (config *RunConfig) validatePlacementHostAddr() error {
128-
placementHostAddr := strings.TrimSpace(config.PlacementHostAddr)
129-
// If user explicitly set empty, honor that to disable placement
130+
// nil => default localhost:port; empty => disable; non-empty => ensure port
131+
if config.PlacementHostAddr == nil {
132+
addr := "localhost"
133+
if runtime.GOOS == daprWindowsOS {
134+
addr += ":6050"
135+
} else {
136+
addr += ":50005"
137+
}
138+
config.PlacementHostAddr = &addr
139+
return nil
140+
}
141+
placementHostAddr := strings.TrimSpace(*config.PlacementHostAddr)
130142
if len(placementHostAddr) == 0 {
143+
empty := ""
144+
config.PlacementHostAddr = &empty
131145
return nil
132146
}
133147
if indx := strings.Index(placementHostAddr, ":"); indx == -1 {
@@ -137,26 +151,29 @@ func (config *RunConfig) validatePlacementHostAddr() error {
137151
placementHostAddr += ":50005"
138152
}
139153
}
140-
config.PlacementHostAddr = placementHostAddr
154+
config.PlacementHostAddr = &placementHostAddr
141155
return nil
142156
}
143157

144158
func (config *RunConfig) validateSchedulerHostAddr() error {
145-
schedulerHostAddr := strings.TrimSpace(config.SchedulerHostAddress)
159+
// nil => leave as-is (set later based on version), empty => disable; non-empty => ensure port
160+
if config.SchedulerHostAddress == nil {
161+
return nil
162+
}
163+
schedulerHostAddr := strings.TrimSpace(*config.SchedulerHostAddress)
146164
if len(schedulerHostAddr) == 0 {
165+
empty := ""
166+
config.SchedulerHostAddress = &empty
147167
return nil
148168
}
149-
150169
if indx := strings.Index(schedulerHostAddr, ":"); indx == -1 {
151170
if runtime.GOOS == daprWindowsOS {
152171
schedulerHostAddr += ":6060"
153172
} else {
154173
schedulerHostAddr += ":50006"
155174
}
156175
}
157-
158-
config.SchedulerHostAddress = schedulerHostAddr
159-
176+
config.SchedulerHostAddress = &schedulerHostAddr
160177
return nil
161178
}
162179

@@ -406,6 +423,13 @@ func getArgsFromSchema(schema reflect.Value, args []string) []string {
406423
args = append(args, key, val)
407424
}
408425
}
426+
case *string:
427+
if vType != nil {
428+
val := strings.TrimSpace(*vType)
429+
if len(val) != 0 && (!hasIfneq || val != ifneq) {
430+
args = append(args, key, val)
431+
}
432+
}
409433
default:
410434
value := fmt.Sprintf("%v", reflect.ValueOf(valueField))
411435
if len(value) != 0 && (!hasIfneq || value != ifneq) {

pkg/standalone/run_test.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/stretchr/testify/assert"
2323
)
2424

25+
func strPtr(s string) *string { return &s }
26+
2527
func TestGetEnv(t *testing.T) {
2628
config := &RunConfig{
2729
SharedRunConfig: SharedRunConfig{},
@@ -144,68 +146,72 @@ func TestGetEnv(t *testing.T) {
144146

145147
func TestValidatePlacementHostAddr(t *testing.T) {
146148
t.Run("empty disables placement", func(t *testing.T) {
147-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: ""}}
149+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: strPtr("")}}
148150
err := cfg.validatePlacementHostAddr()
149151
assert.NoError(t, err)
150-
assert.Equal(t, "", cfg.PlacementHostAddr)
152+
assert.NotNil(t, cfg.PlacementHostAddr)
153+
assert.Equal(t, "", *cfg.PlacementHostAddr)
151154
})
152155

153156
t.Run("whitespace disables placement", func(t *testing.T) {
154-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: " "}}
157+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: strPtr(" ")}}
155158
err := cfg.validatePlacementHostAddr()
156159
assert.NoError(t, err)
157-
assert.Equal(t, " ", cfg.PlacementHostAddr)
160+
assert.NotNil(t, cfg.PlacementHostAddr)
161+
assert.Equal(t, "", *cfg.PlacementHostAddr)
158162
})
159163

160164
t.Run("default port appended when hostname provided without port", func(t *testing.T) {
161-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: "localhost"}}
165+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: strPtr("localhost")}}
162166
err := cfg.validatePlacementHostAddr()
163167
assert.NoError(t, err)
164168
if runtime.GOOS == daprWindowsOS {
165-
assert.True(t, strings.HasSuffix(cfg.PlacementHostAddr, ":6050"))
169+
assert.True(t, strings.HasSuffix(*cfg.PlacementHostAddr, ":6050"))
166170
} else {
167-
assert.True(t, strings.HasSuffix(cfg.PlacementHostAddr, ":50005"))
171+
assert.True(t, strings.HasSuffix(*cfg.PlacementHostAddr, ":50005"))
168172
}
169173
})
170174

171175
t.Run("custom port preserved when provided", func(t *testing.T) {
172-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: "1.2.3.4:12345"}}
176+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{PlacementHostAddr: strPtr("1.2.3.4:12345")}}
173177
err := cfg.validatePlacementHostAddr()
174178
assert.NoError(t, err)
175-
assert.Equal(t, "1.2.3.4:12345", cfg.PlacementHostAddr)
179+
assert.Equal(t, "1.2.3.4:12345", *cfg.PlacementHostAddr)
176180
})
177181
}
178182

179183
func TestValidateSchedulerHostAddr(t *testing.T) {
180184
t.Run("empty disables scheduler", func(t *testing.T) {
181-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: ""}}
185+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: strPtr("")}}
182186
err := cfg.validateSchedulerHostAddr()
183187
assert.NoError(t, err)
184-
assert.Equal(t, "", cfg.SchedulerHostAddress)
188+
assert.NotNil(t, cfg.SchedulerHostAddress)
189+
assert.Equal(t, "", *cfg.SchedulerHostAddress)
185190
})
186191

187192
t.Run("whitespace disables scheduler", func(t *testing.T) {
188-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: " "}}
193+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: strPtr(" ")}}
189194
err := cfg.validateSchedulerHostAddr()
190195
assert.NoError(t, err)
191-
assert.Equal(t, " ", cfg.SchedulerHostAddress)
196+
assert.NotNil(t, cfg.SchedulerHostAddress)
197+
assert.Equal(t, "", *cfg.SchedulerHostAddress)
192198
})
193199

194200
t.Run("default port appended when hostname provided without port", func(t *testing.T) {
195-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: "localhost"}}
201+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: strPtr("localhost")}}
196202
err := cfg.validateSchedulerHostAddr()
197203
assert.NoError(t, err)
198204
if runtime.GOOS == daprWindowsOS {
199-
assert.True(t, strings.HasSuffix(cfg.SchedulerHostAddress, ":6060"))
205+
assert.True(t, strings.HasSuffix(*cfg.SchedulerHostAddress, ":6060"))
200206
} else {
201-
assert.True(t, strings.HasSuffix(cfg.SchedulerHostAddress, ":50006"))
207+
assert.True(t, strings.HasSuffix(*cfg.SchedulerHostAddress, ":50006"))
202208
}
203209
})
204210

205211
t.Run("custom port preserved when provided", func(t *testing.T) {
206-
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: "1.2.3.4:45678"}}
212+
cfg := &RunConfig{SharedRunConfig: SharedRunConfig{SchedulerHostAddress: strPtr("1.2.3.4:45678")}}
207213
err := cfg.validateSchedulerHostAddr()
208214
assert.NoError(t, err)
209-
assert.Equal(t, "1.2.3.4:45678", cfg.SchedulerHostAddress)
215+
assert.Equal(t, "1.2.3.4:45678", *cfg.SchedulerHostAddress)
210216
})
211217
}

0 commit comments

Comments
 (0)