-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add ability to custom handle redirects #5678
base: master
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 | ||
---|---|---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |||
"sigs.k8s.io/kustomize/api/ifc" | ||||
"sigs.k8s.io/kustomize/api/internal/git" | ||||
"sigs.k8s.io/kustomize/api/konfig" | ||||
"sigs.k8s.io/kustomize/kyaml/errors" | ||||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||||
) | ||||
|
||||
|
@@ -659,6 +660,35 @@ func TestLoaderHTTP(t *testing.T) { | |||
_, err := l2.Load(x.path) | ||||
require.Error(err) | ||||
} | ||||
|
||||
var testCaseRedirect = []testData{ | ||||
{ | ||||
path: "https://example.com/resource.yaml", | ||||
expectedContent: "https content", | ||||
}, | ||||
Comment on lines
+664
to
+668
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. Looking at the code below, do you plan to add more tests? 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. I have no plans to add another tests. |
||||
} | ||||
for _, x := range testCaseRedirect { | ||||
expectedLocation := "https://test.com/resource.yaml" | ||||
hc := makeFakeHTTPClient(func(req *http.Request) *http.Response { | ||||
response := &http.Response{ | ||||
StatusCode: MultipleChoicesRedirectCode, | ||||
Body: io.NopCloser(bytes.NewBufferString("")), | ||||
Header: make(http.Header), | ||||
} | ||||
response.Header.Add("Location", expectedLocation) | ||||
return response | ||||
}) | ||||
l2 := l1 | ||||
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. What does 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. It is loaders. I use solution from testcase from
|
||||
l2.http = hc | ||||
_, err := l2.Load(x.path) | ||||
require.Error(err) | ||||
var redErr *RedirectionError | ||||
var path string = "" | ||||
if errors.As(err, &redErr) { | ||||
path = redErr.NewPath | ||||
} | ||||
require.Equal(expectedLocation, path) | ||||
} | ||||
} | ||||
|
||||
// setupOnDisk sets up a file system on disk and directory that is cleaned after | ||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -423,7 +423,12 @@ func (kt *KustTarget) accumulateResources( | |||||
if errors.Is(errF, load.ErrHTTP) { | ||||||
return nil, errF | ||||||
} | ||||||
var redErr *load.RedirectionError | ||||||
if errors.As(errF, &redErr) { | ||||||
path = redErr.NewPath | ||||||
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. I think this code is using redirect 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. I investigated in these scenarious
|
||||||
} | ||||||
ldr, err := kt.ldr.New(path) | ||||||
|
||||||
if err != nil { | ||||||
// If accumulateFile found malformed YAML and there was a failure | ||||||
// loading the resource as a base, then the resource is likely a | ||||||
|
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.
Maybe That is better to solve redirects here than return
RedirectionError
and a new path.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.
Hi! It does not work in all cases. For example if I return redirect to git. In that case httpClient has noe credentials for download content