Skip to content

fix(state): handle deleted artifacts in satellite state replication - #622

Open
harshal0704 wants to merge 2 commits into
container-registry:mainfrom
harshal0704:fix/handle-deleted-artifacts-replication
Open

fix(state): handle deleted artifacts in satellite state replication#622
harshal0704 wants to merge 2 commits into
container-registry:mainfrom
harshal0704:fix/handle-deleted-artifacts-replication

Conversation

@harshal0704

@harshal0704 harshal0704 commented Aug 12, 2026

Copy link
Copy Markdown

Description

This PR fixes an issue in Harbor Satellite state processing where artifacts marked as deleted (deleted: true) in Ground Control state manifests were being replicated/pulled to local satellite storage instead of being deleted.

Summary of Changes

  1. internal/satellite/state/replicator.go:
    • Added Deleted bool field to Entity struct with json:"deleted,omitempty" for backward compatibility with persisted state.
  2. internal/satellite/state/state_process.go:
    • FetchEntitiesFromState: Propagated artifact.IsDeleted() into Entity.Deleted.
    • GetChanges:
      • Filtered out entity.Deleted on initial sync (oldEntities == nil) so deleted images are not pulled on first satellite sync.
      • Routed newEntity.Deleted with active oldEntity (!oldEntity.Deleted) to entityToDelete and skipped replication.
      • Guarded deletion scheduling with !oldEntity.Deleted to ensure deletion is idempotent and not repeatedly scheduled on subsequent reconciliation loops.
      • Handled re-added/re-published artifacts (oldEntity.Deleted == true and newEntity.Deleted == false) by allowing re-replication.
  3. internal/satellite/state/state_process_test.go:
    • Added 7 unit test cases in TestGetChanges and TestFetchEntitiesFromState covering initial sync filtering, active entity deletion, loop idempotency, re-added artifact replication, and deleted flag propagation.

Verification & Test Evidence

All unit tests pass cleanly across the workspace:

go test -v ./internal/satellite/state/...
# PASS ok github.com/container-registry/harbor-satellite/internal/satellite/state 0.239s
go test ./...
# PASS

Additional context

  • All commits are signed off per DCO requirements (Signed-off-by).
  • Changes are fully backward compatible with persisted state.json (json:"deleted,omitempty").

Review in cubic

- Add Deleted field to Entity struct for tracking deletion state
- Propagate artifact.IsDeleted() in FetchEntitiesFromState
- Filter out deleted artifacts on initial sync (oldEntities == nil)
- Route newEntity.Deleted with active oldEntity to entityToDelete in GetChanges
- Guard deletion scheduling with !oldEntity.Deleted for reconciliation idempotency
- Allow re-replication of previously deleted artifacts if re-added upstream
- Add comprehensive unit tests covering all deletion edge cases

Signed-off-by: Harshal <harshal@iitbhilai.ac.in>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@harshal0704, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0bbae41a-95b8-4aba-b90b-817a08b59ff9

📥 Commits

Reviewing files that changed from the base of the PR and between 7986d0e and a81b409.

📒 Files selected for processing (3)
  • internal/satellite/state/replicator.go
  • internal/satellite/state/state_process.go
  • internal/satellite/state/state_process_test.go
📝 Walkthrough

Walkthrough

The state replication model now preserves artifact deletion status. GetChanges filters deleted entities, schedules active entities for deletion, skips repeated deletions, and replicates restored entities. Tests cover these reconciliation cases.

Changes

Deleted artifact reconciliation

Layer / File(s) Summary
Entity deletion mapping
internal/satellite/state/replicator.go, internal/satellite/state/state_process.go, internal/satellite/state/state_process_test.go
Entity includes an optional Deleted field. FetchEntitiesFromState copies each artifact’s deletion status. Tests cover active and deleted artifacts.
Deletion reconciliation
internal/satellite/state/state_process.go, internal/satellite/state/state_process_test.go
GetChanges excludes deleted entities from initial replication, schedules active entities for deletion, skips already-deleted entities, and replicates entities that become active again. Tests cover these cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StateJSON as State JSON
  participant FetchEntitiesFromState
  participant GetChanges
  participant SatelliteStorage as Satellite storage
  StateJSON->>FetchEntitiesFromState: Read artifact deletion status
  FetchEntitiesFromState->>GetChanges: Provide Entity.Deleted
  GetChanges->>SatelliteStorage: Schedule active deleted entities for deletion
  GetChanges->>SatelliteStorage: Replicate restored entities
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary fix for deleted artifacts in satellite state replication.
Description check ✅ Passed The description follows the template and documents the fix, implementation, testing, and additional context.
Linked Issues check ✅ Passed The changes satisfy issue #621 by tracking deletion state, deleting active entities, supporting idempotency, and re-replicating restored artifacts.
Out of Scope Changes check ✅ Passed All code and test changes directly support the linked issue and stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@gitar-bot

gitar-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

@codacy-production

codacy-production Bot commented Aug 12, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 44 duplication

Metric Results
Complexity 15
Duplication 44

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/satellite/state/state_process.go`:
- Around line 209-215: Update the reconciliation key used by the
state-processing logic around the deleted-entity branch to include Repository,
Name, and Tag consistently in both map construction and lookup, preventing
cross-repository collisions. Add a regression test covering identical names and
tags in two repositories and verify deletion only affects the matching
repository entity.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2959c0e-7e0c-4e12-8d54-8cfb5451097b

📥 Commits

Reviewing files that changed from the base of the PR and between 341cb42 and 7986d0e.

📒 Files selected for processing (3)
  • internal/satellite/state/replicator.go
  • internal/satellite/state/state_process.go
  • internal/satellite/state/state_process_test.go

Comment thread internal/satellite/state/state_process.go

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/satellite/state/state_process.go
Comment thread internal/satellite/state/state_process.go
- Add Deleted field to Entity struct for tracking deletion state
- Propagate artifact.IsDeleted() in FetchEntitiesFromState
- Filter out deleted artifacts on initial sync (oldEntities == nil)
- Route newEntity.Deleted with active oldEntity to entityToDelete in GetChanges
- Guard deletion scheduling with !oldEntity.Deleted for reconciliation idempotency
- Allow re-replication of previously deleted artifacts if re-added upstream
- Key entity lookup by Repository|Name|Tag to prevent cross-repository collisions
- Update initial-sync log message to reflect deleted-artifact filtering
- Add comprehensive unit tests covering all deletion and collision edge cases

Signed-off-by: Harshal <harshal@iitbhilai.ac.in>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/satellite/state/replicator.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(state): deleted artifacts in state JSON are replicated instead of removed

1 participant