Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Seipel
gitlab-runner
Commits
c4ee6fdd
Unverified
Commit
c4ee6fdd
authored
8 years ago
by
Tomasz Maczukin
Browse files
Options
Downloads
Patches
Plain Diff
Remove confusing compatibility check
parent
80b12155
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/client.go
+15
-17
15 additions, 17 deletions
network/client.go
network/gitlab.go
+0
-28
0 additions, 28 deletions
network/gitlab.go
network/gitlab_test.go
+0
-87
0 additions, 87 deletions
network/gitlab_test.go
with
15 additions
and
132 deletions
network/client.go
+
15
−
17
View file @
c4ee6fdd
...
@@ -49,17 +49,16 @@ var (
...
@@ -49,17 +49,16 @@ var (
type
client
struct
{
type
client
struct
{
http
.
Client
http
.
Client
url
*
url
.
URL
url
*
url
.
URL
caFile
string
caFile
string
certFile
string
certFile
string
keyFile
string
keyFile
string
caData
[]
byte
caData
[]
byte
skipVerify
bool
skipVerify
bool
updateTime
time
.
Time
updateTime
time
.
Time
lastUpdate
string
lastUpdate
string
compatibleWithGitLab
bool
requestBackOffs
map
[
string
]
*
backoff
.
Backoff
requestBackOffs
map
[
string
]
*
backoff
.
Backoff
lock
sync
.
Mutex
lock
sync
.
Mutex
}
}
type
ResponseTLSData
struct
{
type
ResponseTLSData
struct
{
...
@@ -361,12 +360,11 @@ func newClient(requestCredentials requestCredentials) (c *client, err error) {
...
@@ -361,12 +360,11 @@ func newClient(requestCredentials requestCredentials) (c *client, err error) {
}
}
c
=
&
client
{
c
=
&
client
{
url
:
url
,
url
:
url
,
caFile
:
requestCredentials
.
GetTLSCAFile
(),
caFile
:
requestCredentials
.
GetTLSCAFile
(),
certFile
:
requestCredentials
.
GetTLSCertFile
(),
certFile
:
requestCredentials
.
GetTLSCertFile
(),
keyFile
:
requestCredentials
.
GetTLSKeyFile
(),
keyFile
:
requestCredentials
.
GetTLSKeyFile
(),
compatibleWithGitLab
:
true
,
requestBackOffs
:
make
(
map
[
string
]
*
backoff
.
Backoff
),
requestBackOffs
:
make
(
map
[
string
]
*
backoff
.
Backoff
),
}
}
host
:=
strings
.
Split
(
url
.
Host
,
":"
)[
0
]
host
:=
strings
.
Split
(
url
.
Host
,
":"
)[
0
]
...
...
This diff is collapsed.
Click to expand it.
network/gitlab.go
+
0
−
28
View file @
c4ee6fdd
...
@@ -21,8 +21,6 @@ import (
...
@@ -21,8 +21,6 @@ import (
const
clientError
=
-
100
const
clientError
=
-
100
var
notSupportingGitLabPre90Message
=
"GitLab Runner >= 9.0 can be used ONLY with GitLab CE/EE >= 9.0"
type
GitLabClient
struct
{
type
GitLabClient
struct
{
clients
map
[
string
]
*
client
clients
map
[
string
]
*
client
lock
sync
.
Mutex
lock
sync
.
Mutex
...
@@ -95,28 +93,6 @@ func (n *GitLabClient) doJSON(credentials requestCredentials, method, uri string
...
@@ -95,28 +93,6 @@ func (n *GitLabClient) doJSON(credentials requestCredentials, method, uri string
return
c
.
doJSON
(
uri
,
method
,
statusCode
,
request
,
response
)
return
c
.
doJSON
(
uri
,
method
,
statusCode
,
request
,
response
)
}
}
func
(
n
*
GitLabClient
)
checkGitLabVersionCompatibility
(
runner
common
.
RunnerCredentials
)
{
request
:=
common
.
VerifyRunnerRequest
{
Token
:
"compatiblity-check"
,
}
result
,
statusText
,
_
:=
n
.
doJSON
(
&
runner
,
"POST"
,
"runners/verify"
,
http
.
StatusOK
,
&
request
,
nil
)
switch
result
{
case
http
.
StatusForbidden
:
runner
.
Log
()
.
Println
(
"Checking GitLab compatibility..."
,
"OK"
)
default
:
runner
.
Log
()
.
WithFields
(
logrus
.
Fields
{
"result"
:
result
,
"statusText"
:
statusText
,
"reason"
:
notSupportingGitLabPre90Message
,
})
.
Errorln
(
"Checking GitLab compatibility..."
,
"not-compatible"
)
c
,
_
:=
n
.
getClient
(
&
runner
)
c
.
compatibleWithGitLab
=
false
}
}
func
(
n
*
GitLabClient
)
RegisterRunner
(
runner
common
.
RunnerCredentials
,
description
,
tags
string
,
runUntagged
,
locked
bool
)
*
common
.
RegisterRunnerResponse
{
func
(
n
*
GitLabClient
)
RegisterRunner
(
runner
common
.
RunnerCredentials
,
description
,
tags
string
,
runUntagged
,
locked
bool
)
*
common
.
RegisterRunnerResponse
{
// TODO: pass executor
// TODO: pass executor
request
:=
common
.
RegisterRunnerRequest
{
request
:=
common
.
RegisterRunnerRequest
{
...
@@ -143,7 +119,6 @@ func (n *GitLabClient) RegisterRunner(runner common.RunnerCredentials, descripti
...
@@ -143,7 +119,6 @@ func (n *GitLabClient) RegisterRunner(runner common.RunnerCredentials, descripti
return
nil
return
nil
default
:
default
:
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
"Registering runner..."
,
"failed"
)
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
"Registering runner..."
,
"failed"
)
n
.
checkGitLabVersionCompatibility
(
runner
)
return
nil
return
nil
}
}
}
}
...
@@ -168,7 +143,6 @@ func (n *GitLabClient) VerifyRunner(runner common.RunnerCredentials) bool {
...
@@ -168,7 +143,6 @@ func (n *GitLabClient) VerifyRunner(runner common.RunnerCredentials) bool {
return
true
return
true
default
:
default
:
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
"Verifying runner..."
,
"failed"
)
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
"Verifying runner..."
,
"failed"
)
n
.
checkGitLabVersionCompatibility
(
runner
)
return
true
return
true
}
}
}
}
...
@@ -193,7 +167,6 @@ func (n *GitLabClient) UnregisterRunner(runner common.RunnerCredentials) bool {
...
@@ -193,7 +167,6 @@ func (n *GitLabClient) UnregisterRunner(runner common.RunnerCredentials) bool {
return
false
return
false
default
:
default
:
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
baseLogText
,
"failed"
)
runner
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Errorln
(
baseLogText
,
"failed"
)
n
.
checkGitLabVersionCompatibility
(
runner
)
return
false
return
false
}
}
}
}
...
@@ -245,7 +218,6 @@ func (n *GitLabClient) RequestJob(config common.RunnerConfig) (*common.JobRespon
...
@@ -245,7 +218,6 @@ func (n *GitLabClient) RequestJob(config common.RunnerConfig) (*common.JobRespon
return
nil
,
false
return
nil
,
false
default
:
default
:
config
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Warningln
(
"Checking for jobs..."
,
"failed"
)
config
.
Log
()
.
WithField
(
"status"
,
statusText
)
.
Warningln
(
"Checking for jobs..."
,
"failed"
)
n
.
checkGitLabVersionCompatibility
(
config
.
RunnerCredentials
)
return
nil
,
true
return
nil
,
true
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
network/gitlab_test.go
+
0
−
87
View file @
c4ee6fdd
...
@@ -890,90 +890,3 @@ func TestArtifactsDownload(t *testing.T) {
...
@@ -890,90 +890,3 @@ func TestArtifactsDownload(t *testing.T) {
state
=
c
.
DownloadArtifacts
(
fileNotFoundTokenCredentials
,
artifactsFileName
)
state
=
c
.
DownloadArtifacts
(
fileNotFoundTokenCredentials
,
artifactsFileName
)
assert
.
Equal
(
t
,
DownloadNotFound
,
state
,
"Artifacts should be bit downloaded if it's not found"
)
assert
.
Equal
(
t
,
DownloadNotFound
,
state
,
"Artifacts should be bit downloaded if it's not found"
)
}
}
func
prepareAPIv4CompatibilityTestEnvironment
(
name
string
,
handler
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
))
(
server
*
httptest
.
Server
,
runner
RunnerConfig
)
{
server
=
httptest
.
NewServer
(
http
.
HandlerFunc
(
handler
))
runner
=
RunnerConfig
{
Name
:
name
,
RunnerCredentials
:
RunnerCredentials
{
URL
:
server
.
URL
,
Token
:
"valid"
,
},
}
return
}
func
execAPIv4CompatibilityTestRequest
(
t
*
testing
.
T
,
requestType
string
,
runner
RunnerConfig
,
isCompatible
bool
)
{
t
.
Run
(
fmt
.
Sprintf
(
"%s/%s"
,
requestType
,
runner
.
Name
),
func
(
t
*
testing
.
T
)
{
c
:=
NewGitLabClient
()
switch
requestType
{
case
"register runner"
:
c
.
RegisterRunner
(
runner
.
RunnerCredentials
,
""
,
""
,
false
,
false
)
case
"verify runner"
:
c
.
VerifyRunner
(
runner
.
RunnerCredentials
)
case
"unregister runner"
:
c
.
UnregisterRunner
(
runner
.
RunnerCredentials
)
case
"request job"
:
c
.
RequestJob
(
runner
)
}
client
,
err
:=
c
.
getClient
(
&
runner
.
RunnerCredentials
)
assert
.
NoError
(
t
,
err
)
if
isCompatible
{
assert
.
True
(
t
,
client
.
compatibleWithGitLab
,
"Client should be marked as compatible with GitLab"
)
}
else
{
assert
.
False
(
t
,
client
.
compatibleWithGitLab
,
"Client should be marked as not compatible with GitLab"
)
}
})
}
func
TestAPIv4Compatibility
(
t
*
testing
.
T
)
{
serverPre90
,
runnerPre90
:=
prepareAPIv4CompatibilityTestEnvironment
(
"pre 9.0"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
URL
.
Path
{
case
"/api/v4/runners"
:
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
case
"/api/v4/runners/verify"
:
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
case
"/api/v4/jobs/request"
:
w
.
WriteHeader
(
http
.
StatusNotFound
)
}
})
defer
serverPre90
.
Close
()
server90
,
runner90
:=
prepareAPIv4CompatibilityTestEnvironment
(
"9.0"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
URL
.
Path
{
case
"/api/v4/runners"
:
switch
r
.
Method
{
case
"POST"
:
res
:=
make
(
map
[
string
]
interface
{})
res
[
"token"
]
=
"token-here"
output
,
err
:=
json
.
Marshal
(
res
)
require
.
NoError
(
t
,
err
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusCreated
)
w
.
Write
(
output
)
case
"DELETE"
:
w
.
WriteHeader
(
http
.
StatusNoContent
)
}
case
"/api/v4/runners/verify"
:
w
.
WriteHeader
(
http
.
StatusOK
)
case
"/api/v4/jobs/request"
:
w
.
WriteHeader
(
http
.
StatusNoContent
)
}
})
defer
server90
.
Close
()
execAPIv4CompatibilityTestRequest
(
t
,
"register runner"
,
runnerPre90
,
false
)
execAPIv4CompatibilityTestRequest
(
t
,
"register runner"
,
runner90
,
true
)
execAPIv4CompatibilityTestRequest
(
t
,
"verify runner"
,
runnerPre90
,
false
)
execAPIv4CompatibilityTestRequest
(
t
,
"verify runner"
,
runner90
,
true
)
execAPIv4CompatibilityTestRequest
(
t
,
"unregister runner"
,
runnerPre90
,
false
)
execAPIv4CompatibilityTestRequest
(
t
,
"unregister runner"
,
runner90
,
true
)
execAPIv4CompatibilityTestRequest
(
t
,
"request job"
,
runnerPre90
,
false
)
execAPIv4CompatibilityTestRequest
(
t
,
"request job"
,
runner90
,
true
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment