diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2017-12-20 10:13:17 -0600 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2017-12-21 11:46:30 -0600 |
commit | c0301a753f33547c7ce173114e1e25f27d3d02cc (patch) | |
tree | 1c48061bf80a5522e61e3172bd9fb42a3cd311a7 | |
parent | 168175193d5585dae40c1f90a7af741545d5b3f8 (diff) | |
download | gitlab-ce-41053-extend-cluster-applications-to-allow-install-to-prometheus.tar.gz |
Transform Gitlab::Kubernetes::Helm into a class41053-extend-cluster-applications-to-allow-install-to-prometheus
Also changes prometheus description
-rw-r--r-- | app/assets/javascripts/clusters/components/applications.vue | 11 | ||||
-rw-r--r-- | app/services/clusters/applications/base_helm_service.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/41053-extend-cluster-applications-to-allow-install-to-prometheus.yml | 2 | ||||
-rw-r--r-- | db/schema.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/helm.rb | 37 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/helm/api.rb | 42 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/helm/install_command.rb | 76 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/helm/pod.rb | 102 | ||||
-rw-r--r-- | spec/lib/gitlab/kubernetes/helm/api_spec.rb (renamed from spec/lib/gitlab/kubernetes/helm_spec.rb) | 15 | ||||
-rw-r--r-- | spec/services/clusters/applications/install_service_spec.rb | 2 |
10 files changed, 155 insertions, 137 deletions
diff --git a/app/assets/javascripts/clusters/components/applications.vue b/app/assets/javascripts/clusters/components/applications.vue index f59f6396337..cd58b88db69 100644 --- a/app/assets/javascripts/clusters/components/applications.vue +++ b/app/assets/javascripts/clusters/components/applications.vue @@ -68,9 +68,14 @@ export default { )); }, prometheusDescription() { - return _.escape(s__( - 'ClusterIntegration|Prometheus is an open-source monitoring and alerting toolkit which allows you to define custom metrics, generate accurate reports, and develop custom dashboards.', - )); + return sprintf( + _.escape(s__('ClusterIntegration|Prometheus is an open-source monitoring system with %{gitlabIntegrationLink} to monitor deployed applications.')), { + gitlabIntegrationLink: `<a href="https://docs.gitlab.com/ce/user/project/integrations/prometheus.html", target="_blank" rel="noopener noreferrer"> + ${_.escape(s__('ClusterIntegration|Gitlab Integration'))} + </a>`, + }, + false, + ); }, }, }; diff --git a/app/services/clusters/applications/base_helm_service.rb b/app/services/clusters/applications/base_helm_service.rb index 9a4ce31cb39..cba1b920f7c 100644 --- a/app/services/clusters/applications/base_helm_service.rb +++ b/app/services/clusters/applications/base_helm_service.rb @@ -18,7 +18,7 @@ module Clusters end def helm_api - @helm_api ||= Gitlab::Kubernetes::Helm.new(kubeclient) + @helm_api ||= Gitlab::Kubernetes::Helm::Api.new(kubeclient) end def install_command diff --git a/changelogs/unreleased/41053-extend-cluster-applications-to-allow-install-to-prometheus.yml b/changelogs/unreleased/41053-extend-cluster-applications-to-allow-install-to-prometheus.yml index 5c9ca8da986..ffb79d7d79f 100644 --- a/changelogs/unreleased/41053-extend-cluster-applications-to-allow-install-to-prometheus.yml +++ b/changelogs/unreleased/41053-extend-cluster-applications-to-allow-install-to-prometheus.yml @@ -1,5 +1,5 @@ --- -title: Add Prometheus to available Cluster applicatoins +title: Add Prometheus to available Cluster applications merge_request: 15895 author: type: added diff --git a/db/schema.rb b/db/schema.rb index 36f07dbe29a..77c2109a9fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171212203433) do +ActiveRecord::Schema.define(version: 20171219121201) do + # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "pg_trgm" diff --git a/lib/gitlab/kubernetes/helm.rb b/lib/gitlab/kubernetes/helm.rb index 8765780dd5c..0f0588b8b23 100644 --- a/lib/gitlab/kubernetes/helm.rb +++ b/lib/gitlab/kubernetes/helm.rb @@ -1,43 +1,8 @@ module Gitlab module Kubernetes - class Helm + module Helm HELM_VERSION = '2.7.0'.freeze NAMESPACE = 'gitlab-managed-apps'.freeze - - def initialize(kubeclient) - @kubeclient = kubeclient - @namespace = Gitlab::Kubernetes::Namespace.new(NAMESPACE, kubeclient) - end - - def install(command) - @namespace.ensure_exists! - @kubeclient.create_pod(pod_resource(command)) - end - - ## - # Returns Pod phase - # - # https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase - # - # values: "Pending", "Running", "Succeeded", "Failed", "Unknown" - # - def installation_status(pod_name) - @kubeclient.get_pod(pod_name, @namespace.name).status.phase - end - - def installation_log(pod_name) - @kubeclient.get_pod_log(pod_name, @namespace.name).body - end - - def delete_installation_pod!(pod_name) - @kubeclient.delete_pod(pod_name, @namespace.name) - end - - private - - def pod_resource(command) - Pod.new(command, @namespace.name, @kubeclient).generate - end end end end diff --git a/lib/gitlab/kubernetes/helm/api.rb b/lib/gitlab/kubernetes/helm/api.rb new file mode 100644 index 00000000000..ebd7dc1b100 --- /dev/null +++ b/lib/gitlab/kubernetes/helm/api.rb @@ -0,0 +1,42 @@ +module Gitlab + module Kubernetes + module Helm + class Api + def initialize(kubeclient) + @kubeclient = kubeclient + @namespace = Gitlab::Kubernetes::Namespace.new(Gitlab::Kubernetes::Helm::NAMESPACE, kubeclient) + end + + def install(command) + @namespace.ensure_exists! + @kubeclient.create_pod(pod_resource(command)) + end + + ## + # Returns Pod phase + # + # https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase + # + # values: "Pending", "Running", "Succeeded", "Failed", "Unknown" + # + def installation_status(pod_name) + @kubeclient.get_pod(pod_name, @namespace.name).status.phase + end + + def installation_log(pod_name) + @kubeclient.get_pod_log(pod_name, @namespace.name).body + end + + def delete_installation_pod!(pod_name) + @kubeclient.delete_pod(pod_name, @namespace.name) + end + + private + + def pod_resource(command) + Pod.new(command, @namespace.name, @kubeclient).generate + end + end + end + end +end diff --git a/lib/gitlab/kubernetes/helm/install_command.rb b/lib/gitlab/kubernetes/helm/install_command.rb index 846a1948434..8d8c441a4b1 100644 --- a/lib/gitlab/kubernetes/helm/install_command.rb +++ b/lib/gitlab/kubernetes/helm/install_command.rb @@ -1,50 +1,52 @@ module Gitlab module Kubernetes - class Helm::InstallCommand - attr_reader :name, :install_helm, :chart, :chart_values_file - - def initialize(name, install_helm: false, chart: false, chart_values_file: false) - @name = name - @install_helm = install_helm - @chart = chart - @chart_values_file = chart_values_file - end + module Helm + class InstallCommand + attr_reader :name, :install_helm, :chart, :chart_values_file + + def initialize(name, install_helm: false, chart: false, chart_values_file: false) + @name = name + @install_helm = install_helm + @chart = chart + @chart_values_file = chart_values_file + end - def pod_name - "install-#{name}" - end + def pod_name + "install-#{name}" + end - def generate_script(namespace_name) - [ - install_dps_command, - init_command, - complete_command(namespace_name) - ].join("\n") - end + def generate_script(namespace_name) + [ + install_dps_command, + init_command, + complete_command(namespace_name) + ].join("\n") + end - private + private - def init_command - if install_helm - 'helm init >/dev/null' - else - 'helm init --client-only >/dev/null' + def init_command + if install_helm + 'helm init >/dev/null' + else + 'helm init --client-only >/dev/null' + end end - end - def complete_command(namespace_name) - return unless chart + def complete_command(namespace_name) + return unless chart - "helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null" - end + "helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null" + end - def install_dps_command - <<~HEREDOC - set -eo pipefail - apk add -U ca-certificates openssl >/dev/null - wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v#{Gitlab::Kubernetes::Helm::HELM_VERSION}-linux-amd64.tar.gz | tar zxC /tmp >/dev/null - mv /tmp/linux-amd64/helm /usr/bin/ - HEREDOC + def install_dps_command + <<~HEREDOC + set -eo pipefail + apk add -U ca-certificates openssl >/dev/null + wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v#{Gitlab::Kubernetes::Helm::HELM_VERSION}-linux-amd64.tar.gz | tar zxC /tmp >/dev/null + mv /tmp/linux-amd64/helm /usr/bin/ + HEREDOC + end end end end diff --git a/lib/gitlab/kubernetes/helm/pod.rb b/lib/gitlab/kubernetes/helm/pod.rb index e57d0eb8a5b..233f6bf6227 100644 --- a/lib/gitlab/kubernetes/helm/pod.rb +++ b/lib/gitlab/kubernetes/helm/pod.rb @@ -1,66 +1,68 @@ module Gitlab module Kubernetes - class Helm::Pod - def initialize(command, namespace_name, kubeclient) - @command = command - @namespace_name = namespace_name - @kubeclient = kubeclient - end + module Helm + class Pod + def initialize(command, namespace_name, kubeclient) + @command = command + @namespace_name = namespace_name + @kubeclient = kubeclient + end - def generate - spec = { containers: [container_specification], restartPolicy: 'Never' } - if command.chart_values_file - generate_config_map - spec['volumes'] = volumes_specification + def generate + spec = { containers: [container_specification], restartPolicy: 'Never' } + if command.chart_values_file + generate_config_map + spec['volumes'] = volumes_specification + end + ::Kubeclient::Resource.new(metadata: metadata, spec: spec) end - ::Kubeclient::Resource.new(metadata: metadata, spec: spec) - end - private + private - attr_reader :command, :namespace_name, :kubeclient + attr_reader :command, :namespace_name, :kubeclient - def container_specification - container = { - name: 'helm', - image: 'alpine:3.6', - env: generate_pod_env(command), - command: %w(/bin/sh), - args: %w(-c $(COMMAND_SCRIPT)) - } - container[:volumeMounts] = volume_mounts_specification if command.chart_values_file - container - end + def container_specification + container = { + name: 'helm', + image: 'alpine:3.6', + env: generate_pod_env(command), + command: %w(/bin/sh), + args: %w(-c $(COMMAND_SCRIPT)) + } + container[:volumeMounts] = volume_mounts_specification if command.chart_values_file + container + end - def labels - { 'gitlab.org/action': 'install', 'gitlab.org/application': command.name } - end + def labels + { 'gitlab.org/action': 'install', 'gitlab.org/application': command.name } + end - def metadata - { name: command.pod_name, namespace: namespace_name, labels: labels } - end + def metadata + { name: command.pod_name, namespace: namespace_name, labels: labels } + end - def volume_mounts_specification - [{ name: 'config-volume', mountPath: '/etc/config' }] - end + def volume_mounts_specification + [{ name: 'config-volume', mountPath: '/etc/config' }] + end - def volumes_specification - [{ name: 'config-volume', configMap: { name: 'values-config' } }] - end + def volumes_specification + [{ name: 'config-volume', configMap: { name: 'values-config' } }] + end - def generate_pod_env(command) - { - HELM_VERSION: Gitlab::Kubernetes::Helm::HELM_VERSION, - TILLER_NAMESPACE: namespace_name, - COMMAND_SCRIPT: command.generate_script(namespace_name) - }.map { |key, value| { name: key, value: value } } - end + def generate_pod_env(command) + { + HELM_VERSION: Gitlab::Kubernetes::Helm::HELM_VERSION, + TILLER_NAMESPACE: namespace_name, + COMMAND_SCRIPT: command.generate_script(namespace_name) + }.map { |key, value| { name: key, value: value } } + end - def generate_config_map - resource = ::Kubeclient::Resource.new - resource.metadata = { name: 'values-config', namespace: namespace_name } - resource.data = YAML.load_file(command.chart_values_file) - kubeclient.create_config_map(resource) + def generate_config_map + resource = ::Kubeclient::Resource.new + resource.metadata = { name: 'values-config', namespace: namespace_name } + resource.data = YAML.load_file(command.chart_values_file) + kubeclient.create_config_map(resource) + end end end end diff --git a/spec/lib/gitlab/kubernetes/helm_spec.rb b/spec/lib/gitlab/kubernetes/helm/api_spec.rb index 630b4634985..69112fe90b1 100644 --- a/spec/lib/gitlab/kubernetes/helm_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/api_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' -describe Gitlab::Kubernetes::Helm do +describe Gitlab::Kubernetes::Helm::Api do let(:client) { double('kubernetes client') } let(:helm) { described_class.new(client) } - let(:namespace) { Gitlab::Kubernetes::Namespace.new(described_class::NAMESPACE, client) } + let(:gitlab_namespace) { Gitlab::Kubernetes::Helm::NAMESPACE } + let(:namespace) { Gitlab::Kubernetes::Namespace.new(gitlab_namespace, client) } let(:install_helm) { true } let(:chart) { 'stable/a_chart' } let(:application_name) { 'app_name' } @@ -11,12 +12,12 @@ describe Gitlab::Kubernetes::Helm do subject { helm } before do - allow(Gitlab::Kubernetes::Namespace).to receive(:new).with(described_class::NAMESPACE, client).and_return(namespace) + allow(Gitlab::Kubernetes::Namespace).to receive(:new).with(gitlab_namespace, client).and_return(namespace) end describe '#initialize' do it 'creates a namespace object' do - expect(Gitlab::Kubernetes::Namespace).to receive(:new).with(described_class::NAMESPACE, client) + expect(Gitlab::Kubernetes::Namespace).to receive(:new).with(gitlab_namespace, client) subject end @@ -41,7 +42,7 @@ describe Gitlab::Kubernetes::Helm do let(:pod) { Kubeclient::Resource.new(status: { phase: phase }) } # partial representation it 'fetches POD phase from kubernetes cluster' do - expect(client).to receive(:get_pod).with(command.pod_name, described_class::NAMESPACE).once.and_return(pod) + expect(client).to receive(:get_pod).with(command.pod_name, gitlab_namespace).once.and_return(pod) expect(subject.installation_status(command.pod_name)).to eq(phase) end @@ -52,7 +53,7 @@ describe Gitlab::Kubernetes::Helm do let(:response) { RestClient::Response.new(log) } it 'fetches POD phase from kubernetes cluster' do - expect(client).to receive(:get_pod_log).with(command.pod_name, described_class::NAMESPACE).once.and_return(response) + expect(client).to receive(:get_pod_log).with(command.pod_name, gitlab_namespace).once.and_return(response) expect(subject.installation_log(command.pod_name)).to eq(log) end @@ -60,7 +61,7 @@ describe Gitlab::Kubernetes::Helm do describe '#delete_installation_pod!' do it 'deletes the POD from kubernetes cluster' do - expect(client).to receive(:delete_pod).with(command.pod_name, described_class::NAMESPACE).once + expect(client).to receive(:delete_pod).with(command.pod_name, gitlab_namespace).once subject.delete_installation_pod!(command.pod_name) end diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb index 5885c86c2d4..ad175226e92 100644 --- a/spec/services/clusters/applications/install_service_spec.rb +++ b/spec/services/clusters/applications/install_service_spec.rb @@ -5,7 +5,7 @@ describe Clusters::Applications::InstallService do let(:application) { create(:clusters_applications_helm, :scheduled) } let!(:install_command) { application.install_command } let(:service) { described_class.new(application) } - let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm) } + let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm::Api) } before do allow(service).to receive(:install_command).and_return(install_command) |