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
fd9d2f49
Commit
fd9d2f49
authored
Sep 12, 2018
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kubernetes secret are namespaced, so must always pass a namespace arg.
In our case it's 'default'.
parent
3c5c6c2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
10 deletions
+11
-10
app/services/clusters/gcp/kubernetes.rb
app/services/clusters/gcp/kubernetes.rb
+1
-0
app/services/clusters/gcp/kubernetes/create_service_account_service.rb
...clusters/gcp/kubernetes/create_service_account_service.rb
+5
-5
app/services/clusters/gcp/kubernetes/fetch_kubernetes_token_service.rb
...clusters/gcp/kubernetes/fetch_kubernetes_token_service.rb
+1
-1
spec/support/helpers/kubernetes_helpers.rb
spec/support/helpers/kubernetes_helpers.rb
+4
-4
No files found.
app/services/clusters/gcp/kubernetes.rb
View file @
fd9d2f49
...
@@ -4,6 +4,7 @@ module Clusters
...
@@ -4,6 +4,7 @@ module Clusters
module
Gcp
module
Gcp
module
Kubernetes
module
Kubernetes
SERVICE_ACCOUNT_NAME
=
'gitlab'
SERVICE_ACCOUNT_NAME
=
'gitlab'
SERVICE_ACCOUNT_NAMESPACE
=
'default'
SERVICE_ACCOUNT_TOKEN_NAME
=
'gitlab-token'
SERVICE_ACCOUNT_TOKEN_NAME
=
'gitlab-token'
CLUSTER_ROLE_BINDING_NAME
=
'gitlab-admin'
CLUSTER_ROLE_BINDING_NAME
=
'gitlab-admin'
CLUSTER_ROLE_NAME
=
'cluster-admin'
CLUSTER_ROLE_NAME
=
'cluster-admin'
...
...
app/services/clusters/gcp/kubernetes/create_service_account_service.rb
View file @
fd9d2f49
...
@@ -20,16 +20,16 @@ module Clusters
...
@@ -20,16 +20,16 @@ module Clusters
private
private
def
service_account_resource
def
service_account_resource
Gitlab
::
Kubernetes
::
ServiceAccount
.
new
(
service_account_name
,
namespace
).
generate
Gitlab
::
Kubernetes
::
ServiceAccount
.
new
(
service_account_name
,
service_account_
namespace
).
generate
end
end
def
service_account_token_resource
def
service_account_token_resource
Gitlab
::
Kubernetes
::
ServiceAccountToken
.
new
(
Gitlab
::
Kubernetes
::
ServiceAccountToken
.
new
(
SERVICE_ACCOUNT_TOKEN_NAME
,
service_account_name
,
namespace
).
generate
SERVICE_ACCOUNT_TOKEN_NAME
,
service_account_name
,
service_account_
namespace
).
generate
end
end
def
cluster_role_binding_resource
def
cluster_role_binding_resource
subjects
=
[{
kind:
'ServiceAccount'
,
name:
service_account_name
,
namespace:
namespace
}]
subjects
=
[{
kind:
'ServiceAccount'
,
name:
service_account_name
,
namespace:
service_account_
namespace
}]
Gitlab
::
Kubernetes
::
ClusterRoleBinding
.
new
(
Gitlab
::
Kubernetes
::
ClusterRoleBinding
.
new
(
CLUSTER_ROLE_BINDING_NAME
,
CLUSTER_ROLE_BINDING_NAME
,
...
@@ -42,8 +42,8 @@ module Clusters
...
@@ -42,8 +42,8 @@ module Clusters
SERVICE_ACCOUNT_NAME
SERVICE_ACCOUNT_NAME
end
end
def
namespace
def
service_account_
namespace
'default'
SERVICE_ACCOUNT_NAMESPACE
end
end
end
end
end
end
...
...
app/services/clusters/gcp/kubernetes/fetch_kubernetes_token_service.rb
View file @
fd9d2f49
...
@@ -18,7 +18,7 @@ module Clusters
...
@@ -18,7 +18,7 @@ module Clusters
private
private
def
get_secret
def
get_secret
kubeclient
.
get_secret
(
SERVICE_ACCOUNT_TOKEN_NAME
).
as_json
kubeclient
.
get_secret
(
SERVICE_ACCOUNT_TOKEN_NAME
,
SERVICE_ACCOUNT_NAMESPACE
).
as_json
rescue
Kubeclient
::
HttpError
=>
err
rescue
Kubeclient
::
HttpError
=>
err
raise
err
unless
err
.
error_code
==
404
raise
err
unless
err
.
error_code
==
404
...
...
spec/support/helpers/kubernetes_helpers.rb
View file @
fd9d2f49
...
@@ -33,15 +33,15 @@ module KubernetesHelpers
...
@@ -33,15 +33,15 @@ module KubernetesHelpers
WebMock
.
stub_request
(
:get
,
deployments_url
).
to_return
(
response
||
kube_deployments_response
)
WebMock
.
stub_request
(
:get
,
deployments_url
).
to_return
(
response
||
kube_deployments_response
)
end
end
def
stub_kubeclient_get_secret
(
api_url
,
**
options
)
def
stub_kubeclient_get_secret
(
api_url
,
namespace:
'default'
,
**
options
)
options
[
:metadata_name
]
||=
"default-token-1"
options
[
:metadata_name
]
||=
"default-token-1"
WebMock
.
stub_request
(
:get
,
api_url
+
"/api/v1/secrets/
#{
options
[
:metadata_name
]
}
"
)
WebMock
.
stub_request
(
:get
,
api_url
+
"/api/v1/
namespaces/
#{
namespace
}
/
secrets/
#{
options
[
:metadata_name
]
}
"
)
.
to_return
(
kube_response
(
kube_v1_secret_body
(
options
)))
.
to_return
(
kube_response
(
kube_v1_secret_body
(
options
)))
end
end
def
stub_kubeclient_get_secret_error
(
api_url
,
name
)
def
stub_kubeclient_get_secret_error
(
api_url
,
name
,
namespace:
'default'
)
WebMock
.
stub_request
(
:get
,
api_url
+
"/api/v1/secrets/
#{
name
}
"
)
WebMock
.
stub_request
(
:get
,
api_url
+
"/api/v1/
namespaces/
#{
namespace
}
/
secrets/
#{
name
}
"
)
.
to_return
(
status:
[
404
,
"Internal Server Error"
])
.
to_return
(
status:
[
404
,
"Internal Server Error"
])
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