summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-09 10:18:16 +1300
committerThong Kuah <tkuah@gitlab.com>2018-10-23 23:36:44 +1300
commit27979aac0a9975933e246a7f0fb987b255b47d96 (patch)
treeb6f4f60dda5a81cc65d5f21d3a3a9628babb32c3
parent8d81f2690c5c277065c6f4a1f9eecc5e771d8cfe (diff)
downloadgitlab-ce-27979aac0a9975933e246a7f0fb987b255b47d96.tar.gz
Split hashed_clients into one per api_group
Essentially make #build_kubeclient do less. Should be much clearer now
-rw-r--r--lib/gitlab/kubernetes/kube_client.rb43
1 files changed, 32 insertions, 11 deletions
diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb
index 0125b6005cf..4527ca2accb 100644
--- a/lib/gitlab/kubernetes/kube_client.rb
+++ b/lib/gitlab/kubernetes/kube_client.rb
@@ -63,33 +63,54 @@ module Gitlab
@api_prefix = api_prefix
@kubeclient_options = kubeclient_options
@default_api_version = default_api_version
-
- @hashed_clients = {}
end
def core_client(api_version: default_api_version)
- build_kubeclient('api', api_version)
+ core_clients[api_version]
end
def rbac_client(api_version: default_api_version)
- build_kubeclient('apis/rbac.authorization.k8s.io', api_version)
+ rbac_clients[api_version]
end
def extensions_client(api_version: LATEST_EXTENSIONS_VERSION)
- build_kubeclient('apis/extensions', api_version)
+ extensions_clients[api_version]
end
private
- def build_kubeclient(api_group, api_version)
- raise ArgumentError, "Unknown api group #{api_group}" unless SUPPORTED_API_GROUPS.include?(api_group)
+ def core_clients
+ strong_memoize(:core_clients) do
+ Hash.new do |hash, api_version|
+ hash[api_version] = build_kubeclient('api', api_version)
+ end
+ end
+ end
- key = api_group_with_version(api_group, api_version)
- @hashed_clients[key] ||= ::Kubeclient::Client.new(join_api_url(api_prefix, api_group), api_version, **kubeclient_options)
+ def rbac_clients
+ strong_memoize(:rbac_clients) do
+ Hash.new do |hash, api_version|
+ hash[api_version] = build_kubeclient('apis/rbac.authorization.k8s.io', api_version)
+ end
+ end
end
- def api_group_with_version(api_group, api_version)
- api_group + '/' + api_version
+ def extensions_clients
+ strong_memoize(:extensions_clients) do
+ Hash.new do |hash, api_version|
+ hash[api_version] = build_kubeclient('apis/extensions', api_version)
+ end
+ end
+ end
+
+ def build_kubeclient(api_group, api_version)
+ raise ArgumentError, "Unknown api group #{api_group}" unless SUPPORTED_API_GROUPS.include?(api_group)
+
+ ::Kubeclient::Client.new(
+ join_api_url(api_prefix, api_group),
+ api_version,
+ **kubeclient_options
+ )
end
def join_api_url(api_prefix, api_path)