Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ dapr stop --run-file /path/to/directory -k
err = executeStopWithRunFile(runFilePath)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Failed to stop Dapr and app processes: %s", err)
} else {
print.SuccessStatusEvent(os.Stdout, "Dapr and app processes stopped successfully")
os.Exit(1)
}
print.SuccessStatusEvent(os.Stdout, "Dapr and app processes stopped successfully")
return
Comment on lines 61 to 67

@Mukuwul Mukuwul Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - and CI actually caught this immediately: the existing stop_without_install e2e was asserting the old behavior (error message + exit 0). I flipped that assertion to require a non-zero exit in a369916, so it now doubles as the regression test for this path.

}
config, _, cErr := getRunConfigFromRunFile(runFilePath)
if cErr != nil {
print.FailureStatusEvent(os.Stderr, "Failed to parse run template file %q: %s", runFilePath, cErr.Error())
os.Exit(1)
}
err = kubernetes.Stop(runFilePath, config)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Error stopping deployments from multi-app run template: %v", err)
os.Exit(1)
}
return
}
if stopAppID != "" {
args = append(args, stopAppID)
Expand All @@ -84,14 +87,19 @@ dapr stop --run-file /path/to/directory -k
os.Exit(1)
}
cliPIDToNoOfApps := standalone.GetCLIPIDCountMap(apps)
stopFailed := false
for _, appID := range args {
err = standalone.Stop(appID, cliPIDToNoOfApps, apps)
if err != nil {
print.FailureStatusEvent(os.Stderr, "failed to stop app id %s: %s", appID, err)
stopFailed = true
} else {
print.SuccessStatusEvent(os.Stdout, "app stopped successfully: %s", appID)
}
}
if stopFailed {
os.Exit(1)
}
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ dapr uninstall --runtime-path <path-to-install-directory>

if err != nil {
print.FailureStatusEvent(os.Stderr, fmt.Sprintf("Error removing Dapr: %s", err))
} else {
print.SuccessStatusEvent(os.Stdout, "Dapr has been removed successfully")
os.Exit(1)
}
print.SuccessStatusEvent(os.Stdout, "Dapr has been removed successfully")
Comment on lines 91 to +95

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this - there isn't a clean way to force standalone.Uninstall or kubernetes.Uninstall to fail from the e2e harness today without mocking, so uninstall doesn't have a dedicated exit-code test yet. If there's a preferred fault-injection pattern in this repo I'm happy to add one.

},
}

Expand Down
15 changes: 11 additions & 4 deletions pkg/kubernetes/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,20 @@ func deployYamlToK8s(yamlToDeployPath string) error {
return nil
}

func deleteYamlK8s(yamlToDeletePath string) error {
func deleteYamlK8s(yamlToDeletePath string, ignoreNotFound bool) error {
print.InfoStatusEvent(os.Stdout, "Deleting %q from Kubernetes", yamlToDeletePath)
_, err := os.Stat(yamlToDeletePath)
if os.IsNotExist(err) {
return fmt.Errorf("error given file %q does not exist", yamlToDeletePath)
}
_, err = utils.RunCmdAndWait("kubectl", "delete", "-f", yamlToDeletePath)
args := []string{"delete", "-f", yamlToDeletePath}
if ignoreNotFound {
// "dapr stop -f -k" races with the graceful shutdown performed by the
// "dapr run -f -k" process on receiving the stop signal; resources
// already deleted by the other process must not fail the stop.
args = append(args, "--ignore-not-found")
}
_, err = utils.RunCmdAndWait("kubectl", args...)
if err != nil {
return fmt.Errorf("error deleting the yaml %s from Kubernetes: %w", yamlToDeletePath, err)
}
Expand All @@ -412,9 +419,9 @@ func gracefullyShutdownK8sDeployment(runStates []runState, client k8s.Interface,
errs := make([]error, 0, len(runStates)*4)
for _, r := range runStates {
if len(r.serviceFilePath) != 0 {
errs = append(errs, deleteYamlK8s(r.serviceFilePath))
errs = append(errs, deleteYamlK8s(r.serviceFilePath, false))
}
errs = append(errs, deleteYamlK8s(r.deploymentFilePath))
errs = append(errs, deleteYamlK8s(r.deploymentFilePath, false))
labelSelector := map[string]string{
daprAppIDKey: r.app.AppID,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func Stop(runFilePath string, config runfileconfig.RunFileConfig) error {
serviceFilePath := filepath.Join(deployDir, serviceFileName)
deploymentFilePath := filepath.Join(deployDir, deploymentFileName)
if app.CreateService {
err = deleteYamlK8s(serviceFilePath)
err = deleteYamlK8s(serviceFilePath, true)
if err != nil {
appError = true
}
errs = append(errs, err)
}
err = deleteYamlK8s(deploymentFilePath)
err = deleteYamlK8s(deploymentFilePath, true)
if err != nil {
appError = true
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/standalone/init_negative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestStandaloneInitNegatives(t *testing.T) {

t.Run("stop without install", func(t *testing.T) {
output, err := cmdStopWithAppID("test")
require.NoError(t, err, "expected no error on stop without install")
require.Error(t, err, "expected non-zero exit code on stop without install")
require.Contains(t, output, "failed to stop app id test: couldn't find app id test", "expected output to match")
})

Expand Down
Loading