-
Notifications
You must be signed in to change notification settings - Fork 263
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
improved create service error message #312
improved create service error message #312
Conversation
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.
@odra: 0 warnings.
In response to this:
Fixes #159
Proposed Changes
- Checks if the error when creating a service is a "NotFound" error and returns a custom error message
Release Note
NONE
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.
Hi @odra. Thanks for your PR. I'm waiting for a knative 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. |
4361a48
to
5fec4bf
Compare
5fec4bf
to
cc31f2e
Compare
@@ -134,6 +134,9 @@ func flush(out io.Writer) { | |||
func createService(client v1alpha1.KnClient, service *serving_v1alpha1_api.Service, namespace string, out io.Writer) error { | |||
err := client.CreateService(service) | |||
if err != nil { | |||
if api_errors.IsNotFound(err) { |
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.
Fixes for service create, but other commands would still report the error mentioned in issue, I think this needs to be fixed in more generic way which applies to other commands as well.
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 could implement it in the KnClient
level for each method if that makes sense
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.
Good idea. Maybe rephrase to a shorter sentence like (and to put knative later in the sentence to allow the proper capitalization):
no Knative serving API found on the backend. Please verify the installation.
open for other suggestions, though. I wonder whether we should also wrap the original error ? But I think there is no extra context information in that error which goes beyond that information.
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 thought about wrapping it into a custom error struct but there is not a lot of information returned by the original error struct itself besides the error message.. could still be useful in the future, idk :)
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.
/ok-to-test
cde74fb
to
7935c1f
Compare
"strings" | ||
) | ||
|
||
func newInvalidCRD(apiGroup string) *KNError { |
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.
decided to make to more generic to be used for more types if needed
"strings" | ||
) | ||
|
||
func isCRDError(status api_errors.APIStatus) bool { |
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 added it here since we only have one for now
pkg/errors/factory.go
Outdated
return false | ||
} | ||
|
||
func Build(err error) error { |
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 created a error package to deal with this, it returns a valid error interface + the APIStatus object as well.
It returns the original error in case of a casting error or if the error could not be identified by the error package
|
||
import api_errors "k8s.io/apimachinery/pkg/api/errors" | ||
|
||
type KNError struct { |
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.
using a generic error struct for now, each error could use its own struct if neededin the future
pkg/errors/factory.go
Outdated
|
||
func isCRDError(status api_errors.APIStatus) bool { | ||
for _, cause := range status.Status().Details.Causes { | ||
if strings.HasPrefix(cause.Message, "404") && cause.Type == v1.CauseTypeUnexpectedServerResponse { |
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 inspected the APIStatus error returned by kubernetes and saw that it returned a 404 error within the causes
array, this does not happen in case it is a usual not found error.
) | ||
|
||
func newInvalidCRD(apiGroup string) *KNError { | ||
parts := strings.Split(apiGroup, ".") |
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 would like some feedback on this approach, I am using the first item in the resource group as the "api name" - both serving and revision return serving
/retest |
0a18252
to
79938ef
Compare
/retest |
|
||
err = newInvalidCRD("") | ||
assert.Error(t, err, "no Knative API found on the backend. Please verify the installation.") | ||
|
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.
Why the last extra line?
err := newInvalidCRD("serving.knative.dev") | ||
assert.Error(t, err, "no Knative serving API found on the backend. Please verify the installation.") | ||
|
||
err = newInvalidCRD("serving") |
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.
But “serving” would be a valid API group name, no? Why not use something like “fake-serving”?
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.
this function just creates an error struct based on the api group string that is sent as argument - those tests verifies if the api name was properly parsed.
return err | ||
} | ||
|
||
var knerr *KNError |
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.
New line not needed...
pkg/errors/factory.go
Outdated
return false | ||
} | ||
|
||
func Build(err error) error { |
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.
“Build” seems a misnomer for this function? Also it’s public so add a comment.
pkg/errors/factory_test.go
Outdated
) | ||
|
||
func TestBuild(t *testing.T) { | ||
//default non api error |
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 would separate these cases into their own
t.Run(“default non API error”, func(t *testing.T){
})
This allows some parallelism, clarifies the output (and error) since each test gets the title added to it’s run output. You might need to be clever for setup and tear down. See some of the other tests for examples, e.g., tests in plugin or in core
package.
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package errors |
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.
Is a new package needed here? If this ends up being the only error, I would say no, if not then definitely. Not clear we had any new errors until now. Might be something to poll or get feedback from the group on.
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.
Overall, I don’t hate this. Left some comments that should be easy to address. The main concern would be in adding new package. For me, I’d be OK as long as this package does not end up being the sole one for the package. Since that would make it “lonely and sad” but seriously an abuse of packaging :)
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: maximilien, odra 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 |
I wasn't sure if it needed a package on its own as well but I thought it makes sense if more errors get added in there - I could add it in a errors.go file with the client package if you want to. |
The following is the coverage report on pkg/.
|
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 like this better. Still ambivalent about creating new errors
package.
Would be good to have some other opinions on this? @rhuss or @navidshaikh or others.
Left a message asking the others for their opinions. Let's see if anyone feels strongly one way or the other. Thanks for your patience. |
/lgtm Overall I like it. Gives us a place for error translation in The Future, which we can refactor as needed. |
/test pull-knative-client-integration-tests-latest-release |
This is required when running the script from Prow jobs, to establish the authentication. Bonuses: * update documentation * used the term "gcr" instead of project to clearly differentiate from the GCP projects parsed from a YAML file * separated the deletion functions for testing purposes * assorted code refactoring, documentation, simplification, fixing and nitpicking
Fixes #159
Proposed Changes
Release Note