diff --git a/api/v2beta1/helmrelease_types.go b/api/v2beta1/helmrelease_types.go index 24d0e1d0e..8dbc52958 100644 --- a/api/v2beta1/helmrelease_types.go +++ b/api/v2beta1/helmrelease_types.go @@ -184,6 +184,12 @@ type HelmReleaseSpec struct { // of their definition. // +optional PostRenderers []PostRenderer `json:"postRenderers,omitempty"` + + // EventMetadata is an optional field for adding metadata to events emitted by the + // controller. Metadata fields added by the controller have priority over the fields + // added here. + // +optional + EventMetadata map[string]string `json:"eventMetadata,omitempty"` } // GetInstall returns the configuration for Helm install actions for the diff --git a/api/v2beta1/zz_generated.deepcopy.go b/api/v2beta1/zz_generated.deepcopy.go index 5fb7ee4db..5608f2543 100644 --- a/api/v2beta1/zz_generated.deepcopy.go +++ b/api/v2beta1/zz_generated.deepcopy.go @@ -276,6 +276,13 @@ func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.EventMetadata != nil { + in, out := &in.EventMetadata, &out.EventMetadata + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmReleaseSpec. diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index 80dbdb60d..7b6ee77b1 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -198,6 +198,13 @@ spec: - name type: object type: array + eventMetadata: + additionalProperties: + type: string + description: EventMetadata is an optional field for adding metadata + to events emitted by the controller. Metadata fields added by the + controller have priority over the fields added here. + type: object install: description: Install holds the configuration for Helm install actions for this HelmRelease. diff --git a/docs/api/helmrelease.md b/docs/api/helmrelease.md index c1f5bcdc7..e912296ce 100644 --- a/docs/api/helmrelease.md +++ b/docs/api/helmrelease.md @@ -357,6 +357,20 @@ Kubernetes pkg/apis/apiextensions/v1.JSON of their definition.

+ + +eventMetadata
+ +map[string]string + + + +(Optional) +

EventMetadata is an optional field for adding metadata to events emitted by the +controller. Metadata fields added by the controller have priority over the fields +added here.

+ + @@ -1166,6 +1180,20 @@ Kubernetes pkg/apis/apiextensions/v1.JSON of their definition.

+ + +eventMetadata
+ +map[string]string + + + +(Optional) +

EventMetadata is an optional field for adding metadata to events emitted by the +controller. Metadata fields added by the controller have priority over the fields +added here.

+ + diff --git a/docs/spec/v2beta1/helmreleases.md b/docs/spec/v2beta1/helmreleases.md index c396146e5..982d68c39 100644 --- a/docs/spec/v2beta1/helmreleases.md +++ b/docs/spec/v2beta1/helmreleases.md @@ -128,6 +128,12 @@ type HelmReleaseSpec struct { // of their definition. // +optional PostRenderers []PostRenderer `json:"postRenderers,omitempty"` + + // EventMetadata is an optional field for adding metadata to events emitted by the + // controller. Metadata fields added by the controller have priority over the fields + // added here. + // +optional + EventMetadata map[string]string `json:"eventMetadata,omitempty"` } // KubeConfig references a Kubernetes secret that contains a kubeconfig file. diff --git a/internal/controllers/helmrelease_controller.go b/internal/controllers/helmrelease_controller.go index 18f9055af..22992b89d 100644 --- a/internal/controllers/helmrelease_controller.go +++ b/internal/controllers/helmrelease_controller.go @@ -796,9 +796,14 @@ func (r *HelmReleaseReconciler) requestsForHelmChartChange(o client.Object) []re // event emits a Kubernetes event and forwards the event to notification controller if configured. func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, revision, severity, msg string) { meta := make(map[string]string) + addMetadata := func(key, value string) { meta[v2.GroupVersion.Group+"/"+key] = value } + + for key, value := range hr.Spec.EventMetadata { + addMetadata(key, value) + } if revision != "" { - meta[v2.GroupVersion.Group+"/revision"] = revision + addMetadata("revision", revision) } // values hash. here json.Marshal() gives stability to the hash @@ -807,7 +812,7 @@ func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, re valuesBytes = nil ctrl.LoggerFrom(ctx).Error(err, "unable to marshal helm values") } - meta[v2.GroupVersion.Group+"/config_checksum"] = fmt.Sprintf("%x", sha256.Sum256(valuesBytes)) + addMetadata("config_checksum", fmt.Sprintf("%x", sha256.Sum256(valuesBytes))) eventtype := "Normal" if severity == eventv1.EventSeverityError {