Browse Source

Merge pull request #1472 from weaveworks/promo-notifs-2

Add events for container release
Michael Bridgen 1 year ago
parent
commit
73256e99ef
No account linked to committer's email address

+ 3
- 3
cmd/fluxctl/release_cmd.go View File

@@ -137,7 +137,7 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error
137 137
 	}
138 138
 
139 139
 	ctx := context.Background()
140
-	spec := update.ReleaseSpec{
140
+	spec := update.ReleaseImageSpec{
141 141
 		ServiceSpecs: controllers,
142 142
 		ImageSpec:    image,
143 143
 		Kind:         kind,
@@ -182,10 +182,10 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error
182 182
 	return await(ctx, cmd.OutOrStdout(), cmd.OutOrStderr(), opts.API, jobID, !opts.dryRun, opts.verbosity)
183 183
 }
184 184
 
185
-func promptSpec(out io.Writer, result job.Result, verbosity int) (update.ContainerSpecs, error) {
185
+func promptSpec(out io.Writer, result job.Result, verbosity int) (update.ReleaseContainersSpec, error) {
186 186
 	menu := update.NewMenu(out, result.Result, verbosity)
187 187
 	containerSpecs, err := menu.Run()
188
-	return update.ContainerSpecs{
188
+	return update.ReleaseContainersSpec{
189 189
 		Kind:           update.ReleaseKindExecute,
190 190
 		ContainerSpecs: containerSpecs,
191 191
 		SkipMismatches: false,

+ 6
- 6
cmd/fluxctl/release_cmd_test.go View File

@@ -12,29 +12,29 @@ import (
12 12
 func TestReleaseCommand_CLIConversion(t *testing.T) {
13 13
 	for _, v := range []struct {
14 14
 		args         []string
15
-		expectedSpec update.ReleaseSpec
15
+		expectedSpec update.ReleaseImageSpec
16 16
 	}{
17
-		{[]string{"--update-all-images", "--all"}, update.ReleaseSpec{
17
+		{[]string{"--update-all-images", "--all"}, update.ReleaseImageSpec{
18 18
 			ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
19 19
 			ImageSpec:    update.ImageSpecLatest,
20 20
 			Kind:         update.ReleaseKindExecute,
21 21
 		}},
22
-		{[]string{"--update-all-images", "--all", "--dry-run"}, update.ReleaseSpec{
22
+		{[]string{"--update-all-images", "--all", "--dry-run"}, update.ReleaseImageSpec{
23 23
 			ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
24 24
 			ImageSpec:    update.ImageSpecLatest,
25 25
 			Kind:         update.ReleaseKindPlan,
26 26
 		}},
27
-		{[]string{"--update-image=alpine:latest", "--all"}, update.ReleaseSpec{
27
+		{[]string{"--update-image=alpine:latest", "--all"}, update.ReleaseImageSpec{
28 28
 			ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
29 29
 			ImageSpec:    "alpine:latest",
30 30
 			Kind:         update.ReleaseKindExecute,
31 31
 		}},
32
-		{[]string{"--update-all-images", "--controller=deployment/flux"}, update.ReleaseSpec{
32
+		{[]string{"--update-all-images", "--controller=deployment/flux"}, update.ReleaseImageSpec{
33 33
 			ServiceSpecs: []update.ResourceSpec{"default:deployment/flux"},
34 34
 			ImageSpec:    update.ImageSpecLatest,
35 35
 			Kind:         update.ReleaseKindExecute,
36 36
 		}},
37
-		{[]string{"--update-all-images", "--all", "--exclude=deployment/test,deployment/yeah"}, update.ReleaseSpec{
37
+		{[]string{"--update-all-images", "--all", "--exclude=deployment/test,deployment/yeah"}, update.ReleaseImageSpec{
38 38
 			ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
39 39
 			ImageSpec:    update.ImageSpecLatest,
40 40
 			Kind:         update.ReleaseKindExecute,

+ 5
- 6
daemon/daemon_test.go View File

@@ -144,7 +144,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
144 144
 
145 145
 	ctx := context.Background()
146 146
 
147
-	t.Run("no filter", func (t *testing.T) {
147
+	t.Run("no filter", func(t *testing.T) {
148 148
 		s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{})
149 149
 		if err != nil {
150 150
 			t.Fatalf("Error: %s", err.Error())
@@ -153,7 +153,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
153 153
 			t.Fatalf("Expected %v but got %v", 2, len(s))
154 154
 		}
155 155
 	})
156
-	t.Run("filter id", func (t *testing.T) {
156
+	t.Run("filter id", func(t *testing.T) {
157 157
 		s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
158 158
 			Namespace: "",
159 159
 			Services:  []flux.ResourceID{flux.MustParseResourceID(svc)}})
@@ -165,7 +165,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
165 165
 		}
166 166
 	})
167 167
 
168
-	t.Run("filter id and namespace", func (t *testing.T) {
168
+	t.Run("filter id and namespace", func(t *testing.T) {
169 169
 		_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
170 170
 			Namespace: "foo",
171 171
 			Services:  []flux.ResourceID{flux.MustParseResourceID(svc)}})
@@ -174,7 +174,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
174 174
 		}
175 175
 	})
176 176
 
177
-	t.Run("filter unsupported id kind", func (t *testing.T) {
177
+	t.Run("filter unsupported id kind", func(t *testing.T) {
178 178
 		_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
179 179
 			Namespace: "foo",
180 180
 			Services:  []flux.ResourceID{flux.MustParseResourceID("default:unsupportedkind/goodbyeworld")}})
@@ -184,7 +184,6 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
184 184
 	})
185 185
 }
186 186
 
187
-
188 187
 // When I call list images for a service, it should return images
189 188
 func TestDaemon_ListImagesWithOptions(t *testing.T) {
190 189
 	d, start, clean, _, _, _ := mockDaemon(t)
@@ -848,7 +847,7 @@ func (w *wait) ForImageTag(t *testing.T, d *Daemon, service, container, tag stri
848 847
 func updateImage(ctx context.Context, d *Daemon, t *testing.T) job.ID {
849 848
 	return updateManifest(ctx, t, d, update.Spec{
850 849
 		Type: update.Images,
851
-		Spec: update.ReleaseSpec{
850
+		Spec: update.ReleaseImageSpec{
852 851
 			Kind:         update.ReleaseKindExecute,
853 852
 			ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
854 853
 			ImageSpec:    newHelloImage,

+ 27
- 2
daemon/loop.go View File

@@ -306,8 +306,30 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
306 306
 
307 307
 			// Interpret some notes as events to send to the upstream
308 308
 			switch n.Spec.Type {
309
+			case update.Containers:
310
+				spec := n.Spec.Spec.(update.ReleaseContainersSpec)
311
+				noteEvents = append(noteEvents, event.Event{
312
+					ServiceIDs: n.Result.AffectedResources(),
313
+					Type:       event.EventRelease,
314
+					StartedAt:  started,
315
+					EndedAt:    time.Now().UTC(),
316
+					LogLevel:   event.LogLevelInfo,
317
+					Metadata: &event.ReleaseEventMetadata{
318
+						ReleaseEventCommon: event.ReleaseEventCommon{
319
+							Revision: commits[i].Revision,
320
+							Result:   n.Result,
321
+							Error:    n.Result.Error(),
322
+						},
323
+						Spec: event.ReleaseSpec{
324
+							Type: event.ReleaseContainersSpecType,
325
+							ReleaseContainersSpec: &spec,
326
+						},
327
+						Cause: n.Spec.Cause,
328
+					},
329
+				})
330
+				includes[event.EventRelease] = true
309 331
 			case update.Images:
310
-				spec := n.Spec.Spec.(update.ReleaseSpec)
332
+				spec := n.Spec.Spec.(update.ReleaseImageSpec)
311 333
 				noteEvents = append(noteEvents, event.Event{
312 334
 					ServiceIDs: n.Result.AffectedResources(),
313 335
 					Type:       event.EventRelease,
@@ -320,7 +342,10 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
320 342
 							Result:   n.Result,
321 343
 							Error:    n.Result.Error(),
322 344
 						},
323
-						Spec:  spec,
345
+						Spec: event.ReleaseSpec{
346
+							Type:             event.ReleaseImageSpecType,
347
+							ReleaseImageSpec: &spec,
348
+						},
324 349
 						Cause: n.Spec.Cause,
325 350
 					},
326 351
 				})

+ 49
- 6
event/event.go View File

@@ -95,10 +95,12 @@ func (e Event) String() string {
95 95
 		if len(strImageIDs) == 0 {
96 96
 			strImageIDs = []string{"no image changes"}
97 97
 		}
98
-		for _, spec := range metadata.Spec.ServiceSpecs {
99
-			if spec == update.ResourceSpecAll {
100
-				strServiceIDs = []string{"all services"}
101
-				break
98
+		if metadata.Spec.Type == "" || metadata.Spec.Type == ReleaseImageSpecType {
99
+			for _, spec := range metadata.Spec.ReleaseImageSpec.ServiceSpecs {
100
+				if spec == update.ResourceSpecAll {
101
+					strServiceIDs = []string{"all services"}
102
+					break
103
+				}
102 104
 			}
103 105
 		}
104 106
 		if len(strServiceIDs) == 0 {
@@ -239,11 +241,52 @@ type ReleaseEventCommon struct {
239 241
 	Error string `json:"error,omitempty"`
240 242
 }
241 243
 
244
+const (
245
+	// ReleaseImageSpecType is a type of release spec when there are update.Images
246
+	ReleaseImageSpecType = "releaseImageSpecType"
247
+	// ReleaseContainersSpecType is a type of release spec when there are update.Containers
248
+	ReleaseContainersSpecType = "releaseContainersSpecType"
249
+)
250
+
251
+// ReleaseSpec is a spec for images and containers release
252
+type ReleaseSpec struct {
253
+	// Type is ReleaseImageSpecType or ReleaseContainersSpecType
254
+	// if empty (for previous version), then use ReleaseImageSpecType
255
+	Type                  string
256
+	ReleaseImageSpec      *update.ReleaseImageSpec
257
+	ReleaseContainersSpec *update.ReleaseContainersSpec
258
+}
259
+
260
+// UnmarshalJSON for old version of spec (update.ReleaseImageSpec) where Type is empty
261
+func (s *ReleaseSpec) UnmarshalJSON(b []byte) error {
262
+	type T ReleaseSpec
263
+	t := (*T)(s)
264
+	if err := json.Unmarshal(b, t); err != nil {
265
+		return err
266
+	}
267
+
268
+	switch t.Type {
269
+	case "":
270
+		r := &update.ReleaseImageSpec{}
271
+		if err := json.Unmarshal(b, r); err != nil {
272
+			return err
273
+		}
274
+		s.Type = ReleaseImageSpecType
275
+		s.ReleaseImageSpec = r
276
+
277
+	case ReleaseImageSpecType, ReleaseContainersSpecType:
278
+		// all good
279
+	default:
280
+		return errors.New("unknown ReleaseSpec type")
281
+	}
282
+	return nil
283
+}
284
+
242 285
 // ReleaseEventMetadata is the metadata for when service(s) are released
243 286
 type ReleaseEventMetadata struct {
244 287
 	ReleaseEventCommon
245
-	Spec  update.ReleaseSpec `json:"spec"`
246
-	Cause update.Cause       `json:"cause"`
288
+	Spec  ReleaseSpec  `json:"spec"`
289
+	Cause update.Cause `json:"cause"`
247 290
 }
248 291
 
249 292
 // AutoReleaseEventMetadata is for when service(s) are released

+ 38
- 3
event/event_test.go View File

@@ -8,7 +8,7 @@ import (
8 8
 )
9 9
 
10 10
 var (
11
-	spec = update.ReleaseSpec{
11
+	spec = update.ReleaseImageSpec{
12 12
 		ImageSpec: update.ImageSpecLatest,
13 13
 	}
14 14
 	cause = update.Cause{
@@ -22,7 +22,10 @@ func TestEvent_ParseReleaseMetaData(t *testing.T) {
22 22
 		Type: EventRelease,
23 23
 		Metadata: &ReleaseEventMetadata{
24 24
 			Cause: cause,
25
-			Spec:  spec,
25
+			Spec: ReleaseSpec{
26
+				Type:             ReleaseImageSpecType,
27
+				ReleaseImageSpec: &spec,
28
+			},
26 29
 		},
27 30
 	}
28 31
 
@@ -35,7 +38,7 @@ func TestEvent_ParseReleaseMetaData(t *testing.T) {
35 38
 	}
36 39
 	switch r := e.Metadata.(type) {
37 40
 	case *ReleaseEventMetadata:
38
-		if r.Spec.ImageSpec != spec.ImageSpec ||
41
+		if r.Spec.ReleaseImageSpec.ImageSpec != spec.ImageSpec ||
39 42
 			r.Cause != cause {
40 43
 			t.Fatal("Release event wasn't marshalled/unmarshalled")
41 44
 		}
@@ -60,3 +63,35 @@ func TestEvent_ParseNoMetadata(t *testing.T) {
60 63
 		t.Fatal("Hasn't been unmarshalled properly")
61 64
 	}
62 65
 }
66
+
67
+// TestEvent_ParseOldReleaseMetaData makes sure the parsing code can
68
+// handle the older format events recorded against commits.
69
+func TestEvent_ParseOldReleaseMetaData(t *testing.T) {
70
+	// A minimal example of an old-style ReleaseEventMetadata. NB it
71
+	// must have at least an entry for "spec", since otherwise the
72
+	// JSON unmarshaller will not attempt to unparse the spec and
73
+	// thereby invoke the specialised UnmarshalJSON.
74
+	oldData := `
75
+{
76
+  "spec": {
77
+    "serviceSpecs": ["<all>"]
78
+  }
79
+}
80
+`
81
+	var eventData ReleaseEventMetadata
82
+	if err := json.Unmarshal([]byte(oldData), &eventData); err != nil {
83
+		t.Fatal(err)
84
+	}
85
+	if eventData.Spec.Type != ReleaseImageSpecType {
86
+		t.Error("did not set spec type to ReleaseImageSpecType")
87
+	}
88
+	if eventData.Spec.ReleaseImageSpec == nil {
89
+		t.Error("did not set .ReleaseImageSpec as expected")
90
+	}
91
+	if eventData.Spec.ReleaseContainersSpec != nil {
92
+		t.Error("unexpectedly set .ReleaseContainersSpec")
93
+	}
94
+	if len(eventData.Spec.ReleaseImageSpec.ServiceSpecs) != 1 {
95
+		t.Error("expected service specs of len 1")
96
+	}
97
+}

+ 1
- 1
http/daemon/server.go View File

@@ -227,7 +227,7 @@ func (s HTTPServer) UpdateImages(w http.ResponseWriter, r *http.Request) {
227 227
 		excludes = append(excludes, s)
228 228
 	}
229 229
 
230
-	spec := update.ReleaseSpec{
230
+	spec := update.ReleaseImageSpec{
231 231
 		ServiceSpecs: serviceSpecs,
232 232
 		ImageSpec:    imageSpec,
233 233
 		Kind:         releaseKind,

+ 26
- 26
release/releaser_test.go View File

@@ -243,7 +243,7 @@ func Test_InitContainer(t *testing.T) {
243 243
 	}
244 244
 
245 245
 	initSpec, _ := update.ParseResourceSpec(initWorkloadID.String())
246
-	spec := update.ReleaseSpec{
246
+	spec := update.ReleaseImageSpec{
247 247
 		ServiceSpecs: []update.ResourceSpec{initSpec},
248 248
 		ImageSpec:    update.ImageSpecLatest,
249 249
 		Kind:         update.ReleaseKindExecute,
@@ -268,13 +268,13 @@ func Test_FilterLogic(t *testing.T) {
268 268
 	notInRepoSpec, _ := update.ParseResourceSpec(notInRepoService)
269 269
 	for _, tst := range []struct {
270 270
 		Name     string
271
-		Spec     update.ReleaseSpec
271
+		Spec     update.ReleaseImageSpec
272 272
 		Expected expected
273 273
 	}{
274 274
 		// ignored if: excluded OR not included OR not correct image.
275 275
 		{
276 276
 			Name: "include specific service",
277
-			Spec: update.ReleaseSpec{
277
+			Spec: update.ReleaseImageSpec{
278 278
 				ServiceSpecs: []update.ResourceSpec{hwSvcSpec},
279 279
 				ImageSpec:    update.ImageSpecLatest,
280 280
 				Kind:         update.ReleaseKindExecute,
@@ -302,7 +302,7 @@ func Test_FilterLogic(t *testing.T) {
302 302
 			},
303 303
 		}, {
304 304
 			Name: "exclude specific service",
305
-			Spec: update.ReleaseSpec{
305
+			Spec: update.ReleaseImageSpec{
306 306
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
307 307
 				ImageSpec:    update.ImageSpecLatest,
308 308
 				Kind:         update.ReleaseKindExecute,
@@ -334,7 +334,7 @@ func Test_FilterLogic(t *testing.T) {
334 334
 			},
335 335
 		}, {
336 336
 			Name: "update specific image",
337
-			Spec: update.ReleaseSpec{
337
+			Spec: update.ReleaseImageSpec{
338 338
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
339 339
 				ImageSpec:    update.ImageSpecFromRef(newHwRef),
340 340
 				Kind:         update.ReleaseKindExecute,
@@ -363,7 +363,7 @@ func Test_FilterLogic(t *testing.T) {
363 363
 			// skipped if: not ignored AND (locked or not found in cluster)
364 364
 			// else: service is pending.
365 365
 			Name: "skipped & service is pending",
366
-			Spec: update.ReleaseSpec{
366
+			Spec: update.ReleaseImageSpec{
367 367
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
368 368
 				ImageSpec:    update.ImageSpecLatest,
369 369
 				Kind:         update.ReleaseKindExecute,
@@ -395,7 +395,7 @@ func Test_FilterLogic(t *testing.T) {
395 395
 			},
396 396
 		}, {
397 397
 			Name: "all overrides spec",
398
-			Spec: update.ReleaseSpec{
398
+			Spec: update.ReleaseImageSpec{
399 399
 				ServiceSpecs: []update.ResourceSpec{hwSvcSpec, update.ResourceSpecAll},
400 400
 				ImageSpec:    update.ImageSpecLatest,
401 401
 				Kind:         update.ReleaseKindExecute,
@@ -427,7 +427,7 @@ func Test_FilterLogic(t *testing.T) {
427 427
 			},
428 428
 		}, {
429 429
 			Name: "service not in repo",
430
-			Spec: update.ReleaseSpec{
430
+			Spec: update.ReleaseImageSpec{
431 431
 				ServiceSpecs: []update.ResourceSpec{notInRepoSpec},
432 432
 				ImageSpec:    update.ImageSpecLatest,
433 433
 				Kind:         update.ReleaseKindExecute,
@@ -468,12 +468,12 @@ func Test_Force_lockedController(t *testing.T) {
468 468
 	}
469 469
 	for _, tst := range []struct {
470 470
 		Name     string
471
-		Spec     update.ReleaseSpec
471
+		Spec     update.ReleaseImageSpec
472 472
 		Expected expected
473 473
 	}{
474 474
 		{
475 475
 			Name: "force ignores service lock (--controller --update-image)",
476
-			Spec: update.ReleaseSpec{
476
+			Spec: update.ReleaseImageSpec{
477 477
 				ServiceSpecs: []update.ResourceSpec{lockedSvcSpec},
478 478
 				ImageSpec:    update.ImageSpecFromRef(newLockedRef),
479 479
 				Kind:         update.ReleaseKindExecute,
@@ -488,7 +488,7 @@ func Test_Force_lockedController(t *testing.T) {
488 488
 			},
489 489
 		}, {
490 490
 			Name: "force does not ignore lock if updating all controllers (--all --update-image)",
491
-			Spec: update.ReleaseSpec{
491
+			Spec: update.ReleaseImageSpec{
492 492
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
493 493
 				ImageSpec:    update.ImageSpecFromRef(newLockedRef),
494 494
 				Kind:         update.ReleaseKindExecute,
@@ -504,7 +504,7 @@ func Test_Force_lockedController(t *testing.T) {
504 504
 		},
505 505
 		{
506 506
 			Name: "force ignores service lock (--controller --update-all-images)",
507
-			Spec: update.ReleaseSpec{
507
+			Spec: update.ReleaseImageSpec{
508 508
 				ServiceSpecs: []update.ResourceSpec{lockedSvcSpec},
509 509
 				ImageSpec:    update.ImageSpecLatest,
510 510
 				Kind:         update.ReleaseKindExecute,
@@ -519,7 +519,7 @@ func Test_Force_lockedController(t *testing.T) {
519 519
 			},
520 520
 		}, {
521 521
 			Name: "force does not ignore lock if updating all controllers (--all --update-all-images)",
522
-			Spec: update.ReleaseSpec{
522
+			Spec: update.ReleaseImageSpec{
523 523
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
524 524
 				ImageSpec:    update.ImageSpecLatest,
525 525
 				Kind:         update.ReleaseKindExecute,
@@ -571,12 +571,12 @@ func Test_Force_filteredContainer(t *testing.T) {
571 571
 	}
572 572
 	for _, tst := range []struct {
573 573
 		Name     string
574
-		Spec     update.ReleaseSpec
574
+		Spec     update.ReleaseImageSpec
575 575
 		Expected expected
576 576
 	}{
577 577
 		{
578 578
 			Name: "force ignores container tag pattern (--controller --update-image)",
579
-			Spec: update.ReleaseSpec{
579
+			Spec: update.ReleaseImageSpec{
580 580
 				ServiceSpecs: []update.ResourceSpec{semverSvcSpec},
581 581
 				ImageSpec:    update.ImageSpecFromRef(newHwRef), // does not match filter
582 582
 				Kind:         update.ReleaseKindExecute,
@@ -592,7 +592,7 @@ func Test_Force_filteredContainer(t *testing.T) {
592 592
 		},
593 593
 		{
594 594
 			Name: "force ignores container tag pattern (--all --update-image)",
595
-			Spec: update.ReleaseSpec{
595
+			Spec: update.ReleaseImageSpec{
596 596
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
597 597
 				ImageSpec:    update.ImageSpecFromRef(newHwRef), // does not match filter
598 598
 				Kind:         update.ReleaseKindExecute,
@@ -608,7 +608,7 @@ func Test_Force_filteredContainer(t *testing.T) {
608 608
 		},
609 609
 		{
610 610
 			Name: "force complies with semver when updating all images (--controller --update-all-image)",
611
-			Spec: update.ReleaseSpec{
611
+			Spec: update.ReleaseImageSpec{
612 612
 				ServiceSpecs: []update.ResourceSpec{semverSvcSpec},
613 613
 				ImageSpec:    update.ImageSpecLatest, // will filter images by semver and pick newest version
614 614
 				Kind:         update.ReleaseKindExecute,
@@ -624,7 +624,7 @@ func Test_Force_filteredContainer(t *testing.T) {
624 624
 		},
625 625
 		{
626 626
 			Name: "force complies with semver when updating all images (--all --update-all-image)",
627
-			Spec: update.ReleaseSpec{
627
+			Spec: update.ReleaseImageSpec{
628 628
 				ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
629 629
 				ImageSpec:    update.ImageSpecLatest,
630 630
 				Kind:         update.ReleaseKindExecute,
@@ -670,12 +670,12 @@ func Test_ImageStatus(t *testing.T) {
670 670
 	testSvcSpec, _ := update.ParseResourceSpec(testSvc.ID.String())
671 671
 	for _, tst := range []struct {
672 672
 		Name     string
673
-		Spec     update.ReleaseSpec
673
+		Spec     update.ReleaseImageSpec
674 674
 		Expected expected
675 675
 	}{
676 676
 		{
677 677
 			Name: "image not found",
678
-			Spec: update.ReleaseSpec{
678
+			Spec: update.ReleaseImageSpec{
679 679
 				ServiceSpecs: []update.ResourceSpec{testSvcSpec},
680 680
 				ImageSpec:    update.ImageSpecLatest,
681 681
 				Kind:         update.ReleaseKindExecute,
@@ -692,7 +692,7 @@ func Test_ImageStatus(t *testing.T) {
692 692
 			},
693 693
 		}, {
694 694
 			Name: "image up to date",
695
-			Spec: update.ReleaseSpec{
695
+			Spec: update.ReleaseImageSpec{
696 696
 				ServiceSpecs: []update.ResourceSpec{hwSvcSpec},
697 697
 				ImageSpec:    update.ImageSpecLatest,
698 698
 				Kind:         update.ReleaseKindExecute,
@@ -746,7 +746,7 @@ func Test_UpdateMultidoc(t *testing.T) {
746 746
 		repo:      checkout,
747 747
 		registry:  mockRegistry,
748 748
 	}
749
-	spec := update.ReleaseSpec{
749
+	spec := update.ReleaseImageSpec{
750 750
 		ServiceSpecs: []update.ResourceSpec{"default:deployment/multi-deploy"},
751 751
 		ImageSpec:    update.ImageSpecLatest,
752 752
 		Kind:         update.ReleaseKindExecute,
@@ -794,7 +794,7 @@ func Test_UpdateList(t *testing.T) {
794 794
 		repo:      checkout,
795 795
 		registry:  mockRegistry,
796 796
 	}
797
-	spec := update.ReleaseSpec{
797
+	spec := update.ReleaseImageSpec{
798 798
 		ServiceSpecs: []update.ResourceSpec{"default:deployment/list-deploy"},
799 799
 		ImageSpec:    update.ImageSpecLatest,
800 800
 		Kind:         update.ReleaseKindExecute,
@@ -1014,7 +1014,7 @@ func Test_UpdateContainers(t *testing.T) {
1014 1014
 			},
1015 1015
 		},
1016 1016
 	} {
1017
-		specs := update.ContainerSpecs{
1017
+		specs := update.ReleaseContainersSpec{
1018 1018
 			ContainerSpecs: map[flux.ResourceID][]update.ContainerUpdate{tst.WorkloadID: tst.Spec},
1019 1019
 			Kind:           update.ReleaseKindExecute,
1020 1020
 		}
@@ -1040,7 +1040,7 @@ func Test_UpdateContainers(t *testing.T) {
1040 1040
 	}
1041 1041
 }
1042 1042
 
1043
-func testRelease(t *testing.T, ctx *ReleaseContext, spec update.ReleaseSpec, expected update.Result) {
1043
+func testRelease(t *testing.T, ctx *ReleaseContext, spec update.ReleaseImageSpec, expected update.Result) {
1044 1044
 	results, err := Release(ctx, spec, log.NewNopLogger())
1045 1045
 	assert.NoError(t, err)
1046 1046
 	assert.Equal(t, expected, results)
@@ -1059,7 +1059,7 @@ func (m *badManifests) UpdateImage(def []byte, resourceID flux.ResourceID, conta
1059 1059
 
1060 1060
 func Test_BadRelease(t *testing.T) {
1061 1061
 	cluster := mockCluster(hwSvc)
1062
-	spec := update.ReleaseSpec{
1062
+	spec := update.ReleaseImageSpec{
1063 1063
 		ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
1064 1064
 		ImageSpec:    update.ImageSpecFromRef(newHwRef),
1065 1065
 		Kind:         update.ReleaseKindExecute,

+ 1
- 1
remote/mock.go View File

@@ -160,7 +160,7 @@ func ServerTestBattery(t *testing.T, wrap func(mock api.UpstreamServer) api.Upst
160 160
 
161 161
 	updateSpec := update.Spec{
162 162
 		Type: update.Images,
163
-		Spec: update.ReleaseSpec{
163
+		Spec: update.ReleaseImageSpec{
164 164
 			ServiceSpecs: []update.ResourceSpec{
165 165
 				update.ResourceSpecAll,
166 166
 			},

+ 1
- 1
remote/rpc/compat.go View File

@@ -47,7 +47,7 @@ func requireSpecKinds(s update.Spec, kinds []string) error {
47 47
 				return fmt.Errorf("Unsupported resource kind: %s", kind)
48 48
 			}
49 49
 		}
50
-	case update.ReleaseSpec:
50
+	case update.ReleaseImageSpec:
51 51
 		for _, ss := range s.ServiceSpecs {
52 52
 			if err := requireServiceSpecKinds(ss, kinds); err != nil {
53 53
 				return err

update/containers.go → update/release_containers.go View File

@@ -15,8 +15,8 @@ import (
15 15
 
16 16
 var zeroImageRef = image.Ref{}
17 17
 
18
-// ContainerSpecs defines the spec for a `containers` manifest update.
19
-type ContainerSpecs struct {
18
+// ReleaseContainersSpec defines the spec for a `containers` manifest update.
19
+type ReleaseContainersSpec struct {
20 20
 	Kind           ReleaseKind
21 21
 	ContainerSpecs map[flux.ResourceID][]ContainerUpdate
22 22
 	SkipMismatches bool
@@ -25,7 +25,7 @@ type ContainerSpecs struct {
25 25
 
26 26
 // CalculateRelease computes required controller updates to satisfy this specification.
27 27
 // It returns an error if any spec calculation fails unless `SkipMismatches` is true.
28
-func (s ContainerSpecs) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*ControllerUpdate, Result, error) {
28
+func (s ReleaseContainersSpec) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*ControllerUpdate, Result, error) {
29 29
 	results := Result{}
30 30
 	prefilter, postfilter := s.filters()
31 31
 	all, err := rc.SelectServices(results, prefilter, postfilter)
@@ -36,7 +36,7 @@ func (s ContainerSpecs) CalculateRelease(rc ReleaseContext, logger log.Logger) (
36 36
 	return updates, results, s.resultsError(results)
37 37
 }
38 38
 
39
-func (s ContainerSpecs) resultsError(results Result) error {
39
+func (s ReleaseContainersSpec) resultsError(results Result) error {
40 40
 	failures := 0
41 41
 	successes := 0
42 42
 	for _, res := range results {
@@ -56,7 +56,7 @@ func (s ContainerSpecs) resultsError(results Result) error {
56 56
 	return nil
57 57
 }
58 58
 
59
-func (s ContainerSpecs) filters() ([]ControllerFilter, []ControllerFilter) {
59
+func (s ReleaseContainersSpec) filters() ([]ControllerFilter, []ControllerFilter) {
60 60
 	var rids []flux.ResourceID
61 61
 	for rid := range s.ContainerSpecs {
62 62
 		rids = append(rids, rid)
@@ -69,7 +69,7 @@ func (s ContainerSpecs) filters() ([]ControllerFilter, []ControllerFilter) {
69 69
 	return pre, []ControllerFilter{}
70 70
 }
71 71
 
72
-func (s ContainerSpecs) controllerUpdates(results Result, all []*ControllerUpdate) []*ControllerUpdate {
72
+func (s ReleaseContainersSpec) controllerUpdates(results Result, all []*ControllerUpdate) []*ControllerUpdate {
73 73
 	var updates []*ControllerUpdate
74 74
 	for _, u := range all {
75 75
 		cs, err := u.Controller.ContainersOrError()
@@ -157,15 +157,15 @@ func (s ContainerSpecs) controllerUpdates(results Result, all []*ControllerUpdat
157 157
 	return updates
158 158
 }
159 159
 
160
-func (s ContainerSpecs) ReleaseKind() ReleaseKind {
160
+func (s ReleaseContainersSpec) ReleaseKind() ReleaseKind {
161 161
 	return s.Kind
162 162
 }
163 163
 
164
-func (s ContainerSpecs) ReleaseType() ReleaseType {
164
+func (s ReleaseContainersSpec) ReleaseType() ReleaseType {
165 165
 	return "containers"
166 166
 }
167 167
 
168
-func (s ContainerSpecs) CommitMessage(result Result) string {
168
+func (s ReleaseContainersSpec) CommitMessage(result Result) string {
169 169
 	var workloads []string
170 170
 	body := &bytes.Buffer{}
171 171
 	for _, res := range result.AffectedResources() {

update/release.go → update/release_image.go View File

@@ -51,7 +51,7 @@ type ReleaseContext interface {
51 51
 
52 52
 // NB: these get sent from fluxctl, so we have to maintain the json format of
53 53
 // this. Eugh.
54
-type ReleaseSpec struct {
54
+type ReleaseImageSpec struct {
55 55
 	ServiceSpecs []ResourceSpec
56 56
 	ImageSpec    ImageSpec
57 57
 	Kind         ReleaseKind
@@ -61,7 +61,7 @@ type ReleaseSpec struct {
61 61
 
62 62
 // ReleaseType gives a one-word description of the release, mainly
63 63
 // useful for labelling metrics or log messages.
64
-func (s ReleaseSpec) ReleaseType() ReleaseType {
64
+func (s ReleaseImageSpec) ReleaseType() ReleaseType {
65 65
 	switch {
66 66
 	case s.ImageSpec == ImageSpecLatest:
67 67
 		return "latest_images"
@@ -70,7 +70,7 @@ func (s ReleaseSpec) ReleaseType() ReleaseType {
70 70
 	}
71 71
 }
72 72
 
73
-func (s ReleaseSpec) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*ControllerUpdate, Result, error) {
73
+func (s ReleaseImageSpec) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*ControllerUpdate, Result, error) {
74 74
 	results := Result{}
75 75
 	timer := NewStageTimer("select_services")
76 76
 	updates, err := s.selectServices(rc, results)
@@ -89,11 +89,11 @@ func (s ReleaseSpec) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*
89 89
 	return updates, results, nil
90 90
 }
91 91
 
92
-func (s ReleaseSpec) ReleaseKind() ReleaseKind {
92
+func (s ReleaseImageSpec) ReleaseKind() ReleaseKind {
93 93
 	return s.Kind
94 94
 }
95 95
 
96
-func (s ReleaseSpec) CommitMessage(result Result) string {
96
+func (s ReleaseImageSpec) CommitMessage(result Result) string {
97 97
 	image := strings.Trim(s.ImageSpec.String(), "<>")
98 98
 	var services []string
99 99
 	for _, spec := range s.ServiceSpecs {
@@ -105,7 +105,7 @@ func (s ReleaseSpec) CommitMessage(result Result) string {
105 105
 // Take the spec given in the job, and figure out which services are
106 106
 // in question based on the running services and those defined in the
107 107
 // repo. Fill in the release results along the way.
108
-func (s ReleaseSpec) selectServices(rc ReleaseContext, results Result) ([]*ControllerUpdate, error) {
108
+func (s ReleaseImageSpec) selectServices(rc ReleaseContext, results Result) ([]*ControllerUpdate, error) {
109 109
 	// Build list of filters
110 110
 	prefilters, postfilters, err := s.filters(rc)
111 111
 	if err != nil {
@@ -115,7 +115,7 @@ func (s ReleaseSpec) selectServices(rc ReleaseContext, results Result) ([]*Contr
115 115
 	return rc.SelectServices(results, prefilters, postfilters)
116 116
 }
117 117
 
118
-func (s ReleaseSpec) filters(rc ReleaseContext) ([]ControllerFilter, []ControllerFilter, error) {
118
+func (s ReleaseImageSpec) filters(rc ReleaseContext) ([]ControllerFilter, []ControllerFilter, error) {
119 119
 	var prefilters, postfilters []ControllerFilter
120 120
 
121 121
 	ids := []flux.ResourceID{}
@@ -157,7 +157,7 @@ func (s ReleaseSpec) filters(rc ReleaseContext) ([]ControllerFilter, []Controlle
157 157
 	return prefilters, postfilters, nil
158 158
 }
159 159
 
160
-func (s ReleaseSpec) markSkipped(results Result) {
160
+func (s ReleaseImageSpec) markSkipped(results Result) {
161 161
 	for _, v := range s.ServiceSpecs {
162 162
 		if v == ResourceSpecAll {
163 163
 			continue
@@ -181,7 +181,7 @@ func (s ReleaseSpec) markSkipped(results Result) {
181 181
 // however we do want to see if we *can* do the replacements, because
182 182
 // if not, it indicates there's likely some problem with the running
183 183
 // system vs the definitions given in the repo.)
184
-func (s ReleaseSpec) calculateImageUpdates(rc ReleaseContext, candidates []*ControllerUpdate, results Result, logger log.Logger) ([]*ControllerUpdate, error) {
184
+func (s ReleaseImageSpec) calculateImageUpdates(rc ReleaseContext, candidates []*ControllerUpdate, results Result, logger log.Logger) ([]*ControllerUpdate, error) {
185 185
 	// Compile an `ImageRepos` of all relevant images
186 186
 	var imageRepos ImageRepos
187 187
 	var singleRepo image.CanonicalName

+ 2
- 2
update/spec.go View File

@@ -49,7 +49,7 @@ func (spec *Spec) UnmarshalJSON(in []byte) error {
49 49
 		}
50 50
 		spec.Spec = update
51 51
 	case Images:
52
-		var update ReleaseSpec
52
+		var update ReleaseImageSpec
53 53
 		if err := json.Unmarshal(wire.SpecBytes, &update); err != nil {
54 54
 			return err
55 55
 		}
@@ -67,7 +67,7 @@ func (spec *Spec) UnmarshalJSON(in []byte) error {
67 67
 		}
68 68
 		spec.Spec = update
69 69
 	case Containers:
70
-		var update ContainerSpecs
70
+		var update ReleaseContainersSpec
71 71
 		if err := json.Unmarshal(wire.SpecBytes, &update); err != nil {
72 72
 			return err
73 73
 		}

Loading…
Cancel
Save