-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: proxy cache serve local on remote not found #22153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: proxy cache serve local on remote not found #22153
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22153 +/- ##
===========================================
+ Coverage 45.36% 65.88% +20.51%
===========================================
Files 244 1073 +829
Lines 13333 116013 +102680
Branches 2719 2927 +208
===========================================
+ Hits 6049 76430 +70381
- Misses 6983 35350 +28367
- Partials 301 4233 +3932
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Thanks for the PR. But IMO this is a "feat" rather than a "fix".
This is a break-change to the original design, which returns 404 when the remote content is removed. Because we have passed the "feature freeze" and will hit "feature complete" in July, I don't think it can be made into v2.14. Are you willing to continue working on this after the branch for 2.14 is cut? We can continue the discussion in the issue. IMO at least an option should be added, so user can choose whether to server local content when the remote artifact is removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my understanding, this is a break change. More discussion needed.
Hi @reasonerjt , I understand your point of view regarding this being considered a In the meantime, I found a workaround by returning a 429 response for each 404 returned by the remote registry. Since I have this workaround, I am willing to wait for your decision on whether to update the documentation or merge my change. However, I think that giving users a choice via a parameter might create confusion about the feature. In my opinion, serving the local cache when the remote registry responds with a 404 is the very concept of a proxy cache. And the Harbor documentation seems to agree with me. |
@AYDEV-FR Thanks for pointing this out, let me double check why this change in the doc was made, if this is on purpose, I agree this is a |
Hi @AYDEV-FR I am also running into the same problem and I would be interested to know how did you implement the workaround to return a 429 from the registry? |
Is there any update on this? Especially with bitnami's upcoming removal of images from docker.io, having the pull-through cache continue serving removed, but cached, images would be incredibly usefull. After all, that's probably one of the reasons people configure Harbor as a pull-through cache. To not just reduce traffic, but also keep workloads operational in case upstream images go away for whatever reason. |
@AYDEV-FR great work https://github.com/goharbor/community/pull/144/files#diff-78dea958499f3e23826611cf839d9a96615a0b420f33520e92d564f2fb17d24fR127 as per the Harbor proxy spec. proxy cache is said to delete the local manifest if it does not exist in remote. But in the document it is said to be serving the artifact even when the remote artifact is deleted. Also adding to that we did a change only in 2.14 to delete the local artifact which makes it pretty clear that harbor is previously serving the artifact. Which makes this a fix. This also delves into the question of data integrity and what to do with stale data.. I believe we should do this as a fix since I feel like harbor was serving in the past. And this is a behaviour different from the spec mentioned above. So we should update the spec. there is also this parity between the pull through cache vs proxy cache. Harbor doesn't support pull through cache. maybe we can do that. |
@bupd Harbor 2.14 made the opposite change: #22175 Maybe the best option is to make it configurable, leaving the current implementation in place as default? It could be a checkbox setting on the proxy cache level, something like |
Also from the distribution spec it is clear that Harbor should serve artifacts that it locally has even if the remote artifact is deleted. Also given the use case and demand and Harbor already might been doing this in the past makes it clear to have it in 2.14.1 |
Given that the Proposal PR is merged with lazy consensus with lack of reviews. given that spec is clearly titled as A true pull-through cache should be able to serve content even when the remote resource is deleted or completely offline, which is a critical distinction from an online-only proxy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AYDEV-FR Thanks for your contribution
please do rebase, otherwise LGTM a much needed change in harbor
Signed-off-by: AYDEV-FR <[email protected]>
Signed-off-by: AYDEV-FR <[email protected]>
f2e80f9
to
69adb22
Compare
Hi @bupd and @reasonerjt, Thanks for your review ! I’ve rebased my code and run multiple tests with the changes in my PR.
When the repo is not available, the cache is correctly served from If the repo returns 503, while Harbor is still detecting it as unhealthy:
If the repo returns 404 for the manifest (e.g., the image has been deleted), it's my code behaves as expected:
The change is working well. Would it be possible to merge this and release a v2.14.1 as @bupd suggested? |
any update? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the proxy cache logic to serve locally cached images when they exist locally but are no longer found in the remote repository, aligning implementation with documented behavior.
- Updates
UseLocalManifest
function to check for local artifact existence before returning "not found" error - Removes automatic deletion logic for locally cached manifests when remote returns 404
- Updates corresponding test case to expect success instead of error when local cache exists but remote doesn't
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/controller/proxy/controller.go | Modified logic to serve from local cache when remote artifact is not found |
src/controller/proxy/controller_test.go | Updated test case to reflect new behavior of serving from local cache |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: Vadim Bauer <[email protected]>
Comprehensive Summary of your change
This PR updates the proxy cache logic so that if an image exists in the local cache but has been deleted from the remote repository, Harbor will serve the cached image instead of failing with a "not found" error. This brings the implementation in line with the documented behavior and improves reliability when remote repositories are unavailable or images have been removed upstream.
You can find more details about this change in issue #22106.
Implementation Notes
I hesitated between modifying the
remote.ManifestExist
function inharbor/src/controller/proxy/controller.go
(since it does not return a 404 error directly inharbor/src/pkg/registry/client.go
):However, to avoid unintended side effects by changing this function's behavior, I decided to keep the current "404 not found" handling (which returns no error) and instead update the
UseLocalManifest
function inharbor/src/controller/proxy/controller.go
:Issue being fixed
Fixes #22106
No documentation modification is needed because this PR enforces behavior that is already described in the documentation:
Please confirm you've completed the following: