Skip to content

Commit 341d176

Browse files
author
Gereon Frey
committed
Add comments to syncRoutes function
This should help to make obvious what the different steps are doing. Also added information on the route related diffs in the delta.
1 parent 982441e commit 341d176

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/resource/route_table/hooks.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func (rm *resourceManager) syncRoutes(
4848
rlog := ackrtlog.FromContext(ctx)
4949
exit := rlog.Trace("rm.syncRoutes")
5050
defer func(err error) { exit(err) }(err)
51+
52+
// To determine the required updates to the route table, the routes to be
53+
// added and deleted will be collected first.
5154
toAdd := []*svcapitypes.CreateRouteInput{}
5255
toDelete := []*svcapitypes.CreateRouteInput{}
5356

@@ -65,18 +68,27 @@ func (rm *resourceManager) syncRoutes(
6568
}
6669

6770
switch {
71+
// If the route table is created all routes need to be added.
6872
case delta == nil:
6973
toAdd = removeLocalRoute(desired.ko.Spec.Routes)
74+
// If there are changes to the routes in the delta ...
7075
case delta.DifferentAt("Spec.Routes"):
76+
// ... iterate over all the differences ...
7177
for _, diff := range delta.Differences {
78+
// ... and if the current one is regarding the routes ...
7279
if diff.Path.Contains("Spec.Routes") {
80+
// ... take the routes to add from the left side of the diff ...
7381
toAdd = diff.A.([]*svcapitypes.CreateRouteInput)
82+
// ... and the routes to delete from the right side (see the
83+
// customPreCompare function for information on the diff
84+
// structure).
7485
toDelete = diff.B.([]*svcapitypes.CreateRouteInput)
7586
}
7687
}
7788
default: // nothing to do
7889
}
7990

91+
// Finally delete and add the routes that were collected.
8092
for _, route := range toDelete {
8193
rlog.Debug("deleting route from route table")
8294
if err = rm.deleteRoute(ctx, latest, *route); err != nil {
@@ -201,6 +213,8 @@ var computeTagsDelta = tags.ComputeTagsDelta
201213

202214
// customPreCompare ensures that default values of types are initialised and
203215
// server side defaults are excluded from the delta.
216+
// The left side (`A`) of any `Spec.Routes` diff contains the routes to add, the
217+
// right side (`B`) the routes that must be deleted.
204218
func customPreCompare(
205219
delta *ackcompare.Delta,
206220
a *resource,

0 commit comments

Comments
 (0)