From af49bcaa52dd50b21dbca5f529d5bf011a481683 Mon Sep 17 00:00:00 2001 From: Irbe Krumina Date: Thu, 2 Nov 2023 14:36:20 +0000 Subject: [PATCH] cmd/k8s-operator: set different app type for operator with proxy (#10081) Updates tailscale/tailscale#9222 plain k8s-operator should have hostinfo.App set to 'k8s-operator', operator with proxy should have it set to 'k8s-operator-proxy'. In proxy mode, we were setting the type after it had already been set to 'k8s-operator' Signed-off-by: Irbe Krumina --- cmd/k8s-operator/operator.go | 13 +++++++++++-- cmd/k8s-operator/proxy.go | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/k8s-operator/operator.go b/cmd/k8s-operator/operator.go index a5d6cb07f..79d70778a 100644 --- a/cmd/k8s-operator/operator.go +++ b/cmd/k8s-operator/operator.go @@ -67,10 +67,20 @@ func main() { zlog := kzap.NewRaw(opts...).Sugar() logf.SetLogger(zapr.NewLogger(zlog.Desugar())) + // The operator can run either as a plain operator or it can + // additionally act as api-server proxy + // https://tailscale.com/kb/1236/kubernetes-operator/?q=kubernetes#accessing-the-kubernetes-control-plane-using-an-api-server-proxy. + mode := parseAPIProxyMode() + if mode == apiserverProxyModeDisabled { + hostinfo.SetApp("k8s-operator") + } else { + hostinfo.SetApp("k8s-operator-proxy") + } + s, tsClient := initTSNet(zlog) defer s.Close() restConfig := config.GetConfigOrDie() - maybeLaunchAPIServerProxy(zlog, restConfig, s) + maybeLaunchAPIServerProxy(zlog, restConfig, s, mode) runReconcilers(zlog, s, tsNamespace, restConfig, tsClient, image, priorityClassName, tags, tsFirewallMode) } @@ -78,7 +88,6 @@ func main() { // CLIENT_ID_FILE and CLIENT_SECRET_FILE environment variables to authenticate // with Tailscale. func initTSNet(zlog *zap.SugaredLogger) (*tsnet.Server, *tailscale.Client) { - hostinfo.SetApp("k8s-operator") var ( clientIDPath = defaultEnv("CLIENT_ID_FILE", "") clientSecretPath = defaultEnv("CLIENT_SECRET_FILE", "") diff --git a/cmd/k8s-operator/proxy.go b/cmd/k8s-operator/proxy.go index 74cda258f..da9cf5bfa 100644 --- a/cmd/k8s-operator/proxy.go +++ b/cmd/k8s-operator/proxy.go @@ -21,7 +21,6 @@ import ( "k8s.io/client-go/transport" "tailscale.com/client/tailscale" "tailscale.com/client/tailscale/apitype" - "tailscale.com/hostinfo" "tailscale.com/tailcfg" "tailscale.com/tsnet" "tailscale.com/types/logger" @@ -84,12 +83,10 @@ func parseAPIProxyMode() apiServerProxyMode { // maybeLaunchAPIServerProxy launches the auth proxy, which is a small HTTP server // that authenticates requests using the Tailscale LocalAPI and then proxies // them to the kube-apiserver. -func maybeLaunchAPIServerProxy(zlog *zap.SugaredLogger, restConfig *rest.Config, s *tsnet.Server) { - mode := parseAPIProxyMode() +func maybeLaunchAPIServerProxy(zlog *zap.SugaredLogger, restConfig *rest.Config, s *tsnet.Server, mode apiServerProxyMode) { if mode == apiserverProxyModeDisabled { return } - hostinfo.SetApp("k8s-operator-proxy") startlog := zlog.Named("launchAPIProxy") if mode == apiserverProxyModeNoAuth { restConfig = rest.AnonymousClientConfig(restConfig)