Skip to content

fix: remove Kubernetes resources on app management uninstall and daemon removal - #1210

Open
oleksandr-nc wants to merge 1 commit into
mainfrom
fix/ui-uninstall-k8s
Open

oleksandr-nc wants to merge 1 commit into
mainfrom
fix/ui-uninstall-k8s

Conversation

@oleksandr-nc

Copy link
Copy Markdown
Contributor

Removing an ExApp in the app management unregistered it but left its Kubernetes Deployment, Service and volume in the cluster, and so did removing its Kubernetes deploy daemon in the admin settings. Only occ app_api:app:unregister removed them.

Changes

  • KubernetesActions::removeExAppResources() removes an ExApp's Kubernetes resources, for every role of a multi-role ExApp, and keeps the volume unless data removal is asked for. The occ command, the uninstall route and the daemon removal use it.
  • A multi-role ExApp whose first role fails to be removed still has its other roles removed.

…on removal

Signed-off-by: Oleksandr Piskun <oleksandr2088@icloud.com>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

Kubernetes resource removal now uses a shared method that reads saved service roles and removes each configured deployment, or removes the single deployment when no roles are saved. Role removal continues after a failure and returns the first error. The unregister command, app management controller, and daemon-removal service call the shared method. The controller and service log data deletion after successful removal. Tests cover role removal and Kubernetes cleanup through these paths. The changelog records the cleanup fix.

Merge Risk: Moderate · up to 26220

Removing an ExApp or its Kubernetes daemon can report success while some deployments or volumes remain in the cluster, with no registration left to retry the cleanup. Fix the failure handling before merging. The removeContainer=false case only affects direct API callers.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: removing Kubernetes resources on app management uninstall and on daemon removal. The raw summary confirms the uninstall route and the daemon removal path both call the new …
Description check Passed The description states the bug: unregistering an ExApp in app management, or removing its Kubernetes deploy daemon, left Kubernetes Deployment, Service and volume behind. It also lists the new Kuberne…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: removing Kubernetes resources on app management uninstall and on daemon removal. The raw summary confirms the uninstall route and the daemon removal path both call the new removal logic, so the title matches the main change.

Full details: Description check

Explanation

The description states the bug: unregistering an ExApp in app management, or removing its Kubernetes deploy daemon, left Kubernetes Deployment, Service and volume behind. It also lists the new KubernetesActions::removeExAppResources() method, the callers, volume retention, and multi-role removal. This matches the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59ab8663-3c42-49da-809f-9e7a7c5e1699
Commits

Reviewing files that changed from the base of the PR and between 072b6b4 and 26220bc.

Files selected for processing: 10

  • CHANGELOG.md
  • lib/Command/ExApp/Unregister.php
  • lib/Controller/ExAppsPageController.php
  • lib/DeployActions/KubernetesActions.php
  • lib/Service/AppAPIService.php
  • tests/php/Command/ExApp/UnregisterTest.php
  • tests/php/Controller/ExAppsPageControllerTest.php
  • tests/php/DeployActions/KubernetesActionsTest.php
  • tests/php/Service/AppAPIServiceTest.php
  • tests/psalm-baseline.xml
Files with no reviewable changes: 1

  • tests/psalm-baseline.xml

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

}
}
} elseif ($daemonConfig->getAcceptsDeployId() === $this->kubernetesActions->getAcceptsDeployId()) {
$removeError = $this->kubernetesActions->removeExAppResources($daemonConfig, $exApp->getAppid(), removeData: $removeData);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Honor removeContainer before deleting Kubernetes deployments.

uninstallApp() documents $removeContainer as whether to remove the ExApp container. The Kubernetes branch removes the ExApp deployments without checking that flag. A caller that passes removeContainer: false still loses the running workload.

The non-harp Docker branch guards its container removal with $removeContainer. Apply the same guard to the Kubernetes branch.

Suggested fix

--- "a/lib/Controller/ExAppsPageController.php"
+++ "b/lib/Controller/ExAppsPageController.php"
@@ -514,12 +514,14 @@
 						}
 					}
 				}
 			} elseif ($daemonConfig->getAcceptsDeployId() === $this->kubernetesActions->getAcceptsDeployId()) {
-				$removeError = $this->kubernetesActions->removeExAppResources($daemonConfig, $exApp->getAppid(), removeData: $removeData);
-				if ($removeData && $removeError === '') {
-					$this->exAppService->logExAppDataDeleted($exApp);
-				}
+				if ($removeContainer) {
+					$removeError = $this->kubernetesActions->removeExAppResources($daemonConfig, $exApp->getAppid(), removeData: $removeData);
+					if ($removeData && $removeError === '') {
+						$this->exAppService->logExAppDataDeleted($exApp);
+					}
+				}
 			}
 			$this->exAppService->unregisterExApp($appId);
 		}
 		return new JSONResponse();

Comment on lines +519 to +521
if ($removeData && $removeError === '') {
$this->exAppService->logExAppDataDeleted($exApp);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Quick win

Preserve the registration when Kubernetes cleanup fails.

If HaRP is unavailable or one role cannot be removed, $removeError is nonempty. The controller still calls unregisterExApp() at Line 523 and returns success. ExAppService::unregisterExApp() also deletes k8s_service_roles, so remaining deployments lose their cleanup metadata and the administrator cannot retry removal through AppAPI.

Return an error before unregistration when cleanup fails. Retain the registration and deployment options for a retry.

Comment on lines +871 to +873
if ($this->kubernetesActions->removeExAppResources($daemonConfig, $exApp->getAppid(), true) === '') {
$this->exAppService->logExAppDataDeleted($exApp);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Heavy lift

Keep failed Kubernetes ExApps and their role list when cleanup fails.

When removeExAppResources() returns an error, the loop skips logExAppDataDeleted(), but the following unregisterExApp() still runs. That call removes the ExApp's deploy options, including k8s_service_roles, and the ExApp row. A partial multi-role failure can leave role resources in the cluster with no record of their roles. unregisterDaemonConfig() then deletes the daemon config and reports success, so the failure is silent.

Keeping the ExApp registered alone does not allow a retry, because the daemon config is also deleted. A safe fix needs these changes:

  • Skip unregisterExApp() for an ExApp whose removal returned an error, so its deploy options stay in place.
  • Return the failure from removeExAppsByDaemonConfigName() instead of void. The controller must not delete the daemon config or report success when a cleanup failed.
  • Decide whether the Docker branches need the same rule, because they also unregister after a failed removal.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant