diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/models/clusters/platforms/kubernetes.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/models/clusters/platforms/kubernetes.rb')
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index b85a902d58b..84de5828491 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -94,9 +94,20 @@ module Clusters return unless enabled? pods = read_pods(environment.deployment_namespace) + deployments = read_deployments(environment.deployment_namespace) - # extract_relevant_pod_data avoids uploading all the pod info into ReactiveCaching - { pods: extract_relevant_pod_data(pods) } + ingresses = if ::Feature.enabled?(:canary_ingress_weight_control, environment.project, default_enabled: true) + read_ingresses(environment.deployment_namespace) + else + [] + end + + # extract only the data required for display to avoid unnecessary caching + { + pods: extract_relevant_pod_data(pods), + deployments: extract_relevant_deployment_data(deployments), + ingresses: extract_relevant_ingress_data(ingresses) + } end def terminals(environment, data) @@ -109,6 +120,25 @@ module Clusters @kubeclient ||= build_kube_client! 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) + ingresses = data[:ingresses].presence || [] + + ::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods_attrs: pods, ingresses: ingresses) + end + + def ingresses(namespace) + ingresses = read_ingresses(namespace) + ingresses.map { |ingress| ::Gitlab::Kubernetes::Ingress.new(ingress) } + end + + def patch_ingress(namespace, ingress, data) + kubeclient.patch_ingress(ingress.name, data, namespace) + end + private def default_namespace(project, environment_name:) @@ -140,6 +170,18 @@ module Clusters [] end + def read_deployments(namespace) + kubeclient.get_deployments(namespace: namespace).as_json + rescue Kubeclient::ResourceNotFoundError + [] + end + + def read_ingresses(namespace) + kubeclient.get_ingresses(namespace: namespace).as_json + rescue Kubeclient::ResourceNotFoundError + [] + end + def build_kube_client! raise "Incomplete settings" unless api_url @@ -231,8 +273,24 @@ module Clusters } end end + + def extract_relevant_deployment_data(deployments) + deployments.map do |deployment| + { + 'metadata' => deployment.fetch('metadata', {}).slice('name', 'generation', 'labels', 'annotations'), + 'spec' => deployment.fetch('spec', {}).slice('replicas'), + 'status' => deployment.fetch('status', {}).slice('observedGeneration') + } + end + end + + def extract_relevant_ingress_data(ingresses) + ingresses.map do |ingress| + { + 'metadata' => ingress.fetch('metadata', {}).slice('name', 'labels', 'annotations') + } + end + end end end end - -Clusters::Platforms::Kubernetes.prepend_if_ee('EE::Clusters::Platforms::Kubernetes') |