Skip to content

Commit 4c4ea04

Browse files
committed
Review comments
Signed-off-by: joshvanl <[email protected]>
1 parent eb77bea commit 4c4ea04

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

cmd/workflow/workflow.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"strings"
2121
"time"
2222

23+
"github.com/spf13/cobra"
24+
2325
"github.com/dapr/cli/pkg/kubernetes"
2426
"github.com/dapr/cli/pkg/standalone"
2527
"github.com/dapr/cli/pkg/workflow"
2628
"github.com/dapr/kit/ptr"
2729
kittime "github.com/dapr/kit/time"
28-
"github.com/spf13/cobra"
2930
)
3031

3132
const (
@@ -69,7 +70,7 @@ func outputFunc(cmd *cobra.Command) *string {
6970
pre := cmd.PreRunE
7071
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
7172
if !slices.Contains(outputs, outputFormat) {
72-
return errors.New("invalid value for --output. Supported values are 'table', 'wide', 'yaml', 'json'.")
73+
return errors.New("invalid value for --output. Supported values are 'short', 'wide', 'yaml', 'json'.")
7374
}
7475

7576
if pre != nil {

pkg/workflow/dclient/dclient.go

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
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+
114
package dclient
215

316
import (
@@ -59,51 +72,13 @@ func stand(ctx context.Context, appID string) (*Client, error) {
5972
return nil, err
6073
}
6174

62-
var comp *v1alpha1.Component
63-
for _, c := range comps {
64-
for _, meta := range c.Spec.Metadata {
65-
if meta.Name == "actorStateStore" && meta.Value.String() == "true" {
66-
comp = &c
67-
break
68-
}
69-
}
70-
}
71-
72-
if comp == nil {
73-
return nil, fmt.Errorf("no state store configured for app id %s", appID)
74-
}
75-
76-
client, err := client.NewClientWithAddress("127.0.0.1:" + strconv.Itoa(proc.GRPCPort))
77-
if err != nil {
78-
return nil, err
79-
}
80-
81-
driver, err := driverFromType(comp.Spec.Type)
75+
c, err := clientFromComponents(comps, appID, strconv.Itoa(proc.GRPCPort))
8276
if err != nil {
8377
return nil, err
8478
}
79+
c.Cancel = func() {}
8580

86-
// Optimistically use the connection string in self-hosted mode.
87-
var connString *string
88-
var tableName *string
89-
for _, meta := range comp.Spec.Metadata {
90-
switch meta.Name {
91-
case "connectionString":
92-
connString = ptr.Of(meta.Value.String())
93-
case "tableName":
94-
tableName = ptr.Of(meta.Value.String())
95-
case "collectionName":
96-
tableName = ptr.Of(meta.Value.String())
97-
}
98-
}
99-
100-
return &Client{
101-
Dapr: client,
102-
Cancel: func() {},
103-
StateStoreDriver: driver,
104-
ConnectionString: connString,
105-
TableName: tableName,
106-
}, nil
81+
return c, nil
10782
}
10883

10984
func kube(namespace string, appID string) (*Client, error) {
@@ -155,13 +130,25 @@ func kube(namespace string, appID string) (*Client, error) {
155130
if err != nil {
156131
return nil, err
157132
}
133+
158134
comps, err := kubernetes.ListComponents(kclient, pod.Namespace)
159135
if err != nil {
160136
return nil, err
161137
}
162138

139+
c, err := clientFromComponents(comps.Items, appID, pod.DaprGRPCPort)
140+
if err != nil {
141+
portForward.Stop()
142+
}
143+
144+
c.Cancel = portForward.Stop
145+
146+
return c, nil
147+
}
148+
149+
func clientFromComponents(comps []v1alpha1.Component, appID string, port string) (*Client, error) {
163150
var comp *v1alpha1.Component
164-
for _, c := range comps.Items {
151+
for _, c := range comps {
165152
for _, meta := range c.Spec.Metadata {
166153
if meta.Name == "actorStateStore" && meta.Value.String() == "true" {
167154
comp = &c
@@ -179,9 +166,8 @@ func kube(namespace string, appID string) (*Client, error) {
179166
return nil, err
180167
}
181168

182-
client, err := client.NewClientWithAddress("localhost:" + pod.DaprGRPCPort)
169+
client, err := client.NewClientWithAddress("localhost:" + port)
183170
if err != nil {
184-
portForward.Stop()
185171
return nil, err
186172
}
187173

@@ -195,7 +181,6 @@ func kube(namespace string, appID string) (*Client, error) {
195181

196182
return &Client{
197183
Dapr: client,
198-
Cancel: portForward.Stop,
199184
StateStoreDriver: driver,
200185
TableName: tableName,
201186
}, nil

0 commit comments

Comments
 (0)