Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event metadata field to HelmRelease spec #682

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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