Browse Source

Break dependencies among git, job, event packages

These all use each others types, and that makes it difficult to
refactor other packages without introducing cycles. To break the
dependencies, I needed to:

 - make git accept any (JSON serialisable) value as a note

 - stop referring to an event type in the job package, and thereby the
   API and client
Michael Bridgen 1 year ago
parent
commit
25bbcd4c11
9 changed files with 119 additions and 115 deletions
  1. 12
    14
      cmd/fluxctl/await.go
  2. 49
    41
      daemon/daemon.go
  3. 3
    2
      daemon/loop.go
  4. 2
    2
      daemon/note.go
  5. 17
    19
      git/gittest/repo_test.go
  6. 7
    9
      git/operations.go
  7. 15
    23
      git/operations_test.go
  8. 3
    3
      git/working.go
  9. 11
    2
      job/job.go

+ 12
- 14
cmd/fluxctl/await.go View File

@@ -8,8 +8,6 @@ import (
8 8
 	"time"
9 9
 
10 10
 	"github.com/weaveworks/flux/api"
11
-	"github.com/weaveworks/flux/event"
12
-	"github.com/weaveworks/flux/git"
13 11
 	"github.com/weaveworks/flux/job"
14 12
 	"github.com/weaveworks/flux/update"
15 13
 )
@@ -19,35 +17,35 @@ var ErrTimeout = errors.New("timeout")
19 17
 // await polls for a job to complete, then for the resulting commit to
20 18
 // be applied
