diff options
Diffstat (limited to 'lib/gitlab/kubernetes')
-rw-r--r-- | lib/gitlab/kubernetes/helm.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/node.rb | 78 |
2 files changed, 79 insertions, 1 deletions
diff --git a/lib/gitlab/kubernetes/helm.rb b/lib/gitlab/kubernetes/helm.rb index 9507f7bc117..39bd8d5a01f 100644 --- a/lib/gitlab/kubernetes/helm.rb +++ b/lib/gitlab/kubernetes/helm.rb @@ -3,7 +3,7 @@ module Gitlab module Kubernetes module Helm - HELM_VERSION = '2.16.6' + HELM_VERSION = '2.16.9' KUBECTL_VERSION = '1.13.12' NAMESPACE = 'gitlab-managed-apps' NAMESPACE_LABELS = { 'app.gitlab.com/managed_by' => :gitlab }.freeze diff --git a/lib/gitlab/kubernetes/node.rb b/lib/gitlab/kubernetes/node.rb new file mode 100644 index 00000000000..bd765ef3852 --- /dev/null +++ b/lib/gitlab/kubernetes/node.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +module Gitlab + module Kubernetes + class Node + def initialize(cluster) + @cluster = cluster + end + + def all + nodes.map do |node| + attributes = node(node) + attributes.merge(node_metrics(node)) + end + end + + private + + attr_reader :cluster + + def nodes_from_cluster + graceful_request { cluster.kubeclient.get_nodes } + end + + def nodes_metrics_from_cluster + graceful_request { cluster.kubeclient.metrics_client.get_nodes } + end + + def nodes + @nodes ||= nodes_from_cluster[:response].to_a + end + + def nodes_metrics + @nodes_metrics ||= nodes_metrics_from_cluster[:response].to_a + end + + def node_metrics_from_node(node) + nodes_metrics.find do |node_metric| + node_metric.metadata.name == node.metadata.name + end + end + + def graceful_request(&block) + ::Gitlab::Kubernetes::KubeClient.graceful_request(cluster.id, &block) + end + + def node(node) + { + 'metadata' => { + 'name' => node.metadata.name + }, + 'status' => { + 'capacity' => { + 'cpu' => node.status.capacity.cpu, + 'memory' => node.status.capacity.memory + }, + 'allocatable' => { + 'cpu' => node.status.allocatable.cpu, + 'memory' => node.status.allocatable.memory + } + } + } + end + + def node_metrics(node) + node_metrics = node_metrics_from_node(node) + return {} unless node_metrics + + { + 'usage' => { + 'cpu' => node_metrics.usage.cpu, + 'memory' => node_metrics.usage.memory + } + } + end + end + end +end |