From a14115522f58fce7aac07d8c75ef3e1d119a6baf Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 6 Mar 2018 17:54:32 +0000 Subject: [PATCH] Supply more structured info in sync errors Instead of using a map, which forces us to give a glommed-together string as the key (so that it can be JSONed), use a slice of structs with the unglommed data. --- daemon/loop.go | 9 ++++++--- event/event.go | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/daemon/loop.go b/daemon/loop.go index 44023e5533..dfa8817a67 100644 --- a/daemon/loop.go +++ b/daemon/loop.go @@ -193,15 +193,18 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) { return errors.Wrap(err, "loading resources from repo") } - var syncErrors map[string]string + var syncErrors []event.ResourceError // TODO supply deletes argument from somewhere (command-line?) if err := fluxsync.Sync(d.Manifests, allResources, d.Cluster, false, logger); err != nil { logger.Log("err", err) switch syncerr := err.(type) { case cluster.SyncError: - syncErrors = map[string]string{} for _, e := range syncerr { - syncErrors[fmt.Sprintf("%s (%s)", e.ResourceID(), e.Source())] = e.Error.Error() + syncErrors = append(syncErrors, event.ResourceError{ + ID: e.ResourceID().String(), + Path: e.Source(), + Error: e.Error.Error(), + }) } default: return err diff --git a/event/event.go b/event/event.go index ee2a6f44df..0e2b03de33 100644 --- a/event/event.go +++ b/event/event.go @@ -195,6 +195,12 @@ type Commit struct { Message string `json:"message"` } +type ResourceError struct { + ID string + Path string + Error string +} + // SyncEventMetadata is the metadata for when new a commit is synced to the cluster type SyncEventMetadata struct { // for parsing old events; Commits is now used in preference @@ -205,7 +211,7 @@ type SyncEventMetadata struct { // ourselves) Includes map[string]bool `json:"includes,omitempty"` // Per-resource errors - Errors map[string]string `json:"errors,omitempty"` + Errors []ResourceError `json:"errors,omitempty"` // `true` if we have no record of having synced before InitialSync bool `json:"initialSync,omitempty"` }