From 2b62b61b324ce96f844f657df72f691c69615023 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Thu, 16 Nov 2023 18:55:23 -0500 Subject: [PATCH] Fix invalid ServiceExport Conflict status condition This occurs if there's more than one service exported in a cluster. The conflict checking was processing all local EndpointSlices instead of only those corresponding to the service in question. Signed-off-by: Tom Pantelis --- pkg/agent/controller/clusterip_service_test.go | 13 +++++++++++++ pkg/agent/controller/endpoint_slice.go | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/pkg/agent/controller/clusterip_service_test.go b/pkg/agent/controller/clusterip_service_test.go index 7b75e7a8b..71023c1ac 100644 --- a/pkg/agent/controller/clusterip_service_test.go +++ b/pkg/agent/controller/clusterip_service_test.go @@ -19,13 +19,16 @@ limitations under the License. package controller_test import ( + "context" "fmt" "strconv" . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "github.com/submariner-io/admiral/pkg/resource" "github.com/submariner-io/admiral/pkg/syncer/test" testutil "github.com/submariner-io/admiral/pkg/test" + "github.com/submariner-io/lighthouse/pkg/agent/controller" "github.com/submariner-io/lighthouse/pkg/constants" corev1 "k8s.io/api/core/v1" discovery "k8s.io/api/discovery/v1" @@ -272,6 +275,16 @@ func testClusterIPServiceInOneCluster() { // Ensure the resources for the first Service weren't overwritten t.awaitAggregatedServiceImport(mcsv1a1.ClusterSetIP, t.cluster1.service.Name, t.cluster1.service.Namespace, &t.cluster1) + + t.cluster1.ensureNoServiceExportCondition(mcsv1a1.ServiceExportConflict) + + Eventually(func() interface{} { + obj, err := serviceExportClientFor(t.cluster1.localDynClient, service.Namespace).Get(context.Background(), + serviceExport.Name, metav1.GetOptions{}) + Expect(err).To(Succeed()) + + return controller.FindServiceExportStatusCondition(toServiceExport(obj).Status.Conditions, mcsv1a1.ServiceExportConflict) + }).Should(BeNil(), "Unexpected ServiceExport status condition") }) }) diff --git a/pkg/agent/controller/endpoint_slice.go b/pkg/agent/controller/endpoint_slice.go index 71857c8f5..6cbba171c 100644 --- a/pkg/agent/controller/endpoint_slice.go +++ b/pkg/agent/controller/endpoint_slice.go @@ -247,6 +247,10 @@ func (c *EndpointSliceController) checkForConflicts(_, name, namespace string) ( for _, o := range epsList { eps := o.(*discovery.EndpointSlice) + if eps.Labels[mcsv1a1.LabelServiceName] != name || eps.Labels[constants.LabelSourceNamespace] != namespace { + continue + } + servicePorts := c.serviceExportClient.toServicePorts(eps.Ports) if prevServicePorts == nil { prevServicePorts = servicePorts