Commit fd9d2f49 authored by Thong Kuah's avatar Thong Kuah

Kubernetes secret are namespaced, so must always pass a namespace arg.

In our case it's 'default'.
parent 3c5c6c2c
...@@ -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'
......
...@@ -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
......
...@@ -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
......
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment