[arvados] created: 2.7.0-6567-g38051951da
git repository hosting
git at public.arvados.org
Tue May 14 20:33:02 UTC 2024
at 38051951da96557240fa64ffffe33a992f49d46d (commit)
commit 38051951da96557240fa64ffffe33a992f49d46d
Author: Tom Clegg <tom at curii.com>
Date: Tue May 14 16:29:26 2024 -0400
21773: Use ARVADOS_KEEP_SERVICES env var in server context.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/sdk/go/arvados/client.go b/sdk/go/arvados/client.go
index 09185d1d6b..b6cd98f5e0 100644
--- a/sdk/go/arvados/client.go
+++ b/sdk/go/arvados/client.go
@@ -158,13 +158,14 @@ func NewClientFromConfig(cluster *Cluster) (*Client, error) {
}
}
return &Client{
- Client: hc,
- Scheme: ctrlURL.Scheme,
- APIHost: ctrlURL.Host,
- Insecure: cluster.TLS.Insecure,
- Timeout: 5 * time.Minute,
- DiskCacheSize: cluster.Collections.WebDAVCache.DiskCacheSize,
- requestLimiter: &requestLimiter{maxlimit: int64(cluster.API.MaxConcurrentRequests / 4)},
+ Client: hc,
+ Scheme: ctrlURL.Scheme,
+ APIHost: ctrlURL.Host,
+ Insecure: cluster.TLS.Insecure,
+ KeepServiceURIs: parseKeepServiceURIs(os.Getenv("ARVADOS_KEEP_SERVICES")),
+ Timeout: 5 * time.Minute,
+ DiskCacheSize: cluster.Collections.WebDAVCache.DiskCacheSize,
+ requestLimiter: &requestLimiter{maxlimit: int64(cluster.API.MaxConcurrentRequests / 4)},
}, nil
}
@@ -221,18 +222,6 @@ func NewClientFromEnv() *Client {
vars[kv[0]] = kv[1]
}
}
- var svcs []string
- for _, s := range strings.Split(vars["ARVADOS_KEEP_SERVICES"], " ") {
- if s == "" {
- continue
- } else if u, err := url.Parse(s); err != nil {
- log.Printf("ARVADOS_KEEP_SERVICES: %q: %s", s, err)
- } else if !u.IsAbs() {
- log.Printf("ARVADOS_KEEP_SERVICES: %q: not an absolute URI", s)
- } else {
- svcs = append(svcs, s)
- }
- }
var insecure bool
if s := strings.ToLower(vars["ARVADOS_API_HOST_INSECURE"]); s == "1" || s == "yes" || s == "true" {
insecure = true
@@ -242,12 +231,28 @@ func NewClientFromEnv() *Client {
APIHost: vars["ARVADOS_API_HOST"],
AuthToken: vars["ARVADOS_API_TOKEN"],
Insecure: insecure,
- KeepServiceURIs: svcs,
+ KeepServiceURIs: parseKeepServiceURIs(vars["ARVADOS_KEEP_SERVICES"]),
Timeout: 5 * time.Minute,
loadedFromEnv: true,
}
}
+func parseKeepServiceURIs(svclist string) []string {
+ var svcs []string
+ for _, s := range strings.Split(svclist, " ") {
+ if s == "" {
+ continue
+ } else if u, err := url.Parse(s); err != nil {
+ log.Printf("ARVADOS_KEEP_SERVICES: %q: %s", s, err)
+ } else if !u.IsAbs() {
+ log.Printf("ARVADOS_KEEP_SERVICES: %q: not an absolute URI", s)
+ } else {
+ svcs = append(svcs, s)
+ }
+ }
+ return svcs
+}
+
var reqIDGen = httpserver.IDGenerator{Prefix: "req-"}
var nopCancelFunc context.CancelFunc = func() {}
diff --git a/sdk/go/arvados/client_test.go b/sdk/go/arvados/client_test.go
index 55e2f998c4..1aefb31c04 100644
--- a/sdk/go/arvados/client_test.go
+++ b/sdk/go/arvados/client_test.go
@@ -255,10 +255,29 @@ func (*clientSuite) TestLoadConfig(c *check.C) {
// Environment variables override settings.conf
os.Setenv("ARVADOS_API_HOST", "[::]:3")
os.Setenv("ARVADOS_API_HOST_INSECURE", "0")
+ os.Setenv("ARVADOS_KEEP_SERVICES", "http://[::]:12345")
client = NewClientFromEnv()
c.Check(client.AuthToken, check.Equals, "token_from_settings_file2")
c.Check(client.APIHost, check.Equals, "[::]:3")
c.Check(client.Insecure, check.Equals, false)
+ c.Check(client.KeepServiceURIs, check.DeepEquals, []string{"http://[::]:12345"})
+
+ // ARVADOS_KEEP_SERVICES environment variable overrides
+ // cluster config, but ARVADOS_API_HOST/TOKEN do not.
+ os.Setenv("ARVADOS_KEEP_SERVICES", "http://[::]:12345")
+ os.Setenv("ARVADOS_API_HOST", "wronghost.example")
+ os.Setenv("ARVADOS_API_TOKEN", "wrongtoken")
+ cfg := Cluster{}
+ cfg.Services.Controller.ExternalURL = URL{Scheme: "https", Host: "ctrl.example:55555", Path: "/"}
+ cfg.Services.Keepstore.InternalURLs = map[URL]ServiceInstance{
+ URL{Scheme: "https", Host: "keep0.example:55555", Path: "/"}: ServiceInstance{},
+ }
+ client, err := NewClientFromConfig(&cfg)
+ c.Check(err, check.IsNil)
+ c.Check(client.AuthToken, check.Equals, "")
+ c.Check(client.APIHost, check.Equals, "ctrl.example:55555")
+ c.Check(client.Insecure, check.Equals, false)
+ c.Check(client.KeepServiceURIs, check.DeepEquals, []string{"http://[::]:12345"})
}
var _ = check.Suite(&clientRetrySuite{})
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list