From 06a10125fca86b4a0cdcaff3f297bf02fce103d7 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Wed, 22 Feb 2023 18:26:17 -0800 Subject: [PATCH] cmd/k8s-operator: set hostinfo.Package This allows identifying the operator. Updates #5055 Signed-off-by: Maisem Ali --- cmd/k8s-operator/operator.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/k8s-operator/operator.go b/cmd/k8s-operator/operator.go index 5d9824de7..5d81d84fb 100644 --- a/cmd/k8s-operator/operator.go +++ b/cmd/k8s-operator/operator.go @@ -39,10 +39,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" "sigs.k8s.io/yaml" "tailscale.com/client/tailscale" + "tailscale.com/hostinfo" "tailscale.com/ipn" "tailscale.com/ipn/store/kubestore" "tailscale.com/tsnet" "tailscale.com/types/logger" + "tailscale.com/types/opt" "tailscale.com/util/dnsname" ) @@ -61,7 +63,7 @@ func main() { clientSecretPath = defaultEnv("CLIENT_SECRET_FILE", "") image = defaultEnv("PROXY_IMAGE", "tailscale/tailscale:latest") tags = defaultEnv("PROXY_TAGS", "tag:k8s") - shouldRunAuthProxy = defaultEnv("AUTH_PROXY", "false") + shouldRunAuthProxy = defaultBool("AUTH_PROXY", false) ) var opts []kzap.Opts @@ -95,6 +97,13 @@ func main() { } tsClient := tailscale.NewClient("-", nil) tsClient.HTTPClient = credentials.Client(context.Background()) + + if shouldRunAuthProxy { + hostinfo.SetPackage("k8s-operator-proxy") + } else { + hostinfo.SetPackage("k8s-operator") + } + s := &tsnet.Server{ Hostname: hostname, Logf: zlog.Named("tailscaled").Debugf, @@ -225,7 +234,7 @@ waitOnline: } startlog.Infof("Startup complete, operator running") - if shouldRunAuthProxy == "true" { + if shouldRunAuthProxy { rc, err := rest.TransportFor(restConfig) if err != nil { startlog.Fatalf("could not get rest transport: %v", err) @@ -696,6 +705,15 @@ func getSingleObject[T any, O ptrObject[T]](ctx context.Context, c client.Client return ret, nil } +func defaultBool(envName string, defVal bool) bool { + vs := os.Getenv(envName) + if vs == "" { + return defVal + } + v, _ := opt.Bool(vs).Get() + return v +} + func defaultEnv(envName, defVal string) string { v := os.Getenv(envName) if v == "" {