Skip to content
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

Add git ls-remote to validate the remote GIT repository #5573

Merged
merged 2 commits into from
Nov 19, 2015

Conversation

mfojtik
Copy link
Contributor

@mfojtik mfojtik commented Nov 2, 2015

Fixes: #4564
Fixes: #5944

@bparees @soltysh this will use git ls-remote command to check the source repository URL. It should pickup all credentials we have for the GIT in case the repo is private. It also perform check if the repository is reachable. Proxy vars should be picked up as well (I didn't tested this).

@@ -27,6 +26,10 @@ const (
urlCheckTimeout = 16 * time.Second
)

var (
GitAuthenticationError, GitNotFoundError error
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't these nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, should stop drinking

Copy link
Contributor

Choose a reason for hiding this comment

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

These should be error types. See for example

@soltysh
Copy link
Contributor

soltysh commented Nov 2, 2015

Other than what Michalis already pointed out, looks good.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

@soltysh @Kargakis thanks, errors fixed.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

[test]

@soltysh
Copy link
Contributor

soltysh commented Nov 2, 2015

LGTM

succ := make(chan bool, 1)
go func() {
out, err = cmd.CombinedOutput()
succ <- true
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't really care about this value so this should be an empty struct.

@0xmichalis
Copy link
Contributor

one more nit, LGTM otherwise

@0xmichalis
Copy link
Contributor

Actually can you add a test case for this as well?

@bparees
Copy link
Contributor

bparees commented Nov 2, 2015

if this works with proxies, you should remove the logic that skips this check when a proxy is set.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

i fixed everything, but do not merge this yet, need to test if the proxy stuff works as expected

// remote repository failed to authenticate.
// Since this is calling the 'git' binary, the proxy settings should be
// available for this command.
func checkRemoteGit(url string, timeout time.Duration) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the original issue was a long hang when an invalid IP or host was specified... does this fail fast in cases like that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the timeout, but not a test exercising it... is that possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt it hangs when it was asking for password in case you have private repos.... and yes, there is no test exercising this, something I have to follow up

Copy link
Contributor

Choose a reason for hiding this comment

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

@mfojtik there was also an issue with long hangs when the hostname didn't exist (or rather the hostname existed, but nothing was listening at the other end), as @liggitt was saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bparees the timeout should take care of that issue IMHO, but agree with @liggitt we should have extended test that exercise this... will need some fake server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i can, also I think github is asking me for a password even if I request "https://github.com/openshift/foo"

Copy link
Contributor

Choose a reason for hiding this comment

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

Per #3624 it would be good not to rely on external services, using Jordan's idea of httptest returning 401 is preferable, imho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@soltysh @liggitt already done, the test is not depending on anything external now

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@soltysh i would not be that optimistic, I might revert the github test to have positive case ;-)

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

@bparees tested with proxy/without proxy and by accident tested also the timeout... it all works, so this is mergeable now

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

[test] again

if !testConnection {
return nil

if strings.Contains(string(out), "Authentication failed") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a switch

@mfojtik mfojtik force-pushed the fix-git-check branch 2 times, most recently from 7e614a1 to 4724788 Compare November 2, 2015 15:41
@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2015

@liggitt @bparees test case added

@bparees
Copy link
Contributor

bparees commented Nov 2, 2015

@mfojtik this works when going through a proxy? the scenario that was broken before that lead to reworking this was a git server that could only be reached via proxy. (the testing that was done which was insufficient was accessing a git server via a proxy, when that git server could also be reached w/o using the proxy)

if err != nil {
t.Errorf("expected no error, got %q", err)
}
err = checkRemoteGit("https://254.254.254.254/foo/bar", 10*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

lower the time limit, we don't want this test to take 30 seconds to run

Copy link
Contributor

Choose a reason for hiding this comment

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

20 seconds. one of those tests won't normally hit the timeout.

Copy link
Contributor

Choose a reason for hiding this comment

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

/pedant

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't say it would take 30 seconds. I said I didn't want it to take 30 seconds, which I don't 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

well it won't, so desire met? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are two now :-) the first one should never hit the timeout, I will lower the second one :-) is that ok?

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2015

@liggitt @bparees rebased and test fixed (no more github ;-)

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2015

[test]

@bparees bparees changed the title Add git ls-remote to validate the remote GIT repository [POST-3.1] Add git ls-remote to validate the remote GIT repository Nov 3, 2015
// ignored. This command will replace git:// with https:// in that case.
if strings.HasPrefix(gitSource.URI, "git://") {
glog.V(4).Infof("Using https:// instead of git:// prefix for %q", gitSource.URI)
out, err := exec.Command("git", "config", "--global", `url."https://".insteadOf git://`).CombinedOutput()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bparees sanity check required

@mfojtik mfojtik force-pushed the fix-git-check branch 3 times, most recently from 34c27af to 611ad20 Compare November 18, 2015 14:17

// When the protocol is git:// the HTTPS_PROXY and HTTP_PROXY variables are
// ignored. This command will replace git:// with https:// in that case.
if strings.HasPrefix(gitSource.URI, "git://") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is wrong... the git:// protocol is not http/https-based, and should not be using http_proxy/https_proxy. It's over a completely different port, so switching to https:// could actually break the check (https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#The-Git-Protocol)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt the command bellow this will set it global, so the clone (if https succeed) will work normally.

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test Waiting: Determining build queue position

@mfojtik mfojtik force-pushed the fix-git-check branch 2 times, most recently from 61e1ad0 to d69b2b0 Compare November 18, 2015 15:52
@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 18, 2015

[testonlyextended][extended:core(s2i build with proxy)]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to ebbbcc0

@openshift-bot
Copy link
Contributor

Evaluated for origin testonlyextended up to ebbbcc0

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/7212/) (Extended Tests: core(s2i build with proxy))

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/testonlyextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/7218/) (Extended Tests: core(s2i build with proxy))

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 18, 2015

@bparees ready for review/merge

@bparees
Copy link
Contributor

bparees commented Nov 18, 2015

[merge]

1 similar comment
@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 19, 2015

[merge]

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 19, 2015

[merge] !

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/4058/) (Image: devenv-rhel7_2742)

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 19, 2015

@bparees @csrwng each merge failed with different flaky test :-)

This time, new-app is the winner:

I1119 04:46:11.727845     509 newapp.go:533] Using "https://github.com/openshift/ruby-hello-world" as the source for build
error: installing "installable:file" requires that you grant the image access to run with your credentials

Previously it was new-app again:

!!! Error in test/cmd/newapp.sh:65
    '[ "$(oc new-app --search --image-stream=postgresql | grep -E "Tags:\s+9.2, 9.4, latest")" ]' exited with status 1

And before it was timeout starting openshift server :-)

@csrwng
Copy link
Contributor

csrwng commented Nov 19, 2015

The merge failure is an integration test flake:

--- FAIL: TestConcurrentBuildControllers-2 (6.84s)
    buildcontroller_test.go:109: Error: received unexpected build status: New

which is assigned to me: #5937
I'm making it a priority to get it fixed this morning.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 19, 2015

[merge]

(an innocent chicken was sacrificed)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to ebbbcc0

openshift-bot pushed a commit that referenced this pull request Nov 19, 2015
@openshift-bot openshift-bot merged commit aa8e6ba into openshift:master Nov 19, 2015
@mfojtik mfojtik deleted the fix-git-check branch September 5, 2018 21:07
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.

8 participants