From 57c0accd403bf9e171584c78ca36a5f7188e7b37 Mon Sep 17 00:00:00 2001 From: Tara Gu Date: Thu, 12 Dec 2019 14:09:48 -0500 Subject: [PATCH] In unit tests, apply service defaults after service options --- pkg/reconciler/service/service_test.go | 345 +++++++++++++------------ pkg/testing/v1/service.go | 5 + pkg/testing/v1alpha1/service.go | 6 +- pkg/testing/v1beta1/service.go | 6 +- 4 files changed, 198 insertions(+), 164 deletions(-) diff --git a/pkg/reconciler/service/service_test.go b/pkg/reconciler/service/service_test.go index b471d02d3f23..981ac61423a3 100644 --- a/pkg/reconciler/service/service_test.go +++ b/pkg/reconciler/service/service_test.go @@ -59,14 +59,16 @@ func TestReconcile(t *testing.T) { Name: "nop deletion reconcile", // Test that with a DeletionTimestamp we do nothing. Objects: []runtime.Object{ - Service("delete-pending", "foo", WithServiceDeletionTimestamp), + Service("delete-pending", "foo", WithServiceDeletionTimestamp, WithServiceDefaults), }, Key: "foo/delete-pending", }, { Name: "inline - byo rev name used in traffic serialize", Objects: []runtime.Object{ - Service("byo-rev", "foo", WithInlineNamedRevision), - config("byo-rev", "foo", WithInlineNamedRevision, WithGeneration(2)), + Service("byo-rev", "foo", WithInlineNamedRevision, WithServiceDefaults), + config("byo-rev", "foo", + []ServiceOption{WithInlineNamedRevision, WithServiceDefaults}, + WithGeneration(2)), }, // Route should not be created until config progresses WantCreates: []runtime.Object{}, @@ -74,7 +76,7 @@ func TestReconcile(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("byo-rev", "foo", WithInlineNamedRevision, // Route conditions should be at init state while Config should be OutOfDate - WithInitSvcConditions, WithOutOfDateConfig), + WithInitSvcConditions, WithOutOfDateConfig, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Updated", "Updated Service %q", "byo-rev"), @@ -82,17 +84,17 @@ func TestReconcile(t *testing.T) { }, { Name: "inline - byo rev name used in traffic", Objects: []runtime.Object{ - Service("byo-rev", "foo", WithInlineNamedRevision), + Service("byo-rev", "foo", WithInlineNamedRevision, WithServiceDefaults), }, Key: "foo/byo-rev", WantCreates: []runtime.Object{ - config("byo-rev", "foo", WithInlineNamedRevision), - route("byo-rev", "foo", WithInlineNamedRevision), + config("byo-rev", "foo", []ServiceOption{WithInlineNamedRevision, WithServiceDefaults}), + route("byo-rev", "foo", []ServiceOption{WithInlineNamedRevision, WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("byo-rev", "foo", WithInlineNamedRevision, // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Created", "Created Configuration %q", "byo-rev"), @@ -102,17 +104,17 @@ func TestReconcile(t *testing.T) { }, { Name: "inline - create route and service", Objects: []runtime.Object{ - Service("run-latest", "foo", WithInlineRollout), + Service("run-latest", "foo", WithInlineRollout, WithServiceDefaults), }, Key: "foo/run-latest", WantCreates: []runtime.Object{ - config("run-latest", "foo", WithInlineRollout), - route("run-latest", "foo", WithInlineRollout), + config("run-latest", "foo", []ServiceOption{WithInlineRollout, WithServiceDefaults}), + route("run-latest", "foo", []ServiceOption{WithInlineRollout, WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("run-latest", "foo", WithInlineRollout, // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Created", "Created Configuration %q", "run-latest"), @@ -122,17 +124,17 @@ func TestReconcile(t *testing.T) { }, { Name: "runLatest - create route and service", Objects: []runtime.Object{ - Service("run-latest", "foo", WithRunLatestRollout), + Service("run-latest", "foo", WithRunLatestRollout, WithServiceDefaults), }, Key: "foo/run-latest", WantCreates: []runtime.Object{ - config("run-latest", "foo", WithRunLatestRollout), - route("run-latest", "foo", WithRunLatestRollout), + config("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("run-latest", "foo", WithRunLatestRollout, // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -149,17 +151,17 @@ func TestReconcile(t *testing.T) { }, { Name: "pinned - create route and service", Objects: []runtime.Object{ - Service("pinned", "foo", WithPinnedRollout("pinned-0001")), + Service("pinned", "foo", WithPinnedRollout("pinned-0001"), WithServiceDefaults), }, Key: "foo/pinned", WantCreates: []runtime.Object{ - config("pinned", "foo", WithPinnedRollout("pinned-0001")), - route("pinned", "foo", WithPinnedRollout("pinned-0001")), + config("pinned", "foo", []ServiceOption{WithPinnedRollout("pinned-0001"), WithServiceDefaults}), + route("pinned", "foo", []ServiceOption{WithPinnedRollout("pinned-0001"), WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("pinned", "foo", WithPinnedRollout("pinned-0001"), // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -178,17 +180,17 @@ func TestReconcile(t *testing.T) { // using Release. Name: "pinned - create route and service - via release", Objects: []runtime.Object{ - Service("pinned2", "foo", WithReleaseRollout("pinned2-0001")), + Service("pinned2", "foo", WithReleaseRollout("pinned2-0001"), WithServiceDefaults), }, Key: "foo/pinned2", WantCreates: []runtime.Object{ - config("pinned2", "foo", WithReleaseRollout("pinned2-0001")), - route("pinned2", "foo", WithReleaseRollout("pinned2-0001")), + config("pinned2", "foo", []ServiceOption{WithReleaseRollout("pinned2-0001"), WithServiceDefaults}), + route("pinned2", "foo", []ServiceOption{WithReleaseRollout("pinned2-0001"), WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("pinned2", "foo", WithReleaseRollout("pinned2-0001"), // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -206,12 +208,12 @@ func TestReconcile(t *testing.T) { Name: "pinned - with ready config and route", Objects: []runtime.Object{ Service("pinned3", "foo", WithReleaseRollout("pinned3-00001"), - WithInitSvcConditions), - config("pinned3", "foo", WithReleaseRollout("pinned3-00001"), + WithInitSvcConditions, WithServiceDefaults), + config("pinned3", "foo", []ServiceOption{WithReleaseRollout("pinned3-00001"), WithServiceDefaults}, WithGeneration(1), WithObservedGen, WithLatestCreated("pinned3-00001"), WithLatestReady("pinned3-00001")), - route("pinned3", "foo", WithReleaseRollout("pinned3-00001"), + route("pinned3", "foo", []ServiceOption{WithReleaseRollout("pinned3-00001"), WithServiceDefaults}, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -250,7 +252,8 @@ func TestReconcile(t *testing.T) { RevisionName: "pinned3-00001", Percent: nil, }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -268,17 +271,17 @@ func TestReconcile(t *testing.T) { }, { Name: "release - with @latest", Objects: []runtime.Object{ - Service("release", "foo", WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword)), + Service("release", "foo", WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), WithServiceDefaults), }, Key: "foo/release", WantCreates: []runtime.Object{ - config("release", "foo", WithReleaseRollout("release-00001")), - route("release", "foo", WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword)), + config("release", "foo", []ServiceOption{WithReleaseRollout("release-00001"), WithServiceDefaults}), + route("release", "foo", []ServiceOption{WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("release", "foo", WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -295,17 +298,17 @@ func TestReconcile(t *testing.T) { }, { Name: "release - create route and service", Objects: []runtime.Object{ - Service("release", "foo", WithReleaseRollout("release-00001", "release-00002")), + Service("release", "foo", WithReleaseRollout("release-00001", "release-00002"), WithServiceDefaults), }, Key: "foo/release", WantCreates: []runtime.Object{ - config("release", "foo", WithReleaseRollout("release-00001", "release-00002")), - route("release", "foo", WithReleaseRollout("release-00001", "release-00002")), + config("release", "foo", []ServiceOption{WithReleaseRollout("release-00001", "release-00002"), WithServiceDefaults}), + route("release", "foo", []ServiceOption{WithReleaseRollout("release-00001", "release-00002"), WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("release", "foo", WithReleaseRollout("release-00001", "release-00002"), // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -322,11 +325,11 @@ func TestReconcile(t *testing.T) { }, { Name: "release - update service, route not ready", Objects: []runtime.Object{ - Service("release-nr", "foo", WithReleaseRollout("release-nr-00002"), WithInitSvcConditions), - config("release-nr", "foo", WithReleaseRollout("release-nr-00002"), + Service("release-nr", "foo", WithReleaseRollout("release-nr-00002"), WithInitSvcConditions, WithServiceDefaults), + config("release-nr", "foo", []ServiceOption{WithReleaseRollout("release-nr-00002"), WithServiceDefaults}, WithCreatedAndReady("release-nr-00002", "release-nr-00002")), // NB: route points to the previous revision. - route("release-nr", "foo", WithReleaseRollout("release-nr-00002"), RouteReady, + route("release-nr", "foo", []ServiceOption{WithReleaseRollout("release-nr-00002"), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -346,7 +349,7 @@ func TestReconcile(t *testing.T) { RevisionName: "release-nr-00001", Percent: ptr.Int64(100), }, - })), + }), WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -361,11 +364,11 @@ func TestReconcile(t *testing.T) { }, { Name: "release - update service, route not ready, 2 rev, no split", Objects: []runtime.Object{ - Service("release-nr", "foo", WithReleaseRollout("release-nr-00002", "release-nr-00003"), WithInitSvcConditions), - config("release-nr", "foo", WithReleaseRollout("release-nr-00002", "release-nr-00003"), + Service("release-nr", "foo", WithReleaseRollout("release-nr-00002", "release-nr-00003"), WithInitSvcConditions, WithServiceDefaults), + config("release-nr", "foo", []ServiceOption{WithReleaseRollout("release-nr-00002", "release-nr-00003"), WithServiceDefaults}, WithCreatedAndReady("release-nr-00003", "release-nr-00003")), // NB: route points to the previous revision. - route("release-nr", "foo", WithReleaseRollout("release-nr-00002", "release-nr-00003"), + route("release-nr", "foo", []ServiceOption{WithReleaseRollout("release-nr-00002", "release-nr-00003"), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -385,7 +388,8 @@ func TestReconcile(t *testing.T) { RevisionName: "release-nr-00001", Percent: ptr.Int64(100), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -402,12 +406,13 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("release-nr-ts", "foo", WithReleaseRolloutAndPercentage(42, "release-nr-ts-00002", "release-nr-ts-00003"), - WithInitSvcConditions), + WithInitSvcConditions, + WithServiceDefaults), config("release-nr-ts", "foo", - WithReleaseRolloutAndPercentage(42, "release-nr-ts-00002", "release-nr-ts-00003"), + []ServiceOption{WithReleaseRolloutAndPercentage(42, "release-nr-ts-00002", "release-nr-ts-00003"), WithServiceDefaults}, WithCreatedAndReady("release-nr-ts-00003", "release-nr-ts-00003")), route("release-nr-ts", "foo", - WithReleaseRolloutAndPercentage(42, "release-nr-ts-00002", "release-nr-ts-00003"), + []ServiceOption{WithReleaseRolloutAndPercentage(42, "release-nr-ts-00002", "release-nr-ts-00003"), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -437,7 +442,8 @@ func TestReconcile(t *testing.T) { RevisionName: "release-nr-ts-00002", Percent: ptr.Int64(42), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -454,12 +460,13 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("release-nr-ts2", "foo", WithReleaseRolloutAndPercentage(58, "release-nr-ts2-00002", "release-nr-ts2-00003"), - WithInitSvcConditions), + WithInitSvcConditions, + WithServiceDefaults), config("release-nr-ts2", "foo", - WithReleaseRolloutAndPercentage(58, "release-nr-ts2-00002", "release-nr-ts2-00003"), + []ServiceOption{WithReleaseRolloutAndPercentage(58, "release-nr-ts2-00002", "release-nr-ts2-00003"), WithServiceDefaults}, WithCreatedAndReady("release-nr-ts2-00003", "release-nr-ts2-00003")), route("release-nr-ts2", "foo", - WithReleaseRolloutAndPercentage(58, "release-nr-ts2-00002", "release-nr-ts2-00003"), + []ServiceOption{WithReleaseRolloutAndPercentage(58, "release-nr-ts2-00002", "release-nr-ts2-00003"), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, // NB: here the revisions match, but percentages, don't. WithStatusTraffic(v1alpha1.TrafficTarget{ @@ -490,7 +497,8 @@ func TestReconcile(t *testing.T) { RevisionName: "release-nr-ts2-00003", Percent: ptr.Int64(42), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -506,9 +514,9 @@ func TestReconcile(t *testing.T) { Name: "release - route and config ready, using @latest", Objects: []runtime.Object{ Service("release-ready-lr", "foo", - WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), WithInitSvcConditions), + WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), WithInitSvcConditions, WithServiceDefaults), route("release-ready-lr", "foo", - WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), + []ServiceOption{WithReleaseRollout(v1alpha1.ReleaseLatestRevisionKeyword), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic([]v1alpha1.TrafficTarget{{ TrafficTarget: v1.TrafficTarget{ @@ -522,7 +530,7 @@ func TestReconcile(t *testing.T) { RevisionName: "release-ready-lr-00001", }, }}...), MarkTrafficAssigned, MarkIngressReady), - config("release-ready-lr", "foo", WithReleaseRollout("release-ready-lr"), + config("release-ready-lr", "foo", []ServiceOption{WithReleaseRollout("release-ready-lr"), WithServiceDefaults}, WithGeneration(1), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("release-ready-lr-00001"), @@ -548,6 +556,7 @@ func TestReconcile(t *testing.T) { RevisionName: "release-ready-lr-00001", }, }}...), + WithServiceDefaults, ), }}, WantPatches: []clientgotesting.PatchActionImpl{{ @@ -568,10 +577,11 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("release-ready-lr", "foo", WithReleaseRolloutAndPercentage( - 42, "release-ready-lr-00001", v1alpha1.ReleaseLatestRevisionKeyword), WithInitSvcConditions), + 42, "release-ready-lr-00001", v1alpha1.ReleaseLatestRevisionKeyword), WithInitSvcConditions, + WithServiceDefaults), route("release-ready-lr", "foo", - WithReleaseRolloutAndPercentage( - 42, "release-ready-lr-00001", v1alpha1.ReleaseLatestRevisionKeyword), + []ServiceOption{WithReleaseRolloutAndPercentage( + 42, "release-ready-lr-00001", v1alpha1.ReleaseLatestRevisionKeyword), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic([]v1alpha1.TrafficTarget{{ TrafficTarget: v1.TrafficTarget{ @@ -591,7 +601,7 @@ func TestReconcile(t *testing.T) { RevisionName: "release-ready-lr-00002", }, }}...), MarkTrafficAssigned, MarkIngressReady), - config("release-ready-lr", "foo", WithReleaseRollout("release-ready-lr"), + config("release-ready-lr", "foo", []ServiceOption{WithReleaseRollout("release-ready-lr"), WithServiceDefaults}, WithGeneration(2), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("release-ready-lr-00002"), @@ -624,6 +634,7 @@ func TestReconcile(t *testing.T) { RevisionName: "release-ready-lr-00002", }, }}...), + WithServiceDefaults, ), }}, WantPatches: []clientgotesting.PatchActionImpl{{ @@ -644,10 +655,11 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("release-ready", "foo", WithReleaseRolloutAndPercentage(58, /*candidate traffic percentage*/ - "release-ready-00001", "release-ready-00002"), WithInitSvcConditions), + "release-ready-00001", "release-ready-00002"), WithInitSvcConditions, + WithServiceDefaults), route("release-ready", "foo", - WithReleaseRolloutAndPercentage(58, /*candidate traffic percentage*/ - "release-ready-00001", "release-ready-00002"), + []ServiceOption{WithReleaseRolloutAndPercentage(58, /*candidate traffic percentage*/ + "release-ready-00001", "release-ready-00002"), WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -668,7 +680,7 @@ func TestReconcile(t *testing.T) { Percent: nil, }, }), MarkTrafficAssigned, MarkIngressReady), - config("release-ready", "foo", WithRunLatestRollout, + config("release-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(2), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("release-ready-00002"), WithLatestReady("release-ready-00002")), @@ -701,6 +713,7 @@ func TestReconcile(t *testing.T) { Percent: nil, }, }), + WithServiceDefaults, ), }}, WantPatches: []clientgotesting.PatchActionImpl{{ @@ -720,17 +733,17 @@ func TestReconcile(t *testing.T) { Name: "release - create route and service and percentage", Objects: []runtime.Object{ Service("release-with-percent", "foo", WithReleaseRolloutAndPercentage(10, /*candidate traffic percentage*/ - "release-with-percent-00001", "release-with-percent-00002")), + "release-with-percent-00001", "release-with-percent-00002"), WithServiceDefaults), }, Key: "foo/release-with-percent", WantCreates: []runtime.Object{ - config("release-with-percent", "foo", WithReleaseRolloutAndPercentage(10, "release-with-percent-00001", "release-with-percent-00002")), - route("release-with-percent", "foo", WithReleaseRolloutAndPercentage(10, "release-with-percent-00001", "release-with-percent-00002")), + config("release-with-percent", "foo", []ServiceOption{WithReleaseRolloutAndPercentage(10, "release-with-percent-00001", "release-with-percent-00002"), WithServiceDefaults}), + route("release-with-percent", "foo", []ServiceOption{WithReleaseRolloutAndPercentage(10, "release-with-percent-00001", "release-with-percent-00002"), WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("release-with-percent", "foo", WithReleaseRolloutAndPercentage(10, "release-with-percent-00001", "release-with-percent-00002"), // The first reconciliation will initialize the status conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -747,9 +760,9 @@ func TestReconcile(t *testing.T) { }, { Name: "runLatest - no updates", Objects: []runtime.Object{ - Service("no-updates", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("no-updates", "foo", WithRunLatestRollout), - config("no-updates", "foo", WithRunLatestRollout), + Service("no-updates", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("no-updates", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + config("no-updates", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -766,19 +779,20 @@ func TestReconcile(t *testing.T) { func(s *v1alpha1.Service) { s.Annotations = presources.UnionMaps(s.Annotations, map[string]string{"new-key": "new-value"}) - }), - config("update-annos", "foo", WithRunLatestRollout), - route("update-annos", "foo", WithRunLatestRollout), + }, + WithServiceDefaults), + config("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, Key: "foo/update-annos", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-annos", "foo", WithRunLatestRollout, + Object: config("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(s *v1alpha1.Configuration) { s.Annotations = presources.UnionMaps(s.Annotations, map[string]string{"new-key": "new-value"}) }), }, { - Object: route("update-annos", "foo", WithRunLatestRollout, + Object: route("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(s *v1alpha1.Route) { s.Annotations = presources.UnionMaps(s.Annotations, map[string]string{"new-key": "new-value"}) @@ -794,13 +808,13 @@ func TestReconcile(t *testing.T) { }, { Name: "runLatest - delete annotations", Objects: []runtime.Object{ - Service("update-annos", "foo", WithRunLatestRollout, WithInitSvcConditions), - config("update-annos", "foo", WithRunLatestRollout, + Service("update-annos", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + config("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(s *v1alpha1.Configuration) { s.Annotations = presources.UnionMaps(s.Annotations, map[string]string{"new-key": "new-value"}) }), - route("update-annos", "foo", WithRunLatestRollout, + route("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(s *v1alpha1.Route) { s.Annotations = presources.UnionMaps(s.Annotations, map[string]string{"new-key": "new-value"}) @@ -808,9 +822,9 @@ func TestReconcile(t *testing.T) { }, Key: "foo/update-annos", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-annos", "foo", WithRunLatestRollout), + Object: config("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, { - Object: route("update-annos", "foo", WithRunLatestRollout), + Object: route("update-annos", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -822,18 +836,18 @@ func TestReconcile(t *testing.T) { }, { Name: "runLatest - update route and service", Objects: []runtime.Object{ - Service("update-route-and-config", "foo", WithRunLatestRollout, WithInitSvcConditions), + Service("update-route-and-config", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), // Mutate the Config/Route to have a different body than we want. - config("update-route-and-config", "foo", WithRunLatestRollout, + config("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, // This is just an unexpected mutation of the config spec vs. the service spec. WithConfigContainerConcurrency(5)), - route("update-route-and-config", "foo", WithRunLatestRollout, MutateRoute), + route("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, MutateRoute), }, Key: "foo/update-route-and-config", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-route-and-config", "foo", WithRunLatestRollout), + Object: config("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, { - Object: route("update-route-and-config", "foo", WithRunLatestRollout), + Object: route("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -847,12 +861,12 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("update-route-and-config", "foo", WithRunLatestRollout, func(svc *v1alpha1.Service) { svc.Spec.DeprecatedRunLatest.Configuration.GetTemplate().Name = "update-route-and-config-blah" - }, WithInitSvcConditions), + }, WithInitSvcConditions, WithServiceDefaults), // Mutate the Config/Route to have a different body than we want. - config("update-route-and-config", "foo", WithRunLatestRollout, + config("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, // Change the concurrency to ensure it is corrected. WithConfigContainerConcurrency(5)), - route("update-route-and-config", "foo", WithRunLatestRollout, MutateRoute), + route("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, MutateRoute), &v1alpha1.Revision{ ObjectMeta: metav1.ObjectMeta{ Name: "update-route-and-config-blah", @@ -863,7 +877,7 @@ func TestReconcile(t *testing.T) { }, Key: "foo/update-route-and-config", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-route-and-config", "foo", WithRunLatestRollout, + Object: config("update-route-and-config", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(cfg *v1alpha1.Configuration) { cfg.Spec.GetTemplate().Name = "update-route-and-config-blah" }), @@ -873,7 +887,7 @@ func TestReconcile(t *testing.T) { svc.Spec.DeprecatedRunLatest.Configuration.GetTemplate().Name = "update-route-and-config-blah" }, WithInitSvcConditions, func(svc *v1alpha1.Service) { svc.Status.MarkRevisionNameTaken("update-route-and-config-blah") - }), + }, WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -889,15 +903,15 @@ func TestReconcile(t *testing.T) { Name: "runLatest - update route and config labels", Objects: []runtime.Object{ // Mutate the Service to add some more labels - Service("update-route-and-config-labels", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceLabel("new-label", "new-value")), - config("update-route-and-config-labels", "foo", WithRunLatestRollout), - route("update-route-and-config-labels", "foo", WithRunLatestRollout), + Service("update-route-and-config-labels", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceLabel("new-label", "new-value"), WithServiceDefaults), + config("update-route-and-config-labels", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("update-route-and-config-labels", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, Key: "foo/update-route-and-config-labels", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-route-and-config-labels", "foo", WithRunLatestRollout, WithConfigLabel("new-label", "new-value")), + Object: config("update-route-and-config-labels", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithConfigLabel("new-label", "new-value")), }, { - Object: route("update-route-and-config-labels", "foo", WithRunLatestRollout, WithRouteLabel(map[string]string{"new-label": "new-value", + Object: route("update-route-and-config-labels", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithRouteLabel(map[string]string{"new-label": "new-value", "serving.knative.dev/service": "update-route-and-config-labels"})), }}, WantPatches: []clientgotesting.PatchActionImpl{{ @@ -912,17 +926,17 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ // Mutate the Service to add some more labels Service("update-child-labels-ignore-route-label", "foo", - WithRunLatestRollout, WithInitSvcConditions, WithServiceLabel("new-label", "new-value")), + WithRunLatestRollout, WithInitSvcConditions, WithServiceLabel("new-label", "new-value"), WithServiceDefaults), config("update-child-labels-ignore-route-label", "foo", - WithRunLatestRollout, WithConfigLabel("serving.knative.dev/route", "update-child-labels-ignore-route-label")), - route("update-child-labels-ignore-route-label", "foo", WithRunLatestRollout), + []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithConfigLabel("serving.knative.dev/route", "update-child-labels-ignore-route-label")), + route("update-child-labels-ignore-route-label", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, Key: "foo/update-child-labels-ignore-route-label", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-child-labels-ignore-route-label", "foo", WithRunLatestRollout, WithConfigLabel("new-label", "new-value"), + Object: config("update-child-labels-ignore-route-label", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithConfigLabel("new-label", "new-value"), WithConfigLabel("serving.knative.dev/route", "update-child-labels-ignore-route-label")), }, { - Object: route("update-child-labels-ignore-route-label", "foo", WithRunLatestRollout, WithRouteLabel(map[string]string{"new-label": "new-value", + Object: route("update-child-labels-ignore-route-label", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithRouteLabel(map[string]string{"new-label": "new-value", "serving.knative.dev/service": "update-child-labels-ignore-route-label"})), }}, WantPatches: []clientgotesting.PatchActionImpl{{ @@ -940,14 +954,14 @@ func TestReconcile(t *testing.T) { Service("bad-config-update", "foo", WithInitSvcConditions, WithRunLatestRollout, func(svc *v1alpha1.Service) { svc.Spec.DeprecatedRunLatest.Configuration.GetTemplate().Spec.GetContainer().Image = "#" - }), - config("bad-config-update", "foo", WithRunLatestRollout), - route("bad-config-update", "foo", WithRunLatestRollout), + }, WithServiceDefaults), + config("bad-config-update", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("bad-config-update", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, Key: "foo/bad-config-update", WantErr: true, WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("bad-config-update", "foo", WithRunLatestRollout, + Object: config("bad-config-update", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, func(cfg *v1alpha1.Configuration) { cfg.Spec.GetTemplate().Spec.GetContainer().Image = "#" }), @@ -964,17 +978,17 @@ func TestReconcile(t *testing.T) { InduceFailure("create", "routes"), }, Objects: []runtime.Object{ - Service("create-route-failure", "foo", WithRunLatestRollout), + Service("create-route-failure", "foo", WithRunLatestRollout, WithServiceDefaults), }, Key: "foo/create-route-failure", WantCreates: []runtime.Object{ - config("create-route-failure", "foo", WithRunLatestRollout), - route("create-route-failure", "foo", WithRunLatestRollout), + config("create-route-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("create-route-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("create-route-failure", "foo", WithRunLatestRollout, // First reconcile initializes conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Created", "Created Configuration %q", "create-route-failure"), @@ -990,17 +1004,17 @@ func TestReconcile(t *testing.T) { InduceFailure("create", "configurations"), }, Objects: []runtime.Object{ - Service("create-config-failure", "foo", WithRunLatestRollout), + Service("create-config-failure", "foo", WithRunLatestRollout, WithServiceDefaults), }, Key: "foo/create-config-failure", WantCreates: []runtime.Object{ - config("create-config-failure", "foo", WithRunLatestRollout), + config("create-config-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), // We don't get to creating the Route. }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("create-config-failure", "foo", WithRunLatestRollout, // First reconcile initializes conditions. - WithInitSvcConditions), + WithInitSvcConditions, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "CreationFailed", "Failed to create Configuration %q: %v", @@ -1015,14 +1029,14 @@ func TestReconcile(t *testing.T) { InduceFailure("update", "routes"), }, Objects: []runtime.Object{ - Service("update-route-failure", "foo", WithRunLatestRollout, WithInitSvcConditions), + Service("update-route-failure", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), // Mutate the Route to have an unexpected body to trigger an update. - route("update-route-failure", "foo", WithRunLatestRollout, MutateRoute), - config("update-route-failure", "foo", WithRunLatestRollout), + route("update-route-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, MutateRoute), + config("update-route-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, Key: "foo/update-route-failure", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: route("update-route-failure", "foo", WithRunLatestRollout), + Object: route("update-route-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile Route: inducing failure for update routes"), @@ -1035,16 +1049,16 @@ func TestReconcile(t *testing.T) { InduceFailure("update", "configurations"), }, Objects: []runtime.Object{ - Service("update-config-failure", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("update-config-failure", "foo", WithRunLatestRollout), + Service("update-config-failure", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("update-config-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), // Mutate the Config to have an unexpected body to trigger an update. - config("update-config-failure", "foo", WithRunLatestRollout, + config("update-config-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, // This is just an unexpected mutation of the config spec vs. the service spec. WithConfigContainerConcurrency(5)), }, Key: "foo/update-config-failure", WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: config("update-config-failure", "foo", WithRunLatestRollout), + Object: config("update-config-failure", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile Configuration: inducing failure for update configurations"), @@ -1057,18 +1071,19 @@ func TestReconcile(t *testing.T) { InduceFailure("update", "services"), }, Objects: []runtime.Object{ - Service("run-latest", "foo", WithRunLatestRollout), + Service("run-latest", "foo", WithRunLatestRollout, WithServiceDefaults), }, Key: "foo/run-latest", WantCreates: []runtime.Object{ - config("run-latest", "foo", WithRunLatestRollout), - route("run-latest", "foo", WithRunLatestRollout), + config("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("run-latest", "foo", WithRunLatestRollout, // We attempt to update the Service to initialize its // conditions, which is where we induce the failure. - WithInitSvcConditions), + WithInitSvcConditions, + WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Created", "Created Configuration %q", "run-latest"), @@ -1080,8 +1095,8 @@ func TestReconcile(t *testing.T) { Name: "runLatest - route and config ready, propagate ready", // When both route and config are ready, the service should become ready. Objects: []runtime.Object{ - Service("all-ready", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("all-ready", "foo", WithRunLatestRollout, RouteReady, + Service("all-ready", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("all-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -1089,7 +1104,7 @@ func TestReconcile(t *testing.T) { Percent: ptr.Int64(100), }, }), MarkTrafficAssigned, MarkIngressReady), - config("all-ready", "foo", WithRunLatestRollout, + config("all-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(1), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("all-ready-00001"), WithLatestReady("all-ready-00001")), @@ -1105,7 +1120,8 @@ func TestReconcile(t *testing.T) { RevisionName: "all-ready-00001", Percent: ptr.Int64(100), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1125,8 +1141,8 @@ func TestReconcile(t *testing.T) { // When both route and config are ready, the service should become ready. Objects: []runtime.Object{ Service("all-ready", "foo", WithRunLatestRollout, WithInitSvcConditions, - WithReadyConfig("all-ready-00001")), - route("all-ready", "foo", WithRunLatestRollout, RouteReady, + WithReadyConfig("all-ready-00001"), WithServiceDefaults), + route("all-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -1134,7 +1150,7 @@ func TestReconcile(t *testing.T) { Percent: ptr.Int64(100), }, }), MarkTrafficAssigned, MarkIngressReady), - config("all-ready", "foo", WithRunLatestRollout, + config("all-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(1), WithObservedGen, WithGeneration(2), // These turn a Configuration to Ready=true WithLatestCreated("all-ready-00001"), WithLatestReady("all-ready-00001")), @@ -1151,7 +1167,8 @@ func TestReconcile(t *testing.T) { RevisionName: "all-ready-00001", Percent: ptr.Int64(100), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1168,8 +1185,8 @@ func TestReconcile(t *testing.T) { // When both route and config are ready, but the route points to the previous revision // the service should not be ready. Objects: []runtime.Object{ - Service("config-only-ready", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("config-only-ready", "foo", WithRunLatestRollout, RouteReady, + Service("config-only-ready", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("config-only-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -1177,7 +1194,7 @@ func TestReconcile(t *testing.T) { Percent: ptr.Int64(100), }, }), MarkTrafficAssigned, MarkIngressReady), - config("config-only-ready", "foo", WithRunLatestRollout, + config("config-only-ready", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(2 /*will generate revision -00002*/), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("config-only-ready-00002"), WithLatestReady("config-only-ready-00002")), @@ -1192,7 +1209,8 @@ func TestReconcile(t *testing.T) { RevisionName: "config-only-ready-00001", Percent: ptr.Int64(100), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1210,8 +1228,8 @@ func TestReconcile(t *testing.T) { // Gen 2: config update fails; // => service is still OK serving Gen 1. Objects: []runtime.Object{ - Service("config-fails", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("config-fails", "foo", WithRunLatestRollout, RouteReady, + Service("config-fails", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("config-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -1219,7 +1237,7 @@ func TestReconcile(t *testing.T) { Percent: ptr.Int64(100), }, }), MarkTrafficAssigned, MarkIngressReady), - config("config-fails", "foo", WithRunLatestRollout, WithGeneration(2), + config("config-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(2), WithLatestReady("config-fails-00001"), WithLatestCreated("config-fails-00002"), MarkLatestCreatedFailed("blah"), WithObservedGen), }, @@ -1234,7 +1252,8 @@ func TestReconcile(t *testing.T) { }, }), WithFailedConfig("config-fails-00002", "RevisionFailed", "blah"), - WithServiceLatestReadyRevision("config-fails-00001")), + WithServiceLatestReadyRevision("config-fails-00001"), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1250,16 +1269,16 @@ func TestReconcile(t *testing.T) { Name: "runLatest - config fails, propagate failure", // When config fails, the service should fail. Objects: []runtime.Object{ - Service("config-fails", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("config-fails", "foo", WithRunLatestRollout, RouteReady), - config("config-fails", "foo", WithRunLatestRollout, WithGeneration(1), WithObservedGen, + Service("config-fails", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("config-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady), + config("config-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(1), WithObservedGen, WithLatestCreated("config-fails-00001"), MarkLatestCreatedFailed("blah")), }, Key: "foo/config-fails", WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("config-fails", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceStatusRouteNotReady, WithFailedConfig( - "config-fails-00001", "RevisionFailed", "blah")), + "config-fails-00001", "RevisionFailed", "blah"), WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1275,10 +1294,10 @@ func TestReconcile(t *testing.T) { Name: "runLatest - route fails, propagate failure", // When route fails, the service should fail. Objects: []runtime.Object{ - Service("route-fails", "foo", WithRunLatestRollout, WithInitSvcConditions), - route("route-fails", "foo", WithRunLatestRollout, + Service("route-fails", "foo", WithRunLatestRollout, WithInitSvcConditions, WithServiceDefaults), + route("route-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteFailed("Propagate me, please", "")), - config("route-fails", "foo", WithRunLatestRollout, WithGeneration(1), WithObservedGen, + config("route-fails", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(1), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("route-fails-00001"), WithLatestReady("route-fails-00001")), }, @@ -1288,7 +1307,8 @@ func TestReconcile(t *testing.T) { // When the Configuration is Ready, and the Route has failed, // we expect the following changed to our status conditions. WithReadyConfig("route-fails-00001"), - WithFailedRoute("Propagate me, please", "")), + WithFailedRoute("Propagate me, please", ""), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1304,14 +1324,14 @@ func TestReconcile(t *testing.T) { Name: "runLatest - not owned config exists", WantErr: true, Objects: []runtime.Object{ - Service("run-latest", "foo", WithRunLatestRollout), - config("run-latest", "foo", WithRunLatestRollout, WithConfigOwnersRemoved), + Service("run-latest", "foo", WithRunLatestRollout, WithServiceDefaults), + config("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithConfigOwnersRemoved), }, Key: "foo/run-latest", WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("run-latest", "foo", WithRunLatestRollout, // The first reconciliation will initialize the status conditions. - WithInitSvcConditions, MarkConfigurationNotOwned), + WithInitSvcConditions, MarkConfigurationNotOwned, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "InternalError", `service: "run-latest" does not own configuration: "run-latest"`), @@ -1320,15 +1340,15 @@ func TestReconcile(t *testing.T) { Name: "runLatest - not owned route exists", WantErr: true, Objects: []runtime.Object{ - Service("run-latest", "foo", WithRunLatestRollout), - config("run-latest", "foo", WithRunLatestRollout), - route("run-latest", "foo", WithRunLatestRollout, WithRouteOwnersRemoved), + Service("run-latest", "foo", WithRunLatestRollout, WithServiceDefaults), + config("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}), + route("run-latest", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithRouteOwnersRemoved), }, Key: "foo/run-latest", WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: Service("run-latest", "foo", WithRunLatestRollout, // The first reconciliation will initialize the status conditions. - WithInitSvcConditions, MarkRouteNotOwned), + WithInitSvcConditions, MarkRouteNotOwned, WithServiceDefaults), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "InternalError", `service: "run-latest" does not own route: "run-latest"`), @@ -1340,9 +1360,9 @@ func TestReconcile(t *testing.T) { Objects: []runtime.Object{ Service("new-owner", "foo", WithRunLatestRollout, WithInitSvcConditions, // This service was unhappy with the prior owner situation. - MarkConfigurationNotOwned, MarkRouteNotOwned), + MarkConfigurationNotOwned, MarkRouteNotOwned, WithServiceDefaults), // The service owns these, which should result in a happy result. - route("new-owner", "foo", WithRunLatestRollout, RouteReady, + route("new-owner", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, RouteReady, WithURL, WithAddress, WithInitRouteConditions, WithStatusTraffic(v1alpha1.TrafficTarget{ TrafficTarget: v1.TrafficTarget{ @@ -1350,7 +1370,7 @@ func TestReconcile(t *testing.T) { Percent: ptr.Int64(100), }, }), MarkTrafficAssigned, MarkIngressReady), - config("new-owner", "foo", WithRunLatestRollout, WithGeneration(1), WithObservedGen, + config("new-owner", "foo", []ServiceOption{WithRunLatestRollout, WithServiceDefaults}, WithGeneration(1), WithObservedGen, // These turn a Configuration to Ready=true WithLatestCreated("new-owner-00001"), WithLatestReady("new-owner-00001")), }, @@ -1365,7 +1385,8 @@ func TestReconcile(t *testing.T) { RevisionName: "new-owner-00001", Percent: ptr.Int64(100), }, - })), + }), + WithServiceDefaults), }}, WantPatches: []clientgotesting.PatchActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ @@ -1403,8 +1424,8 @@ func TestNew(t *testing.T) { } } -func config(name, namespace string, so ServiceOption, co ...ConfigOption) *v1alpha1.Configuration { - s := Service(name, namespace, so) +func config(name, namespace string, sos []ServiceOption, co ...ConfigOption) *v1alpha1.Configuration { + s := Service(name, namespace, sos...) s.SetDefaults(v1.WithUpgradeViaDefaulting(context.Background())) cfg, err := resources.MakeConfiguration(s) if err != nil { @@ -1416,8 +1437,8 @@ func config(name, namespace string, so ServiceOption, co ...ConfigOption) *v1alp return cfg } -func route(name, namespace string, so ServiceOption, ro ...RouteOption) *v1alpha1.Route { - s := Service(name, namespace, so) +func route(name, namespace string, sos []ServiceOption, ro ...RouteOption) *v1alpha1.Route { + s := Service(name, namespace, sos...) s.SetDefaults(v1.WithUpgradeViaDefaulting(context.Background())) route, err := resources.MakeRoute(s) if err != nil { diff --git a/pkg/testing/v1/service.go b/pkg/testing/v1/service.go index 634545868595..c30bbc50969c 100644 --- a/pkg/testing/v1/service.go +++ b/pkg/testing/v1/service.go @@ -93,6 +93,11 @@ func WithNumberedPort(number int32) ServiceOption { } } +// WithServiceDefaults will set the default values on the service. +func WithServiceDefaults(svc *v1.Service) ServiceOption { + svc.SetDefaults(context.Background()) +} + // WithResourceRequirements attaches resource requirements to the service func WithResourceRequirements(resourceRequirements corev1.ResourceRequirements) ServiceOption { return func(svc *v1.Service) { diff --git a/pkg/testing/v1alpha1/service.go b/pkg/testing/v1alpha1/service.go index c7306446d527..b2d298f08acd 100644 --- a/pkg/testing/v1alpha1/service.go +++ b/pkg/testing/v1alpha1/service.go @@ -60,13 +60,17 @@ func ServiceWithoutNamespace(name string, so ...ServiceOption) *v1alpha1.Service Name: name, }, } - s.SetDefaults(context.Background()) for _, opt := range so { opt(s) } return s } +// WithServiceDefaults will set the default values on the service. +func WithServiceDefaults(svc *v1alpha1.Service) { + svc.SetDefaults(context.Background()) +} + // WithServiceDeletionTimestamp will set the DeletionTimestamp on the Service. func WithServiceDeletionTimestamp(r *v1alpha1.Service) { t := metav1.NewTime(time.Unix(1e9, 0)) diff --git a/pkg/testing/v1beta1/service.go b/pkg/testing/v1beta1/service.go index d287bec8de54..d023851fb3f7 100644 --- a/pkg/testing/v1beta1/service.go +++ b/pkg/testing/v1beta1/service.go @@ -38,7 +38,6 @@ func Service(name, namespace string, so ...ServiceOption) *v1beta1.Service { Namespace: namespace, }, } - s.SetDefaults(context.Background()) for _, opt := range so { opt(s) } @@ -59,6 +58,11 @@ func ServiceWithoutNamespace(name string, so ...ServiceOption) *v1beta1.Service return s } +// WithServiceDefaults will set the default values on the service. +func WithServiceDefaults(svc *v1beta1.Service) { + svc.SetDefaults(context.Background()) +} + // WithInlineConfigSpec confgures the Service to use the given config spec func WithInlineConfigSpec(config v1.ConfigurationSpec) ServiceOption { return func(svc *v1beta1.Service) {