Commit b6883c11 authored by James Fargher's avatar James Fargher

Rename KubernetesService to become a proper EE module

Clusters::Platforms::Kubernetes is now the only include
parent b4993f95
......@@ -192,4 +192,4 @@ module Clusters
end
end
Clusters::Platforms::Kubernetes.prepend(EE::KubernetesService)
Clusters::Platforms::Kubernetes.prepend(EE::Clusters::Platforms::Kubernetes)
# frozen_string_literal: true
module EE
module KubernetesService
extend ActiveSupport::Concern
LOGS_LIMIT = 500.freeze
def calculate_reactive_cache_for(environment)
result = super
result[:deployments] = read_deployments(environment.deployment_namespace) if result
result
end
def rollout_status(environment, data)
project = environment.project
deployments = filter_by_project_environment(data[:deployments], project.full_path_slug, environment.slug)
pods = filter_by_project_environment(data[:pods], project.full_path_slug, environment.slug) if data[:pods]&.any?
legacy_deployments = filter_by_legacy_label(data[:deployments], project.full_path_slug, environment.slug)
::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods: pods, legacy_deployments: legacy_deployments)
end
def read_pod_logs(pod_name, namespace, container: nil)
kubeclient.get_pod_log(pod_name, namespace, container: container, tail_lines: LOGS_LIMIT).as_json
rescue Kubeclient::ResourceNotFoundError
[]
end
private
def read_deployments(namespace)
kubeclient.get_deployments(namespace: namespace).as_json
rescue Kubeclient::ResourceNotFoundError
[]
end
end
end
# frozen_string_literal: true
module EE
module Clusters
module Platforms
module Kubernetes
extend ActiveSupport::Concern
LOGS_LIMIT = 500.freeze
def calculate_reactive_cache_for(environment)
result = super
result[:deployments] = read_deployments(environment.deployment_namespace) if result
result
end
def rollout_status(environment, data)
project = environment.project
deployments = filter_by_project_environment(data[:deployments], project.full_path_slug, environment.slug)
pods = filter_by_project_environment(data[:pods], project.full_path_slug, environment.slug) if data[:pods]&.any?
legacy_deployments = filter_by_legacy_label(data[:deployments], project.full_path_slug, environment.slug)
::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods: pods, legacy_deployments: legacy_deployments)
end
def read_pod_logs(pod_name, namespace, container: nil)
kubeclient.get_pod_log(pod_name, namespace, container: container, tail_lines: LOGS_LIMIT).as_json
rescue Kubeclient::ResourceNotFoundError
[]
end
private
def read_deployments(namespace)
kubeclient.get_deployments(namespace: namespace).as_json
rescue Kubeclient::ResourceNotFoundError
[]
end
end
end
end
end
......@@ -84,7 +84,7 @@ describe Projects::EnvironmentsController do
environment_scope: '*', projects: [project])
create(:deployment, :success, environment: environment)
allow_any_instance_of(EE::KubernetesService).to receive(:read_pod_logs)
allow_any_instance_of(EE::Clusters::Platforms::Kubernetes).to receive(:read_pod_logs)
.with(pod_name, environment.deployment_namespace).and_return(kube_logs_body)
allow_any_instance_of(Gitlab::Kubernetes::RolloutStatus).to receive(:instances)
.and_return([{ pod_name: pod_name }])
......
......@@ -16,7 +16,7 @@ describe 'Environment > Pod Logs', :js do
create(:cluster, :provided_by_gcp, environment_scope: '*', projects: [project])
create(:deployment, :success, environment: environment)
allow_any_instance_of(EE::KubernetesService).to receive(:read_pod_logs)
allow_any_instance_of(EE::Clusters::Platforms::Kubernetes).to receive(:read_pod_logs)
.with(pod_name, environment.deployment_namespace).and_return(kube_logs_body)
allow_any_instance_of(EE::Environment).to receive(:pod_names).and_return(pod_names)
......
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