Skip to content

Commit b766d59

Browse files
JoshVanLcicoyle
authored andcommitted
Fix workflow resource path lookup
In standalone mode, if the resource path is not explicitly defined in the daprd process arguments, the workflow engine fails to locate the resource files, used to fetch the actor state store component manifest. This change updates the resource path lookup logic to use the default component path when the resource path is not defined. Signed-off-by: joshvanl <[email protected]>
1 parent df58963 commit b766d59

File tree

14 files changed

+140
-40
lines changed

14 files changed

+140
-40
lines changed

cmd/buildinfo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/spf13/cobra"
2121

22+
"github.com/dapr/cli/cmd/runtime"
2223
"github.com/dapr/cli/pkg/print"
2324
"github.com/dapr/cli/pkg/standalone"
2425
)
@@ -31,7 +32,7 @@ var BuildInfoCmd = &cobra.Command{
3132
dapr build-info
3233
`,
3334
Run: func(cmd *cobra.Command, args []string) {
34-
out, err := standalone.GetBuildInfo(daprRuntimePath, cliVersion)
35+
out, err := standalone.GetBuildInfo(runtime.GetDaprRuntimePath(), cliVersion)
3536
if err != nil {
3637
print.FailureStatusEvent(os.Stderr, "Error getting build info: %s", err.Error())
3738
os.Exit(1)

cmd/dapr.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222
"github.com/spf13/viper"
2323

24+
"github.com/dapr/cli/cmd/runtime"
2425
"github.com/dapr/cli/cmd/scheduler"
2526
"github.com/dapr/cli/cmd/workflow"
2627
"github.com/dapr/cli/pkg/api"
@@ -62,11 +63,10 @@ const (
6263
)
6364

6465
var (
65-
cliVersion string
66-
versionFlag bool
67-
daprVer daprVersion
68-
logAsJSON bool
69-
daprRuntimePath string
66+
cliVersion string
67+
versionFlag bool
68+
daprVer daprVersion
69+
logAsJSON bool
7070
)
7171

7272
// Execute adds all child commands to the root command.
@@ -93,7 +93,7 @@ func initConfig() {
9393
print.EnableJSONFormat()
9494
}
9595
// err intentionally ignored since daprd may not yet be installed.
96-
runtimeVer, _ := standalone.GetRuntimeVersion(daprRuntimePath)
96+
runtimeVer, _ := standalone.GetRuntimeVersion(runtime.GetDaprRuntimePath())
9797

9898
daprVer = daprVersion{
9999
// Set in Execute() method in this file before initConfig() is called by cmd.Execute().
@@ -108,8 +108,8 @@ func initConfig() {
108108

109109
func init() {
110110
RootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "version for dapr")
111-
RootCmd.PersistentFlags().StringVarP(&daprRuntimePath, "runtime-path", "", "", "The path to the dapr runtime installation directory")
112111
RootCmd.PersistentFlags().BoolVarP(&logAsJSON, "log-as-json", "", false, "Log output in JSON format")
112+
runtime.Register(RootCmd)
113113

114114
RootCmd.AddCommand(scheduler.SchedulerCmd)
115115
RootCmd.AddCommand(workflow.WorkflowCmd)

cmd/dashboard.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/pkg/browser"
2424
"github.com/spf13/cobra"
2525

26+
"github.com/dapr/cli/cmd/runtime"
2627
"github.com/dapr/cli/pkg/kubernetes"
2728
"github.com/dapr/cli/pkg/print"
2829
"github.com/dapr/cli/pkg/standalone"
@@ -83,7 +84,7 @@ dapr dashboard -k -p 0
8384
`,
8485
Run: func(cmd *cobra.Command, args []string) {
8586
if dashboardVersionCmd {
86-
dashboardVer, err := standalone.GetDashboardVersion(daprRuntimePath)
87+
dashboardVer, err := standalone.GetDashboardVersion(runtime.GetDaprRuntimePath())
8788
if err != nil {
8889
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
8990
os.Exit(1)
@@ -195,7 +196,7 @@ dapr dashboard -k -p 0
195196
<-portForward.GetStop()
196197
} else {
197198
// Standalone mode.
198-
dashboardCmd, err := standalone.NewDashboardCmd(daprRuntimePath, dashboardLocalPort)
199+
dashboardCmd, err := standalone.NewDashboardCmd(runtime.GetDaprRuntimePath(), dashboardLocalPort)
199200
if err != nil {
200201
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
201202
} else {

cmd/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/spf13/cobra"
2323
"github.com/spf13/viper"
2424

25+
"github.com/dapr/cli/cmd/runtime"
2526
"github.com/dapr/cli/pkg/kubernetes"
2627
"github.com/dapr/cli/pkg/print"
2728
"github.com/dapr/cli/pkg/standalone"
@@ -107,7 +108,7 @@ dapr init --runtime-path <path-to-install-directory>
107108
imageRegistryURI := ""
108109
var err error
109110

110-
if len(strings.TrimSpace(daprRuntimePath)) != 0 {
111+
if len(strings.TrimSpace(runtime.GetDaprRuntimePath())) != 0 {
111112
print.FailureStatusEvent(os.Stderr, "--runtime-path is only valid for self-hosted mode")
112113
os.Exit(1)
113114
}
@@ -178,7 +179,7 @@ dapr init --runtime-path <path-to-install-directory>
178179
schedulerHostPort = nil
179180
}
180181

181-
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume, schedulerHostPort)
182+
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, runtime.GetDaprRuntimePath(), &schedulerVolume, schedulerHostPort)
182183
if err != nil {
183184
print.FailureStatusEvent(os.Stderr, err.Error())
184185
os.Exit(1)

cmd/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
daprRuntime "github.com/dapr/dapr/pkg/runtime"
3535

36+
cmdruntime "github.com/dapr/cli/cmd/runtime"
3637
"github.com/dapr/cli/pkg/kubernetes"
3738
"github.com/dapr/cli/pkg/metadata"
3839
"github.com/dapr/cli/pkg/print"
@@ -159,7 +160,7 @@ dapr run --run-file /path/to/directory -k
159160
fmt.Println(print.WhiteBold("WARNING: no application command found."))
160161
}
161162

162-
daprDirPath, err := standalone.GetDaprRuntimePath(daprRuntimePath)
163+
daprDirPath, err := standalone.GetDaprRuntimePath(cmdruntime.GetDaprRuntimePath())
163164
if err != nil {
164165
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
165166
os.Exit(1)
@@ -206,7 +207,7 @@ dapr run --run-file /path/to/directory -k
206207
AppHealthThreshold: appHealthThreshold,
207208
EnableAPILogging: enableAPILogging,
208209
APIListenAddresses: apiListenAddresses,
209-
DaprdInstallPath: daprRuntimePath,
210+
DaprdInstallPath: cmdruntime.GetDaprRuntimePath(),
210211
}
211212

212213
// placement-host-address flag handling: only set pointer if flag was explicitly changed

cmd/runtime/runtime.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2025 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package runtime
15+
16+
import "github.com/spf13/cobra"
17+
18+
var (
19+
daprRuntimePath string
20+
)
21+
22+
func Register(cmd *cobra.Command) {
23+
cmd.PersistentFlags().StringVarP(&daprRuntimePath, "runtime-path", "", "", "The path to the dapr runtime installation directory")
24+
}
25+
26+
func GetDaprRuntimePath() string {
27+
return daprRuntimePath
28+
}

cmd/uninstall.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222
"github.com/spf13/viper"
2323

24+
cmdruntime "github.com/dapr/cli/cmd/runtime"
2425
"github.com/dapr/cli/pkg/kubernetes"
2526
"github.com/dapr/cli/pkg/print"
2627
"github.com/dapr/cli/pkg/standalone"
@@ -70,7 +71,7 @@ dapr uninstall --runtime-path <path-to-install-directory>
7071
var err error
7172

7273
if uninstallKubernetes {
73-
if len(strings.TrimSpace(daprRuntimePath)) != 0 {
74+
if len(strings.TrimSpace(cmdruntime.GetDaprRuntimePath())) != 0 {
7475
print.FailureStatusEvent(os.Stderr, "--runtime-path is only valid for self-hosted mode")
7576
os.Exit(1)
7677
}
@@ -84,7 +85,7 @@ dapr uninstall --runtime-path <path-to-install-directory>
8485
}
8586
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
8687
dockerNetwork := viper.GetString("network")
87-
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, daprRuntimePath)
88+
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, cmdruntime.GetDaprRuntimePath())
8889
}
8990

9091
if err != nil {

pkg/workflow/dclient/dclient.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import (
2727
"github.com/dapr/kit/ptr"
2828
)
2929

30+
type Options struct {
31+
KubernetesMode bool
32+
Namespace string
33+
AppID string
34+
RuntimePath string
35+
}
36+
3037
type Client struct {
3138
Dapr client.Client
3239
Cancel context.CancelFunc
@@ -35,44 +42,53 @@ type Client struct {
3542
TableName *string
3643
}
3744

38-
func DaprClient(ctx context.Context, kubernetesMode bool, namespace, appID string) (*Client, error) {
45+
func DaprClient(ctx context.Context, opts Options) (*Client, error) {
3946
client.SetLogger(nil)
4047

4148
var client *Client
4249
var err error
43-
if kubernetesMode {
44-
client, err = kube(namespace, appID)
50+
if opts.KubernetesMode {
51+
client, err = kube(opts)
4552
} else {
46-
client, err = stand(ctx, appID)
53+
client, err = stand(ctx, opts)
4754
}
4855

4956
return client, err
5057
}
5158

52-
func stand(ctx context.Context, appID string) (*Client, error) {
59+
func stand(ctx context.Context, opts Options) (*Client, error) {
5360
list, err := standalone.List()
5461
if err != nil {
5562
return nil, err
5663
}
5764

5865
var proc *standalone.ListOutput
5966
for _, c := range list {
60-
if c.AppID == appID {
67+
if c.AppID == opts.AppID {
6168
proc = &c
6269
break
6370
}
6471
}
6572

6673
if proc == nil {
67-
return nil, fmt.Errorf("Dapr app with id '%s' not found", appID)
74+
return nil, fmt.Errorf("Dapr app with id '%s' not found", opts.AppID)
75+
}
76+
77+
if len(proc.ResourcePaths) == 0 {
78+
daprDirPath, err := standalone.GetDaprRuntimePath(opts.RuntimePath)
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
proc.ResourcePaths = []string{standalone.GetDaprComponentsPath(daprDirPath)}
6884
}
6985

70-
comps, err := loader.NewLocalLoader(appID, proc.ResourcePaths).Load(ctx)
86+
comps, err := loader.NewLocalLoader(opts.AppID, proc.ResourcePaths).Load(ctx)
7187
if err != nil {
7288
return nil, err
7389
}
7490

75-
c, err := clientFromComponents(comps, appID, strconv.Itoa(proc.GRPCPort))
91+
c, err := clientFromComponents(comps, opts.AppID, strconv.Itoa(proc.GRPCPort))
7692
if err != nil {
7793
return nil, err
7894
}
@@ -81,22 +97,22 @@ func stand(ctx context.Context, appID string) (*Client, error) {
8197
return c, nil
8298
}
8399

84-
func kube(namespace string, appID string) (*Client, error) {
85-
list, err := kubernetes.List(namespace)
100+
func kube(opts Options) (*Client, error) {
101+
list, err := kubernetes.List(opts.Namespace)
86102
if err != nil {
87103
return nil, err
88104
}
89105

90106
var pod *kubernetes.ListOutput
91107
for _, p := range list {
92-
if p.AppID == appID {
108+
if p.AppID == opts.AppID {
93109
pod = &p
94110
break
95111
}
96112
}
97113

98114
if pod == nil {
99-
return nil, fmt.Errorf("Dapr app with id '%s' not found in namespace %s", appID, namespace)
115+
return nil, fmt.Errorf("Dapr app with id '%s' not found in namespace %s", opts.AppID, opts.Namespace)
100116
}
101117

102118
config, _, err := kubernetes.GetKubeConfigClient()
@@ -111,7 +127,7 @@ func kube(namespace string, appID string) (*Client, error) {
111127

112128
portForward, err := kubernetes.NewPortForward(
113129
config,
114-
namespace,
130+
opts.Namespace,
115131
pod.PodName,
116132
"localhost",
117133
port,
@@ -136,7 +152,7 @@ func kube(namespace string, appID string) (*Client, error) {
136152
return nil, err
137153
}
138154

139-
c, err := clientFromComponents(comps.Items, appID, pod.DaprGRPCPort)
155+
c, err := clientFromComponents(comps.Items, opts.AppID, pod.DaprGRPCPort)
140156
if err != nil {
141157
portForward.Stop()
142158
}

pkg/workflow/events.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package workflow
1616
import (
1717
"context"
1818

19+
"github.com/dapr/cli/cmd/runtime"
1920
"github.com/dapr/cli/pkg/workflow/dclient"
2021
"github.com/dapr/durabletask-go/workflow"
2122
)
@@ -30,7 +31,12 @@ type RaiseEventOptions struct {
3031
}
3132

3233
func RaiseEvent(ctx context.Context, opts RaiseEventOptions) error {
33-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
34+
cli, err := dclient.DaprClient(ctx, dclient.Options{
35+
KubernetesMode: opts.KubernetesMode,
36+
Namespace: opts.Namespace,
37+
AppID: opts.AppID,
38+
RuntimePath: runtime.GetDaprRuntimePath(),
39+
})
3440
if err != nil {
3541
return err
3642
}
@@ -55,7 +61,12 @@ type SuspendOptions struct {
5561
}
5662

5763
func Suspend(ctx context.Context, opts SuspendOptions) error {
58-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
64+
cli, err := dclient.DaprClient(ctx, dclient.Options{
65+
KubernetesMode: opts.KubernetesMode,
66+
Namespace: opts.Namespace,
67+
AppID: opts.AppID,
68+
RuntimePath: runtime.GetDaprRuntimePath(),
69+
})
5970
if err != nil {
6071
return err
6172
}
@@ -75,7 +86,12 @@ type ResumeOptions struct {
7586
}
7687

7788
func Resume(ctx context.Context, opts ResumeOptions) error {
78-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
89+
cli, err := dclient.DaprClient(ctx, dclient.Options{
90+
KubernetesMode: opts.KubernetesMode,
91+
Namespace: opts.Namespace,
92+
AppID: opts.AppID,
93+
RuntimePath: runtime.GetDaprRuntimePath(),
94+
})
7995
if err != nil {
8096
return err
8197
}
@@ -95,7 +111,12 @@ type TerminateOptions struct {
95111
}
96112

97113
func Terminate(ctx context.Context, opts TerminateOptions) error {
98-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
114+
cli, err := dclient.DaprClient(ctx, dclient.Options{
115+
KubernetesMode: opts.KubernetesMode,
116+
Namespace: opts.Namespace,
117+
AppID: opts.AppID,
118+
RuntimePath: runtime.GetDaprRuntimePath(),
119+
})
99120
if err != nil {
100121
return err
101122
}

0 commit comments

Comments
 (0)