@@ -48,6 +48,9 @@ func (rm *resourceManager) syncRoutes(
48
48
rlog := ackrtlog .FromContext (ctx )
49
49
exit := rlog .Trace ("rm.syncRoutes" )
50
50
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.
51
54
toAdd := []* svcapitypes.CreateRouteInput {}
52
55
toDelete := []* svcapitypes.CreateRouteInput {}
53
56
@@ -65,18 +68,27 @@ func (rm *resourceManager) syncRoutes(
65
68
}
66
69
67
70
switch {
71
+ // If the route table is created all routes need to be added.
68
72
case delta == nil :
69
73
toAdd = removeLocalRoute (desired .ko .Spec .Routes )
74
+ // If there are changes to the routes in the delta ...
70
75
case delta .DifferentAt ("Spec.Routes" ):
76
+ // ... iterate over all the differences ...
71
77
for _ , diff := range delta .Differences {
78
+ // ... and if the current one is regarding the routes ...
72
79
if diff .Path .Contains ("Spec.Routes" ) {
80
+ // ... take the routes to add from the left side of the diff ...
73
81
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).
74
85
toDelete = diff .B .([]* svcapitypes.CreateRouteInput )
75
86
}
76
87
}
77
88
default : // nothing to do
78
89
}
79
90
91
+ // Finally delete and add the routes that were collected.
80
92
for _ , route := range toDelete {
81
93
rlog .Debug ("deleting route from route table" )
82
94
if err = rm .deleteRoute (ctx , latest , * route ); err != nil {
@@ -201,6 +213,8 @@ var computeTagsDelta = tags.ComputeTagsDelta
201
213
202
214
// customPreCompare ensures that default values of types are initialised and
203
215
// 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.
204
218
func customPreCompare (
205
219
delta * ackcompare.Delta ,
206
220
a * resource ,
0 commit comments