Browse Source

Helm: add support for external application config in yaml format (#2020)

* support yamlConfigMap

* add support of external config map

* remove test config

* update helm version and readme

* pass kafka-ui.yaml directly as helm chart value

* fix configmap metadata name

* update readme

Co-authored-by: Azat Safin <azsafin@provectus.com>
Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
azatsafin 3 years ago
parent
commit
f98c26e4fa

+ 1 - 1
charts/kafka-ui/Chart.yaml

@@ -2,6 +2,6 @@ apiVersion: v2
 name: kafka-ui
 description: A Helm chart for kafka-UI
 type: application
-version: 0.0.3
+version: 0.0.4
 appVersion: latest
 icon: https://github.com/provectus/kafka-ui/raw/master/documentation/images/kafka-ui-logo.png

+ 13 - 10
charts/kafka-ui/README.md

@@ -6,16 +6,19 @@ Most of the Helm charts parameters are common, follow table describe unique para
 
 ### Kafka-UI parameters
 
-| Parameter| Description| Default|
-|---|---|---|
-| `existingConfigMap`| Name of the existing ConfigMap with Kafka-UI environment variables | `nil`|
-| `existingSecret`| Name of the existing Secret with Kafka-UI environment variables| `nil`|
-| `envs.secret`| Set of the sensitive environment variables to pass to Kafka-UI | `{}`|
-| `envs.config`| Set of the environment variables to pass to Kafka-UI | `{}`|
-| `networkPolicy.enabled` | Enable network policies | `false`|
-| `networkPolicy.egressRules.customRules` | Custom network egress policy rules | `[]`|
-| `networkPolicy.ingressRules.customRules` | Custom network ingress policy rules | `[]`|
-| `podLabels` | Extra labels for Kafka-UI pod | `{}`|
+| Parameter                                | Description                                                                                                                                    | Default |
+| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
+| `existingConfigMap`                      | Name of the existing ConfigMap with Kafka-UI environment variables                                                                             | `nil`   |
+| `existingSecret`                         | Name of the existing Secret with Kafka-UI environment variables                                                                                | `nil`   |
+| `envs.secret`                            | Set of the sensitive environment variables to pass to Kafka-UI                                                                                 | `{}`    |
+| `envs.config`                            | Set of the environment variables to pass to Kafka-UI                                                                                           | `{}`    |
+| `yamlApplicationConfigConfigMap`         | Map with name and keyName keys, name refers to the existing ConfigMap, keyName refers to the ConfigMap key with Kafka-UI config in Yaml format | `{}`    |
+| `yamlApplicationConfig`                  | Kafka-UI config in Yaml format                                                                                                                 | `{}`    |
+| `networkPolicy.enabled`                  | Enable network policies                                                                                                                        | `false` |
+| `networkPolicy.egressRules.customRules`  | Custom network egress policy rules                                                                                                             | `[]`    |
+| `networkPolicy.ingressRules.customRules` | Custom network ingress policy rules                                                                                                            | `[]`    |
+| `podLabels`                              | Extra labels for Kafka-UI pod                                                                                                                  | `{}`    |
+
 
 ## Example
 

+ 3 - 1
charts/kafka-ui/templates/configmap.yaml

@@ -1,3 +1,4 @@
+{{- if .Values.envs.config -}}
 apiVersion: v1
 kind: ConfigMap
 metadata:
@@ -5,4 +6,5 @@ metadata:
   labels:
     {{- include "kafka-ui.labels" . | nindent 4 }}
 data:
-  {{- toYaml .Values.envs.config | nindent 2 }}
+  {{- toYaml .Values.envs.config | nindent 2 }}
+{{- end -}}

+ 11 - 0
charts/kafka-ui/templates/configmap_fromValues.yaml

@@ -0,0 +1,11 @@
+{{- if .Values.yamlApplicationConfig -}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "kafka-ui.fullname" . }}-fromvalues
+  labels:
+    {{- include "kafka-ui.labels" . | nindent 4 }}
+data:
+  config.yml: 
+    {{- toYaml .Values.yamlApplicationConfig | nindent 4}}
+{{ end }}

+ 43 - 7
charts/kafka-ui/templates/deployment.yaml

@@ -42,23 +42,37 @@ spec:
             {{- toYaml .Values.securityContext | nindent 12 }}
           image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
           imagePullPolicy: {{ .Values.image.pullPolicy }}
-          {{- with .Values.env }}
+          {{- if or .Values.env  .Values.yamlApplicationConfig .Values.yamlApplicationConfigConfigMap}}
           env:
