Open DavidS-ovm opened 1 day ago
from comparing the sources https://github.com/overmindtech/aws-source/blob/main/cmd/root.go https://github.com/overmindtech/harness-source/blob/main/cmd/root.go // copy of aws-source https://github.com/overmindtech/stdlib-source/blob/main/cmd/root.go https://github.com/overmindtech/k8s-source/blob/main/cmd/root.go is the outlier, doing everything manually
using https://github.com/overmindtech/discovery/blob/main/cmd.go https://github.com/overmindtech/discovery/blob/main/engine.go
we can pull the following cli options/env vars centrally into cmd.go in AddEngineFlags "nats-servers": natsServers, "nats-jwt": natsJWT, "nats-nkey-seed": natsNKeySeedLog, "nats-connection-name": natsConnectionName, and healthCheckPort := viper.GetInt("health-check-port")
centralise var tokenClient auth.TokenClient
into discovery supplimenting EngineConfigFromViper
modify each of the sources, if we overide the sane defaults. eg k8s vs aws: nats ReconnectWait
update NewEngine in discovery to print out the variables used
With MANAGED and LOCAL sources' configs drifting apart further, handling of ApiUrl, NATS_SERVERS, and other options needs to be fully centralised here, to be able to make a single decision and keep MANAGED considerations out of custom sources.
Take the entirety of https://github.com/overmindtech/stdlib-source/blob/a54fd03513e797a031324415a794a60c150817f1/cmd/root.go#L50-L126 and lift it into
discovery.EngineConfigFromViper
. This includes the following distinct bits:net.JoinHostPort(os.Getenv("API_SERVER_SERVICE_HOST"), os.Getenv("API_SERVER_SERVICE_PORT"))
IFF MANAGEDCreateClients
using above information--nats-jwt
,--nats-nkey-seed
, and--nats-connection-name
flag handling into discoverytokenClient, heartbeatOptions
os.Getenv("NATS_SERVERS")
IFF MANAGED (see https://github.com/overmindtech/srcman/blob/feb5020b160bb6bdbc31b9ae4b05e9759fabb9a6/controllers/source_resources.go#L381-L382)Got Config
logging for all discovery-based stuff; leave sources to do their own logging for local configdiscovery.NewEngine(ec)
intoec.NewEngine()
Then all sources need to be upgraded to excise the existing code and replace it with a double whammy of
discovery.EngineConfigFromViper(...).NewEngine(....)
.discovery
?