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.
This commit is contained in:
James Shubin
2025-03-19 05:41:04 -04:00
parent 02fca6409a
commit 5665259784
5 changed files with 12 additions and 14 deletions

View File

@@ -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...)
},

View File

@@ -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

View File

@@ -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,

View File

@@ -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.

View File

@@ -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...)
},