Skip to content
Snippets Groups Projects
Unverified Commit c4ee6fdd authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Remove confusing compatibility check

parent 80b12155
Branches
Tags
No related merge requests found
...@@ -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]
......
...@@ -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
} }
} }
......
...@@ -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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment