Skip to content

provide the ability to modify the prefix of error reporting and ignor… - #11639

Merged
openshift-bot merged 1 commit into
openshift:masterfrom
pweil-:bulk-level-filter
Nov 1, 2016
Merged

openshift-bot merged 1 commit into
openshift:masterfrom
pweil-:bulk-level-filter

Conversation

@pweil-

@pweil- pweil- commented Oct 28, 2016

Copy link
Copy Markdown

…e some errors in cmd operations

@ffranz - proposed for https://bugzilla.redhat.com/show_bug.cgi?id=1332432

Provides the ability to not include errors during run which in turn controls Failure or Success message output. Additionally allows customization of the prefix used during the bulk action so you can choose to report warnings, hints, or anything else in the message.

@openshift/cli-review

@pweil-

pweil- commented Oct 28, 2016

Copy link
Copy Markdown
Author

Example output:

 $ oadm router
info: password for stats user admin has been set to y1LmlIYswk
--> Creating router router ...
    warning: serviceaccounts "router" already exists
    warning: clusterrolebinding "router-router-role" already exists
    deploymentconfig "router" created
    service "router" created
--> Success

@liggitt

liggitt commented Oct 28, 2016

Copy link
Copy Markdown
Contributor

this seems like turning human readable messages into an API, which we don't want to do.

Comment thread pkg/cmd/admin/router/router.go Outdated

if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 {
levelFilter := func(e error) string {
if match, _ := regexp.MatchString("serviceaccounts|rolebinding.*already exists", e.Error()); match {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems super fragile

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be anything that you'd consider less fragile, a check against IsAlreadyExists and then looking for SA for example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you have a well qualified error here, and a IsAlreadyExists check from the api would work. Definitely better.

@pweil-

pweil- commented Oct 28, 2016

Copy link
Copy Markdown
Author

this seems like turning human readable messages into an API, which we don't want to do.

other suggestions? I considered just iterating through the list of returned errors in the command itself and parsing them out that way however that doesn't improve any of the output. It will still show "error:" and "Failure".

@pweil-

pweil- commented Oct 28, 2016

Copy link
Copy Markdown
Author

Thinking about this a bit more, could you elaborate a bit on your stance here? This is not touching any part of the message other than the prefix which was hardcoded to "error" and the ability to control reporting "Success" vs "Failure" of a bulk action.

Most of that is already controllable with the Bulk.After anyway, this just allows a little more fine grained control on the default mechanisms (NewPrintNameOrErrorAfterIndent).

@pweil-

pweil- commented Oct 28, 2016

Copy link
Copy Markdown
Author

[test]

Comment thread pkg/cmd/admin/router/router.go Outdated

if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 {
levelFilter := func(e error) string {
if match, _ := regexp.MatchString("serviceaccounts|rolebinding.*already exists", e.Error()); match {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you have a well qualified error here, and a IsAlreadyExists check from the api would work. Definitely better.

Comment thread pkg/config/cmd/cmd.go Outdated

// ErrorFilterFunc provides a way to filter errors during the Bulk.Run. This may be used in conjunction with
// BulkAction.WithMessageAndPrefix if you are reporting items as warnings.
type ErrorFilterFunc func(e error) bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very clear to me what the return value means, does a true means "filter out" or "keep it"? Mention it in the doc, or call it IgnoreErrorFunc, BypassErrorFunc, FatalErrorFunc, or something similar.

Comment thread pkg/config/cmd/cmd.go Outdated

func (b BulkAction) WithMessage(action, individual string) Runner {
// PrefixFilter allows customization of the prefix that will be printed for any error that occurs in the BulkAction.
type PrefixFilter func(e error) string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe PrefixForError, ErrorPrefixMsg, or something similar?

@pweil-
pweil- force-pushed the bulk-level-filter branch from 9d20a01 to ba6d3aa Compare October 28, 2016 17:34
@pweil-

pweil- commented Oct 28, 2016

Copy link
Copy Markdown
Author

@fabianofranz updated naming and docs based on feedback. PTAL

@pweil-
pweil- force-pushed the bulk-level-filter branch 2 times, most recently from f0c89df to 9d08c22 Compare October 28, 2016 18:09
Comment thread pkg/cmd/admin/router/router.go Outdated
// only ignore SA/RB errors if we were creating the service account and
// check for their specific type/name combination
if errors.IsAlreadyExists(e) && createServiceAccount {
if strings.Contains(e.Error(), "serviceaccounts") && strings.Contains(e.Error(), cfg.ServiceAccount) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error you get here is a errors.StatusError, in which case you would have Kind and Name well structured to perform this comparison. Can you confirm?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is. Updated to use StatusError's Details and broke it out into a method since it was getting a bit long with casts and nil checks.

@pweil-
pweil- force-pushed the bulk-level-filter branch from 9d08c22 to 4b35045 Compare October 28, 2016 19:27

@fabianofranz fabianofranz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit otherwise LGTM, @liggitt anything else?

Comment thread pkg/cmd/admin/router/router.go Outdated
}

if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 {
levelFilter := func(e error) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

levelPrefixer? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

@pweil-
pweil- force-pushed the bulk-level-filter branch from 4b35045 to cfd133f Compare October 31, 2016 13:24
@pweil-

pweil- commented Oct 31, 2016

Copy link
Copy Markdown
Author

@pweil-
pweil- force-pushed the bulk-level-filter branch from cfd133f to 08423a7 Compare October 31, 2016 16:56
@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin test up to 08423a7

@openshift-bot

Copy link
Copy Markdown
Contributor

@fabianofranz

Copy link
Copy Markdown
Contributor

[merge]

2 similar comments
@pweil-

pweil- commented Nov 1, 2016

Copy link
Copy Markdown
Author

[merge]

@pweil-

pweil- commented Nov 1, 2016

Copy link
Copy Markdown
Author

[merge]

@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin merge up to 08423a7

@openshift-bot

openshift-bot commented Nov 1, 2016 •

Copy link
Copy Markdown
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10920/) (Base Commit: 751085f) (Image: devenv-rhel7_5289)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants