Skip to content

Commit 86e6f18

Browse files
author
Gereon Frey
committed
Rename variables to make intent more obvious
The delta contains the routes that are different between the "desired" and the "latest" state. The identical ones are ignored.
1 parent 5cce445 commit 86e6f18

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

pkg/resource/route_table/hooks.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ var computeTagsDelta = tags.ComputeTagsDelta
213213

214214
// customPreCompare ensures that default values of types are initialised and
215215
// 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.
216+
// The left side (`A`) of any `Spec.Routes` diff contains the routes that are
217+
// desired, but do not exist. Analogously, the right side (`B`) contains the
218+
// routes that exist, but are not desired.
218219
func customPreCompare(
219220
delta *ackcompare.Delta,
220221
a *resource,
@@ -223,8 +224,8 @@ func customPreCompare(
223224
a.ko.Spec.Routes = removeLocalRoute(a.ko.Spec.Routes)
224225
b.ko.Spec.Routes = removeLocalRoute(b.ko.Spec.Routes)
225226

226-
toAdd := []*svcapitypes.CreateRouteInput{}
227-
toDelete := b.ko.Spec.DeepCopy().Routes
227+
desired := []*svcapitypes.CreateRouteInput{}
228+
latest := b.ko.Spec.DeepCopy().Routes
228229

229230
remove := func(s []*svcapitypes.CreateRouteInput, i int) []*svcapitypes.CreateRouteInput {
230231
if i < len(s)-1 { // if not last element just copy the last element to where the removed element was
@@ -233,24 +234,22 @@ func customPreCompare(
233234
return s[:len(s)-1]
234235
}
235236

236-
// Routes that are desired, but not in latest, need to be added.
237-
// Routes that are in latest, but not desired, need to be deleted.
238-
// Everything else, we don't touch.
237+
// Routes that are desired, but already exist in latest, can be ignored.
239238
for _, routeA := range a.ko.Spec.Routes {
240239
found := false
241-
for idx, routeB := range toDelete {
240+
for idx, routeB := range latest {
242241
if found = reflect.DeepEqual(routeA, routeB); found {
243-
toDelete = remove(toDelete, idx)
242+
latest = remove(latest, idx)
244243
break
245244
}
246245
}
247246
if !found {
248-
toAdd = append(toAdd, routeA.DeepCopy())
247+
desired = append(desired, routeA.DeepCopy())
249248
}
250249
}
251250

252-
if len(toAdd) > 0 || len(toDelete) > 0 {
253-
delta.Add("Spec.Routes", toAdd, toDelete)
251+
if len(desired) > 0 || len(latest) > 0 {
252+
delta.Add("Spec.Routes", desired, latest)
254253
}
255254
}
256255

0 commit comments

Comments
 (0)