Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #1521: Add cluster name to aggregated SI status on local SI creation #1529

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
2 changes: 1 addition & 1 deletion pkg/agent/controller/headless_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("Headless Service export", func() {
Context("and no backend service EndpointSlice initially exists", func() {
It("should eventually export the EndpointSlice", func() {
t.cluster1.createServiceExport()
t.awaitAggregatedServiceImport(mcsv1a1.Headless, t.cluster1.service.Name, t.cluster1.service.Namespace)
t.awaitAggregatedServiceImport(mcsv1a1.Headless, t.cluster1.service.Name, t.cluster1.service.Namespace, &t.cluster1)

t.cluster1.createServiceEndpointSlices()
t.awaitEndpointSlice(&t.cluster1)
Expand Down
21 changes: 19 additions & 2 deletions pkg/agent/controller/service_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ func (c *ServiceImportController) Distribute(ctx context.Context, obj runtime.Ob
Type: localServiceImport.Spec.Type,
Ports: []mcsv1a1.ServicePort{},
},
Status: mcsv1a1.ServiceImportStatus{
Clusters: []mcsv1a1.ClusterStatus{
{
Cluster: c.clusterID,
},
},
},
}

conflict := false
Expand Down Expand Up @@ -327,9 +334,19 @@ func (c *ServiceImportController) Distribute(ctx context.Context, obj runtime.Ob
} else {
c.serviceExportClient.removeStatusCondition(ctx, serviceName, serviceNamespace, mcsv1a1.ServiceExportConflict,
typeConflictReason)

var added bool

existing.Status.Clusters, added = slices.AppendIfNotPresent(existing.Status.Clusters,
mcsv1a1.ClusterStatus{Cluster: c.clusterID}, clusterStatusKey)

if added {
logger.V(log.DEBUG).Infof("Added cluster name %q to aggregated ServiceImport %q. New status: %#v",
c.clusterID, existing.Name, existing.Status.Clusters)
}
}

return obj, nil
return c.converter.toUnstructured(existing), nil
})
if err == nil && !conflict {
err = c.startEndpointsController(localServiceImport)
Expand All @@ -342,7 +359,7 @@ func (c *ServiceImportController) Distribute(ctx context.Context, obj runtime.Ob
}

if result == util.OperationResultCreated {
logger.V(log.DEBUG).Infof("Created aggregated ServiceImport %q", aggregate.Name)
logger.V(log.DEBUG).Infof("Created aggregated ServiceImport %s", resource.ToJSON(aggregate))
}

return err
Expand Down
10 changes: 0 additions & 10 deletions pkg/agent/controller/service_import_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ func newServiceImportAggregator(brokerClient dynamic.Interface, brokerNamespace,

func (a *ServiceImportAggregator) updateOnCreateOrUpdate(ctx context.Context, name, namespace string) error {
return a.update(ctx, name, namespace, func(existing *mcsv1a1.ServiceImport) error {
var added bool

existing.Status.Clusters, added = slices.AppendIfNotPresent(existing.Status.Clusters,
mcsv1a1.ClusterStatus{Cluster: a.clusterID}, clusterStatusKey)

if added {
logger.V(log.DEBUG).Infof("Added cluster name %q to aggregated ServiceImport %q. New status: %#v",
a.clusterID, existing.Name, existing.Status.Clusters)
}

return a.setServicePorts(ctx, existing)
})
}
Expand Down
Loading