Skip to content

Commit

Permalink
Add event metadata field to HelmRelease spec
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Pimenta <[email protected]>
  • Loading branch information
matheuscscp committed May 1, 2023
1 parent d1cc2fe commit fd78f93
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions api/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions docs/api/helmrelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ Kubernetes pkg/apis/apiextensions/v1.JSON
of their definition.</p>
</td>
</tr>
<tr>
<td>
<code>eventMetadata</code><br>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>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.</p>
</td>
</tr>
</table>
</td>
</tr>
Expand Down Expand Up @@ -1166,6 +1180,20 @@ Kubernetes pkg/apis/apiextensions/v1.JSON
of their definition.</p>
</td>
</tr>
<tr>
<td>
<code>eventMetadata</code><br>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>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.</p>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
6 changes: 6 additions & 0 deletions docs/spec/v2beta1/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion internal/controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,17 @@ 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(_ context.Context, hr v2.HelmRelease, revision, severity, msg string) {
var meta map[string]string
addMetadata := func(key, value string) {
if meta == nil {
meta = make(map[string]string)
}
meta[v2.GroupVersion.Group+"/"+key] = value
}
for key, value := range hr.Spec.EventMetadata {
addMetadata(key, value)
}
if revision != "" {
meta = map[string]string{v2.GroupVersion.Group + "/revision": revision}
addMetadata("revision", revision)
}
eventtype := "Normal"
if severity == eventv1.EventSeverityError {
Expand Down

0 comments on commit fd78f93

Please sign in to comment.