Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
26634f13
Commit
26634f13
authored
Aug 04, 2020
by
Matt Kasa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return gitaly info in kubernetes internal API
Closes
https://gitlab.com/gitlab-org/gitlab/-/issues/229462
parent
dadf02e5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
61 deletions
+91
-61
changelogs/unreleased/mattkasa-229462-gitaly-kubernetes-api.yml
...logs/unreleased/mattkasa-229462-gitaly-kubernetes-api.yml
+5
-0
lib/api/internal/kubernetes.rb
lib/api/internal/kubernetes.rb
+52
-49
spec/requests/api/internal/kubernetes_spec.rb
spec/requests/api/internal/kubernetes_spec.rb
+34
-12
No files found.
changelogs/unreleased/mattkasa-229462-gitaly-kubernetes-api.yml
0 → 100644
View file @
26634f13
---
title
:
Return gitaly info in kubernetes internal API
merge_request
:
38654
author
:
type
:
added
lib/api/internal/kubernetes.rb
View file @
26634f13
...
@@ -5,52 +5,67 @@ module API
...
@@ -5,52 +5,67 @@ module API
module
Internal
module
Internal
class
Kubernetes
<
Grape
::
API
::
Instance
class
Kubernetes
<
Grape
::
API
::
Instance
helpers
do
helpers
do
def
agent_token
@agent_token
||=
cluster_agent_token_from_authorization_token
end
def
agent
@agent
||=
agent_token
.
agent
end
def
repo_type
def
repo_type
Gitlab
::
GlRepository
::
PROJECT
Gitlab
::
GlRepository
::
PROJECT
end
end
def
gl_repository
(
project
)
def
gitaly_info
(
project
)
repo_type
.
identifier_for_container
(
project
)
shard
=
repo_type
.
repository_for
(
project
).
shard
{
address:
Gitlab
::
GitalyClient
.
address
(
shard
),
token:
Gitlab
::
GitalyClient
.
token
(
shard
),
features:
Feature
::
Gitaly
.
server_feature_flags
}
end
end
def
gl_repository_path
(
project
)
def
gitaly_repository
(
project
)
repo_type
.
repository_for
(
project
).
full_path
{
storage_name:
project
.
repository_storage
,
relative_path:
project
.
disk_path
+
'.git'
,
gl_repository:
repo_type
.
identifier_for_container
(
project
),
gl_project_path:
repo_type
.
repository_for
(
project
).
full_path
}
end
end
def
check_feature_enabled
def
check_feature_enabled
not_found!
unless
Feature
.
enabled?
(
:kubernetes_agent_internal_api
)
not_found!
unless
Feature
.
enabled?
(
:kubernetes_agent_internal_api
)
end
end
def
check_agent_token
forbidden!
unless
agent_token
end
end
end
namespace
'internal'
do
namespace
'internal'
do
namespace
'kubernetes'
do
namespace
'kubernetes'
do
before
do
check_feature_enabled
check_agent_token
end
desc
'Gets agent info'
do
desc
'Gets agent info'
do
detail
'Retrieves agent info for the given token'
detail
'Retrieves agent info for the given token'
end
end
route_setting
:authentication
,
cluster_agent_token_allowed:
true
route_setting
:authentication
,
cluster_agent_token_allowed:
true
get
'/agent_info'
do
get
'/agent_info'
do
check_feature_enabled
agent_token
=
cluster_agent_token_from_authorization_token
if
agent_token
agent
=
agent_token
.
agent
project
=
agent
.
project
project
=
agent
.
project
@gl_project_string
=
"project-
#{
project
.
id
}
"
status
200
status
200
{
{
project_id:
project
.
id
,
project_id:
project
.
id
,
agent_id:
agent
.
id
,
agent_id:
agent
.
id
,
agent_name:
agent
.
name
,
agent_name:
agent
.
name
,
storage_name:
project
.
repository_storage
,
gitaly_info:
gitaly_info
(
project
),
relative_path:
project
.
disk_path
+
'.git'
,
gitaly_repository:
gitaly_repository
(
project
)
gl_repository:
gl_repository
(
project
),
gl_project_path:
gl_repository_path
(
project
)
}
}
else
status
403
end
end
end
desc
'Gets project info'
do
desc
'Gets project info'
do
...
@@ -58,11 +73,6 @@ module API
...
@@ -58,11 +73,6 @@ module API
end
end
route_setting
:authentication
,
cluster_agent_token_allowed:
true
route_setting
:authentication
,
cluster_agent_token_allowed:
true
get
'/project_info'
do
get
'/project_info'
do
check_feature_enabled
agent_token
=
cluster_agent_token_from_authorization_token
if
agent_token
project
=
find_project
(
params
[
:id
])
project
=
find_project
(
params
[
:id
])
# TODO sort out authorization for real
# TODO sort out authorization for real
...
@@ -71,19 +81,12 @@ module API
...
@@ -71,19 +81,12 @@ module API
not_found!
not_found!
end
end
@gl_project_string
=
"project-
#{
project
.
id
}
"
status
200
status
200
{
{
project_id:
project
.
id
,
project_id:
project
.
id
,
storage_name:
project
.
repository_storage
,
gitaly_info:
gitaly_info
(
project
),
relative_path:
project
.
disk_path
+
'.git'
,
gitaly_repository:
gitaly_repository
(
project
)
gl_repository:
gl_repository
(
project
),
gl_project_path:
gl_repository_path
(
project
)
}
}
else
status
403
end
end
end
end
end
end
end
...
...
spec/requests/api/internal/kubernetes_spec.rb
View file @
26634f13
...
@@ -33,13 +33,24 @@ RSpec.describe API::Internal::Kubernetes do
...
@@ -33,13 +33,24 @@ RSpec.describe API::Internal::Kubernetes do
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
).
to
match
(
expect
(
json_response
[
'agent_id'
]).
to
eq
(
agent
.
id
)
a_hash_including
(
expect
(
json_response
[
'agent_name'
]).
to
eq
(
agent
.
name
)
'project_id'
=>
project
.
id
,
expect
(
json_response
[
'storage_name'
]).
to
eq
(
project
.
repository_storage
)
'agent_id'
=>
agent
.
id
,
expect
(
json_response
[
'relative_path'
]).
to
eq
(
project
.
disk_path
+
'.git'
)
'agent_name'
=>
agent
.
name
,
expect
(
json_response
[
'gl_repository'
]).
to
eq
(
"project-
#{
project
.
id
}
"
)
'gitaly_info'
=>
a_hash_including
(
expect
(
json_response
[
'gl_project_path'
]).
to
eq
(
project
.
full_path
)
'address'
=>
match
(
/\.socket$/
),
'token'
=>
'secret'
,
'features'
=>
{}
),
'gitaly_repository'
=>
a_hash_including
(
'storage_name'
=>
project
.
repository_storage
,
'relative_path'
=>
project
.
disk_path
+
'.git'
,
'gl_repository'
=>
"project-
#{
project
.
id
}
"
,
'gl_project_path'
=>
project
.
full_path
)
)
)
end
end
end
end
...
@@ -92,11 +103,22 @@ RSpec.describe API::Internal::Kubernetes do
...
@@ -92,11 +103,22 @@ RSpec.describe API::Internal::Kubernetes do
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
).
to
match
(
expect
(
json_response
[
'storage_name'
]).
to
eq
(
project
.
repository_storage
)
a_hash_including
(
expect
(
json_response
[
'relative_path'
]).
to
eq
(
project
.
disk_path
+
'.git'
)
'project_id'
=>
project
.
id
,
expect
(
json_response
[
'gl_repository'
]).
to
eq
(
"project-
#{
project
.
id
}
"
)
'gitaly_info'
=>
a_hash_including
(
expect
(
json_response
[
'gl_project_path'
]).
to
eq
(
project
.
full_path
)
'address'
=>
match
(
/\.socket$/
),
'token'
=>
'secret'
,
'features'
=>
{}
),
'gitaly_repository'
=>
a_hash_including
(
'storage_name'
=>
project
.
repository_storage
,
'relative_path'
=>
project
.
disk_path
+
'.git'
,
'gl_repository'
=>
"project-
#{
project
.
id
}
"
,
'gl_project_path'
=>
project
.
full_path
)
)
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment