@@ -35,34 +35,39 @@ const sentryDefaultAddress = "localhost:50001"
3535
3636// RunConfig represents the application configuration parameters.
3737type RunConfig struct {
38- AppID string `env:"APP_ID" arg:"app-id"`
39- AppPort int `env:"APP_PORT" arg:"app-port"`
40- HTTPPort int `env:"DAPR_HTTP_PORT" arg:"dapr-http-port"`
41- GRPCPort int `env:"DAPR_GRPC_PORT" arg:"dapr-grpc-port"`
42- ConfigFile string `arg:"config"`
43- Protocol string `arg:"app-protocol"`
44- Arguments []string
45- APIListenAddresses string `arg:"dapr-listen-addresses"`
46- EnableProfiling bool `arg:"enable-profiling"`
47- ProfilePort int `arg:"profile-port"`
48- LogLevel string `arg:"log-level"`
49- MaxConcurrency int `arg:"app-max-concurrency"`
50- PlacementHostAddr string `arg:"placement-host-address"`
38+ AppID string `env:"APP_ID" arg:"app-id" yaml:"app_id"`
39+ AppPort int `env:"APP_PORT" arg:"app-port" yaml:"app_port"`
40+ HTTPPort int `env:"DAPR_HTTP_PORT" arg:"dapr-http-port" yaml:"dapr_http_port"`
41+ GRPCPort int `env:"DAPR_GRPC_PORT" arg:"dapr-grpc-port" yaml:"dapr_grpc_port"`
42+ ProfilePort int `arg:"profile-port" yaml:"profile_port"`
43+ Command []string `yaml:"command"`
44+ MetricsPort int `env:"DAPR_METRICS_PORT" arg:"metrics-port" yaml:"metrics_port"`
45+ UnixDomainSocket string `arg:"unix-domain-socket" yaml:"unix_domain_socket"`
46+ InternalGRPCPort int `arg:"dapr-internal-grpc-port" yaml:"dapr_internal_grpc_port"`
47+ DaprPathCmdFlag string `yaml:"dapr_path_cmd_flag"`
48+ SharedRunConfig `yaml:",inline"`
49+ }
50+
51+ // SharedRunConfig represents the application configuration parameters, which can be shared across many apps.
52+ type SharedRunConfig struct {
53+ ConfigFile string `arg:"config" yaml:"config_file"`
54+ AppProtocol string `arg:"app-protocol" yaml:"app_protocol"`
55+ APIListenAddresses string `arg:"dapr-listen-addresses" yaml:"api_listen_addresses"`
56+ EnableProfiling bool `arg:"enable-profiling" yaml:"enable_profiling"`
57+ LogLevel string `arg:"log-level" yaml:"log_level"`
58+ MaxConcurrency int `arg:"app-max-concurrency" yaml:"_appmax_concurrency"`
59+ PlacementHostAddr string `arg:"placement-host-address" yaml:"placement_host_address"`
5160 ComponentsPath string `arg:"components-path"`
52- ResourcesPath string `arg:"resources-path"`
53- AppSSL bool `arg:"app-ssl"`
54- MetricsPort int `env:"DAPR_METRICS_PORT" arg:"metrics-port"`
55- MaxRequestBodySize int `arg:"dapr-http-max-request-size"`
56- HTTPReadBufferSize int `arg:"dapr-http-read-buffer-size"`
57- UnixDomainSocket string `arg:"unix-domain-socket"`
58- InternalGRPCPort int `arg:"dapr-internal-grpc-port"`
59- EnableAppHealth bool `arg:"enable-app-health-check"`
60- AppHealthPath string `arg:"app-health-check-path"`
61- AppHealthInterval int `arg:"app-health-probe-interval" ifneq:"0"`
62- AppHealthTimeout int `arg:"app-health-probe-timeout" ifneq:"0"`
63- AppHealthThreshold int `arg:"app-health-threshold" ifneq:"0"`
64- EnableAPILogging bool `arg:"enable-api-logging"`
65- DaprPathCmdFlag string
61+ ResourcesPath string `arg:"resources-path" yaml:"resources_path"`
62+ AppSSL bool `arg:"app-ssl" yaml:"app_ssl"`
63+ MaxRequestBodySize int `arg:"dapr-http-max-request-size" yaml:"dapr_http_max_request_size"`
64+ HTTPReadBufferSize int `arg:"dapr-http-read-buffer-size" yaml:"dapr_http_read_buffer_size"`
65+ EnableAppHealth bool `arg:"enable-app-health-check" yaml:"enable_app_health_check"`
66+ AppHealthPath string `arg:"app-health-check-path" yaml:"app_health_check_path"`
67+ AppHealthInterval int `arg:"app-health-probe-interval" ifneq:"0" yaml:"app_health_probe_interval"`
68+ AppHealthTimeout int `arg:"app-health-probe-timeout" ifneq:"0" yaml:"app_health_probe_timeout"`
69+ AppHealthThreshold int `arg:"app-health-threshold" ifneq:"0" yaml:"app_health_threshold"`
70+ EnableAPILogging bool `arg:"enable-api-logging" yaml:"enable_api_logging"`
6671}
6772
6873func (meta * DaprMeta ) newAppID () string {
@@ -239,10 +244,33 @@ func (config *RunConfig) getArgs() []string {
239244 args := []string {}
240245
241246 schema := reflect .ValueOf (* config )
247+ args = getArgsFromSchema (schema , args )
248+
249+ if config .ConfigFile != "" {
250+ sentryAddress := mtlsEndpoint (config .ConfigFile )
251+ if sentryAddress != "" {
252+ // mTLS is enabled locally, set it up.
253+ args = append (args , "--enable-mtls" , "--sentry-address" , sentryAddress )
254+ }
255+ }
256+
257+ if print .IsJSONLogEnabled () {
258+ args = append (args , "--log-as-json" )
259+ }
260+ return args
261+ }
262+
263+ // Recursive function to get all the args from the config struct.
264+ // This is needed because the config struct has embedded struct.
265+ func getArgsFromSchema (schema reflect.Value , args []string ) []string {
242266 for i := 0 ; i < schema .NumField (); i ++ {
243267 valueField := schema .Field (i ).Interface ()
244268 typeField := schema .Type ().Field (i )
245269 key := typeField .Tag .Get ("arg" )
270+ if typeField .Type .Kind () == reflect .Struct {
271+ args = getArgsFromSchema (schema .Field (i ), args )
272+ continue
273+ }
246274 if len (key ) == 0 {
247275 continue
248276 }
@@ -262,18 +290,6 @@ func (config *RunConfig) getArgs() []string {
262290 }
263291 }
264292 }
265-
266- if config .ConfigFile != "" {
267- sentryAddress := mtlsEndpoint (config .ConfigFile )
268- if sentryAddress != "" {
269- // mTLS is enabled locally, set it up.
270- args = append (args , "--enable-mtls" , "--sentry-address" , sentryAddress )
271- }
272- }
273-
274- if print .IsJSONLogEnabled () {
275- args = append (args , "--log-as-json" )
276- }
277293 return args
278294}
279295
@@ -343,16 +359,16 @@ func mtlsEndpoint(configFile string) string {
343359}
344360
345361func getAppCommand (config * RunConfig ) * exec.Cmd {
346- argCount := len (config .Arguments )
362+ argCount := len (config .Command )
347363
348364 if argCount == 0 {
349365 return nil
350366 }
351- command := config .Arguments [0 ]
367+ command := config .Command [0 ]
352368
353369 args := []string {}
354370 if argCount > 1 {
355- args = config .Arguments [1 :]
371+ args = config .Command [1 :]
356372 }
357373
358374 cmd := exec .Command (command , args ... )
0 commit comments