Commit 27979aac authored by Thong Kuah's avatar Thong Kuah

Split hashed_clients into one per api_group

Essentially make #build_kubeclient do less.

Should be much clearer now
parent 8d81f269
...@@ -63,33 +63,54 @@ module Gitlab ...@@ -63,33 +63,54 @@ module Gitlab
@api_prefix = api_prefix @api_prefix = api_prefix
@kubeclient_options = kubeclient_options @kubeclient_options = kubeclient_options
@default_api_version = default_api_version @default_api_version = default_api_version
@hashed_clients = {}
end end
def core_client(api_version: default_api_version) def core_client(api_version: default_api_version)
build_kubeclient('api', api_version) core_clients[api_version]
end end
def rbac_client(api_version: default_api_version) def rbac_client(api_version: default_api_version)
build_kubeclient('apis/rbac.authorization.k8s.io', api_version) rbac_clients[api_version]
end end
def extensions_client(api_version: LATEST_EXTENSIONS_VERSION) def extensions_client(api_version: LATEST_EXTENSIONS_VERSION)
build_kubeclient('apis/extensions', api_version) extensions_clients[api_version]
end end
private private
def build_kubeclient(api_group, api_version) def core_clients
raise ArgumentError, "Unknown api group #{api_group}" unless SUPPORTED_API_GROUPS.include?(api_group) 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) def rbac_clients
@hashed_clients[key] ||= ::Kubeclient::Client.new(join_api_url(api_prefix, api_group), api_version, **kubeclient_options) 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 end
def api_group_with_version(api_group, api_version) def extensions_clients
api_group + '/' + api_version 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 end
def join_api_url(api_prefix, api_path) def join_api_url(api_prefix, api_path)
......
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