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

[proposal] add the app version to events #798

Closed
YohannHammad opened this issue Oct 23, 2023 · 3 comments
Closed

[proposal] add the app version to events #798

YohannHammad opened this issue Oct 23, 2023 · 3 comments

Comments

@YohannHammad
Copy link

YohannHammad commented Oct 23, 2023

Hello everyone,

I made a small PoC to achieve this result:
image

The goal would be to be able to indicate in a HelmRelease the key corresponding to the version of the application (usually the tag of an image). This way it would be possible to show the version of the application in alerts in addition to the version of the chart.

The code is obviously very dirty because I was just testing the feasibility:

// helmrelease_controller.go
func (r *HelmReleaseReconciler) event(_ context.Context, hr v2.HelmRelease, revision, severity, msg string) {
	var eventMeta map[string]string
	var appVersion string

	if revision != "" || hr.Status.LastAttemptedValuesChecksum != "" {
		eventMeta = make(map[string]string)
		appVersion = hr.GetAppVersion()
		if revision != "" {
			eventMeta[v2.GroupVersion.Group+"/"+eventv1.MetaRevisionKey] = revision
		}
		if hr.Status.LastAttemptedValuesChecksum != "" {
			eventMeta[v2.GroupVersion.Group+"/"+eventv1.MetaTokenKey] = hr.Status.LastAttemptedValuesChecksum
		}
		if (appVersion != "") {
			eventMeta[v2.GroupVersion.Group+"/appVersion"] = appVersion
		}
	}

	eventType := corev1.EventTypeNormal
	if severity == eventv1.EventSeverityError {
		eventType = corev1.EventTypeWarning
	}
	r.EventRecorder.AnnotatedEventf(&hr, eventMeta, eventType, severity, msg)
}
// helmrelease_types.go
func (in HelmRelease) GetAppVersion() string {
	var values map[string]map[string]map[string]string
	if in.Spec.Values != nil {
		_ = json.Unmarshal(in.Spec.Values.Raw, &values)
	}
	return values["app"]["image"]["tag"]
}

Do you think this is something that could be added?

@leosunmo
Copy link

It would be great to be able to add additional annotations to events from the controllers, especially the Helm Controller. We similarly struggle to get enough metadata about a release for developers to find it useful.

@souleb
Copy link
Member

souleb commented Apr 17, 2024

we are open to a PR for this. Some related discussions are happening in fluxcd/flux2#4718.

@stefanprodan
Copy link
Member

Implemented in #968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants