-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Handle HTTP error codes in file loader #4334
Conversation
GitHub release files like https://github.com/fluxcd/helm-controller/releases/download/v0.14.0/helm-controller.crds.yaml seems to be hosted on Azure and it seems that there are egress limits that can be reached, e.g.: ```xml <?xml version="1.0" encoding="utf-8"?><Error><Code>ServerBusy</Code><Message>Egress is over the account limit. RequestId:f4a46b38-001e-0046-2437-ec16e2000000 Time:2021-12-08T13:28:03.8542138Z</Message></Error> ``` This patch allows to have a clear Error message instead of just `missing Resource metadata`: ``` Error: accumulating resources: accumulation err='accumulating resources from 'https://github.com/fluxcd/source-controller/releases/download/v0.19.0/source-controller.crds.yaml': URL returned error 503 (Service Unavailable)': evalsymlink failure on '/private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases/download/v0.19.0/source-controller.crds.yaml' : lstat /private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases: no such file or directory ``` Signed-off-by: Sylvain Rabot <[email protected]>
Hi @sylr. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
It is useless and it clogs the error message. Signed-off-by: Sylvain Rabot <[email protected]>
@sylr: This PR has multiple commits, and the default merge method is: merge. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Signed-off-by: Sylvain Rabot <[email protected]>
Signed-off-by: Sylvain Rabot <[email protected]>
@@ -366,6 +367,10 @@ func (kt *KustTarget) accumulateResources( | |||
for _, path := range paths { | |||
// try loading resource as file then as base (directory or git repository) | |||
if errF := kt.accumulateFile(ra, path, origin); errF != nil { | |||
// not much we can do if the error is an HTTP error so we bail out | |||
if errors.Is(errF, load.ErrorHTTP) { | |||
return nil, errF |
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.
If we get an HTTP error, wouldn't the line 374 ldr, err := kt.ldr.New(path)
take care of this case?
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.
The problem with the error handling of line 374 is that it wraps the initial error with the error of the ldr.New() call and we end up with a very long error which half does not make any sens, i.e., no such file or directory
for an URL:
Error: accumulating resources: accumulation err='accumulating resources from 'https://github.com/fluxcd/source-controller/releases/download/v0.19.0/source-controller.crds.yaml': URL returned error 503 (Service Unavailable)': evalsymlink failure on '/private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases/download/v0.19.0/source-controller.crds.yaml' : lstat /private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases: no such file or directory
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.
Understood, thanks! In that case, can we move these two lines to within the error handling of line 374? E.g.
ldr, err := kt.ldr.New(path)
if err != nil {
if errors.Is(errF, load.ErrorHTTP) {
return nil, errF
}
return nil, errors.Wrapf(
err, "accumulation err='%s'", errF.Error())
}
Perhaps this is messier, but the intent of this code is:
- Try to load the resource as a file.
- If that fails, then regardless of the reason for the error, try to load it as a directory.
- If that also fails, return the error from step 1.
I would like to keep the code as close to its original thought process as possible, while still supporting the improved error message you've added.
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.
I don't like it to be honest, this feels really weird.
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.
Can you elaborate? My intent is so that the code is changed as little as possible while still handling your error case. If we are improving the error message, IMO the check should go in the error handling. It will be helpful to have more justification than "this feels really weird" if you want to put it elsewhere.
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.
It would be very strange to expect that to load from the filesystem, and if it is somehow happening, I don't think it is behaviour we should preserve.
Unfortunately, that code path also handles remote bases which can have https
schemes and it does cause breakage.
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.
Can you share a kustomization example that reproduces the breakage you are talking about ? Thank you.
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.
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.
resources:
- https://github.com/kubernetes-sigs/kustomize.git//examples/multibases/dev/?ref=v1.0.6
works fine in kustomize 4.4 but gives a 404 not found error in 4.5
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.
@natasha41575 absolutely, I'll try to fix that today or tomorrow.
|
||
httpErr := fmt.Errorf("%w: status code %d (%s)", loader.ErrorHTTP, 404, http.StatusText(404)) | ||
accuFromErr := fmt.Errorf("accumulating resources from '%s': %w", url404, httpErr) | ||
expectedErr := fmt.Errorf("accumulating resources: %w", accuFromErr) |
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.
So the error we will get is accumulating resources: accumulating resources from 'https://github.com/thisisa404.yaml': HTTP error: status code 404 (not found)
. That's a pretty good description, probably much more helpful than whatever we were outputting before.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: natasha41575, sylr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
GitHub release files like https://github.com/fluxcd/helm-controller/releases/download/v0.14.0/helm-controller.crds.yaml
seems to be hosted on Azure and it seems that there are egress limits that can be reached, e.g.:
This patch allows to have a clear Error message instead of just
missing Resource metadata
:Signed-off-by: Sylvain Rabot [email protected]