Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add top-level appName field to events
Browse files Browse the repository at this point in the history
Add an optional appName field to events to support referencing associated Acorns

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
  • Loading branch information
njhale committed Jul 17, 2023
1 parent bc1f0c3 commit 4be7b84
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/internal.acorn.io/v1/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type EventInstance struct {
// +optional
Actor string `json:"actor,omitempty"`

// AppName is the name of the app that the event is related to, if any.
// +optional
AppName string `json:"appName,omitempty"`

// Source identifies the object the Event is regarding.
Source EventSource `json:"source"`

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/appdefinition/pullappimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func recordPullEvent(ctx context.Context, recorder event.Recorder, observed meta
Type: AppImagePullSuccessEventType,
Severity: v1.EventSeverityInfo,
Description: fmt.Sprintf("Pulled %s", target.Name),
AppName: obj.GetName(),
Source: event.ObjectSource(obj),
Observed: v1.MicroTime(observed),
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/appdefinition/pullappimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ func TestPullAppImageEvents(t *testing.T) {
Type: AppImagePullSuccessEventType,
Severity: v1.EventSeverityInfo,
Description: "Pulled acorn.io/img:1",
AppName: "foo",
Source: v1.EventSource{Kind: "app", Name: "foo", UID: types.UID("foo-uid")},
Observed: v1.MicroTime(now),
Observed: now,
Details: mustMapify(t, AppImagePullEventDetails{
ResourceVersion: "1",
AutoUpgrade: false,
Expand All @@ -129,8 +130,9 @@ func TestPullAppImageEvents(t *testing.T) {
Type: AppImagePullSuccessEventType,
Severity: v1.EventSeverityInfo,
Description: "Pulled acorn.io/img:1",
AppName: "foo",
Source: v1.EventSource{Kind: "app", Name: "foo"},
Observed: v1.MicroTime(now),
Observed: now,
Details: mustMapify(t, AppImagePullEventDetails{
AutoUpgrade: true,
Previous: ImageSummary{Name: "acorn.io/img:1"},
Expand All @@ -149,8 +151,9 @@ func TestPullAppImageEvents(t *testing.T) {
Type: AppImagePullSuccessEventType,
Severity: v1.EventSeverityInfo,
Description: "Pulled acorn.io/img:1",
AppName: "foo",
Source: v1.EventSource{Kind: "app", Name: "foo"},
Observed: v1.MicroTime(now),
Observed: now,
Details: mustMapify(t, AppImagePullEventDetails{
AutoUpgrade: true,
Target: ImageSummary{Name: "acorn.io/img:1"},
Expand All @@ -169,6 +172,7 @@ func TestPullAppImageEvents(t *testing.T) {
Type: AppImagePullFailureEventType,
Severity: v1.EventSeverityError,
Description: "Failed to pull acorn.io/img:1",
AppName: "foo",
Source: v1.EventSource{Kind: "app", Name: "foo"},
Observed: now,
Details: mustMapify(t, AppImagePullEventDetails{
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/registry/apigroups/acorn/apps/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s *eventRecordingStrategy) Create(ctx context.Context, obj types.Object) (
Severity: v1.EventSeverityInfo,
Details: details,
Description: fmt.Sprintf("App %s/%s created", obj.GetNamespace(), obj.GetName()),
AppName: obj.GetName(),
Source: event.ObjectSource(obj),
Observed: v1.MicroTime(metav1.NowMicro()),
}); err != nil {
Expand Down Expand Up @@ -115,6 +116,7 @@ func (s *eventRecordingStrategy) Delete(ctx context.Context, obj types.Object) (
Severity: v1.EventSeverityInfo,
Details: details,
Description: fmt.Sprintf("App %s/%s deleted", obj.GetNamespace(), obj.GetName()),
AppName: obj.GetName(),
Source: event.ObjectSource(obj),
Observed: v1.MicroTime(metav1.NowMicro()),
}); err != nil {
Expand Down Expand Up @@ -169,6 +171,7 @@ func (s *eventRecordingStrategy) Update(ctx context.Context, obj types.Object) (
Severity: v1.EventSeverityInfo,
Details: details,
Description: fmt.Sprintf("Spec field updated for App %s/%s", obj.GetNamespace(), obj.GetName()),
AppName: obj.GetName(),
Source: event.ObjectSource(obj),
Observed: v1.MicroTime(metav1.NowMicro()),
}); err != nil {
Expand Down

0 comments on commit 4be7b84

Please sign in to comment.