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

linkerd mc link|gateways small improvements #11265

Merged
merged 1 commit into from
Sep 5, 2023
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
23 changes: 16 additions & 7 deletions multicluster/cmd/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"os"
"strings"
"sync/atomic"
"sync"
"time"

"github.com/linkerd/linkerd2/cli/table"
Expand Down Expand Up @@ -198,15 +198,15 @@ func newGatewaysCommand() *cobra.Command {
func getGatewayMetrics(k8sAPI *k8s.KubernetesAPI, pods []corev1.Pod, leaders map[string]struct{}, wait time.Duration) []gatewayMetrics {
var metrics []gatewayMetrics
metricsChan := make(chan gatewayMetrics)
var activeRoutines int32
var wg sync.WaitGroup
for _, pod := range pods {
if _, found := leaders[pod.Name]; !found {
continue
}

atomic.AddInt32(&activeRoutines, 1)
wg.Add(1)
go func(p corev1.Pod) {
defer atomic.AddInt32(&activeRoutines, -1)
defer wg.Done()
name := p.Labels[k8s.RemoteClusterNameLabel]
container, err := getServiceMirrorContainer(p)
if err != nil {
Expand All @@ -224,20 +224,29 @@ func getGatewayMetrics(k8sAPI *k8s.KubernetesAPI, pods []corev1.Pod, leaders map
}
}(pod)
}

go func() {
wg.Wait()
close(metricsChan)
}()

timeout := time.NewTimer(wait)
defer timeout.Stop()

wait:
for {
select {
case metric := <-metricsChan:
if metric.clusterName == "" {
// channel closed
break wait
}
metrics = append(metrics, metric)
case <-timeout.C:
break wait
}
if atomic.LoadInt32(&activeRoutines) == 0 {
break
}
}

return metrics
}

Expand Down
2 changes: 1 addition & 1 deletion multicluster/cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ A full list of configurable values can be found at https://github.com/linkerd/li
cmd.Flags().StringVar(&opts.gatewayAddresses, "gateway-addresses", opts.gatewayAddresses, "If specified, overwrites gateway addresses when gateway service is not type LoadBalancer (comma separated list)")
cmd.Flags().Uint32Var(&opts.gatewayPort, "gateway-port", opts.gatewayPort, "If specified, overwrites gateway port when gateway service is not type LoadBalancer")
cmd.Flags().BoolVar(&opts.ha, "ha", opts.ha, "Enable HA configuration for the service-mirror deployment (default false)")
cmd.Flags().BoolVar(&opts.enableGateway, "gateway", opts.enableGateway, "If false, allows a link to be created against a cluster that does not have a gateway service (default true)")
cmd.Flags().BoolVar(&opts.enableGateway, "gateway", opts.enableGateway, "If false, allows a link to be created against a cluster that does not have a gateway service")

pkgcmd.ConfigureNamespaceFlagCompletion(
cmd, []string{"namespace", "gateway-namespace"},
Expand Down
Loading