-            {{- toYaml . | nindent 12 }}
+            {{- with .Values.env }}
+              {{- toYaml . | nindent 12 }}
+            {{- end }}
+            {{- if or .Values.yamlApplicationConfig .Values.yamlApplicationConfigConfigMap}}
+            - name: SPRING_CONFIG_LOCATION
+              {{- if .Values.yamlApplicationConfig }}
+              value: /kafka-ui/config.yml
+              {{- else if .Values.yamlApplicationConfigConfigMap }}
+              value: /kafka-ui/{{ .Values.yamlApplicationConfigConfigMap.keyName | default "config.yml" }}
+              {{- end }}
+            {{- end }}
           {{- end }}
           envFrom:
             {{- if .Values.existingConfigMap }}
             - configMapRef:
                 name: {{ .Values.existingConfigMap }}
             {{- end }}
+            {{- if .Values.envs.config }}
             - configMapRef:
                 name: {{ include "kafka-ui.fullname" . }}
+            {{- end }}
             {{- if .Values.existingSecret }}
             - secretRef:
                 name: {{ .Values.existingSecret }}
             {{- end }}
+            {{- if .Values.envs.secret}}
             - secretRef:
                 name: {{ include "kafka-ui.fullname" . }}
+            {{- end}}    
           ports:
             - name: http
               containerPort: 8080
@@ -81,13 +95,35 @@ spec:
             timeoutSeconds: 10
           resources:
             {{- toYaml .Values.resources | nindent 12 }}
-          {{- with .Values.volumeMounts }}
+          {{- if or .Values.yamlApplicationConfig .Values.volumeMounts .Values.yamlApplicationConfigConfigMap}}
           volumeMounts:
-            {{- toYaml . | nindent 12 }}
+            {{- with .Values.volumeMounts }} 
+              {{- toYaml . | nindent 12 }}
+            {{- end }}
+            {{- if .Values.yamlApplicationConfig }}
+            - name: kafka-ui-yaml-conf
+              mountPath: /kafka-ui/
+            {{- end }}
+            {{- if .Values.yamlApplicationConfigConfigMap}}
+            - name: kafka-ui-yaml-conf-configmap
+              mountPath: /kafka-ui/
+            {{- end }}
           {{- end }}
-      {{- with .Values.volumes }}
+      {{- if or .Values.yamlApplicationConfig .Values.volumes .Values.yamlApplicationConfigConfigMap}}
       volumes:
-        {{- toYaml . | nindent 8 }}
+        {{- with .Values.volumes }}
+          {{- toYaml . | nindent 8 }}
+        {{- end }}
+        {{- if .Values.yamlApplicationConfig }}
+        - name: kafka-ui-yaml-conf
+          configMap: 
+            name: {{ include "kafka-ui.fullname" . }}-fromvalues
+        {{- end }}
+        {{- if .Values.yamlApplicationConfigConfigMap}}
+        - name: kafka-ui-yaml-conf-configmap
+          configMap: 
+            name: {{ .Values.yamlApplicationConfigConfigMap.name }}
+        {{- end }}
       {{- end }}
       {{- with .Values.nodeSelector }}
       nodeSelector:
@@ -100,4 +136,4 @@ spec:
       {{- with .Values.tolerations }}
       tolerations:
         {{- toYaml . | nindent 8 }}
-      {{- end }}
+      {{- end }}

+ 25 - 3
charts/kafka-ui/values.yaml

@@ -21,6 +21,25 @@ serviceAccount:
   name: ""
 
 existingConfigMap: ""
+yamlApplicationConfig:
+  {}
+  # kafka:
+  #   clusters:
+  #     - name: yaml
+  #       bootstrapServers: kafka-service:9092
+  # spring:
+  #   security:
+  #     oauth2:
+  # auth:
+  #   type: disabled
+  # management:
+  #   health:
+  #     ldap:
+  #       enabled: false
+yamlApplicationConfigConfigMap:
+  {}
+  # keyName: config.yml
+  # name: configMapName
 existingSecret: ""
 envs:
   secret: {}
@@ -50,10 +69,12 @@ networkPolicy:
 podAnnotations: {}
 podLabels: {}
 
-podSecurityContext: {}
+podSecurityContext:
+  {}
   # fsGroup: 2000
 
-securityContext: {}
+securityContext:
+  {}
   # capabilities:
   #   drop:
   #   - ALL
@@ -97,7 +118,8 @@ ingress:
   # Http paths to add to the Ingress after the default path
   succeedingPaths: []
 
-resources: {}
+resources:
+  {}
   # limits:
   #   cpu: 200m
   #   memory: 512Mi