-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
49b464f
Handle HTTP error codes in file loader
sylr e65e571
Do not try to load HTTP resources from FS when error occurs
sylr 738573b
Error on HTTP resources are not nescessarly protocol related
sylr 16495c6
Test HTTP Error thrown by the file loader
sylr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,15 @@ | |
package krusty_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/kustomize/api/internal/utils" | ||
"sigs.k8s.io/kustomize/api/krusty" | ||
"sigs.k8s.io/kustomize/api/loader" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
) | ||
|
||
|
@@ -74,6 +77,31 @@ spec: | |
assert.NoError(t, fSys.RemoveAll(tmpDir.String())) | ||
} | ||
|
||
func TestRemoteResourceWithHTTPError(t *testing.T) { | ||
fSys := filesys.MakeFsOnDisk() | ||
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) | ||
tmpDir, err := filesys.NewTmpConfirmedDir() | ||
assert.NoError(t, err) | ||
|
||
url404 := "https://github.com/thisisa404.yaml" | ||
kusto := filepath.Join(tmpDir.String(), "kustomization.yaml") | ||
assert.NoError(t, fSys.WriteFile(kusto, []byte(fmt.Sprintf(` | ||
resources: | ||
- %s | ||
`, url404)))) | ||
|
||
_, err = b.Run(fSys, tmpDir.String()) | ||
if utils.IsErrTimeout(err) { | ||
// Don't fail on timeouts. | ||
t.SkipNow() | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. So the error we will get is |
||
assert.EqualErrorf(t, err, expectedErr.Error(), url404) | ||
} | ||
|
||
func TestRemoteResourceAnnoOrigin(t *testing.T) { | ||
fSys := filesys.MakeFsOnDisk() | ||
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package loader | ||
|
||
import "fmt" | ||
|
||
var ErrorHTTP = fmt.Errorf("HTTP Error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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.
Perhaps this is messier, but the intent of this code is:
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.
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.
It appears the test changed by #4030 used to pass and may have been broken by this PR. @sylr Would you be able to investigate and confirm?
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.
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.