21 19
 func await(ctx context.Context, stdout, stderr io.Writer, client api.Server, jobID job.ID, apply bool, verbosity int) error {
22
-	metadata, err := awaitJob(ctx, client, jobID)
23
-	if err != nil && err.Error() != git.ErrNoChanges.Error() {
20
+	result, err := awaitJob(ctx, client, jobID)
21
+	if err != nil {
24 22
 		return err
25 23
 	}
26
-	if metadata.Result != nil {
27
-		update.PrintResults(stdout, metadata.Result, verbosity)
24
+	if result.Result != nil {
25
+		update.PrintResults(stdout, result.Result, verbosity)
28 26
 	}
29
-	if metadata.Revision != "" {
30
-		fmt.Fprintf(stderr, "Commit pushed:\t%s\n", metadata.ShortRevision())
27
+	if result.Revision != "" {
28
+		fmt.Fprintf(stderr, "Commit pushed:\t%s\n", result.Revision[:7])
31 29
 	}
32
-	if metadata.Result == nil {
30
+	if result.Result == nil {
33 31
 		fmt.Fprintf(stderr, "Nothing to do\n")
34 32
 		return nil
35 33
 	}
36 34
 
37
-	if apply && metadata.Revision != "" {
38
-		if err := awaitSync(ctx, client, metadata.Revision); err != nil {
35
+	if apply && result.Revision != "" {
36
+		if err := awaitSync(ctx, client, result.Revision); err != nil {
39 37
 			return err
40 38
 		}
41 39
 
42
-		fmt.Fprintf(stderr, "Commit applied:\t%s\n", metadata.ShortRevision())
40
+		fmt.Fprintf(stderr, "Commit applied:\t%s\n", result.Revision[:7])
43 41
 	}
44 42
 
45 43
 	return nil
46 44
 }
47 45
 
48 46
 // await polls for a job to have been completed, with exponential backoff.
49
-func awaitJob(ctx context.Context, client api.Server, jobID job.ID) (event.CommitEventMetadata, error) {
50
-	var result event.CommitEventMetadata
47
+func awaitJob(ctx context.Context, client api.Server, jobID job.ID) (job.Result, error) {
48
+	var result job.Result
51 49
 	err := backoff(100*time.Millisecond, 2, 50, 1*time.Minute, func() (bool, error) {
52 50
 		j, err := client.JobStatus(ctx, jobID)
53 51
 		if err != nil {

+ 49
- 41
daemon/daemon.go View File

@@ -149,22 +149,19 @@ func (d *Daemon) ListImages(ctx context.Context, spec update.ResourceSpec) ([]v6
149 149
 	return res, nil
150 150
 }
151 151
 
152
-// Let's use the CommitEventMetadata as a convenient transport for the
153
-// results of a job; if no commit was made (e.g., if it was a dry
154
-// run), leave the revision field empty.
155
-type DaemonJobFunc func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (*event.CommitEventMetadata, error)
152
+type daemonJobFunc func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (job.Result, error)
156 153
 
157 154
 // executeJob runs a job func in a cloned working directory, keeping track of its status.
158
-func (d *Daemon) executeJob(id job.ID, do DaemonJobFunc, logger log.Logger) (*event.CommitEventMetadata, error) {
155
+func (d *Daemon) executeJob(id job.ID, do daemonJobFunc, logger log.Logger) (job.Result, error) {
159 156
 	ctx, cancel := context.WithTimeout(context.Background(), defaultJobTimeout)
160 157
 	defer cancel()
161 158
 	d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusRunning})
162 159
 	// make a working clone so we don't mess with files we
163 160
 	// will be reading from elsewhere
164
-	var metadata *event.CommitEventMetadata
161
+	var result job.Result
165 162
 	err := d.WithClone(ctx, func(working *git.Checkout) error {
166 163
 		var err error
167
-		metadata, err = do(ctx, id, working, logger)
164
+		result, err = do(ctx, id, working, logger)
168 165
 		if err != nil {
169 166
 			return err
170 167
 		}
@@ -172,14 +169,14 @@ func (d *Daemon) executeJob(id job.ID, do DaemonJobFunc, logger log.Logger) (*ev
172 169
 	})
173 170
 	if err != nil {
174 171
 		d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusFailed, Err: err.Error()})
175
-		return nil, err
172
+		return result, err
176 173
 	}
177
-	d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusSucceeded, Result: *metadata})
178
-	return metadata, nil
174
+	d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusSucceeded, Result: result})
175
+	return result, nil
179 176
 }
180 177
 
181 178
 // queueJob queues a job func to be executed.
182
-func (d *Daemon) queueJob(do DaemonJobFunc) job.ID {
179
+func (d *Daemon) queueJob(do daemonJobFunc) job.ID {
183 180
 	id := job.ID(guid.New())
184 181
 	enqueuedAt := time.Now()
185 182
 	d.Jobs.Enqueue(&job.Job{
@@ -187,18 +184,25 @@ func (d *Daemon) queueJob(do DaemonJobFunc) job.ID {
187 184
 		Do: func(logger log.Logger) error {
188 185
 			queueDuration.Observe(time.Since(enqueuedAt).Seconds())
189 186
 			started := time.Now().UTC()
190
-			metadata, err := d.executeJob(id, do, logger)
187
+			result, err := d.executeJob(id, do, logger)
191 188
 			if err != nil {
192 189
 				return err
193 190
 			}
194
-			logger.Log("revision", metadata.Revision)
195
-			if metadata.Revision != "" {
191
+			logger.Log("revision", result.Revision)
192
+			if result.Revision != "" {
196 193
 				var serviceIDs []flux.ResourceID
197
-				for id, result := range metadata.Result {
194
+				for id, result := range result.Result {
198 195
 					if result.Status == update.ReleaseStatusSuccess {
199 196
 						serviceIDs = append(serviceIDs, id)
200 197
 					}
201 198
 				}
199
+
200
+				metadata := &event.CommitEventMetadata{
201
+					Revision: result.Revision,
202
+					Spec:     result.Spec,
203
+					Result:   result.Result,
204
+				}
205
+
202 206
 				return d.LogEvent(event.Event{
203 207
 					ServiceIDs: serviceIDs,
204 208
 					Type:       event.EventCommit,
@@ -237,11 +241,11 @@ func (d *Daemon) UpdateManifests(ctx context.Context, spec update.Spec) (job.ID,
237 241
 	}
238 242
 }
239 243
 
240
-func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJobFunc {
241
-	return func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (*event.CommitEventMetadata, error) {
244
+func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) daemonJobFunc {
245
+	return func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (job.Result, error) {
242 246
 		// For each update
243 247
 		var serviceIDs []flux.ResourceID
244
-		metadata := &event.CommitEventMetadata{
248
+		result := job.Result{
245 249
 			Spec:   &spec,
246 250
 			Result: update.Result{},
247 251
 		}
@@ -259,19 +263,19 @@ func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJo
259 263
 			err := cluster.UpdateManifest(d.Manifests, working.ManifestDir(), serviceID, func(def []byte) ([]byte, error) {
260 264
 				newDef, err := d.Manifests.UpdatePolicies(def, u)
261 265
 				if err != nil {
262
-					metadata.Result[serviceID] = update.ControllerResult{
266
+					result.Result[serviceID] = update.ControllerResult{
263 267
 						Status: update.ReleaseStatusFailed,
264 268
 						Error:  err.Error(),
265 269
 					}
266 270
 					return nil, err
267 271
 				}
268 272
 				if string(newDef) == string(def) {
269
-					metadata.Result[serviceID] = update.ControllerResult{
273
+					result.Result[serviceID] = update.ControllerResult{
270 274
 						Status: update.ReleaseStatusSkipped,
271 275
 					}
272 276
 				} else {
273 277
 					serviceIDs = append(serviceIDs, serviceID)
274
-					metadata.Result[serviceID] = update.ControllerResult{
278
+					result.Result[serviceID] = update.ControllerResult{
275 279
 						Status: update.ReleaseStatusSuccess,
276 280
 					}
277 281
 				}
@@ -279,18 +283,18 @@ func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJo
279 283
 			})
280 284
 			switch err {
281 285
 			case cluster.ErrNoResourceFilesFoundForService, cluster.ErrMultipleResourceFilesFoundForService:
282
-				metadata.Result[serviceID] = update.ControllerResult{
286
+				result.Result[serviceID] = update.ControllerResult{
283 287
 					Status: update.ReleaseStatusFailed,
284 288
 					Error:  err.Error(),
285 289
 				}
286 290
 			case nil:
287 291
 				// continue
288 292
 			default:
289
-				return nil, err
293
+				return result, err
290 294
 			}
291 295
 		}
292 296
 		if len(serviceIDs) == 0 {
293
-			return metadata, nil
297
+			return result, nil
294 298
 		}
295 299
 
296 300
 		commitAuthor := ""
@@ -298,35 +302,38 @@ func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJo
298 302
 			commitAuthor = spec.Cause.User
299 303
 		}
300 304
 		commitAction := git.CommitAction{Author: commitAuthor, Message: policyCommitMessage(updates, spec.Cause)}
301
-		if err := working.CommitAndPush(ctx, commitAction, &git.Note{JobID: jobID, Spec: spec}); err != nil {
305
+		if err := working.CommitAndPush(ctx, commitAction, &note{JobID: jobID, Spec: spec}); err != nil {
302 306
 			// On the chance pushing failed because it was not
303 307
 			// possible to fast-forward, ask for a sync so the
304 308
 			// next attempt is more likely to succeed.
305 309
 			d.AskForSync()
306
-			return nil, err
310
+			return result, err
307 311
 		}
308 312
 		if anythingAutomated {
309 313
 			d.AskForImagePoll()
310 314
 		}
311 315
 
312 316
 		var err error
313
-		metadata.Revision, err = working.HeadRevision(ctx)
317
+		result.Revision, err = working.HeadRevision(ctx)
314 318
 		if err != nil {
315
-			return nil, err
319
+			return result, err
316 320
 		}
317
-		return metadata, nil
321
+		return result, nil
318 322
 	}
319 323
 }
320 324
 
321
-func (d *Daemon) release(spec update.Spec, c release.Changes) DaemonJobFunc {
322
-	return func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (*event.CommitEventMetadata, error) {
325
+func (d *Daemon) release(spec update.Spec, c release.Changes) daemonJobFunc {
326
+	return func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (job.Result, error) {
323 327
 		rc := release.NewReleaseContext(d.Cluster, d.Manifests, d.Registry, working)
324 328
 		result, err := release.Release(rc, c, logger)
329
+
330
+		var zero job.Result
325 331
 		if err != nil {
326
-			return nil, err
332
+			return zero, err
327 333
 		}
328 334
 
329 335
 		var revision string
336
+
330 337
 		if c.ReleaseKind() == update.ReleaseKindExecute {
331 338
 			commitMsg := spec.Cause.Message
332 339
 			if commitMsg == "" {
@@ -337,20 +344,20 @@ func (d *Daemon) release(spec update.Spec, c release.Changes) DaemonJobFunc {
337 344
 				commitAuthor = spec.Cause.User
338 345
 			}
339 346
 			commitAction := git.CommitAction{Author: commitAuthor, Message: commitMsg}
340
-			if err := working.CommitAndPush(ctx, commitAction, &git.Note{JobID: jobID, Spec: spec, Result: result}); err != nil {
347
+			if err := working.CommitAndPush(ctx, commitAction, &note{JobID: jobID, Spec: spec, Result: result}); err != nil {
341 348
 				// On the chance pushing failed because it was not
342 349
 				// possible to fast-forward, ask the repo to fetch
343 350
 				// from upstream ASAP, so the next attempt is more
344 351
 				// likely to succeed.
345 352
 				d.Repo.Notify()
346
-				return nil, err
353
+				return zero, err
347 354
 			}
348 355
 			revision, err = working.HeadRevision(ctx)
349 356
 			if err != nil {
350
-				return nil, err
357
+				return zero, err
351 358
 			}
352 359
 		}
353
-		return &event.CommitEventMetadata{
360
+		return job.Result{
354 361
 			Revision: revision,
355 362
 			Spec:     &spec,
356 363
 			Result:   result,
@@ -407,14 +414,15 @@ func (d *Daemon) JobStatus(ctx context.Context, jobID job.ID) (job.Status, error
407 414
 
408 415
 		for _, commit := range commits {
409 416
 			if _, ok := notes[commit.Revision]; ok {
410
-				note, _ := working.GetNote(ctx, commit.Revision)
411
-				if note != nil && note.JobID == jobID {
417
+				var n note
418
+				ok, err := working.GetNote(ctx, commit.Revision, &n)
419
+				if ok && err == nil && n.JobID == jobID {
412 420
 					status = job.Status{
413 421
 						StatusString: job.StatusSucceeded,
414
-						Result: event.CommitEventMetadata{
422
+						Result: job.Result{
415 423
 							Revision: commit.Revision,
416
-							Spec:     &note.Spec,
417
-							Result:   note.Result,
424
+							Spec:     &n.Spec,
425
+							Result:   n.Result,
418 426
 						},
419 427
 					}
420 428
 					return nil

+ 3
- 2
daemon/loop.go View File

@@ -280,12 +280,13 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
280 280
 				continue
281 281
 			}
282 282
 			ctx, cancel := context.WithTimeout(ctx, gitOpTimeout)
283
-			n, err := working.GetNote(ctx, commits[i].Revision)
283
+			var n note
284
+			ok, err := working.GetNote(ctx, commits[i].Revision, &n)
284 285
 			cancel()
285 286
 			if err != nil {
286 287
 				return errors.Wrap(err, "loading notes from repo")
287 288
 			}
288
-			if n == nil {
289
+			if !ok {
289 290
 				includes[event.NoneOfTheAbove] = true
290 291
 				continue
291 292
 			}

git/note.go → daemon/note.go View File

@@ -1,11 +1,11 @@
1
-package git
1
+package daemon
2 2
 
3 3
 import (
4 4
 	"github.com/weaveworks/flux/job"
5 5
 	"github.com/weaveworks/flux/update"
6 6
 )
7 7
 
8
-type Note struct {
8
+type note struct {
9 9
 	JobID  job.ID        `json:"jobID"`
10 10
 	Spec   update.Spec   `json:"spec"`
11 11
 	Result update.Result `json:"result"`

+ 17
- 19
git/gittest/repo_test.go View File

@@ -10,13 +10,14 @@ import (
10 10
 
11 11
 	"context"
12 12
 
13
-	"github.com/weaveworks/flux"
14 13
 	"github.com/weaveworks/flux/cluster/kubernetes/testfiles"
15 14
 	"github.com/weaveworks/flux/git"
16
-	"github.com/weaveworks/flux/job"
17
-	"github.com/weaveworks/flux/update"
18 15
 )
19 16
 
17
+type Note struct {
18
+	Comment string
19
+}
20
+
20 21
 func TestCommit(t *testing.T) {
21 22
 	config := TestConfig
22 23
 	config.SkipMessage = " **SKIP**"
@@ -95,11 +96,13 @@ func TestCheckout(t *testing.T) {
95 96
 	if err != nil {
96 97
 		t.Fatal(err)
97 98
 	}
98
-	note, err := checkout.GetNote(ctx, head)
99
+
100
+	var note Note
101
+	ok, err := checkout.GetNote(ctx, head, &note)
99 102
 	if err != nil {
100 103
 		t.Error(err)
101 104
 	}
102
-	if note != nil {
105
+	if ok {
103 106
 		t.Errorf("Expected no note on head revision; got %#v", note)
104 107
 	}
105 108
 
@@ -123,18 +126,8 @@ func TestCheckout(t *testing.T) {
123 126
 	}
124 127
 	// An example note with some of the fields filled in, so we can test
125 128
 	// serialization a bit.
126
-	expectedNote := git.Note{
127
-		JobID: job.ID("jobID1234"),
128
-		Spec: update.Spec{
129
-			Type: update.Images,
130
-			Spec: update.ReleaseSpec{},
131
-		},
132
-		Result: update.Result{
133
-			flux.MustParseResourceID("default/service1"): update.ControllerResult{
134
-				Status: update.ReleaseStatusFailed,
135
-				Error:  "failed the frobulator",
136
-			},
137
-		},
129
+	expectedNote := Note{
130
+		Comment: "Expected comment",
138 131
 	}
139 132
 	commitAction = git.CommitAction{Author: "", Message: "Changed file again"}
140 133
 	if err := checkout.CommitAndPush(ctx, commitAction, &expectedNote); err != nil {
@@ -153,11 +146,16 @@ func TestCheckout(t *testing.T) {
153 146
 		if err != nil {
154 147
 			t.Fatal(err)
155 148
 		}
156
-		note, err := c.GetNote(ctx, rev)
149
+
150
+		var note Note
151
+		ok, err := c.GetNote(ctx, rev, &note)
152
+		if !ok {
153
+			t.Error("note not found")
154
+		}
157 155
 		if err != nil {
158 156
 			t.Error(err)
159 157
 		}
160
-		if !reflect.DeepEqual(*note, expectedNote) {
158
+		if !reflect.DeepEqual(note, expectedNote) {
161 159
 			t.Errorf("note is not what we supplied when committing: %#v", note)
162 160
 		}
163 161
 	}

+ 7
- 9
git/operations.go View File

@@ -128,7 +128,7 @@ func getNotesRef(ctx context.Context, workingDir, ref string) (string, error) {
128 128
 	return strings.TrimSpace(out.String()), nil
129 129
 }
130 130
 
131
-func addNote(ctx context.Context, workingDir, rev, notesRef string, note *Note) error {
131
+func addNote(ctx context.Context, workingDir, rev, notesRef string, note interface{}) error {
132 132
 	b, err := json.Marshal(note)
133 133
 	if err != nil {
134 134
 		return err
@@ -136,20 +136,18 @@ func addNote(ctx context.Context, workingDir, rev, notesRef string, note *Note)
136 136
 	return execGitCmd(ctx, workingDir, nil, "notes", "--ref", notesRef, "add", "-m", string(b), rev)
137 137
 }
138 138
 
139
-// NB return values (*Note, nil), (nil, error), (nil, nil)
140
-func getNote(ctx context.Context, workingDir, notesRef, rev string) (*Note, error) {
139
+func getNote(ctx context.Context, workingDir, notesRef, rev string, note interface{}) (ok bool, err error) {
141 140
 	out := &bytes.Buffer{}
142 141
 	if err := execGitCmd(ctx, workingDir, out, "notes", "--ref", notesRef, "show", rev); err != nil {
143 142
 		if strings.Contains(strings.ToLower(err.Error()), "no note found for object") {
144
-			return nil, nil
143
+			return false, nil
145 144
 		}
146
-		return nil, err
145
+		return false, err
147 146
 	}
148
-	var note Note
149
-	if err := json.NewDecoder(out).Decode(&note); err != nil {
150
-		return nil, err
147
+	if err := json.NewDecoder(out).Decode(note); err != nil {
148
+		return false, err
151 149
 	}
152
-	return &note, nil
150
+	return true, nil
153 151
 }
154 152
 
155 153
 // Get all revisions with a note (NB: DO NOT RELY ON THE ORDERING)

+ 15
- 23
git/operations_test.go View File

@@ -10,8 +10,6 @@ import (
10 10
 	"testing"
11 11
 
12 12
 	"github.com/weaveworks/flux/cluster/kubernetes/testfiles"
13
-	"github.com/weaveworks/flux/job"
14
-	"github.com/weaveworks/flux/update"
15 13
 )
16 14
 
17 15
 const (
@@ -22,6 +20,10 @@ var (
22 20
 	noteIdCounter = 1
23 21
 )
24 22
 
23
+type Note struct {
24
+	ID string
25
+}
26
+
25 27
 func TestListNotes_2Notes(t *testing.T) {
26 28
 	newDir, cleanup := testfiles.TempDir(t)
27 29
 	defer cleanup()
@@ -49,16 +51,17 @@ func TestListNotes_2Notes(t *testing.T) {
49 51
 	if len(notes) != 2 {
50 52
 		t.Fatal("expected two notes")
51 53
 	}
52
-	for n := range notes {
53
-		note, err := getNote(context.Background(), newDir, testNoteRef, n)
54
+	for rev := range notes {
55
+		var note Note
56
+		ok, err := getNote(context.Background(), newDir, testNoteRef, rev, &note)
54 57
 		if err != nil {
55
-			t.Fatal(err)
58
+			t.Error(err)
56 59
 		}
57
-		if note == nil {
58
-			t.Fatal("note is nil")
60
+		if !ok {
61
+			t.Error("note not found for commit:", rev)
59 62
 		}
60
-		if note.JobID != idHEAD_1 && note.JobID != idHEAD {
61
-			t.Fatal("Note id didn't match expected", note.JobID)
63
+		if note.ID != idHEAD_1 && note.ID != idHEAD {
64
+			t.Error("Note contents not expected:", note.ID)
62 65
 		}
63 66
 	}
64 67
 }
@@ -82,21 +85,10 @@ func TestListNotes_0Notes(t *testing.T) {
82 85
 	}
83 86
 }
84 87
 
85
-func testNote(dir, rev string) (job.ID, error) {
86
-	id := job.ID(fmt.Sprintf("%v", noteIdCounter))
88
+func testNote(dir, rev string) (string, error) {
89
+	id := fmt.Sprintf("%v", noteIdCounter)
87 90
 	noteIdCounter += 1
88
-	err := addNote(context.Background(), dir, rev, testNoteRef, &Note{
89
-		id,
90
-		update.Spec{
91
-			update.Auto,
92
-			update.Cause{
93
-				"message",
94
-				"user",
95
-			},
96
-			update.Automated{},
97
-		},
98
-		update.Result{},
99
-	})
91
+	err := addNote(context.Background(), dir, rev, testNoteRef, &Note{ID: id})
100 92
 	return id, err
101 93
 }
102 94
 

+ 3
- 3
git/working.go View File

@@ -97,7 +97,7 @@ func (c *Checkout) ManifestDir() string {
97 97
 
98 98
 // CommitAndPush commits changes made in this checkout, along with any
99 99
 // extra data as a note, and pushes the commit and note to the remote repo.
100
-func (c *Checkout) CommitAndPush(ctx context.Context, commitAction CommitAction, note *Note) error {
100
+func (c *Checkout) CommitAndPush(ctx context.Context, commitAction CommitAction, note interface{}) error {
101 101
 	if !check(ctx, c.dir, c.config.Path) {
102 102
 		return ErrNoChanges
103 103
 	}
@@ -133,8 +133,8 @@ func (c *Checkout) CommitAndPush(ctx context.Context, commitAction CommitAction,
133 133
 }
134 134
 
135 135
 // GetNote gets a note for the revision specified, or nil if there is no such note.
136
-func (c *Checkout) GetNote(ctx context.Context, rev string) (*Note, error) {
137
-	return getNote(ctx, c.dir, c.realNotesRef, rev)
136
+func (c *Checkout) GetNote(ctx context.Context, rev string, note interface{}) (bool, error) {
137
+	return getNote(ctx, c.dir, c.realNotesRef, rev, note)
138 138
 }
139 139
 
140 140
 func (c *Checkout) HeadRevision(ctx context.Context) (string, error) {

+ 11
- 2
job/job.go View File

@@ -5,7 +5,7 @@ import (
5 5
 
6 6
 	"github.com/go-kit/kit/log"
7 7
 
8
-	"github.com/weaveworks/flux/event"
8
+	"github.com/weaveworks/flux/update"
9 9
 )
10 10
 
11 11
 type ID string
@@ -26,12 +26,21 @@ const (
26 26
 	StatusSucceeded StatusString = "succeeded"
27 27
 )
28 28
 
29
+// Result looks like CommitEventMetadata, because that's what we
30
+// used to send. But in the interest of breaking cycles before
31
+// they happen, it's (almost) duplicated here.
32
+type Result struct {
33
+	Revision string        `json:"revision,omitempty"`
34
+	Spec     *update.Spec  `json:"spec,omitempty"`
35
+	Result   update.Result `json:"result,omitempty"`
36
+}
37
+
29 38
 // Status holds the possible states of a job; either,
30 39
 //  1. queued or otherwise pending
31 40
 //  2. succeeded with a job-specific result
32 41
 //  3. failed, resulting in an error and possibly a job-specific result
33 42
 type Status struct {
34
-	Result       event.CommitEventMetadata
43
+	Result       Result
35 44
 	Err          string
36 45
 	StatusString StatusString
37 46
 }

Loading…
Cancel
Save