From 102197e0fa4022feb8bf590b3cf06cac4faf87c7 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Fri, 3 Aug 2018 20:00:58 +0000 Subject: [PATCH 1/2] Add status propagation tests for Service Fixes #1542 This tests: 1. Route + Config Ready -> Service Ready 2. Config Fails + Route Ready -> Service Fails 3. Config Ready + Route Fails -> Service Fails These are similar to the propagation tests in apis/serving/v1alpha1/service_types_test.go but from the reconciler's perspective. --- .../v1alpha1/service/service_test.go | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/pkg/reconciler/v1alpha1/service/service_test.go b/pkg/reconciler/v1alpha1/service/service_test.go index ad178acd5060..80faa9775c03 100644 --- a/pkg/reconciler/v1alpha1/service/service_test.go +++ b/pkg/reconciler/v1alpha1/service/service_test.go @@ -227,6 +227,111 @@ func TestReconcile(t *testing.T) { WantUpdates: []clientgotesting.UpdateActionImpl{{ Object: svcRL("run-latest", "foo", initialConditions...), }}, + }, { + Name: "runLatest - route and config ready, propagate ready", + // When both route and config are ready, the service should become ready. + Objects: []runtime.Object{ + svcRL("all-ready", "foo", initialConditions...), + routeWithStatus(resources.MakeRoute(svcRL("all-ready", "foo", initialConditions...)), + v1alpha1.RouteStatus{ + Conditions: []v1alpha1.RouteCondition{{ + Type: v1alpha1.RouteConditionReady, + Status: corev1.ConditionTrue, + }}, + }), + cfgWithStatus(mustMakeConfig(t, svcRL("all-ready", "foo", initialConditions...)), + v1alpha1.ConfigurationStatus{ + Conditions: []v1alpha1.ConfigurationCondition{{ + Type: v1alpha1.ConfigurationConditionReady, + Status: corev1.ConditionTrue, + }}, + }), + }, + Key: "foo/all-ready", + WantUpdates: []clientgotesting.UpdateActionImpl{{ + Object: svcRL("all-ready", "foo", []v1alpha1.ServiceCondition{{ + Type: v1alpha1.ServiceConditionConfigurationsReady, + Status: corev1.ConditionTrue, + }, { + Type: v1alpha1.ServiceConditionReady, + Status: corev1.ConditionTrue, + }, { + Type: v1alpha1.ServiceConditionRoutesReady, + Status: corev1.ConditionTrue, + }}...), + }}, + }, { + Name: "runLatest - config fails, propagate failure", + // When config fails, the service should fail. + Objects: []runtime.Object{ + svcRL("config-fails", "foo", initialConditions...), + routeWithStatus(resources.MakeRoute(svcRL("config-fails", "foo", initialConditions...)), + v1alpha1.RouteStatus{ + Conditions: []v1alpha1.RouteCondition{{ + Type: v1alpha1.RouteConditionReady, + Status: corev1.ConditionTrue, + }}, + }), + cfgWithStatus(mustMakeConfig(t, svcRL("config-fails", "foo", initialConditions...)), + v1alpha1.ConfigurationStatus{ + Conditions: []v1alpha1.ConfigurationCondition{{ + Type: v1alpha1.ConfigurationConditionReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }}, + }), + }, + Key: "foo/config-fails", + WantUpdates: []clientgotesting.UpdateActionImpl{{ + Object: svcRL("config-fails", "foo", []v1alpha1.ServiceCondition{{ + Type: v1alpha1.ServiceConditionConfigurationsReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }, { + Type: v1alpha1.ServiceConditionReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }, { + Type: v1alpha1.ServiceConditionRoutesReady, + Status: corev1.ConditionTrue, + }}...), + }}, + }, { + Name: "runLatest - route fails, propagate failure", + // When route fails, the service should fail. + Objects: []runtime.Object{ + svcRL("route-fails", "foo", initialConditions...), + routeWithStatus(resources.MakeRoute(svcRL("route-fails", "foo", initialConditions...)), + v1alpha1.RouteStatus{ + Conditions: []v1alpha1.RouteCondition{{ + Type: v1alpha1.RouteConditionReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }}, + }), + cfgWithStatus(mustMakeConfig(t, svcRL("route-fails", "foo", initialConditions...)), + v1alpha1.ConfigurationStatus{ + Conditions: []v1alpha1.ConfigurationCondition{{ + Type: v1alpha1.ConfigurationConditionReady, + Status: corev1.ConditionTrue, + }}, + }), + }, + Key: "foo/route-fails", + WantUpdates: []clientgotesting.UpdateActionImpl{{ + Object: svcRL("route-fails", "foo", []v1alpha1.ServiceCondition{{ + Type: v1alpha1.ServiceConditionConfigurationsReady, + Status: corev1.ConditionTrue, + }, { + Type: v1alpha1.ServiceConditionReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }, { + Type: v1alpha1.ServiceConditionRoutesReady, + Status: corev1.ConditionFalse, + Reason: "Propagate me, please", + }}...), + }}, }} table.Test(t, func(listers *Listers, opt reconciler.Options) controller.Reconciler { @@ -303,3 +408,15 @@ func mutateRoute(rt *v1alpha1.Route) *v1alpha1.Route { rt.Spec = v1alpha1.RouteSpec{} return rt } + +// TODO(1762): Replace with builders. +func cfgWithStatus(cfg *v1alpha1.Configuration, s v1alpha1.ConfigurationStatus) *v1alpha1.Configuration { + cfg.Status = s + return cfg +} + +// TODO(1762): Replace with builders. +func routeWithStatus(rt *v1alpha1.Route, s v1alpha1.RouteStatus) *v1alpha1.Route { + rt.Status = s + return rt +} From 3f14e6d34d52404e89bdf0234e0cc2e43b02d96e Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Tue, 7 Aug 2018 16:18:18 +0000 Subject: [PATCH 2/2] Address nit: Fix TODOs --- pkg/reconciler/v1alpha1/service/service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/reconciler/v1alpha1/service/service_test.go b/pkg/reconciler/v1alpha1/service/service_test.go index 80faa9775c03..7f7fd31779ea 100644 --- a/pkg/reconciler/v1alpha1/service/service_test.go +++ b/pkg/reconciler/v1alpha1/service/service_test.go @@ -409,13 +409,13 @@ func mutateRoute(rt *v1alpha1.Route) *v1alpha1.Route { return rt } -// TODO(1762): Replace with builders. +// TODO(#1762): Replace with builders. func cfgWithStatus(cfg *v1alpha1.Configuration, s v1alpha1.ConfigurationStatus) *v1alpha1.Configuration { cfg.Status = s return cfg } -// TODO(1762): Replace with builders. +// TODO(#1762): Replace with builders. func routeWithStatus(rt *v1alpha1.Route, s v1alpha1.RouteStatus) *v1alpha1.Route { rt.Status = s return rt