如何将变量值传递给 Helm 图表中的.files.glob?

af7jpaap  于 2021-06-13  发布在  Cassandra
关注(0)|答案(0)|浏览(436)

调用 .Files.Glob 下面需要从作为值提供的变量中 .Values.initDBFilesGlob . 值设置正确,但 if 情况并非如此,尽管 .Values.initDBConfigMap 是空的。
如何将变量参数传递给 .Files.Glob ?
有问题的模板( templates/initdb-configmap.yaml 从我的在制品图表https://github.com/northscaler/charts/tree/support-env-specific-init/bitnami/cassandra 我会服从的https://github.com/bitnami/charts/tree/master/bitnami/cassandra 作为公关,一旦这是固定的):

{{- $initDBFilesGlob := .Values.initDBFilesGlob -}}

# "{{ $initDBFilesGlob }}" "{{ .Values.initDBConfigMap }}"

# There should be content below this

{{- if and (.Files.Glob $initDBFilesGlob) (not .Values.initDBConfigMap) }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "cassandra.fullname" . }}-init-scripts
  labels: {{- include "cassandra.labels" . | nindent 4 }}
data:
{{ (.Files.Glob $initDBFilesGlob).AsConfig | indent 2 }}
{{- end }}

文件 values.yaml :

dbUser:
  forcePassword: true
  password: cassandra
initDBFilesGlob: 'files/devops/docker-entrypoint-initdb.d/*'

命令: helm template -f values.yaml foobar /Users/matthewadams/dev/bitnami/charts/bitnami/cassandra 中有个文件 files/devops/docker-entrypoint-initdb.d ,相对于调用命令的目录。
输出:

---

# Source: cassandra/templates/pdb.yaml

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: foobar-cassandra-headless
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
spec:
  selector:
    matchLabels:
      app: cassandra
      release: foobar
  maxUnavailable: 1
---

# Source: cassandra/templates/cassandra-secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: foobar-cassandra
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
type: Opaque
data:
  cassandra-password: "Y2Fzc2FuZHJh"
---

# Source: cassandra/templates/configuration-cm.yaml

# files/conf/*

apiVersion: v1
kind: ConfigMap

# files/conf/*

metadata:
  name: foobar-cassandra-configuration
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
data:
  README.md: |
    Place your Cassandra configuration files here. This will override the values set in any configuration environment variable. This will not be used in case the value *existingConfiguration* is used.

    More information [here](https://github.com/bitnami/bitnami-docker-cassandra#configuration)
---

# Source: cassandra/templates/headless-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: foobar-cassandra-headless
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
spec:
  clusterIP: None
  publishNotReadyAddresses: true
  ports:
    - name: intra
      port: 7000
      targetPort: intra
    - name: tls
      port: 7001
      targetPort: tls
    - name: jmx
      port: 7199
      targetPort: jmx
    - name: cql
      port: 9042
      targetPort: cql
    - name: thrift
      port: 9160
      targetPort: thrift
  selector:
    app: cassandra
    release: foobar
---

# Source: cassandra/templates/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: foobar-cassandra
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
  annotations: 
    {}
spec:
  type: ClusterIP
  ports:
    - name: cql
      port: 9042
      targetPort: cql
      nodePort: null
    - name: thrift
      port: 9160
      targetPort: thrift
      nodePort: null
  selector:
    app: cassandra
    release: foobar
---

# Source: cassandra/templates/statefulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: foobar-cassandra
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
spec:
  selector:
    matchLabels:
      app: cassandra
      release: foobar
  serviceName: foobar-cassandra-headless
  replicas: 1
  updateStrategy:
    type: OnDelete
  template:
    metadata:
      labels:
        app: cassandra
        chart: cassandra-5.1.2
        release: foobar
        heritage: Helm
    spec:

      securityContext:
        fsGroup: 1001
        runAsUser: 1001
      containers:
        - name: cassandra
          command:
            - bash
            - -ec
            # Node 0 is the password seeder
            - |
              if [[ $HOSTNAME =~ (.*)-0$ ]]; then
                echo "Setting node as password seeder"
                export CASSANDRA_PASSWORD_SEEDER=yes
              else
                # Only node 0 will execute the startup initdb scripts
                export CASSANDRA_IGNORE_INITDB_SCRIPTS=1
              fi
              /entrypoint.sh /run.sh
          image: docker.io/bitnami/cassandra:3.11.6-debian-10-r26
          imagePullPolicy: "IfNotPresent"
          env:
            - name: BITNAMI_DEBUG
              value: "false"
            - name: CASSANDRA_CLUSTER_NAME
              value: cassandra
            - name: CASSANDRA_SEEDS
              value: "foobar-cassandra-0.foobar-cassandra-headless.default.svc.cluster.local"
            - name: CASSANDRA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: foobar-cassandra
                  key: cassandra-password
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: CASSANDRA_USER
              value: "cassandra"
            - name: CASSANDRA_NUM_TOKENS
              value: "256"
            - name: CASSANDRA_DATACENTER
              value: dc1
            - name: CASSANDRA_ENDPOINT_SNITCH
              value: SimpleSnitch
            - name: CASSANDRA_ENDPOINT_SNITCH
              value: SimpleSnitch
            - name: CASSANDRA_RACK
              value: rack1
            - name: CASSANDRA_ENABLE_RPC
              value: "true"
          livenessProbe:
            exec:
              command: ["/bin/sh", "-c", "nodetool status"]
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 5
          readinessProbe:
            exec:
              command: ["/bin/sh", "-c", "nodetool status | grep -E \"^UN\\s+${POD_IP}\""]
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 5
          ports:
            - name: intra
              containerPort: 7000
            - name: tls
              containerPort: 7001
            - name: jmx
              containerPort: 7199
            - name: cql
              containerPort: 9042
            - name: thrift
              containerPort: 9160
          resources: 
            limits: {}
            requests: {}
          volumeMounts:
            - name: data
              mountPath: /bitnami/cassandra
            - name: init-db
              mountPath: /docker-entrypoint-initdb.d

            - name: configurations
              mountPath: /bitnami/cassandra/conf
      volumes:
        - name: configurations
          configMap:
            name: foobar-cassandra-configuration
        - name: init-db
          configMap:
            name: foobar-cassandra-init-scripts
  volumeClaimTemplates:
    - metadata:
        name: data
        labels:
          app: cassandra
          release: foobar
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
---

# Source: cassandra/templates/initdb-configmap.yaml

# "files/devops/docker-entrypoint-initdb.d/*" ""

# There should be content below this

如果我在我的 values.yaml 那就定了 initDBFilesGlob ,模板将正确呈现:

...
---

# Source: cassandra/templates/initdb-configmap.yaml

# "files/docker-entrypoint-initdb.d/*" ""

# There should be content below this

apiVersion: v1
kind: ConfigMap
metadata:
  name: foobar-cassandra-init-scripts
  labels:
    app: cassandra
    chart: cassandra-5.1.2
    release: foobar
    heritage: Helm
data:
  README.md: |
    You can copy here your custom `.sh` or `.cql` file so they are executed during the first boot of the image.

    More info in the [bitnami-docker-cassandra](https://github.com/bitnami/bitnami-docker-cassandra#initializing-a-new-instance) repository.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题