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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
8c8ccd31
Commit
8c8ccd31
authored
Sep 07, 2018
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach GitLab how to create Secret of type ServiceAccountToken
Add create_secret to KubeClient
parent
9c5050b1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
0 deletions
+73
-0
lib/gitlab/kubernetes/kube_client.rb
lib/gitlab/kubernetes/kube_client.rb
+1
-0
lib/gitlab/kubernetes/service_account_token.rb
lib/gitlab/kubernetes/service_account_token.rb
+36
-0
spec/lib/gitlab/kubernetes/kube_client_spec.rb
spec/lib/gitlab/kubernetes/kube_client_spec.rb
+1
-0
spec/lib/gitlab/kubernetes/service_account_token_spec.rb
spec/lib/gitlab/kubernetes/service_account_token_spec.rb
+35
-0
No files found.
lib/gitlab/kubernetes/kube_client.rb
View file @
8c8ccd31
...
@@ -31,6 +31,7 @@ module Gitlab
...
@@ -31,6 +31,7 @@ module Gitlab
:create_config_map
,
:create_config_map
,
:create_namespace
,
:create_namespace
,
:create_pod
,
:create_pod
,
:create_secret
,
:create_service_account
,
:create_service_account
,
:update_config_map
,
:update_config_map
,
:update_service_account
,
:update_service_account
,
...
...
lib/gitlab/kubernetes/service_account_token.rb
0 → 100644
View file @
8c8ccd31
# frozen_string_literal: true
module
Gitlab
module
Kubernetes
class
ServiceAccountToken
attr_reader
:name
,
:service_account_name
,
:namespace_name
def
initialize
(
name
,
service_account_name
,
namespace_name
)
@name
=
name
@service_account_name
=
service_account_name
@namespace_name
=
namespace_name
end
def
generate
::
Kubeclient
::
Resource
.
new
(
metadata:
metadata
,
type:
service_acount_token_type
)
end
private
# as per https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/#to-create-additional-api-tokens
def
service_acount_token_type
'kubernetes.io/service-account-token'
end
def
metadata
{
name:
name
,
namespace:
namespace_name
,
annotations:
{
"kubernetes.io/service-account.name"
:
service_account_name
}
}
end
end
end
end
spec/lib/gitlab/kubernetes/kube_client_spec.rb
View file @
8c8ccd31
...
@@ -122,6 +122,7 @@ describe Gitlab::Kubernetes::KubeClient do
...
@@ -122,6 +122,7 @@ describe Gitlab::Kubernetes::KubeClient do
:create_config_map
,
:create_config_map
,
:create_namespace
,
:create_namespace
,
:create_pod
,
:create_pod
,
:create_secret
,
:create_service_account
,
:create_service_account
,
:update_config_map
,
:update_config_map
,
:update_service_account
:update_service_account
...
...
spec/lib/gitlab/kubernetes/service_account_token_spec.rb
0 → 100644
View file @
8c8ccd31
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Kubernetes
::
ServiceAccountToken
do
let
(
:name
)
{
'token-name'
}
let
(
:service_account_name
)
{
'a_service_account'
}
let
(
:namespace_name
)
{
'a_namespace'
}
let
(
:service_account_token
)
{
described_class
.
new
(
name
,
service_account_name
,
namespace_name
)
}
it
{
expect
(
service_account_token
.
name
).
to
eq
(
name
)
}
it
{
expect
(
service_account_token
.
service_account_name
).
to
eq
(
service_account_name
)
}
it
{
expect
(
service_account_token
.
namespace_name
).
to
eq
(
namespace_name
)
}
describe
'#generate'
do
let
(
:resource
)
do
::
Kubeclient
::
Resource
.
new
(
metadata:
{
name:
name
,
namespace:
namespace_name
,
annotations:
{
'kubernetes.io/service-account.name'
:
service_account_name
}
},
type:
'kubernetes.io/service-account-token'
)
end
subject
{
service_account_token
.
generate
}
it
'should build a Kubeclient Resource'
do
is_expected
.
to
eq
(
resource
)
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