TRUCK-ONE / RancherCatalog

Rancher用カタログ(テスト)
0 stars 0 forks source link

Helm テンプレートの [character U+002D '-'] エラーについて #3

Open ShigeRunner opened 5 years ago

ShigeRunner commented 5 years ago

以下のYAML(mysql/v0.2.0/templates/configurationFiles-configmap.yaml) を 使用して MySQL の Rancherカタログを起動した際に、

{{- if .Values.configurationFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mysql.fullname" . }}-configuration
data:
{{- range $key, $val := .Values.configurationFiles }}
  {{ $key }}: |-
{{ $val | indent 4}}
{{- end }}
{{- end -}}
#
##{{- if .Values.mycnf.enable }}
##  default-time-zone: {{ .Values.mycnf.default-time-zone }}
##  general_log: {{ .Values.mycnf.generallog.enable }}
#  {{- if .Values.mycnf.generallog.enable }}
##  general_log_file: {{ .Values.mycnf.generallog.path }}{{ .Values.mycnf.generallog.file }} 
#  command: ["mkdir",{{ .Values.mycnf.generallog.path }}]
#  command: ["chmod","777",{{ .Values.mycnf.generallog.path }}]
#  {{- end }}
#{{- end }}

エラーとして、 Helm template failed. Error: parse error in "mysql/templates/configurationFiles-configmap.yaml": template: mysql/templates/configurationFiles-configmap.yaml:10: bad character U+002D '-' : exit status 1 が表示される。

ShigeRunner commented 5 years ago

以下のYAML(mysql/v0.2.0/templates/configurationFiles-configmap.yaml) を 使用して MySQL の Rancherカタログを起動した際には、起動する。

{{- if .Values.configurationFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mysql.fullname" . }}-configuration
data:
{{- range $key, $val := .Values.configurationFiles }}
  {{ $key }}: |-
{{ $val | indent 4}}
{{- end }}
{{- end -}}

このデータは、Helm Chartsをそのまま引用した場合となる。

ShigeRunner commented 5 years ago
  :
        volumeMounts:
        {{- if .Values.mycnf.generallog.enable }}
        - name: generallog
          mountPath: {{ .Values.mycnf.generallog.path }}
        {{- end }}
  :
      volumes:
      {{- if .Values.mycnf.generallog.enable }}
      - name: generallog
        emptyDir: {}
      {{- end }}
  :

→ general.logを使用しない時は、今まで同様に動く → 使用した場合、下記がワークロード内のポッドのエラーとして表示される。

‎2019‎年‎1‎月‎23‎日 ‎17‎:‎07‎:‎48 2019-01-23T08:07:48.790110Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
‎2019‎年‎1‎月‎23‎日 ‎17‎:‎07‎:‎48 2019-01-23T08:07:48.790150Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/lib/mysql/ is unusable. You can safely remove it.
‎2019‎年‎1‎月‎23‎日 ‎17‎:‎07‎:‎48 2019-01-23T08:07:48.790155Z 0 [ERROR] [MY-010119] [Server] Aborting
ShigeRunner commented 5 years ago

変数名 default-time-zone を defaulttimezone に変更した。 → 名前に ' - 'が付いた値にアクセスするには、インデックステンプレート関数を使用する必要があるため。

例: {{index .Values "gitlab-runner"}}。

ShigeRunner commented 5 years ago

以下のYAML(mysql/v0.2.0/templates/configurationFiles-configmap.yaml) に変更した。

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mysql.fullname" . }}-configuration
data:
{{- if .Values.mycnf.enable }}
{{/* questions.yml を反映する場合 */}}
  my.cnf: |-
    [mysqld]
    default-time-zone={{ .Values.mycnf.defaulttimezone }}
    general_log={{ .Values.mycnf.generallog.enable }}
    general_log_file=/var/lib/mysql/{{ .Values.mycnf.generallog.path }}{{ .Values.mycnf.generallog.file }}
{{- else }}
{{/* values.yml を反映する場合 */}}
{{- range $key, $val := .Values.configurationFiles }}
  {{ $key }}: |-
{{ $val | indent 4}}
{{- end }}
{{- end -}}

起動できるようになった。

しかし、思ったように、general_log の登録できない。