Kubernetes 循环通过传递的纯文本文件的行--set file helm选项,然后按列分析每一行

Kubernetes 循环通过传递的纯文本文件的行--set file helm选项,然后按列分析每一行,kubernetes,kubernetes-helm,sprig-template-functions,Kubernetes,Kubernetes Helm,Sprig Template Functions,我有一个cron文件,我正试图通过--set file选项传递它。 我想循环遍历cron文件行,并为每行创建CronJob类型的新Kubernetes对象 我是这样使用的helminstal--设置文件crons.file=mycron 其中mycron文件看起来像一个典型的cron文件: 0,10,20,30,40,50 * * * * /usr/bin/cmd1 opta optb 35 2-23/3 * * * /usr/bin/cmd2 我无法通过以下简单的纯文本行进行迭代: {{-

我有一个cron文件,我正试图通过
--set file
选项传递它。 我想循环遍历cron文件行,并为每行创建CronJob类型的新Kubernetes对象

我是这样使用的
helminstal--设置文件crons.file=mycron

其中mycron文件看起来像一个典型的cron文件:

0,10,20,30,40,50 * * * * /usr/bin/cmd1 opta optb
35 2-23/3 * * * /usr/bin/cmd2
我无法通过以下简单的纯文本行进行迭代:

{{- range $indx, $line := .Values.crons.file }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: {{ regexFind "[^/]+$" "$line"}}
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron-{{ $indx }}
            image: busybox
            args: 
            - /bin/sh
            - -c
            - {{ regexFind "[^/]+$" "$line"}}
          restartPolicy: OnFailure
{{- end  }}
是否有类似于
fromYaml
的函数,它使纯文本文件可通过
范围
函数进行访问?

支持库包括用于和的函数。如果
splitList
文件位于换行符上,您将得到一个行列表。您可以再次
splitList
空格上的每一行,从各个cron行中获取单独的时间和命令部分

{{/* Iterate over individual lines in the string */}}
{{- range $line := splitList "\n" .Values.crons.file -}}

{{/* Break the line into words */}}
{{- $words := splitList " " $line -}}

{{/* Reconstitute the schedule and command parts from the words */}}
{{- $time := slice $words 0 5 | join " " -}}
{{- $command := slice $words 5 -}}

---
schedule: {{ $time }}
command: {{- $command | toYaml | nindent 2}}
{{ end -}}
支持库包括和的函数。如果
splitList
文件位于换行符上,您将得到一个行列表。您可以再次
splitList
空格上的每一行,从各个cron行中获取单独的时间和命令部分

{{/* Iterate over individual lines in the string */}}
{{- range $line := splitList "\n" .Values.crons.file -}}

{{/* Break the line into words */}}
{{- $words := splitList " " $line -}}

{{/* Reconstitute the schedule and command parts from the words */}}
{{- $time := slice $words 0 5 | join " " -}}
{{- $command := slice $words 5 -}}

---
schedule: {{ $time }}
command: {{- $command | toYaml | nindent 2}}
{{ end -}}
我得到:at:调用slice:reflect.Value.slice时出错:slice索引超出边界我得到:at:调用slice:reflect.Value.slice时出错:slice索引超出边界