-
Notifications
You must be signed in to change notification settings - Fork 35
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
backport proxy and custom timeout support to console v4.11 #148
Merged
kim-tsao
merged 1 commit into
devfile:console-4.11-release
from
kim-tsao:console-4.11-release
Oct 18, 2022
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -81,6 +81,8 @@ type ParserArgs struct { | |
Context context.Context | ||
// K8sClient is the Kubernetes client instance used for interacting with a cluster | ||
K8sClient client.Client | ||
// HTTPTimeout overrides the request and response timeout values for reading a parent devfile reference from the registry. If a negative value is specified, the default timeout will be used. | ||
HTTPTimeout *int | ||
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. any particular reason we make it a pointer? 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. yes, it's to determine if this value is unset or not. If unset, we will use the default value of 30s |
||
} | ||
|
||
// ParseDevfile func populates the devfile data, parses and validates the devfile integrity. | ||
|
@@ -104,6 +106,7 @@ func ParseDevfile(args ParserArgs) (d DevfileObj, err error) { | |
registryURLs: args.RegistryURLs, | ||
context: args.Context, | ||
k8sClient: args.K8sClient, | ||
httpTimeout: args.HTTPTimeout, | ||
} | ||
|
||
flattenedDevfile := true | ||
|
@@ -138,6 +141,8 @@ type resolverTools struct { | |
context context.Context | ||
// K8sClient is the Kubernetes client instance used for interacting with a cluster | ||
k8sClient client.Client | ||
// httpTimeout is the timeout value in seconds passed in from the client. | ||
httpTimeout *int | ||
} | ||
|
||
func populateAndParseDevfile(d DevfileObj, resolveCtx *resolutionContextTree, tool resolverTools, flattenedDevfile bool) (DevfileObj, error) { | ||
|
@@ -378,7 +383,7 @@ func parseFromRegistry(importReference v1.ImportReference, resolveCtx *resolutio | |
id := importReference.Id | ||
registryURL := importReference.RegistryUrl | ||
if registryURL != "" { | ||
devfileContent, err := getDevfileFromRegistry(id, registryURL) | ||
devfileContent, err := getDevfileFromRegistry(id, registryURL, tool.httpTimeout) | ||
if err != nil { | ||
return DevfileObj{}, err | ||
} | ||
|
@@ -392,7 +397,7 @@ func parseFromRegistry(importReference v1.ImportReference, resolveCtx *resolutio | |
|
||
} else if tool.registryURLs != nil { | ||
for _, registryURL := range tool.registryURLs { | ||
devfileContent, err := getDevfileFromRegistry(id, registryURL) | ||
devfileContent, err := getDevfileFromRegistry(id, registryURL, tool.httpTimeout) | ||
if devfileContent != nil && err == nil { | ||
d.Ctx, err = devfileCtx.NewByteContentDevfileCtx(devfileContent) | ||
if err != nil { | ||
|
@@ -411,13 +416,16 @@ func parseFromRegistry(importReference v1.ImportReference, resolveCtx *resolutio | |
return DevfileObj{}, fmt.Errorf("failed to get id: %s from registry URLs provided", id) | ||
} | ||
|
||
func getDevfileFromRegistry(id, registryURL string) ([]byte, error) { | ||
func getDevfileFromRegistry(id, registryURL string, httpTimeout *int) ([]byte, error) { | ||
if !strings.HasPrefix(registryURL, "http://") && !strings.HasPrefix(registryURL, "https://") { | ||
return nil, fmt.Errorf("the provided registryURL: %s is not a valid URL", registryURL) | ||
} | ||
param := util.HTTPRequestParams{ | ||
URL: fmt.Sprintf("%s/devfiles/%s", registryURL, id), | ||
} | ||
|
||
param.Timeout = httpTimeout | ||
|
||
return util.HTTPGetRequest(param, 0) | ||
} | ||
|
||
|
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.
should include
HTTPTimeout
?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.
yes, good catch
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.
actually, that's just an example usage
HTTPTimeout
is optional so we can leave it out