infinispan / infinispan-helm-charts

Apache License 2.0
13 stars 26 forks source link

Add helm meta annotations to created resources #38

Closed ryanemerson closed 2 years ago

ryanemerson commented 2 years ago

To avoid issues with duplicate resources we should add the following annotations:

"meta.helm.sh/release-name :release-name"
"meta.helm.sh/release-namespace: <the current k8s namespace>"

Without these annotations, the second execution of helm template . --validate | oc apply -f - will result in the following error:

helm template --validate . | oc apply -f -
Error: rendered manifests contain a resource that already exists. Unable to continue with install: Secret "release-name-generated-secret" in namespace "alvaro-test09" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "release-name"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "alvaro-test09"
error: no objects passed to apply

We should define a helper template so that we can add these annotations to all resources, something like:

{{/*
Helm Annotations
*/}}
{{- define "infinispan.annotations" }}
meta.helm.sh/release-name: "{{  }}"
meta.helm.sh/release-namespace: "{{ }}"
{{- end }}
alvarolop commented 2 years ago

@ryanemerson I made a conceptual mistake. There is a difference between the name of the release and the name of the server.

The annotation meta.helm.sh/release-name: "{{ }}" should contain the name of the release meta.helm.sh/release-name: {{ .Release.Name }} instead of the name of the Infinispan server meta.helm.sh/release-name: {{ include "infinispan-helm-charts.name" . }}.

The reason is that this is used for Helm versioning. In an app with three services: micA, micB and Infinispan, all should have the same release name, for example my-app, with current configuration, the name of the Helm release must be equal to the name of the infinispan server name.

Current version works now, but with two constrains:

ryanemerson commented 2 years ago

@alvarolop I've created https://github.com/infinispan/infinispan-helm-charts/pull/40, can you confirm this works as expected for your scenario? I'll release a new chart once we have this right.

alvarolop commented 2 years ago

Yes, now it works with the helm template --validate . | oc apply -f - mechanism. Thank you very much. I can apply the same resources several times and it does not fail.

ryanemerson commented 2 years ago

Thanks for verifying @alvarolop. https://github.com/openshift-helm-charts/charts/pull/421

ryanemerson commented 2 years ago

@alvarolop The 0.2.1 release should now be available :tada: