Skip to content

Commit

Permalink
Add values hash to event metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Pimenta <[email protected]>
  • Loading branch information
matheuscscp committed Apr 30, 2023
1 parent d1cc2fe commit 88fa1b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package controllers

import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -792,11 +794,21 @@ 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
func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, revision, severity, msg string) {
meta := make(map[string]string)

if revision != "" {
meta = map[string]string{v2.GroupVersion.Group + "/revision": revision}
meta[v2.GroupVersion.Group+"/revision"] = revision
}

// values hash. here json.Marshal() gives stability to the hash
valuesBytes, err := json.Marshal(hr.GetValues())
if err != nil {
valuesBytes = nil
ctrl.LoggerFrom(ctx).Error(err, "unable to marshal helm values")
}
meta[v2.GroupVersion.Group+"/config_hash"] = fmt.Sprintf("%x", sha256.Sum256(valuesBytes))

eventtype := "Normal"
if severity == eventv1.EventSeverityError {
eventtype = "Warning"
Expand Down

0 comments on commit 88fa1b8

Please sign in to comment.