Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/controllers/cloudmap_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestCloudMapReconciler_Reconcile(t *testing.T) {
assert.NoError(t, err)
endpointSlice := endpointSliceList.Items[0]
assert.Equal(t, test.SvcName, endpointSlice.Labels["multicluster.kubernetes.io/service-name"], "Endpoint slice is created")
assert.Contains(t, endpointSlice.Labels, LabelEndpointSliceManagedBy, "Managed by label is added")
assert.Equal(t, int32(test.Port1), *endpointSlice.Ports[0].Port)
assert.Equal(t, test.EndptIp1, endpointSlice.Endpoints[0].Addresses[0])
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const (

// LabelServiceImportName indicates the name of the multi-cluster service that an EndpointSlice belongs to.
LabelServiceImportName = "multicluster.kubernetes.io/service-name"

// LabelEndpointSliceManagedBy indicates the name of the entity that manages the EndpointSlice.
LabelEndpointSliceManagedBy = "endpointslice.kubernetes.io/managed-by"

// ValueEndpointSliceManagedBy indicates the name of the entity that manages the EndpointSlice.
ValueEndpointSliceManagedBy = "aws-cloud-map-mcs-controller-for-k8s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to spec any unique string is fine, although searching for examples of other controllers that set this value it seems somewhat conventional to use a uri.

)

// ServicePortToPort converts a k8s service port to internal model port
Expand Down Expand Up @@ -203,8 +209,12 @@ func CreateEndpointSliceStruct(svc *v1.Service, svcImportName string) *discovery
return &discovery.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
discovery.LabelServiceName: svc.Name, // derived Service name
LabelServiceImportName: svcImportName, // original ServiceImport name
// derived Service name
discovery.LabelServiceName: svc.Name,
// original ServiceImport name
LabelServiceImportName: svcImportName,
// 'managed-by' label set to controller
LabelEndpointSliceManagedBy: ValueEndpointSliceManagedBy,
},
GenerateName: svc.Name + "-",
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(svc, schema.GroupVersionKind{
Expand Down