Skip to content

Commit b6d7ee4

Browse files
committed
Add setting to not track conditions of VirtualService when reconciling (#941)
* Default to not track conditions of VirtualService when reconciling Routes. Status change is causing too much updates to VirtualService. * Fix tests * trackRouteStatus default to true. Add tests * RouteTrackVirtualService default to false * Revert dates and url for license
1 parent 9fff0e7 commit b6d7ee4

File tree

12 files changed

+521
-8
lines changed

12 files changed

+521
-8
lines changed

config/config-defaults.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ data:
163163
# The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and
164164
# the time when the processes are forcibly halted with a kill signal.
165165
terminationGracePeriodSeconds: 120
166+
# When set to true, Route status will be updated with VirtualService conditions.
167+
routeTrackVirtualService: "false"
166168
167169
# The following images are used to execute builds. They SHOULD NOT be
168170
# modified except in rare circumstances.
@@ -233,4 +235,5 @@ data:
233235
appCPUMin: "100m"
234236
progressDeadlineSeconds: "600"
235237
terminationGracePeriodSeconds: "30"
238+
routeTrackVirtualService: "false"
236239

operator/pkg/apis/kfsystem/kf/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
appCPUMinKey = "appCPUMin"
4444
progressDeadlineSecondsKey = "progressDeadlineSeconds"
4545
terminationGracePeriodSecondsKey = "terminationGracePeriodSeconds"
46+
routeTrackVirtualServiceKey = "routeTrackVirtualService"
4647

4748
// Images used for build purposes
4849

@@ -140,6 +141,9 @@ type DefaultsConfig struct {
140141
// The grace period is the duration in seconds after the processes running in the pod are sent
141142
// a termination signal and the time when the processes are forcibly halted with a kill signal.
142143
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
144+
145+
// RouteTrackVirtualService when set to true, will update Route status with VirtualService conditions.
146+
RouteTrackVirtualService bool `json:"routeTrackVirtualService,omitempty"`
143147
}
144148

145149
// BuiltinDefaultsConfig creates a defaults configuration with default values.
@@ -247,6 +251,7 @@ func (defaultsConfig *DefaultsConfig) getInterfaceValues(leaveEmpty bool) map[st
247251
appCPUMinKey: &defaultsConfig.AppCPUMin,
248252
progressDeadlineSecondsKey: &defaultsConfig.ProgressDeadlineSeconds,
249253
terminationGracePeriodSecondsKey: &defaultsConfig.TerminationGracePeriodSeconds,
254+
routeTrackVirtualServiceKey: &defaultsConfig.RouteTrackVirtualService,
250255
}
251256

252257
if !leaveEmpty {

pkg/apis/kf/config/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
appCPUMinKey = "appCPUMin"
4444
progressDeadlineSecondsKey = "progressDeadlineSeconds"
4545
terminationGracePeriodSecondsKey = "terminationGracePeriodSeconds"
46+
routeTrackVirtualServiceKey = "routeTrackVirtualService"
4647

4748
// Images used for build purposes
4849

@@ -140,6 +141,9 @@ type DefaultsConfig struct {
140141
// The grace period is the duration in seconds after the processes running in the pod are sent
141142
// a termination signal and the time when the processes are forcibly halted with a kill signal.
142143
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
144+
145+
// RouteTrackVirtualService when set to true, will update Route status with VirtualService conditions.
146+
RouteTrackVirtualService bool `json:"routeTrackVirtualService,omitempty"`
143147
}
144148

145149
// BuiltinDefaultsConfig creates a defaults configuration with default values.
@@ -247,6 +251,7 @@ func (defaultsConfig *DefaultsConfig) getInterfaceValues(leaveEmpty bool) map[st
247251
appCPUMinKey: &defaultsConfig.AppCPUMin,
248252
progressDeadlineSecondsKey: &defaultsConfig.ProgressDeadlineSeconds,
249253
terminationGracePeriodSecondsKey: &defaultsConfig.TerminationGracePeriodSeconds,
254+
routeTrackVirtualServiceKey: &defaultsConfig.RouteTrackVirtualService,
250255
}
251256

252257
if !leaveEmpty {

pkg/apis/kf/config/defaults_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestPatchConfigMap(t *testing.T) {
5050
appCPUPerGBOfRAMKey,
5151
progressDeadlineSecondsKey,
5252
terminationGracePeriodSecondsKey,
53+
routeTrackVirtualServiceKey,
5354
}
5455
_, configMap := cmtesting.ConfigMapsFromTestFile(t, DefaultsConfigTestName, allowedPredefinedKey...)
5556
// sanity check the configmap, add more assertions below when new fields

pkg/apis/kf/config/store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestStoreLoadWithContext(t *testing.T) {
5656
appCPUPerGBOfRAMKey,
5757
progressDeadlineSecondsKey,
5858
terminationGracePeriodSecondsKey,
59+
routeTrackVirtualServiceKey,
5960
}
6061
_, configMap := cmtesting.ConfigMapsFromTestFile(t, DefaultsConfigName, allowedPredefinedKey...)
6162
// sanity check the configmap, add more assertions below when new fields

pkg/apis/kf/v1alpha1/app_lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func TestAppStatus_PropagateRouteStatus(t *testing.T) {
669669
route.Status.PropagateRouteSpecFields(qrb.Source)
670670
route.Status.PropagateVirtualService(&networking.VirtualService{
671671
ObjectMeta: metav1.ObjectMeta{Name: "some-vs"},
672-
}, nil)
672+
}, nil, true)
673673
route.Status.PropagateBindings([]RouteDestination{qrb.Destination})
674674
route.Status.PropagateSpaceDomain(&SpaceDomain{
675675
Domain: qrb.Source.Domain,

pkg/apis/kf/v1alpha1/route_lifecycle.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ var _ kmeta.OwnerRefable = (*Route)(nil)
3535
// PropagateVirtualService stores the VirtualService in the RouteStatus.
3636
// If vsErr is set, a reconciliation error is triggered and the name will be
3737
// empty. The state is unknown if both VirtualService and error are nil.
38-
func (status *RouteStatus) PropagateVirtualService(vs *networking.VirtualService, vsErr error) {
38+
// If shouldTrack is false, directly setting the condition to True.
39+
func (status *RouteStatus) PropagateVirtualService(vs *networking.VirtualService, vsErr error, shouldTrack bool) {
3940
cond := status.VirtualServiceCondition()
4041

4142
switch {
43+
case !shouldTrack:
44+
cond.MarkSuccess()
45+
// Update VirtualService when it's not nil. Do not overwrite it back to empty otherwise.
46+
if vs != nil {
47+
status.VirtualService = corev1.LocalObjectReference{Name: vs.Name}
48+
}
4249
case vsErr != nil:
4350
cond.MarkReconciliationError("reconciling", vsErr)
4451
status.VirtualService = corev1.LocalObjectReference{}
45-
4652
case vs == nil:
4753
cond.MarkReconciliationPending()
4854
status.VirtualService = corev1.LocalObjectReference{}

pkg/apis/kf/v1alpha1/route_lifecycle_test.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ func TestRouteStatus_VirtualServiceError(t *testing.T) {
5656
t.Parallel()
5757

5858
status := RouteStatus{}
59-
status.PropagateVirtualService(nil, errors.New("some-reason: some-message"))
59+
status.PropagateVirtualService(nil, errors.New("some-reason: some-message"), true)
6060
apitesting.CheckConditionFailed(status.duck(), RouteConditionVirtualServiceReady, t)
6161
}
6262

6363
func TestRouteStatus_VirtualServiceNil(t *testing.T) {
6464
t.Parallel()
6565

6666
status := RouteStatus{}
67-
status.PropagateVirtualService(nil, nil)
67+
status.PropagateVirtualService(nil, nil, true)
6868
testutil.AssertEqual(t, "VirtualService", "", status.VirtualService.Name)
6969
}
7070

@@ -74,7 +74,36 @@ func TestRouteStatus_VirtualService(t *testing.T) {
7474
status := RouteStatus{}
7575
status.PropagateVirtualService(&networking.VirtualService{
7676
ObjectMeta: metav1.ObjectMeta{Name: "some-name"},
77-
}, nil)
77+
}, nil, true)
78+
testutil.AssertEqual(t, "VirtualService", "some-name", status.VirtualService.Name)
79+
}
80+
81+
func TestRouteStatus_VirtualServiceErrorNotTracking(t *testing.T) {
82+
t.Parallel()
83+
84+
status := RouteStatus{}
85+
status.PropagateVirtualService(nil, errors.New("some-reason: some-message"), false)
86+
apitesting.CheckConditionSucceeded(status.duck(), RouteConditionVirtualServiceReady, t)
87+
}
88+
89+
func TestRouteStatus_VirtualServiceErrorNotTrackingVSNamePopulated(t *testing.T) {
90+
t.Parallel()
91+
status := RouteStatus{}
92+
status.PropagateVirtualService(
93+
&networking.VirtualService{
94+
ObjectMeta: metav1.ObjectMeta{Name: "some-name"},
95+
},
96+
errors.New("some-reason: some-message"),
97+
false)
98+
apitesting.CheckConditionSucceeded(status.duck(), RouteConditionVirtualServiceReady, t)
99+
testutil.AssertEqual(t, "VirtualService", "some-name", status.VirtualService.Name)
100+
101+
status.PropagateVirtualService(
102+
nil,
103+
errors.New("some-reason: some-message"),
104+
false)
105+
apitesting.CheckConditionSucceeded(status.duck(), RouteConditionVirtualServiceReady, t)
106+
// Asserting VirtualService Name didn't change.
78107
testutil.AssertEqual(t, "VirtualService", "some-name", status.VirtualService.Name)
79108
}
80109

pkg/reconciler/route/controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020

21+
config "github.com/google/kf/v2/pkg/apis/kf/config"
2122
v1alpha1 "github.com/google/kf/v2/pkg/apis/kf/v1alpha1"
2223
networking "github.com/google/kf/v2/pkg/apis/networking/v1alpha3"
2324
appinformer "github.com/google/kf/v2/pkg/client/kf/injection/informers/kf/v1alpha1/app"
@@ -46,6 +47,10 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
4647
spaceInformer := spaceinformer.Get(ctx)
4748
serviceInstanceBindingInformer := serviceinstancebindinginformer.Get(ctx)
4849

50+
// Setting up ConfigMap receivers
51+
kfConfigStore := config.NewStore(logger.Named("kf-config-store"))
52+
kfConfigStore.WatchConfigs(cmw)
53+
4954
// Create reconciler
5055
c := &Reconciler{
5156
Base: reconciler.NewBase(ctx, cmw),
@@ -55,6 +60,7 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
5560
virtualServiceLister: vsInformer.Lister(),
5661
networkingClientSet: networkingclient.Get(ctx),
5762
serviceInstanceBindingLister: serviceInstanceBindingInformer.Lister(),
63+
kfConfigStore: kfConfigStore,
5864
}
5965

6066
impl := controller.NewContext(ctx, c, controller.ControllerOptions{WorkQueueName: "Routes", Logger: logger})

pkg/reconciler/route/reconciler.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"sort"
2121

22+
"github.com/google/kf/v2/pkg/apis/kf/config"
2223
"github.com/google/kf/v2/pkg/apis/kf/v1alpha1"
2324
networking "github.com/google/kf/v2/pkg/apis/networking/v1alpha3"
2425
kflisters "github.com/google/kf/v2/pkg/client/kf/listers/kf/v1alpha1"
@@ -34,6 +35,7 @@ import (
3435
"k8s.io/client-go/tools/cache"
3536
"knative.dev/pkg/controller"
3637
"knative.dev/pkg/logging"
38+
pkgreconciler "knative.dev/pkg/reconciler"
3739
)
3840

3941
// Reconciler reconciles a Route object with the K8s cluster.
@@ -47,6 +49,8 @@ type Reconciler struct {
4749
appLister kflisters.AppLister
4850
spaceLister kflisters.SpaceLister
4951
serviceInstanceBindingLister kflisters.ServiceInstanceBindingLister
52+
53+
kfConfigStore pkgreconciler.ConfigStore
5054
}
5155

5256
// Check that our Reconciler implements controller.Reconciler
@@ -85,6 +89,7 @@ func (r *Reconciler) ApplyChanges(
8589
domain string,
8690
) error {
8791
logger := logging.FromContext(ctx)
92+
ctx = r.kfConfigStore.ToContext(ctx)
8893

8994
// Check that the domain is valid for the Space
9095
var spaceDomain *v1alpha1.SpaceDomain
@@ -207,7 +212,14 @@ func (r *Reconciler) ApplyChanges(
207212
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/controllers.md
208213
toReconcile.Status.ObservedGeneration = toReconcile.Generation
209214

210-
toReconcile.Status.PropagateVirtualService(actualVS, sErr)
215+
configDefaults, err := config.FromContext(ctx).Defaults()
216+
if err != nil {
217+
return fmt.Errorf("failed to read config-defaults: %v", err)
218+
}
219+
220+
shouldTrackVirtualService := configDefaults.RouteTrackVirtualService
221+
222+
toReconcile.Status.PropagateVirtualService(actualVS, sErr, shouldTrackVirtualService)
211223
toReconcile.Status.PropagateRouteSpecFields(origRoute.Spec.RouteSpecFields)
212224

213225
rsfString := toReconcile.Spec.RouteSpecFields.String()

0 commit comments

Comments
 (0)