diff --git a/internal/worker/registration.go b/internal/worker/registration.go index ef27cbe0..779cf75e 100644 --- a/internal/worker/registration.go +++ b/internal/worker/registration.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "runtime" + "strings" "time" "github.com/rs/zerolog/log" @@ -18,6 +19,8 @@ import ( "git.blender.org/flamenco/pkg/api" ) +const workerNameEnvVariable = "FLAMENCO_WORKER_NAME" + var ( errSignOnCanceled = errors.New("sign-on cancelled") // For example by closing the context. errSignOnRepeatableFailure = errors.New("unable to sign on at Manager, try again later") // For example failed connections @@ -179,6 +182,16 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W // mustHostname either the hostname or logs a fatal error. func mustHostname() string { + name, ok := os.LookupEnv(workerNameEnvVariable) + if ok && name != "" { + name = strings.TrimSpace(name) + log.Info(). + Str("name", name). + Str("fromVariable", workerNameEnvVariable). + Msg("worker name obtained from environment variable instead of using the hostname") + return name + } + hostname, err := os.Hostname() if err != nil { log.Fatal().Err(err).Msg("error getting hostname")