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
module
Internal
class
Kubernetes
<
Grape
::
API
::
Instance
helpers
do
def
agent_token
@agent_token
||=
cluster_agent_token_from_authorization_token
end
def
agent
@agent
||=
agent_token
.
agent
end
def
repo_type
Gitlab
::
GlRepository
::
PROJECT
end
def
gl_repository
(
project
)
repo_type
.
identifier_for_container
(
project
)
def
gitaly_info
(
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
def
gl_repository_path
(
project
)
repo_type
.
repository_for
(
project
).
full_path
def
gitaly_repository
(
project
)
{
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
def
check_feature_enabled
not_found!
unless
Feature
.
enabled?
(
:kubernetes_agent_internal_api
)
end
def
check_agent_token
forbidden!
unless
agent_token
end
end
namespace
'internal'
do
namespace
'kubernetes'
do
before
do
check_feature_enabled
check_agent_token
end
desc
'Gets agent info'
do
detail
'Retrieves agent info for the given token'
end
route_setting
:authentication
,
cluster_agent_token_allowed:
true
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
@gl_project_string
=
"project-
#{
project
.
id
}
"
status
200
{
project_id:
project
.
id
,
agent_id:
agent
.
id
,
agent_name:
agent
.
name
,
storage_name:
project
.
repository_storage
,
relative_path:
project
.
disk_path
+
'.git'
,
gl_repository:
gl_repository
(
project
),
gl_project_path:
gl_repository_path
(
project
)
gitaly_info:
gitaly_info
(
project
),
gitaly_repository:
gitaly_repository
(
project
)
}
else
status
403
end
end
desc
'Gets project info'
do
...
...
@@ -58,11 +73,6 @@ module API
end
route_setting
:authentication
,
cluster_agent_token_allowed:
true
get
'/project_info'
do
check_feature_enabled
agent_token
=
cluster_agent_token_from_authorization_token
if
agent_token
project
=
find_project
(
params
[
:id
])
# TODO sort out authorization for real
...
...
@@ -71,19 +81,12 @@ module API
not_found!
end
@gl_project_string
=
"project-
#{
project
.
id
}
"
status
200
{
project_id:
project
.
id
,
storage_name:
project
.
repository_storage
,
relative_path:
project
.
disk_path
+
'.git'
,
gl_repository:
gl_repository
(
project
),
gl_project_path:
gl_repository_path
(
project
)
gitaly_info:
gitaly_info
(
project
),
gitaly_repository:
gitaly_repository
(
project
)
}
else
status
403
end
end
end
end
...
...
spec/requests/api/internal/kubernetes_spec.rb
View file @
26634f13
...
...
@@ -33,13 +33,24 @@ RSpec.describe API::Internal::Kubernetes do
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'agent_id'
]).
to
eq
(
agent
.
id
)
expect
(
json_response
[
'agent_name'
]).
to
eq
(
agent
.
name
)
expect
(
json_response
[
'storage_name'
]).
to
eq
(
project
.
repository_storage
)
expect
(
json_response
[
'relative_path'
]).
to
eq
(
project
.
disk_path
+
'.git'
)
expect
(
json_response
[
'gl_repository'
]).
to
eq
(
"project-
#{
project
.
id
}
"
)
expect
(
json_response
[
'gl_project_path'
]).
to
eq
(
project
.
full_path
)
expect
(
json_response
).
to
match
(
a_hash_including
(
'project_id'
=>
project
.
id
,
'agent_id'
=>
agent
.
id
,
'agent_name'
=>
agent
.
name
,
'gitaly_info'
=>
a_hash_including
(
'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
...
...
@@ -92,11 +103,22 @@ RSpec.describe API::Internal::Kubernetes do
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'storage_name'
]).
to
eq
(
project
.
repository_storage
)
expect
(
json_response
[
'relative_path'
]).
to
eq
(
project
.
disk_path
+
'.git'
)
expect
(
json_response
[
'gl_repository'
]).
to
eq
(
"project-
#{
project
.
id
}
"
)
expect
(
json_response
[
'gl_project_path'
]).
to
eq
(
project
.
full_path
)
expect
(
json_response
).
to
match
(
a_hash_including
(
'project_id'
=>
project
.
id
,
'gitaly_info'
=>
a_hash_including
(
'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
...
...
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