From 21a0fe1b9baff12b797bafc3240385c781f847aa Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 17 Apr 2024 09:11:57 -0700 Subject: [PATCH] ipn/store: omit AWS & Kubernetes support on 'small' Linux GOARCHes This removes AWS and Kubernetes support from Linux binaries by default on GOARCH values where people don't typically run on AWS or use Kubernetes, such as 32-bit mips CPUs. It primarily focuses on optimizing for the static binaries we distribute. But for people building it themselves, they can set ts_kube or ts_aws (the opposite of ts_omit_kube or ts_omit_aws) to force it back on. Makes tailscaled binary ~2.3MB (~7%) smaller. Updates #7272, #10627 etc Change-Id: I42a8775119ce006fa321462cb2d28bc985d1c146 Signed-off-by: Brad Fitzpatrick --- build_docker.sh | 1 + ipn/store/store_aws.go | 18 ++++++++++++++++++ ipn/store/{stores_linux.go => store_kube.go} | 8 ++++---- ipn/store/stores.go | 6 +++--- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 ipn/store/store_aws.go rename ipn/store/{stores_linux.go => store_kube.go} (67%) diff --git a/build_docker.sh b/build_docker.sh index 8c134fbc5..16753da77 100755 --- a/build_docker.sh +++ b/build_docker.sh @@ -49,6 +49,7 @@ case "$TARGET" in -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \ --base="${BASE}" \ --tags="${TAGS}" \ + --gotags="ts_kube" \ --repos="${REPOS}" \ --push="${PUSH}" \ --target="${PLATFORM}" \ diff --git a/ipn/store/store_aws.go b/ipn/store/store_aws.go new file mode 100644 index 000000000..e164f9de7 --- /dev/null +++ b/ipn/store/store_aws.go @@ -0,0 +1,18 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +//go:build (ts_aws || (linux && (arm64 || amd64))) && !ts_omit_aws + +package store + +import ( + "tailscale.com/ipn/store/awsstore" +) + +func init() { + registerAvailableExternalStores = append(registerAvailableExternalStores, registerAWSStore) +} + +func registerAWSStore() { + Register("arn:", awsstore.New) +} diff --git a/ipn/store/stores_linux.go b/ipn/store/store_kube.go similarity index 67% rename from ipn/store/stores_linux.go rename to ipn/store/store_kube.go index 2e26de2df..8941620f6 100644 --- a/ipn/store/stores_linux.go +++ b/ipn/store/store_kube.go @@ -1,25 +1,25 @@ // Copyright (c) Tailscale Inc & AUTHORS // SPDX-License-Identifier: BSD-3-Clause +//go:build (ts_kube || (linux && (arm64 || amd64))) && !ts_omit_kube + package store import ( "strings" "tailscale.com/ipn" - "tailscale.com/ipn/store/awsstore" "tailscale.com/ipn/store/kubestore" "tailscale.com/types/logger" ) func init() { - registerAvailableExternalStores = registerExternalStores + registerAvailableExternalStores = append(registerAvailableExternalStores, registerKubeStore) } -func registerExternalStores() { +func registerKubeStore() { Register("kube:", func(logf logger.Logf, path string) (ipn.StateStore, error) { secretName := strings.TrimPrefix(path, "kube:") return kubestore.New(logf, secretName) }) - Register("arn:", awsstore.New) } diff --git a/ipn/store/stores.go b/ipn/store/stores.go index 8bf3a24b0..1a87fc548 100644 --- a/ipn/store/stores.go +++ b/ipn/store/stores.go @@ -28,13 +28,13 @@ var regOnce sync.Once -var registerAvailableExternalStores func() +var registerAvailableExternalStores []func() func registerDefaultStores() { Register("mem:", mem.New) - if registerAvailableExternalStores != nil { - registerAvailableExternalStores() + for _, f := range registerAvailableExternalStores { + f() } }