How do I mount a ConfigMap volume for VMWare's fluentd operator?

8/24/2020

I am trying to mount a Kubernetes configmap for VMWare's Fluentd operator [1]. I've checked the documentation and the helm chart indicates that you have to specify an additional volume as a parameter called fluentd.extraVolumeMounts

The helm chart I'm using to install the operator is below :

#!/bin/sh
# helmenv set to helm3

CHART_URL='https://github.com/vmware/kube-fluentd-operator/releases/download/v1.12.0/log-router-0.3.3.tgz'

# Set environment variables.
REGION='us-east-1'
CLUSTER='dev'
ENV='dev'
IMAGE_TAG='v1.12.0'

VOLUME_MOUNT="
- name: fluentd-es-templates
  mountPath: /templates"

EXTRA_VOLUME="
- name: fluentd-es-templates
  configMap:
    name: fluentd-es-templates"

# Install the fluentd operator in kube-system.
# helm install kfo ${CHART_URL} \
helm upgrade --install kfo ${CHART_URL} \
  --set meta.key=metadata \
  --set meta.values.region=${REGION} \
  --set meta.values.env=${ENV} \
  --set meta.values.cluster=${CLUSTER} \
  --set rbac.create=true \
  --set image.tag=${IMAGE_TAG} \
  --set image.repository=vmware/kube-fluentd-operator \
# --set fluentd.extraVolumeMounts=[$EXTRA_VOLUME]
# --set extraVolumes=[${EXTRA_VOLUME}]

When I un-comment the lines that set the volumes, the helm script fails. My question is, how do I populate the VOLUME_MOUNT and EXTRA_VOLUME variables with the correct json or yaml? I'm trying to do everything in one file and don't want to split things into multiple files.

-- Chesneycar
amazon-ec2
amazon-eks
amazon-web-services
fluentd
kubernetes

1 Answer

8/24/2020

You can still use a values file from within the shell script via process substitution. Here is an example:

#!/usr/bin/env bash
CHART_URL='https://github.com/vmware/kube-fluentd-operator/releases/download/v1.12.0/log-router-0.3.3.tgz'

read -r -d '' values << EOF
meta:
  key: metadata
  values:
    region: "us-east-1"
    env: "dev"
    cluster: "dev"
rbac:
  create: true
image:
  repository: vmware/kube-fluentd-operator
  tag: "v1.12.0"
fluentd:
  extraVolumeMounts:
    - name: fluentd-es-templates
      mountPath: /fluentd/etc/mappings
extraVolumes:
  - name: fluentd-es-templates
    configMap:
      name: fluentd-es-templates
EOF

helm upgrade --install kfo "$CHART_URL" -f <(printf '%s' "$values")

Under the hood this creates a named pipe and passes a file descriptor such as /dev/fd/123 to the helm install command. This feature is not available in some shells, such as dash (/bin/sh in Debian and Ubuntu).

-- jordanm
Source: StackOverflow