Skip to content

Commit c04e6fe

Browse files
committed
Add further support for EndpointSlice in multicluster & healthcheck
While EndpointSlice was used in key locations certain paths do not yet use EndpointSlice as described in #14781 Added support to service-mirror, including new cluster_watcher_headless service in multicluster. Updated healthcheck checkMisconfiguredOpaquePort checks to support EndpointSlice. New test file cluster_watcher_endpointslice_test, and tests added to healthcheck_test. Signed-off-by: Matt Mercer <reg.linkerd2@vurtechs.com> Signed-off-by: matt-mercer <449892+matt-mercer@users.noreply.github.com>
1 parent 3818697 commit c04e6fe

File tree

6 files changed

+1814
-53
lines changed

6 files changed

+1814
-53
lines changed

multicluster/cmd/service-mirror/main.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func Main(args []string) {
5353
repairPeriod := cmd.Duration("endpoint-refresh-period", 1*time.Minute, "frequency to refresh endpoint resolution")
5454
enableHeadlessSvc := cmd.Bool("enable-headless-services", false, "toggle support for headless service mirroring")
5555
enableNamespaceCreation := cmd.Bool("enable-namespace-creation", false, "toggle support for namespace creation")
56+
enableEndpointSlices := cmd.Bool("enable-endpoint-slices", true, "Use EndpointSlice resources instead of Endpoints")
5657
enablePprof := cmd.Bool("enable-pprof", false, "Enable pprof endpoints on the admin server")
5758
localMirror := cmd.Bool("local-mirror", false, "watch the local cluster for federated service members")
5859
federatedServiceSelector := cmd.String("federated-service-selector", k8s.DefaultFederatedServiceSelector, "Selector (label query) for federated service members in the local cluster")
@@ -92,14 +93,23 @@ func Main(args []string) {
9293
// controllerK8sAPI is used by the cluster watcher to manage
9394
// mirror resources such as services, namespaces, and endpoints.
9495

96+
// Build the list of resources to watch based on configuration
97+
localAPIResources := []controllerK8s.APIResource{
98+
controllerK8s.NS,
99+
controllerK8s.Svc,
100+
}
101+
if *enableEndpointSlices {
102+
localAPIResources = append(localAPIResources, controllerK8s.ES)
103+
} else {
104+
localAPIResources = append(localAPIResources, controllerK8s.Endpoint)
105+
}
106+
95107
controllerK8sAPI, err := controllerK8s.InitializeAPI(
96108
rootCtx,
97109
*kubeConfigPath,
98110
false,
99111
"local",
100-
controllerK8s.NS,
101-
controllerK8s.Svc,
102-
controllerK8s.Endpoint,
112+
localAPIResources...,
103113
)
104114
if err != nil {
105115
log.Fatalf("Failed to initialize K8s API: %s", err)
@@ -153,7 +163,7 @@ func Main(args []string) {
153163
ExcludedLabels: excludedLabelList,
154164
},
155165
}
156-
err = startLocalClusterWatcher(ctx, *namespace, controllerK8sAPI, linksAPI, *requeueLimit, *repairPeriod, *enableHeadlessSvc, *enableNamespaceCreation, link)
166+
err = startLocalClusterWatcher(ctx, *namespace, controllerK8sAPI, linksAPI, *requeueLimit, *repairPeriod, *enableHeadlessSvc, *enableNamespaceCreation, *enableEndpointSlices, link)
157167
if err != nil {
158168
log.Fatalf("Failed to start local cluster watcher: %s", err)
159169
}
@@ -200,7 +210,7 @@ func Main(args []string) {
200210
if err != nil {
201211
log.Errorf("Failed to load remote cluster credentials: %s", err)
202212
}
203-
err = restartClusterWatcher(ctx, link, *namespace, *probeSvc, creds, controllerK8sAPI, linksAPI, *requeueLimit, *repairPeriod, metrics, *enableHeadlessSvc, *enableNamespaceCreation)
213+
err = restartClusterWatcher(ctx, link, *namespace, *probeSvc, creds, controllerK8sAPI, linksAPI, *requeueLimit, *repairPeriod, metrics, *enableHeadlessSvc, *enableNamespaceCreation, *enableEndpointSlices)
204214
if err != nil {
205215
// failed to restart cluster watcher; give a bit of slack
206216
// and requeue the link to give it another try
@@ -329,6 +339,7 @@ func restartClusterWatcher(
329339
metrics servicemirror.ProbeMetricVecs,
330340
enableHeadlessSvc bool,
331341
enableNamespaceCreation bool,
342+
enableEndpointSlices bool,
332343
) error {
333344

334345
cleanupWorkers()
@@ -352,7 +363,14 @@ func restartClusterWatcher(
352363
if err != nil {
353364
return fmt.Errorf("unable to parse kube config: %w", err)
354365
}
355-
remoteAPI, err := controllerK8s.InitializeAPIForConfig(ctx, cfg, false, link.Spec.TargetClusterName, controllerK8s.Svc, controllerK8s.Endpoint)
366+
// Build the list of resources to watch based on configuration
367+
remoteAPIResources := []controllerK8s.APIResource{controllerK8s.Svc}
368+
if enableEndpointSlices {
369+
remoteAPIResources = append(remoteAPIResources, controllerK8s.ES)
370+
} else {
371+
remoteAPIResources = append(remoteAPIResources, controllerK8s.Endpoint)
372+
}
373+
remoteAPI, err := controllerK8s.InitializeAPIForConfig(ctx, cfg, false, link.Spec.TargetClusterName, remoteAPIResources...)
356374
if err != nil {
357375
return fmt.Errorf("cannot initialize api for target cluster %s: %w", link.Spec.TargetClusterName, err)
358376
}
@@ -369,6 +387,7 @@ func restartClusterWatcher(
369387
ch,
370388
enableHeadlessSvc,
371389
enableNamespaceCreation,
390+
enableEndpointSlices,
372391
)
373392
if err != nil {
374393
return fmt.Errorf("unable to create cluster watcher: %w", err)
@@ -391,6 +410,7 @@ func startLocalClusterWatcher(
391410
repairPeriod time.Duration,
392411
enableHeadlessSvc bool,
393412
enableNamespaceCreation bool,
413+
enableEndpointSlices bool,
394414
link v1alpha3.Link,
395415
) error {
396416
cw, err := servicemirror.NewRemoteClusterServiceWatcher(
@@ -406,6 +426,7 @@ func startLocalClusterWatcher(
406426
make(chan bool),
407427
enableHeadlessSvc,
408428
enableNamespaceCreation,
429+
enableEndpointSlices,
409430
)
410431
if err != nil {
411432
return fmt.Errorf("unable to create cluster watcher: %w", err)

0 commit comments

Comments
 (0)