-
Notifications
You must be signed in to change notification settings - Fork 256
add error types for kptfile validation and image #1999
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8c344e2
add error types for kptfile validation and image
Shell32-Natsu 3adb1ba
Merge branch 'next' into docker-errors
Shell32-Natsu 2748188
code review
Shell32-Natsu 3db84fe
update error message
Shell32-Natsu 7d514eb
code review
Shell32-Natsu a15600a
Merge branch 'next' into docker-errors
Shell32-Natsu 0b401fc
update image-nonexist test case
Shell32-Natsu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
| // Copyright 2021 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package resolver | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/GoogleContainerTools/kpt/internal/fnruntime" | ||
| ) | ||
|
|
||
| //nolint:gochecknoinits | ||
| func init() { | ||
| AddErrorResolver(&containerImageErrorResolver{}) | ||
| } | ||
|
|
||
| // containerImageErrorResolver is an implementation of the ErrorResolver interface | ||
| // to resolve container image errors. | ||
| type containerImageErrorResolver struct{} | ||
|
|
||
| func (*containerImageErrorResolver) Resolve(err error) (ResolvedResult, bool) { | ||
| var containerImageError *fnruntime.ContainerImageError | ||
| if !errors.As(err, &containerImageError) { | ||
| return ResolvedResult{}, false | ||
| } | ||
| return ResolvedResult{ | ||
| Message: containerImageError.Error(), | ||
| ExitCode: 1, | ||
| }, true | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -163,7 +163,10 @@ func (f *ContainerFn) prepareImage() error { | |
| var output []byte | ||
| var err error | ||
| if output, err = cmd.CombinedOutput(); err != nil { | ||
| return fmt.Errorf("failed to check local function image %q: %w", f.Image, err) | ||
| return &ContainerImageError{ | ||
| Image: f.Image, | ||
| Output: string(output), | ||
| } | ||
| } | ||
| if strings.Contains(string(output), strings.Split(f.Image, ":")[0]) { | ||
| // image exists locally | ||
|
|
@@ -178,8 +181,22 @@ func (f *ContainerFn) prepareImage() error { | |
| ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
| defer cancel() | ||
| cmd = exec.CommandContext(ctx, dockerBin, args...) | ||
| if _, err := cmd.CombinedOutput(); err != nil { | ||
| return fmt.Errorf("function image %q doesn't exist", f.Image) | ||
| if output, err := cmd.CombinedOutput(); err != nil { | ||
| return &ContainerImageError{ | ||
| Image: f.Image, | ||
| Output: string(output), | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ContainerImageError is an error type which will be returned when | ||
| // the container run time cannot verify docker image. | ||
| type ContainerImageError struct { | ||
| Image string | ||
| Output string | ||
| } | ||
|
|
||
| func (e *ContainerImageError) Error() string { | ||
| return fmt.Sprintf("Function image %q doesn't exist.", e.Image) | ||
| } | ||
|
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. Just a note: Eventually, we should develop our own little abstraction |
||
This file contains hidden or 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 hidden or 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 hidden or 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.
Ideally,
kptshould be able to refer to thefunctionConfigfile that has this error, but that will require associating error with the location inKptfileetc and is a bit non-trivial to do. But the previous error containedfunction name, that was helpful in narrow down whichfunctionConfigthe error is referring to. so may be just prependFunction image "gcr.io/....":to the new error 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.
The message is in
Reasonof the error output. There is aFieldvalue in the output which is a path to the field which has issue.IMO this is more accurate.
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.
Oh, my bad, I forgot about the complete CLI out. I thought this is what the user will see. Thanks