@@ -24,7 +24,12 @@ const (
24
24
// TODO move to configuration
25
25
syncPeriod = 2 * time .Second
26
26
27
+ // DerivedServiceAnnotation annotates a ServiceImport with derived Service name
27
28
DerivedServiceAnnotation = "multicluster.k8s.aws/derived-service"
29
+
30
+ // LabelServiceName is used to indicate the name of multi-cluster service
31
+ // that an EndpointSlice belongs to.
32
+ LabelServiceImportName = "multicluster.kubernetes.io/service-name"
28
33
)
29
34
30
35
// CloudMapReconciler reconciles state of Cloud Map services with local ServiceImport objects
@@ -148,7 +153,7 @@ func (r *CloudMapReconciler) reconcileService(ctx context.Context, svc *model.Se
148
153
return err
149
154
}
150
155
151
- err = r .updateEndpointSlices (ctx , svc , existingService )
156
+ err = r .updateEndpointSlices (ctx , svcImport , svc , existingService )
152
157
if err != nil {
153
158
return err
154
159
}
@@ -203,7 +208,7 @@ func (r *CloudMapReconciler) createDerivedService(ctx context.Context, svc *mode
203
208
return nil
204
209
}
205
210
206
- func (r * CloudMapReconciler ) updateEndpointSlices (ctx context.Context , cloudMapService * model.Service , svc * v1.Service ) error {
211
+ func (r * CloudMapReconciler ) updateEndpointSlices (ctx context.Context , svcImport * v1alpha1. ServiceImport , cloudMapService * model.Service , svc * v1.Service ) error {
207
212
existingSlicesList := v1beta1.EndpointSliceList {}
208
213
var existingSlices []* v1beta1.EndpointSlice
209
214
if err := r .Client .List (ctx , & existingSlicesList ,
@@ -212,7 +217,7 @@ func (r *CloudMapReconciler) updateEndpointSlices(ctx context.Context, cloudMapS
212
217
}
213
218
if len (existingSlicesList .Items ) == 0 {
214
219
// create new endpoint slice
215
- existingSlices = createEndpointSlicesStruct (cloudMapService , svc )
220
+ existingSlices = createEndpointSlicesStruct (svcImport , cloudMapService , svc )
216
221
for _ , slice := range existingSlices {
217
222
if err := r .Client .Create (ctx , slice ); err != nil {
218
223
return err
@@ -252,7 +257,7 @@ func createDerivedServiceStruct(svc *model.Service, svcImport *v1alpha1.ServiceI
252
257
}
253
258
}
254
259
255
- func createEndpointSlicesStruct (cloudMapSvc * model.Service , svc * v1.Service ) []* v1beta1.EndpointSlice {
260
+ func createEndpointSlicesStruct (svcImport * v1alpha1. ServiceImport , cloudMapSvc * model.Service , svc * v1.Service ) []* v1beta1.EndpointSlice {
256
261
slices := make ([]* v1beta1.EndpointSlice , 0 )
257
262
258
263
t := true
@@ -279,7 +284,10 @@ func createEndpointSlicesStruct(cloudMapSvc *model.Service, svc *v1.Service) []*
279
284
280
285
slices = append (slices , & v1beta1.EndpointSlice {
281
286
ObjectMeta : metav1.ObjectMeta {
282
- Labels : map [string ]string {v1beta1 .LabelServiceName : svc .Name },
287
+ Labels : map [string ]string {
288
+ v1beta1 .LabelServiceName : svc .Name , // derived Service name
289
+ LabelServiceImportName : svcImport .Name , // original ServiceImport name
290
+ },
283
291
GenerateName : svc .Name + "-" ,
284
292
OwnerReferences : []metav1.OwnerReference {* metav1 .NewControllerRef (svc , schema.GroupVersionKind {
285
293
Version : svc .TypeMeta .APIVersion ,
0 commit comments