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 #1675: Fix inadvertent deletion of aggregated ServiceImports on #1678

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
13 changes: 8 additions & 5 deletions pkg/agent/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ func newTestDiver() *testDriver {
t.brokerEndpointSliceClient = t.syncerConfig.BrokerClient.Resource(*test.GetGroupVersionResourceFor(t.syncerConfig.RestMapper,
&discovery.EndpointSlice{})).Namespace(test.RemoteNamespace)

t.cluster1.init(t.syncerConfig)
t.cluster2.init(t.syncerConfig)
t.cluster1.init(t.syncerConfig, nil)
t.cluster2.init(t.syncerConfig, nil)

return t
}
Expand All @@ -327,15 +327,18 @@ func (t *testDriver) afterEach() {
close(t.stopCh)
}

func (c *cluster) init(syncerConfig *broker.SyncerConfig) {
func (c *cluster) init(syncerConfig *broker.SyncerConfig, dynClient *dynamicfake.FakeDynamicClient) {
for k, v := range c.service.Labels {
c.serviceEndpointSlices[0].Labels[k] = v
}

c.serviceIP = c.service.Spec.ClusterIP

c.localDynClient = dynamicfake.NewSimpleDynamicClient(syncerConfig.Scheme)
fake.AddBasicReactors(&c.localDynClient.Fake)
c.localDynClient = dynClient
if c.localDynClient == nil {
c.localDynClient = dynamicfake.NewSimpleDynamicClient(syncerConfig.Scheme)
fake.AddBasicReactors(&c.localDynClient.Fake)
}

c.localServiceImportReactor = fake.NewFailingReactorForResource(&c.localDynClient.Fake, "serviceimports")

Expand Down
13 changes: 7 additions & 6 deletions pkg/agent/controller/reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ var _ = Describe("Reconciliation", func() {
t.afterEach()
t = newTestDiver()

brokerDynClient := t.syncerConfig.BrokerClient.(*fake.FakeDynamicClient)

// Use the broker client for cluster1 to simulate the broker being on the same cluster.
t.cluster1.init(t.syncerConfig, brokerDynClient)

test.CreateResource(t.cluster1.localServiceImportClient.Namespace(test.LocalNamespace), localServiceImport)
test.CreateResource(t.cluster1.localEndpointSliceClient, localEndpointSlice)
test.CreateResource(t.cluster1.localServiceExportClient, serviceExport)
Expand All @@ -117,12 +122,6 @@ var _ = Describe("Reconciliation", func() {
t.cluster1.start(t, *t.syncerConfig)
t.cluster2.start(t, *t.syncerConfig)

t.awaitNonHeadlessServiceExported(&t.cluster1)

testutil.EnsureNoActionsForResource(&t.cluster1.localDynClient.Fake, "serviceimports", "delete")
testutil.EnsureNoActionsForResource(&t.cluster1.localDynClient.Fake, "endpointslices", "delete")

brokerDynClient := t.syncerConfig.BrokerClient.(*fake.FakeDynamicClient)
testutil.EnsureNoActionsForResource(&brokerDynClient.Fake, "endpointslices", "delete")

// For migration cleanup, it may attempt to delete a local legacy ServiceImport from the broker so ignore it.
Expand All @@ -137,6 +136,8 @@ var _ = Describe("Reconciliation", func() {

return false
}).Should(BeFalse())

t.awaitNonHeadlessServiceExported(&t.cluster1)
})
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/controller/service_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (c *ServiceImportController) reconcileLocalAggregatedServiceImports() {
for i := range siList.Items {
si := c.converter.toServiceImport(&siList.Items[i])

if serviceImportSourceName(si) != "" {
// This is not an aggregated ServiceImport.
if serviceImportSourceName(si) != "" || si.Annotations[mcsv1a1.LabelServiceName] != "" {
// This is not a local aggregated ServiceImport.
continue
}

Expand Down
Loading