mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
The metrics Service and ServiceMonitor handling lived in cmd/k8s-operator, and the ProxyClass reconciler kept its own copy of the ServiceMonitor CRD check, so reconcilers in k8s-operator/reconciler could not share it. This moves it into the tailscaled package as EnsureMetricsResources and EnsureMetricsResourcesDeleted, which take the proxy type and parent, and switches cmd/k8s-operator and the ProxyClass reconciler over to it. No behaviour change. Updates #22034 Signed-off-by: chaosinthecrd <[email protected]>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
|
"tailscale.com/k8s-operator/reconciler/tailscaled"
|
|
)
|
|
|
|
func reconcileMetricsResources(ctx context.Context, logger *zap.SugaredLogger, opts *metricsOpts, pc *tsapi.ProxyClass, cl client.Client) error {
|
|
if opts.proxyType == proxyTypeEgress {
|
|
// Metrics are currently not being enabled for standalone egress proxies.
|
|
return nil
|
|
}
|
|
return tailscaled.EnsureMetricsResources(ctx, cl, logger, opts.metricsOptions(), pc)
|
|
}
|
|
|
|
// maybeCleanupMetricsResources ensures that any metrics resources created for a proxy are deleted.
|
|
func maybeCleanupMetricsResources(ctx context.Context, opts *metricsOpts, cl client.Client) error {
|
|
return tailscaled.EnsureMetricsResourcesDeleted(ctx, cl, opts.metricsOptions())
|
|
}
|
|
|
|
type metricsOpts struct {
|
|
proxyStsName string // name of StatefulSet for proxy
|
|
tsNamespace string // namespace in which Tailscale is installed
|
|
proxyLabels map[string]string // labels of the proxy StatefulSet
|
|
proxyType string
|
|
}
|
|
|
|
// metricsOptions converts opts for the tailscaled metrics helpers.
|
|
func (opts *metricsOpts) metricsOptions() tailscaled.MetricsOptions {
|
|
mo := tailscaled.MetricsOptions{
|
|
StatefulSetName: opts.proxyStsName,
|
|
Namespace: opts.tsNamespace,
|
|
PodLabels: opts.proxyLabels,
|
|
ProxyType: opts.proxyType,
|
|
ParentName: opts.proxyLabels[LabelParentName],
|
|
}
|
|
if isNamespacedProxyType(opts.proxyType) {
|
|
mo.ParentNamespace = opts.proxyLabels[LabelParentNamespace]
|
|
}
|
|
return mo
|
|
}
|
|
|
|
func isNamespacedProxyType(typ string) bool {
|
|
return typ == proxyTypeIngressResource || typ == proxyTypeIngressService
|
|
}
|