-
Notifications
You must be signed in to change notification settings - Fork 94
OCPBUGS-99398: Fix resolveUpstreamRef to properly propagate not-found errors #475
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,13 @@ func (is *imageStream) getImageOfImageStream(ctx context.Context, dgst digest.Di | |
| // not be sent to the master API. If you need unmodified version of the | ||
| // image object, please use getStoredImageOfImageStream. | ||
| func (is *imageStream) GetImageOfImageStream(ctx context.Context, dgst digest.Digest) (*imageapiv1.Image, rerrors.Error) { | ||
| if _, rErr := is.imageStreamGetter.get(); rErr != nil { | ||
| return nil, convertImageStreamGetterError( | ||
| rErr, | ||
| fmt.Sprintf("GetImageOfImageStream: image stream %s not found", is.Reference()), | ||
| ) | ||
| } | ||
|
|
||
| isImage, err := is.getImageOfImageStream(ctx, dgst) | ||
| if err == nil { | ||
| return isImage, nil | ||
|
|
@@ -233,10 +240,9 @@ func (is *imageStream) GetImageOfImageStream(ctx context.Context, dgst digest.Di | |
| func (is *imageStream) resolveUpstreamRef(ctx context.Context, dgst digest.Digest) (reference.DockerImageReference, rerrors.Error) { | ||
| layers, rErr := is.imageStreamGetter.layers() | ||
| if rErr != nil { | ||
| return reference.DockerImageReference{}, rerrors.NewError( | ||
| ErrImageStreamUnknownErrorCode, | ||
| fmt.Sprintf("resolveUpstreamRef: failed to get layers for image stream %s", is.Reference()), | ||
| return reference.DockerImageReference{}, convertImageStreamGetterError( | ||
| rErr, | ||
| fmt.Sprintf("resolveUpstreamRef: failed to get layers for image stream %s", is.Reference()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be correct. Can we have a unit test in place ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should verify if the ImageStream exists in Maybe add an early call to You may even keep the current change as a safety net, just in case.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated as per your suggestion — added an early ImageStream existence check at the top of GetImageOfImageStream(): Could you please have a look if that is what you asked for ? The original fix in resolveUpstreamRef is retained as a safety net for any other code paths that call it directly. |
||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package imagestream | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| rerrors "github.com/openshift/image-registry/pkg/errors" | ||
| ) | ||
|
|
||
| func TestConvertImageStreamGetterError(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| inputCode string | ||
| expectedCode string | ||
| }{ | ||
| { | ||
| name: "NotFound error is propagated as ImageStream NotFound", | ||
| inputCode: ErrImageStreamGetterNotFoundCode, | ||
| expectedCode: ErrImageStreamNotFoundCode, | ||
| }, | ||
| { | ||
| name: "Forbidden error is propagated as ImageStream Forbidden", | ||
| inputCode: ErrImageStreamGetterForbiddenCode, | ||
| expectedCode: ErrImageStreamForbiddenCode, | ||
| }, | ||
| { | ||
| name: "Unknown error remains as ImageStream Unknown", | ||
| inputCode: ErrImageStreamGetterUnknownCode, | ||
| expectedCode: ErrImageStreamUnknownErrorCode, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| inputErr := rerrors.NewError(tc.inputCode, "test/repo", nil) | ||
| result := convertImageStreamGetterError(inputErr, "test message") | ||
|
|
||
| if result.Code() != tc.expectedCode { | ||
| t.Errorf("expected error code %q, got %q", tc.expectedCode, result.Code()) | ||
| } | ||
|
|
||
| if result.Message() != "test message" { | ||
| t.Errorf("expected message %q, got %q", "test message", result.Message()) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use a neutral message for all getter failures.
convertImageStreamGetterErrormaps not-found, forbidden, and unknown errors. Line [205] always reportsimage stream ... not found, so forbidden and unknown failures produce an inaccurate diagnostic. Usefailed to get image stream ...or select the message fromrErr.Code().Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents