Home > other >  Add Zip / Binary file to configmap
Add Zip / Binary file to configmap

Time:03-24

I am trying to add a zip file to our configmap due to the amount of files exceeding the 1mb limit. I deploy our charts with helm and was looking into binaryData but cannot get it to work properly. I wanted to see if anyone had any suggestions on how I could integrate this with helm so when the job is finished it deletes the configmap with it

Here is my configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  {{ .Files.Get "migrations.zip" | b64enc }}
immutable: true

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}-test
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  {{ .Files.Get "test.zip" | b64enc }}
immutable: true

The two zip files live inside the charts and I have a command to unzip them and then run the migration afterwards

CodePudding user response:

binaryData exepcts a map but you are passing a string to it.
When debugging the template we can see

Error: INSTALLATION FAILED: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(ConfigMap.binaryData): invalid type for io.k8s.api.core.v1.ConfigMap.binaryData: got "string", expected "map"

The way to fix this is to add a key before {{ .Files.Get "test.zip" | b64enc }}.

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  migrations: {{ .Files.Get "migrations.zip" | b64enc }}
immutable: true

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}-test
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  test: {{ .Files.Get "test.zip" | b64enc }}
immutable: true
  • Related