Commit 1827f398 authored by Mayra Cabrera's avatar Mayra Cabrera Committed by Kamil Trzciński

Resolve "Managed Prometheus deployment installs a lot of extra stuff"

parent c2afd107
...@@ -36,8 +36,12 @@ module Gitlab ...@@ -36,8 +36,12 @@ module Gitlab
def complete_command(namespace_name) def complete_command(namespace_name)
return unless chart return unless chart
if chart_values_file
"helm install #{chart} --name #{name} --namespace #{namespace_name} -f /data/helm/#{name}/config/values.yaml >/dev/null"
else
"helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null" "helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null"
end end
end
def install_dps_command def install_dps_command
<<~HEREDOC <<~HEREDOC
......
...@@ -10,9 +10,10 @@ module Gitlab ...@@ -10,9 +10,10 @@ module Gitlab
def generate def generate
spec = { containers: [container_specification], restartPolicy: 'Never' } spec = { containers: [container_specification], restartPolicy: 'Never' }
if command.chart_values_file if command.chart_values_file
generate_config_map create_config_map
spec['volumes'] = volumes_specification spec[:volumes] = volumes_specification
end end
::Kubeclient::Resource.new(metadata: metadata, spec: spec) ::Kubeclient::Resource.new(metadata: metadata, spec: spec)
...@@ -35,19 +36,39 @@ module Gitlab ...@@ -35,19 +36,39 @@ module Gitlab
end end
def labels def labels
{ 'gitlab.org/action': 'install', 'gitlab.org/application': command.name } {
'gitlab.org/action': 'install',
'gitlab.org/application': command.name
}
end end
def metadata def metadata
{ name: command.pod_name, namespace: namespace_name, labels: labels } {
name: command.pod_name,
namespace: namespace_name,
labels: labels
}
end end
def volume_mounts_specification def volume_mounts_specification
[{ name: 'config-volume', mountPath: '/etc/config' }] [
{
name: 'configuration-volume',
mountPath: "/data/helm/#{command.name}/config"
}
]
end end
def volumes_specification def volumes_specification
[{ name: 'config-volume', configMap: { name: 'values-config' } }] [
{
name: 'configuration-volume',
configMap: {
name: 'values-content-configuration',
items: [{ key: 'values', path: 'values.yaml' }]
}
}
]
end end
def generate_pod_env(command) def generate_pod_env(command)
...@@ -58,10 +79,10 @@ module Gitlab ...@@ -58,10 +79,10 @@ module Gitlab
}.map { |key, value| { name: key, value: value } } }.map { |key, value| { name: key, value: value } }
end end
def generate_config_map def create_config_map
resource = ::Kubeclient::Resource.new resource = ::Kubeclient::Resource.new
resource.metadata = { name: 'values-config', namespace: namespace_name } resource.metadata = { name: 'values-content-configuration', namespace: namespace_name, labels: { name: 'values-content-configuration' } }
resource.data = YAML.load_file(command.chart_values_file) resource.data = { values: File.read(command.chart_values_file) }
kubeclient.create_config_map(resource) kubeclient.create_config_map(resource)
end end
end end
......
...@@ -100,6 +100,25 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do ...@@ -100,6 +100,25 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
is_expected.to eq(command) is_expected.to eq(command)
end end
end end
context 'when chart values file is present' do
let(:install_command) { described_class.new(prometheus.name, chart: prometheus.chart, chart_values_file: prometheus.chart_values_file) }
let(:command) do
<<~MSG.chomp
set -eo pipefail
apk add -U ca-certificates openssl >/dev/null
wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v2.7.0-linux-amd64.tar.gz | tar zxC /tmp >/dev/null
mv /tmp/linux-amd64/helm /usr/bin/
helm init --client-only >/dev/null
helm install #{prometheus.chart} --name #{prometheus.name} --namespace #{namespace.name} -f /data/helm/#{prometheus.name}/config/values.yaml >/dev/null
MSG
end
it 'should return appropriate command' do
is_expected.to eq(command)
end
end
end end
describe "#pod_name" do describe "#pod_name" do
......
...@@ -52,18 +52,20 @@ describe Gitlab::Kubernetes::Helm::Pod do ...@@ -52,18 +52,20 @@ describe Gitlab::Kubernetes::Helm::Pod do
it 'should include volumes for the container' do it 'should include volumes for the container' do
container = subject.generate.spec.containers.first container = subject.generate.spec.containers.first
expect(container.volumeMounts.first['name']).to eq('config-volume') expect(container.volumeMounts.first['name']).to eq('configuration-volume')
expect(container.volumeMounts.first['mountPath']).to eq('/etc/config') expect(container.volumeMounts.first['mountPath']).to eq("/data/helm/#{app.name}/config")
end end
it 'should include a volume inside the specification' do it 'should include a volume inside the specification' do
spec = subject.generate.spec spec = subject.generate.spec
expect(spec.volumes.first['name']).to eq('config-volume') expect(spec.volumes.first['name']).to eq('configuration-volume')
end end
it 'should mount configMap specification in the volume' do it 'should mount configMap specification in the volume' do
spec = subject.generate.spec spec = subject.generate.spec
expect(spec.volumes.first.configMap['name']).to eq('values-config') expect(spec.volumes.first.configMap['name']).to eq('values-content-configuration')
expect(spec.volumes.first.configMap['items'].first['key']).to eq('values')
expect(spec.volumes.first.configMap['items'].first['path']).to eq('values.yaml')
end end
end end
......
alertmanager: | alertmanager:
enabled: false enabled: false
kubeStateMetrics: | kubeStateMetrics:
enabled: 'false' enabled: false
nodeExporter: | nodeExporter:
enabled: 'false' enabled: false
pushgateway: | pushgateway:
enabled: 'false' enabled: false
serverFiles: | serverFiles:
alerts: '' alerts: ""
rules: '' rules: ""
prometheus.yml: |- prometheus.yml: |-
rule_files: | rule_files:
- /etc/config/rules - /etc/config/rules
- /etc/config/alerts - /etc/config/alerts
scrape_configs: |
scrape_configs:
- job_name: prometheus - job_name: prometheus
static_configs: | static_configs:
- targets: - targets:
- localhost:9090 - localhost:9090
- job_name: 'kubernetes-apiservers' - job_name: 'kubernetes-apiservers'
kubernetes_sd_configs: |
kubernetes_sd_configs:
- role: endpoints - role: endpoints
scheme: https scheme: https
tls_config: tls_config:
...@@ -37,14 +40,17 @@ serverFiles: | ...@@ -37,14 +40,17 @@ serverFiles: |
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name] - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep action: keep
regex: default;kubernetes;https regex: default;kubernetes;https
- job_name: 'kubernetes-nodes' - job_name: 'kubernetes-nodes'
scheme: https scheme: https
tls_config: tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
insecure_skip_verify: true insecure_skip_verify: true
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
kubernetes_sd_configs: kubernetes_sd_configs:
- role: node - role: node
relabel_configs: relabel_configs:
- action: labelmap - action: labelmap
regex: __meta_kubernetes_node_label_(.+) regex: __meta_kubernetes_node_label_(.+)
...@@ -54,14 +60,15 @@ serverFiles: | ...@@ -54,14 +60,15 @@ serverFiles: |
regex: (.+) regex: (.+)
target_label: __metrics_path__ target_label: __metrics_path__
replacement: /api/v1/nodes/${1}/proxy/metrics replacement: /api/v1/nodes/${1}/proxy/metrics
- job_name: 'kubernetes-service-endpoints' - job_name: 'kubernetes-service-endpoints'
kubernetes_sd_configs: kubernetes_sd_configs:
- role: endpoints - role: endpoints
relabel_configs: |
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape] - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep action: keep
regex: 'true' regex: true
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme] - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
action: replace action: replace
target_label: __scheme__ target_label: __scheme__
...@@ -83,24 +90,30 @@ serverFiles: | ...@@ -83,24 +90,30 @@ serverFiles: |
- source_labels: [__meta_kubernetes_service_name] - source_labels: [__meta_kubernetes_service_name]
action: replace action: replace
target_label: kubernetes_name target_label: kubernetes_name
- job_name: 'prometheus-pushgateway' - job_name: 'prometheus-pushgateway'
honor_labels: true honor_labels: true
kubernetes_sd_configs: |
kubernetes_sd_configs:
- role: service - role: service
relabel_configs: |
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe] - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe]
action: keep action: keep
regex: pushgateway regex: pushgateway
- job_name: 'kubernetes-services' - job_name: 'kubernetes-services'
metrics_path: /probe metrics_path: /probe
params: | params:
module: [http_2xx] module: [http_2xx]
kubernetes_sd_configs: |
kubernetes_sd_configs:
- role: service - role: service
relabel_configs: |
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe] - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe]
action: keep action: keep
regex: 'true' regex: true
- source_labels: [__address__] - source_labels: [__address__]
target_label: __param_target target_label: __param_target
- target_label: __address__ - target_label: __address__
...@@ -113,17 +126,25 @@ serverFiles: | ...@@ -113,17 +126,25 @@ serverFiles: |
target_label: kubernetes_namespace target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_service_name] - source_labels: [__meta_kubernetes_service_name]
target_label: kubernetes_name target_label: kubernetes_name
- job_name: 'kubernetes-pods' - job_name: 'kubernetes-pods'
kubernetes_sd_configs: kubernetes_sd_configs:
- role: pod - role: pod
relabel_configs: relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep action: keep
regex: 'true' regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace action: replace
target_label: __metrics_path__ target_label: __metrics_path__
regex: (.+) regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: (.+):(?:\d+);(\d+)
replacement: ${1}:${2}
target_label: __address__
- action: labelmap - action: labelmap
regex: __meta_kubernetes_pod_label_(.+) regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace] - source_labels: [__meta_kubernetes_namespace]
......
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