Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Supply more structured info in sync errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
squaremo committed Mar 6, 2018
1 parent 0a68b28 commit 93bfd7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions daemon/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
Expand Down

0 comments on commit 93bfd7c

Please sign in to comment.