-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
enable webhooks with multiple sources #8580
enable webhooks with multiple sources #8580
Conversation
lgtm but needs test cases |
[test] |
@mfojtik @bparees PTAL. still pending test cases green, but last time they flaked. |
just noticed, tests are still failing. will fix. |
// REVIEW: a real world scenario is that we don't use the same request to | ||
// verify a secret. if that would be the case, then the req.body is already | ||
// consumed for that request after the first try and we return proceed=true | ||
// here even when the git ref doesn't match (which shouldn't happen). |
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.
sorry i'm not following the scenario you're trying to describe
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 was ambiguous in this note. i thought we might reuse a request somewhere else, but i don't see a real case scenario. you have a webhook request, you trigger a build or fail if it doesn't match the ref/secret. it's that simple. i was over thinking it
i fixed the tests, finally. wondering if this works [testonlyintegration] |
[test] |
well, tests fail because of #7429 |
[test] |
@bparees finally it's green, can you take a look whenever you have time |
} | ||
glog.V(2).Infof("Skipping build for BuildConfig %s/%s. None of the supplied refs matched %q", buildCfg.Namespace, buildCfg, git.Ref) | ||
glog.V(2).Infof("Skipping build for BuildConfig %s/%s. None of the supplied refs matched %q", buildCfg.Namespace, buildCfg, buildCfg.Spec.Source.Git.Ref) | ||
return nil, false, nil |
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 return needs to be outside the for loop. you're going to check the first ref and if it doesn't match, return false.
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.
which also means we need better tests.
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.
also since you removed the check for nil, you're always going to return false without checking the data.Git.Ref field, so you need to put that nil check back in.
which again means we need better tests.
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.
gotcha, thanks!
@bparees btw since now there could be possible multiple webhooks do we need to ping the UI team and tell them do add them to the webconsole? right now i think only one type of source shows up there |
@PI-Victor @bparees thanks for heads up. Yeap this was already taken care in as part of jwforres#55 |
this was just pending some tests but now i need to refactor this, since, after rebase, this #8477 broke everything. |
@bparees PTAL. i've eliminated URL tag from the oc describe bc because there are no other tags on the right side of the description. Formatting not that great on github, but they're actually aligned, if you feel strong about keeping the URL tag, i'll add it back.
|
it looks strange having the first url on the same line as the label, and then the rest indented. I think we should just start a new line after the label, eg:
as for URL label removal, we have it for AllowEnv in your example, so i think we should keep it, though it's not totally necessary..but it looks weird not to have it when we have AllowEnv. |
fair point
|
@bparees done. also i figured out in the end there were test cases for different refs so i didn't add anything, i just adapted everything to account for multiple webhooks, i'm not sure what else to do at this point and i hate to say it but maybe it's the way that the whole plugin system for these webhooks is written, that is a problem rather than the tests, what do you think? |
req := GivenRequest("GET") | ||
revision, _, proceed, err := plugin.Extract(buildConfig, secret, "", req) | ||
if err == nil || !strings.Contains(err.Error(), "Unsupported HTTP method") { | ||
t.Errorf("Excepcted unsupported HTTP method, got %v!", 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.
Expected
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.
ah i fixed this but lost it during rebase :D
@openshift/api-review needs review of new describe output for multiple webhooks. @PI-Victor one typo, otherwise lgtm. Regarding what you did w/ the tests: it's ok, but next time around i'd just create a single new test or two that confirms:
Adding the loop to all the other TCs is kinda overkill. |
|
@deads2k yeah the concern is not compatibility, but describe output seems to fall under the api review team's area of interest/approval. |
@bparees thanks for the tip. i suck at writing tests, that's for sure. i can actually do just what you suggested instead of introducing bogus stuff in testing, plus it's not hard to do and also would not take long. i'd like to do it properly |
@PI-Victor knock yourself out, it'll make my rebase for refactoring the webhooks a little easier too. |
if configRef == "" { | ||
configRef = "master" | ||
func GitRefMatches(eventRef string, buildSource *api.BuildSource) bool { | ||
configRef := "master" |
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.
hoist this out to a constant and require it to be passed in - this method shouldn't infer "master"
@bparees ping! i've reviewed the tests cases and also added tests for the webhook.go "controller" hopefully i reduced your work with that. *fingers crossed |
|
||
if triggers == nil { | ||
t.Error("Expected a slice of matched 'triggers', got nil") | ||
} |
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 check the # of matches.
@PI-Victor couple TC nits and then lgtm. |
@bparees btw, what you suggested above was fixed. can we merge? |
t.Error("Expected a slice of matched 'triggers', got nil") | ||
} | ||
|
||
if len(triggers) < 3 { |
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 not check the exact size?
@PI-Victor i'm merging this so we can move on, but i'm not sure why you didn't check for an exact size in your tests. |
i did actually :/, but it went in with some other changes in the git stash. should i fix it now, or are you going to in you PR? |
@PI-Victor go ahead and fix it. |
(merge tag removed) |
*fix oc describe to show multiple webhooks when defined and adapt to the new allowenv variable for generic webhooks *refactor and abstract logic for validating secrets and defined webhooks *fix a bug where the webhook panics whenever the buildconfig source isn't a git repository *adapt current tests to account for multiple webhooks. Signed-off-by: PI-Victor <[email protected]>
Evaluated for origin test up to 93e067e |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/3631/) |
thanks @PI-Victor! [merge] |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/5829/) (Image: devenv-rhel7_4120) |
Evaluated for origin merge up to 93e067e |
fixes: #8551
fixes: #8619
@liggitt @bparees PTAL
*fix oc describe to show multiple webhooks when defined
*refactor and abstract logic for validating secrets and defined webhooks
*fix a bug where the webhook panics whenever the buildconfig source isn't a git repository
Dunno yet what tests fail, so it's still work in progress. Also need to write new tests.
oc describe output now:
single source for each type
multiple sources for one type
Signed-off-by: PI-Victor [email protected]