Skip to content

EPMDEDP-17271: feat: validate Codebase deletion against deployment usage and return structured errors - #312

Merged
SergK merged 1 commit into
masterfrom
fix/EPMDEDP-17271-validate-codebase-deletion
Aug 8, 2026
Merged

EPMDEDP-17271: feat: validate Codebase deletion against deployment usage and return structured errors#312
SergK merged 1 commit into
masterfrom
fix/EPMDEDP-17271-validate-codebase-deletion

Conversation

@SergK

@SergK SergK commented Aug 7, 2026

Copy link
Copy Markdown
Member

A Codebase referenced by a CDPipeline or by a Stage quality gate could be deleted, leaving the deployment pointing at a component that no longer exists. Only admission can prevent that, since any client can issue the delete.

CodebaseValidationWebhook.ValidateDelete now rejects the request when a CDPipeline lists the codebase in spec.applications or spec.applicationsToPromote, lists one of its branches in spec.inputDockerStreams, or a Stage quality gate names it as autotestName. The branch case matters because deleting a Codebase cascades to its branches and the CodebaseBranch webhook lets that cascade through, so the branches' own protection does not apply.

The Codebase and CodebaseBranch checks both report every blocking reference and deny with an *apierrors.StatusError carrying Reason=Forbidden, Code=403 and one metav1.StatusCause per reference, so clients read the referencing resource from Details.Causes rather than parsing the message.

Listing, terminating-resource filtering and CRD-availability handling are shared through pkg/deploymentusage.

@SergK
SergK requested a review from a team as a code owner August 7, 2026 21:13
@SergK
SergK force-pushed the fix/EPMDEDP-17271-validate-codebase-deletion branch 2 times, most recently from 89a784b to 221da00 Compare August 8, 2026 12:31
@epmd-edp

epmd-edp commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Pipeline review-codebase-operator-master-c2c9g ✅ Passed

Status Task Duration
github-set-pending-status 47s
fetch-repository 20s
init-values 7s
get-cache 2m11s
commit-validate 7s
dockerfile-lint 8s
helm-lint 21s
helm-docs 24s
build 45s
sonar 49s
save-cache 6s
buildkit-build 32s
github-report-pipeline-status 16s

…age and return structured errors

A Codebase referenced by a CDPipeline or by a Stage quality gate could be
deleted, leaving the deployment pointing at a component that no longer
exists. Only admission can prevent that, since any client can issue the
delete.

CodebaseValidationWebhook.ValidateDelete now rejects the request when a
CDPipeline lists the codebase in spec.applications or
spec.applicationsToPromote, lists one of its branches in
spec.inputDockerStreams, or a Stage quality gate names it as autotestName.
The branch case matters because deleting a Codebase cascades to its
branches and the CodebaseBranch webhook lets that cascade through, so the
branches' own protection does not apply.

The Codebase and CodebaseBranch checks both report every blocking
reference and deny with an *apierrors.StatusError carrying
Reason=Forbidden, Code=403 and one metav1.StatusCause per reference, so
clients read the referencing resource from Details.Causes rather than
parsing the message.

Listing, terminating-resource filtering and CRD-availability handling are
shared through pkg/deploymentusage.

Neither lookup scans the namespace per branch. The Codebase check selects
branches on a spec.codebaseName field index registered on the manager
cache; a missing index fails the List instead of silently falling back to
a full scan, so RegisterFieldIndexes runs unconditionally before the cache
starts and the webhook denies rather than under-reporting usage. The stale
branch sweep resolves the retaining resource from a single BranchUsageIndex
built per sweep, instead of re-reading the CDPipelines and Stages for every
stale branch; only the auto cleanup strategy consumes it, so branches that
are merely marked keep emitting the events they did before. Measured with
50 codebases of 10 branches, 10 CDPipelines and 20 Stages, a Codebase
delete admission dropped from 1265us to 570us.

Signed-off-by: Sergiy Kulanov <sergiy_kulanov@epam.com>
@SergK
SergK force-pushed the fix/EPMDEDP-17271-validate-codebase-deletion branch from 221da00 to cbd7900 Compare August 8, 2026 13:54
@SergK
SergK merged commit 5ea14c4 into master Aug 8, 2026
6 checks passed
@SergK
SergK deleted the fix/EPMDEDP-17271-validate-codebase-deletion branch August 8, 2026 14:07
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.

2 participants