From 566525978424ad8c1de9b98fde12a02bfc7c8957 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 19 Mar 2025 05:41:04 -0400 Subject: [PATCH] cli, engine, etcd, lib: Move the hostname value to the API Every world implementation needs a unique UUID, might as well move this to the API. --- cli/deploy.go | 5 ++--- engine/world.go | 3 +++ etcd/ssh/ssh.go | 2 -- etcd/world.go | 9 ++++----- lib/main.go | 7 +++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cli/deploy.go b/cli/deploy.go index 5afab0fc..3ceaa79f 100644 --- a/cli/deploy.go +++ b/cli/deploy.go @@ -199,7 +199,6 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error var world engine.World world = &etcd.World{ // XXX: What should some of these fields be? - //Hostname: hostname, Client: etcdClient, //MetadataPrefix: lib.MetadataPrefix, //StoragePrefix: lib.StoragePrefix, @@ -210,7 +209,6 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error if obj.SshUrl != "" { // alternate world implementation over SSH world = &etcdSSH.World{ URL: obj.SshUrl, - //Hostname: hostname, //Client: client, NS: lib.NS, //MetadataPrefix: lib.MetadataPrefix, @@ -224,7 +222,8 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error return false, fmt.Errorf("--ssh-url is not implemented yet") } worldInit := &engine.WorldInit{ - Debug: data.Flags.Debug, + Hostname: "", // XXX: Should we set this? + Debug: data.Flags.Debug, Logf: func(format string, v ...interface{}) { Logf("world: etcd: "+format, v...) }, diff --git a/engine/world.go b/engine/world.go index cdba6cdd..7ecba741 100644 --- a/engine/world.go +++ b/engine/world.go @@ -39,6 +39,9 @@ import ( // WorldInit is some data passed in when starting the World interface. // TODO: This is a lousy struct name, feel free to change it. type WorldInit struct { + // Hostname is the UUID we use to represent ourselves to everyone else. + Hostname string + // Debug represents if we're running in debug mode or not. Debug bool diff --git a/etcd/ssh/ssh.go b/etcd/ssh/ssh.go index b10105a1..ba20965e 100644 --- a/etcd/ssh/ssh.go +++ b/etcd/ssh/ssh.go @@ -81,7 +81,6 @@ type World struct { // NS is the etcd namespace to use. NS string - Hostname string // uuid for the consumer of these MetadataPrefix string // expected metadata prefix StoragePrefix string // storage prefix for etcdfs storage StandaloneFs engine.Fs // store an fs here for local usage @@ -305,7 +304,6 @@ func (obj *World) Init(init *engine.WorldInit) error { obj.World = &etcd.World{ // TODO: Pass through more data if the struct for etcd changes. - Hostname: obj.Hostname, Client: c, MetadataPrefix: obj.MetadataPrefix, StoragePrefix: obj.StoragePrefix, diff --git a/etcd/world.go b/etcd/world.go index 90a0befa..aa4e219f 100644 --- a/etcd/world.go +++ b/etcd/world.go @@ -53,7 +53,6 @@ import ( // World is an etcd backed implementation of the World interface. type World struct { // NOTE: Update the etcd/ssh/ World struct if this one changes. - Hostname string // uuid for the consumer of these // XXX: build your own etcd client... Client interfaces.Client MetadataPrefix string // expected metadata prefix @@ -128,7 +127,7 @@ func (obj *World) ResWatch(ctx context.Context) (chan error, error) { // ResExport exports a list of resources under our hostname namespace. // Subsequent calls replace the previously set collection atomically. func (obj *World) ResExport(ctx context.Context, resourceList []engine.Res) error { - return resources.SetResources(ctx, obj.Client, obj.Hostname, resourceList) + return resources.SetResources(ctx, obj.Client, obj.init.Hostname, resourceList) } // ResCollect gets the collection of exported resources which match the filter. @@ -226,12 +225,12 @@ func (obj *World) StrMapGet(ctx context.Context, namespace string) (map[string]s // StrMapSet sets the namespace value to a particular string under the identity // of its own hostname. func (obj *World) StrMapSet(ctx context.Context, namespace, value string) error { - return strmap.SetStrMap(ctx, obj.Client, obj.Hostname, namespace, &value) + return strmap.SetStrMap(ctx, obj.Client, obj.init.Hostname, namespace, &value) } // StrMapDel deletes the value in a particular namespace. func (obj *World) StrMapDel(ctx context.Context, namespace string) error { - return strmap.SetStrMap(ctx, obj.Client, obj.Hostname, namespace, nil) + return strmap.SetStrMap(ctx, obj.Client, obj.init.Hostname, namespace, nil) } // Scheduler returns a scheduling result of hosts in a particular namespace. @@ -246,7 +245,7 @@ func (obj *World) Scheduler(namespace string, opts ...scheduler.Option) (*schedu modifiedOpts = append(modifiedOpts, scheduler.Logf(obj.init.Logf)) path := fmt.Sprintf(schedulerPathFmt, namespace) - return scheduler.Schedule(obj.Client.GetClient(), path, obj.Hostname, modifiedOpts...) + return scheduler.Schedule(obj.Client.GetClient(), path, obj.init.Hostname, modifiedOpts...) } // URI returns the current FS URI. diff --git a/lib/main.go b/lib/main.go index 6b199940..1706448a 100644 --- a/lib/main.go +++ b/lib/main.go @@ -621,8 +621,7 @@ func (obj *Main) Run() error { // an etcd component from the etcd package added in. var world engine.World world = &etcd.World{ - Hostname: hostname, - Client: client, + Client: client, //NS: NS, MetadataPrefix: MetadataPrefix, StoragePrefix: StoragePrefix, @@ -638,7 +637,6 @@ func (obj *Main) Run() error { world = &etcdSSH.World{ URL: obj.SshUrl, Seeds: obj.Seeds, - Hostname: hostname, NS: NS, MetadataPrefix: MetadataPrefix, StoragePrefix: StoragePrefix, @@ -652,7 +650,8 @@ func (obj *Main) Run() error { } } worldInit := &engine.WorldInit{ - Debug: obj.Debug, + Hostname: hostname, + Debug: obj.Debug, Logf: func(format string, v ...interface{}) { obj.Logf("world: etcd: "+format, v...) },