I’m trying to deploy my application using Helm, but I encounter the following error when running a dry-run upgrade command:
helm upgrade myapp --install --dry-run . -f ./values.yaml --namespace my-namespace --set releaseVersion=1.0.0
Release "myapp" does not exist. Installing it now.
Error: rendered manifests contain a resource that already exists. Unable to continue with install: ConfigMap "myapp-config" in namespace "my-namespace" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-name" must equal "myapp": current value is "old-release-name"
I have the following deployment.yaml file:
{{- if .Values.configMapName }}
- name: {{ $app }}-config-volume
configMap:
name: {{ .Values.configMapName }}
items:
- key: config.json
path: config.json
{{- end }}
{{- if .Values.configMapName }}
- name: {{ $app }}-config-volume
mountPath: /opt/application/config.json
subPath: config.json
readOnly: true
{{- end }}
And the configmap.yaml file:
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config
data:
config.json: |
{
"key": "value"
}
I have different values files for different environments. Initially, I deployed for one environment with a specific release name, and it went fine. Today, I tried to deploy for another environment with a different release name that didn’t have any configMapName in the values file.
During the Helm upgrade, it tries to install the release but fails because a ConfigMap with the same name already exists and has metadata indicating it belongs to a different release.
How can I resolve this error without manually deleting the existing ConfigMap every time?
Is there a way to make Helm ignore the existing ConfigMap and update it with the new release metadata?