diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /app/models/clusters/platforms | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'app/models/clusters/platforms')
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index 9d4f0a89403..165285b34b2 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -10,6 +10,7 @@ module Clusters include NullifyIfBlank RESERVED_NAMESPACES = %w(gitlab-managed-apps).freeze + REQUIRED_K8S_MIN_VERSION = 23 IGNORED_CONNECTION_EXCEPTIONS = [ Gitlab::UrlBlocker::BlockedUrlError, @@ -21,6 +22,8 @@ module Clusters OpenSSL::SSL::SSLError ].freeze + FailedVersionCheckError = Class.new(StandardError) + self.table_name = 'cluster_platforms_kubernetes' self.reactive_cache_work_type = :external_dependency @@ -64,9 +67,7 @@ module Clusters unknown_authorization: nil, rbac: 1, abac: 2 - } - - default_value_for :authorization_type, :rbac + }, _default: :rbac nullify_if_blank :namespace @@ -208,6 +209,29 @@ module Clusters kubeclient.get_ingresses(namespace: namespace).as_json rescue Kubeclient::ResourceNotFoundError [] + rescue NoMethodError => e + # We get NoMethodError for Kubernetes versions < 1.19. Since we only support >= 1.23 + # we will ignore this error for previous versions. For more details read: + # https://gitlab.com/gitlab-org/gitlab/-/issues/371249#note_1079866043 + return [] if server_version < REQUIRED_K8S_MIN_VERSION + + raise e + end + + def server_version + full_url = Gitlab::UrlSanitizer.new("#{api_url}/version").full_url + + # We can't use `kubeclient` to check the cluster version because it does not support it + # https://github.com/ManageIQ/kubeclient/issues/309 + response = Gitlab::HTTP.perform_request( + Net::HTTP::Get, full_url, + headers: { "Authorization" => "Bearer #{token}" }, + cert_store: kubeclient_ssl_options[:cert_store]) + + Gitlab::ErrorTracking.track_exception(FailedVersionCheckError.new) unless response.success? + + json_response = Gitlab::Json.parse(response.body) + json_response["minor"].to_i end def build_kube_client! |