From 2b5fe533f66906482bf0793f65d98235f3091c75 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Wed, 29 Sep 2021 14:18:57 +0200 Subject: [PATCH] (feat) Add Promtail and Netshoot addons (#1058) * add promtail addon * Add Netshoot addon * update common to include envList for addons * Add basic promtail and netshoot unittests --- charts/library/common/Chart.yaml | 2 +- .../addons/code-server/_container.tpl | 10 +- .../templates/addons/netshoot/_container.tpl | 11 +- .../templates/addons/promtail/_container.tpl | 11 +- charts/library/common/values.yaml | 20 ++- templates/questions/addons.yaml | 125 ++++++++++++++++++ tests/library/common/addon_netshoot_spec.rb | 35 +++++ tests/library/common/addon_promtail_spec.rb | 42 ++++++ 8 files changed, 250 insertions(+), 6 deletions(-) create mode 100644 tests/library/common/addon_netshoot_spec.rb create mode 100644 tests/library/common/addon_promtail_spec.rb diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 653be62d294..a0d3c5b5f2d 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 8.0.10 +version: 8.0.11 diff --git a/charts/library/common/templates/addons/code-server/_container.tpl b/charts/library/common/templates/addons/code-server/_container.tpl index 4fef39213a4..652cb5906ad 100644 --- a/charts/library/common/templates/addons/code-server/_container.tpl +++ b/charts/library/common/templates/addons/code-server/_container.tpl @@ -12,8 +12,16 @@ imagePullPolicy: {{ .Values.codeserverImage.pullPolicy }} securityContext: {{- toYaml . | nindent 2 }} {{- end }} -{{- with .Values.addons.codeserver.env }} env: +{{- range $envList := .Values.addons.codeserver.envList }} + {{- if and $envList.name $envList.value }} + - name: {{ $envList.name }} + value: {{ $envList.value | quote }} + {{- else }} + {{- fail "Please specify name/value for codeserver environment variable" }} + {{- end }} +{{- end}} +{{- with .Values.addons.codeserver.env }} {{- range $k, $v := . }} - name: {{ $k }} value: {{ $v | quote }} diff --git a/charts/library/common/templates/addons/netshoot/_container.tpl b/charts/library/common/templates/addons/netshoot/_container.tpl index a44bebb66bb..2d3d46f5525 100644 --- a/charts/library/common/templates/addons/netshoot/_container.tpl +++ b/charts/library/common/templates/addons/netshoot/_container.tpl @@ -9,8 +9,17 @@ imagePullPolicy: {{ .Values.netshootImage.pullPolicy }} securityContext: {{- toYaml . | nindent 2 }} {{- end }} -{{- with .Values.addons.netshoot.env }} + env: +{{- range $envList := .Values.addons.netshoot.envList }} + {{- if and $envList.name $envList.value }} + - name: {{ $envList.name }} + value: {{ $envList.value | quote }} + {{- else }} + {{- fail "Please specify name/value for netshoot environment variable" }} + {{- end }} +{{- end}} +{{- with .Values.addons.netshoot.env }} {{- range $k, $v := . }} - name: {{ $k }} value: {{ $v | quote }} diff --git a/charts/library/common/templates/addons/promtail/_container.tpl b/charts/library/common/templates/addons/promtail/_container.tpl index 2cfbe17a404..fefb3b28909 100644 --- a/charts/library/common/templates/addons/promtail/_container.tpl +++ b/charts/library/common/templates/addons/promtail/_container.tpl @@ -12,8 +12,17 @@ imagePullPolicy: {{ .Values.promtailImage.pullPolicy }} securityContext: {{- toYaml . | nindent 2 }} {{- end }} -{{- with .Values.addons.promtail.env }} + env: +{{- range $envList := .Values.addons.promtail.envList }} + {{- if and $envList.name $envList.value }} + - name: {{ $envList.name }} + value: {{ $envList.value | quote }} + {{- else }} + {{- fail "Please specify name/value for promtail environment variable" }} + {{- end }} +{{- end}} +{{- with .Values.addons.promtail.env }} {{- range $k, $v := . }} - name: {{ $k }} value: {{ $v | quote }} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index c9766ca150a..e520318e05d 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -726,8 +726,8 @@ addons: # -- All variables specified here will be added to the vpn sidecar container # See the documentation of the VPN image for all config values envList: [] - # name: someenv - # value: somevalue + #- name: someenv + # value: somevalue # -- Provide a customized vpn configuration file to be used by the VPN. configFile: @@ -750,6 +750,12 @@ addons: # -- Set any environment variables for code-server here env: {} # TZ: UTC + + # -- All variables specified here will be added to the codeserver sidecar container + # See the documentation of the codeserver image for all config values + envList: [] + #- name: someenv + # value: somevalue # -- Set codeserver command line arguments. # Consider setting --user-data-dir to a persistent location to preserve code-server setting changes args: @@ -825,6 +831,11 @@ addons: enabled: false # -- Set any environment variables for promtail here env: {} + # -- All variables specified here will be added to the promtail sidecar container + # See the documentation of the promtail image for all config values + envList: [] + #- name: someenv + # value: somevalue # -- Set promtail command line arguments args: [] # -- The URL to Loki @@ -852,6 +863,11 @@ addons: # -- Set any environment variables for netshoot here env: {} + # -- All variables specified here will be added to the netshoot sidecar container + # See the documentation of the netshoot image for all config values + envList: [] + #- name: someenv + # value: somevalue securityContext: capabilities: diff --git a/templates/questions/addons.yaml b/templates/questions/addons.yaml index 86dadc64f85..7ccd6bb4fa5 100644 --- a/templates/questions/addons.yaml +++ b/templates/questions/addons.yaml @@ -133,3 +133,128 @@ schema: type: string required: true + + - variable: promtail + label: "Promtail" + schema: + type: dict + attrs: + - variable: enabled + label: "enabled" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: envList + label: "Promtail environment Variables" + schema: + type: list + show_if: [["type", "!=", "disabled"]] + default: [] + items: + - variable: loki + label: "Loki URL" + schema: + type: string + required: true + - variable: envItem + label: "Environment Variable" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + required: true + - variable: value + label: "Value" + schema: + type: string + required: true + - variable: args + label: "Promtail ecommand line arguments" + schema: + type: list + show_if: [["type", "!=", "disabled"]] + default: [] + items: + - variable: arg + label: "Arg" + schema: + type: string + required: true + - variable: logs + label: "Log Paths" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + required: true + - variable: path + label: "Path" + schema: + type: string + required: true + - variable: volumeMounts + label: "volumeMounts" + description: "At least 1 volumeMount is required!" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + required: true + - variable: mountPath + label: "mountPath" + schema: + type: string + required: true + - variable: readOnly + label: "readOnly" + schema: + type: boolean + required: true + default: true + hidden: true + + - variable: netshoot + label: "Netshoot" + schema: + type: dict + attrs: + - variable: enabled + label: "enabled" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: envList + label: "Netshoot environment Variables" + schema: + type: list + show_if: [["type", "!=", "disabled"]] + default: [] + items: + - variable: envItem + label: "Environment Variable" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + required: true + - variable: value + label: "Value" + schema: + type: string + required: true diff --git a/tests/library/common/addon_netshoot_spec.rb b/tests/library/common/addon_netshoot_spec.rb new file mode 100644 index 00000000000..9404008cacf --- /dev/null +++ b/tests/library/common/addon_netshoot_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true +require_relative '../../test_helper' + +class Test < ChartTest + @@chart = Chart.new('charts/library/common-test') + + describe @@chart.name do + describe 'addon::netshoot' do + it 'defaults to disabled' do + deployment = chart.resources(kind: "Deployment").first + containers = deployment["spec"]["template"]["spec"]["containers"] + netshootContainer = containers.find{ |c| c["name"] == "netshoot" } + + assert_nil(netshootContainer) + end + + it 'netshoot can be enabled' do + values = { + addons: { + netshoot: { + enabled: true + } + } + } + + chart.value values + deployment = chart.resources(kind: "Deployment").first + containers = deployment["spec"]["template"]["spec"]["containers"] + netshootContainer = containers.find{ |c| c["name"] == "netshoot" } + + refute_nil(netshootContainer) + end + end + end +end diff --git a/tests/library/common/addon_promtail_spec.rb b/tests/library/common/addon_promtail_spec.rb new file mode 100644 index 00000000000..06e44f89cfe --- /dev/null +++ b/tests/library/common/addon_promtail_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +require_relative '../../test_helper' + +class Test < ChartTest + @@chart = Chart.new('charts/library/common-test') + + describe @@chart.name do + describe 'addon::promtail' do + it 'defaults to disabled' do + deployment = chart.resources(kind: "Deployment").first + containers = deployment["spec"]["template"]["spec"]["containers"] + promtailContainer = containers.find{ |c| c["name"] == "promtail" } + + assert_nil(promtailContainer) + end + + it 'promtail can be enabled' do + values = { + addons: { + promtail: { + enabled: true, + volumeMounts: [ + { + name: "config", + mountPath: "/tmp", + readOnly: true + } + ] + } + } + } + + chart.value values + deployment = chart.resources(kind: "Deployment").first + containers = deployment["spec"]["template"]["spec"]["containers"] + promtailContainer = containers.find{ |c| c["name"] == "promtail" } + + refute_nil(promtailContainer) + end + end + end +end