Skip to content

Commit af49bca

Browse files
authored
cmd/k8s-operator: set different app type for operator with proxy (tailscale#10081)
Updates 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 <irbe@tailscale.com>
1 parent 673ff2c commit af49bca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

cmd/k8s-operator/operator.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,27 @@ func main() {
6767
zlog := kzap.NewRaw(opts...).Sugar()
6868
logf.SetLogger(zapr.NewLogger(zlog.Desugar()))
6969

70+
// The operator can run either as a plain operator or it can
71+
// additionally act as api-server proxy
72+
// https://tailscale.com/kb/1236/kubernetes-operator/?q=kubernetes#accessing-the-kubernetes-control-plane-using-an-api-server-proxy.
73+
mode := parseAPIProxyMode()
74+
if mode == apiserverProxyModeDisabled {
75+
hostinfo.SetApp("k8s-operator")
76+
} else {
77+
hostinfo.SetApp("k8s-operator-proxy")
78+
}
79+
7080
s, tsClient := initTSNet(zlog)
7181
defer s.Close()
7282
restConfig := config.GetConfigOrDie()
73-
maybeLaunchAPIServerProxy(zlog, restConfig, s)
83+
maybeLaunchAPIServerProxy(zlog, restConfig, s, mode)
7484
runReconcilers(zlog, s, tsNamespace, restConfig, tsClient, image, priorityClassName, tags, tsFirewallMode)
7585
}
7686

7787
// initTSNet initializes the tsnet.Server and logs in to Tailscale. It uses the
7888
// CLIENT_ID_FILE and CLIENT_SECRET_FILE environment variables to authenticate
7989
// with Tailscale.
8090
func initTSNet(zlog *zap.SugaredLogger) (*tsnet.Server, *tailscale.Client) {
81-
hostinfo.SetApp("k8s-operator")
8291
var (
8392
clientIDPath = defaultEnv("CLIENT_ID_FILE", "")
8493
clientSecretPath = defaultEnv("CLIENT_SECRET_FILE", "")

cmd/k8s-operator/proxy.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"k8s.io/client-go/transport"
2222
"tailscale.com/client/tailscale"
2323
"tailscale.com/client/tailscale/apitype"
24-
"tailscale.com/hostinfo"
2524
"tailscale.com/tailcfg"
2625
"tailscale.com/tsnet"
2726
"tailscale.com/types/logger"
@@ -84,12 +83,10 @@ func parseAPIProxyMode() apiServerProxyMode {
8483
// maybeLaunchAPIServerProxy launches the auth proxy, which is a small HTTP server
8584
// that authenticates requests using the Tailscale LocalAPI and then proxies
8685
// them to the kube-apiserver.
87-
func maybeLaunchAPIServerProxy(zlog *zap.SugaredLogger, restConfig *rest.Config, s *tsnet.Server) {
88-
mode := parseAPIProxyMode()
86+
func maybeLaunchAPIServerProxy(zlog *zap.SugaredLogger, restConfig *rest.Config, s *tsnet.Server, mode apiServerProxyMode) {
8987
if mode == apiserverProxyModeDisabled {
9088
return
9189
}
92-
hostinfo.SetApp("k8s-operator-proxy")
9390
startlog := zlog.Named("launchAPIProxy")
9491
if mode == apiserverProxyModeNoAuth {
9592
restConfig = rest.AnonymousClientConfig(restConfig)

0 commit comments

Comments
 (0)