feat: add removeOrphans option to project deploy/redeploy#2785
Merged
Conversation
Allow non-GitOps projects to opt into removing orphan containers (services deleted from the compose file) on deploy/redeploy via a per-request removeOrphans flag on DeployOptions, mirroring the existing forceRecreate option. Previously removeOrphans was hardcoded true only for GitOps-managed projects, so imperative API-driven redeploys left orphan containers running. The flag is additive and opt-in; default behavior is unchanged. The redeploy endpoint now accepts an optional DeployOptions body, and RedeployProject forwards options to DeployProject. Existing GitOps and webhook callers pass nil, preserving their behavior (GitOps projects still remove orphans via the GitOpsManagedBy condition).
Follow the codebase convention of suffixing unexported helpers with Internal (e.g. ensureProjectMutableInternal).
kmendell
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in, per-request
removeOrphansflag to the project deploy/redeploy API so non-GitOps projects can remove orphan containers (services deleted from the compose file) on redeploy.Today
removeOrphansis hardcodedtrueonly for GitOps-managed projects (project_service.go, derived fromGitOpsManagedBy). Imperative, API-driven redeploys of regular projects therefore leave orphan containers running — there is no way to request their removal. This adds the missing knob, mirroring the existingforceRecreateoption onDeployOptions.Changes
types/project/project.go— addRemoveOrphans bool \json:"removeOrphans,omitempty"`toDeployOptions(mirrorsForceRecreate`).backend/internal/services/project_service.go— extractresolveRemoveOrphans(gitOpsManaged, options): returnstrueif the project is GitOps-managed or the caller opted in.RedeployProjectnow accepts*project.DeployOptionsand forwards it toDeployProjectinstead ofnil.backend/api/handlers/projects.go—RedeployProjectInputgains an optionalBody *project.DeployOptions(same shape as the existingDeployProjectInput.Body); passed through to the service.gitops_sync_service.go,webhook_service.go— existing internal callers passnil(behavior unchanged; GitOps projects still remove orphans via theGitOpsManagedBycondition).Behavior
Purely additive and non-breaking. The flag can only turn
removeOrphansfromfalse→true, never the reverse. Empty/absent body ⇒niloptions ⇒ current default behavior preserved.POST /environments/{id}/projects/{projectId}/redeploywith{"removeOrphans": true}now removes orphans; an empty body behaves exactly as before./downis left as-is (already removes orphans unconditionally).Tests
TestResolveRemoveOrphans— table test covering the precedence matrix (gitops × flag).TestComposeUpOptions_RemoveOrphans— asserts the flag propagates into composeCreateOptions.RemoveOrphans.go build,go vet,gofmt, and theservices+pkg/projectstest suites all pass.Notes
Disclaimer Greptiles Reviews use AI, make sure to check over its work.
To better help train Greptile on our codebase, if the comment is useful and valid Like the comment, if its not helpful or invalid Dislike
To have Greptile Re-Review the changes, mention
greptileai.Greptile Summary
This PR adds an opt-in
removeOrphansfield toDeployOptionsand threads it through the redeploy API path, allowing non-GitOps projects to request removal of orphan containers on redeploy. The existing behavior for GitOps-managed projects and all other internal callers is fully preserved.resolveRemoveOrphansInternalcentralises the precedence logic (gitOpsManaged || options.RemoveOrphans), and the newTestResolveRemoveOrphanstable test covers all six combinations of the flag matrix.RedeployProjectInputgains an optionalBody *project.DeployOptions, following the exact same pattern as the existingDeployProjectInput; absent/empty body remains nil and behaviour is unchanged.forceRecreateis now also accepted via the redeploy endpoint (since the fullDeployOptionsstruct is forwarded), which is not called out in the PR description but is consistent with the deploy endpoint's API surface.Confidence Score: 5/5
The change is purely additive: no existing call site is altered in behaviour, and all internal callers (GitOps sync, webhook) continue to pass nil options.
The logic is straightforward and well-tested. The resolveRemoveOrphansInternal helper is trivial and covered by a complete 6-case table test. Nil handling throughout is correct, and the HTTP handler follows an identical pattern already used by the deploy endpoint.
No files require special attention.
Reviews (2): Last reviewed commit: "refactor: rename resolveRemoveOrphans to..." | Re-trigger Greptile