Browse Source

Report the affected resources for each event

Hitherto we have used a single list of `ResourceID`s to populate the
event field. It was calculated by looking at which files have changed
since last sync, and which resources are in those changed files.

This is inaccurate because

 1. files don't always contain one resource (though currently, files
 _we can change_ only contain one resource)
 2. each event gets the list of resources changed in _any_ commit.

To address 2., use the Result field from the git note, which has a
record of what was actually changed in that operation.

1.) is less of a problem for now, because we can only change files
containing one resource at present anyway.
Michael Bridgen 2 years ago
parent
commit
f5cd257b2f
2 changed files with 13 additions and 6 deletions
  1. 3
    2
      daemon/loop.go
  2. 10
    4
      update/result.go

+ 3
- 2
daemon/loop.go View File

@@ -241,6 +241,7 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
241 241
 		changedFiles, err := working.ChangedFiles(ctx, oldTagRev)
242 242
 		if err == nil && len(changedFiles) > 0 {
243 243
 			// We had some changed files, we're syncing a diff
244
+			// FIXME(michael): this won't be accurate when a file can have more than one resource
244 245
 			changedResources, err = d.Manifests.LoadManifests(working.Dir(), changedFiles[0], changedFiles[1:]...)
245 246
 		}
246 247
 		cancel()
@@ -310,7 +311,7 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
310 311
 			case update.Images:
311 312
 				spec := n.Spec.Spec.(update.ReleaseSpec)
312 313
 				noteEvents = append(noteEvents, event.Event{
313
-					ServiceIDs: serviceIDs.ToSlice(),
314
+					ServiceIDs: n.Result.AffectedResources(),
314 315
 					Type:       event.EventRelease,
315 316
 					StartedAt:  started,
316 317
 					EndedAt:    time.Now().UTC(),
@@ -329,7 +330,7 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
329 330
 			case update.Auto:
330 331
 				spec := n.Spec.Spec.(update.Automated)
331 332
 				noteEvents = append(noteEvents, event.Event{
332
-					ServiceIDs: serviceIDs.ToSlice(),
333
+					ServiceIDs: n.Result.AffectedResources(),
333 334
 					Type:       event.EventAutoRelease,
334 335
 					StartedAt:  started,
335 336
 					EndedAt:    time.Now().UTC(),

+ 10
- 4
update/result.go View File

@@ -30,6 +30,16 @@ func (r Result) ServiceIDs() []string {
30 30
 	return result
31 31
 }
32 32
 
33
+func (r Result) AffectedResources() flux.ResourceIDs {
34
+	ids := flux.ResourceIDs{}
35
+	for id, result := range r {
36
+		if result.Status == ReleaseStatusSuccess {
37
+			ids = append(ids, id)
38
+		}
39
+	}
40
+	return ids
41
+}
42
+
33 43
 func (r Result) ChangedImages() []string {
34 44
 	images := map[image.Ref]struct{}{}
35 45
 	for _, serviceResult := range r {
@@ -74,10 +84,6 @@ type ControllerResult struct {
74 84
 	PerContainer []ContainerUpdate      // what happened with each container
75 85
 }
76 86
 
77
-func (fr ControllerResult) Msg(id flux.ResourceID) string {
78
-	return fmt.Sprintf("%s service %s as it is %s", fr.Status, id.String(), fr.Error)
79
-}
80
-
81 87
 type ContainerUpdate struct {
82 88
 	Container string
83 89
 	Current   image.Ref

Loading…
Cancel
Save