diff --git a/cmd/containerboot/kube.go b/cmd/containerboot/kube.go index 921e11fa0..62a043974 100644 --- a/cmd/containerboot/kube.go +++ b/cmd/containerboot/kube.go @@ -138,9 +138,9 @@ func initKubeClient(root string) { if err != nil { log.Fatalf("Error creating kube client: %v", err) } - if root != "/" { - // If we are running in a test, we need to set the URL to the - // httptest server. + if (root != "/") || os.Getenv("TS_KUBERNETES_READ_API_SERVER_ADDRESS_FROM_ENV") == "true" { + // Derive the API server address from the environment variables + // Used to set http server in tests, or optionally enabled by flag kc.SetURL(fmt.Sprintf("https://%s:%s", os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT_HTTPS"))) } } diff --git a/ipn/store/kubestore/store_kube.go b/ipn/store/kubestore/store_kube.go index 2da4d8f3a..a61a13aec 100644 --- a/ipn/store/kubestore/store_kube.go +++ b/ipn/store/kubestore/store_kube.go @@ -9,6 +9,7 @@ "context" "fmt" "net" + "os" "strings" "time" @@ -30,6 +31,10 @@ func New(_ logger.Logf, secretName string) (*Store, error) { if err != nil { return nil, err } + if os.Getenv("TS_KUBERNETES_READ_API_SERVER_ADDRESS_FROM_ENV") == "true" { + // Derive the API server address from the environment variables + c.SetURL(fmt.Sprintf("https://%s:%s", os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT_HTTPS"))) + } canPatch, _, err := c.CheckSecretPermissions(context.Background(), secretName) if err != nil { return nil, err