@@ -33,12 +33,31 @@ import (
3333// This is to map to the eventual EDS structure.
3434type serviceEDS struct {
3535 ServiceKey string
36- WaypointInstance []* workloadapi. Workload
36+ WaypointInstance []model. WorkloadInfo
3737 UseWaypoint bool
3838}
3939
40- func (w serviceEDS ) ResourceName () string {
41- return w .ServiceKey
40+ func (s serviceEDS ) ResourceName () string {
41+ return s .ServiceKey
42+ }
43+
44+ func (s serviceEDS ) Equals (other serviceEDS ) bool {
45+ if s .ServiceKey != other .ServiceKey {
46+ return false
47+ }
48+ if s .UseWaypoint != other .UseWaypoint {
49+ return false
50+ }
51+ if len (s .WaypointInstance ) != len (other .WaypointInstance ) {
52+ return false
53+ }
54+ // assumes builder sorted the slices
55+ for i := range s .WaypointInstance {
56+ if ! s .WaypointInstance [i ].Equals (other .WaypointInstance [i ]) {
57+ return false
58+ }
59+ }
60+ return true
4261}
4362
4463// RegisterEdsShim handles triggering xDS events when Envoy EDS needs to change.
@@ -93,12 +112,14 @@ func RegisterEdsShim(
93112 waypointServiceKey = waypointSvc .ResourceName ()
94113 }
95114 workloads := krt .Fetch (ctx , Workloads , krt .FilterIndex (WorkloadsByServiceKey , waypointServiceKey ))
115+ // for comparison in Equals
116+ workloads = slices .SortBy (workloads , func (i model.WorkloadInfo ) string {
117+ return i .Workload .Uid
118+ })
96119 return & serviceEDS {
97- ServiceKey : svc .ResourceName (),
98- UseWaypoint : useWaypoint ,
99- WaypointInstance : slices .Map (workloads , func (e model.WorkloadInfo ) * workloadapi.Workload {
100- return e .Workload
101- }),
120+ ServiceKey : svc .ResourceName (),
121+ UseWaypoint : useWaypoint ,
122+ WaypointInstance : workloads ,
102123 }
103124 },
104125 opts .WithName ("ServiceEds" )... )
0 commit comments