mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-08 22:24:17 +08:00
NET-173 Sync EndpointDetection config (#2374)
* adding serverconfig logic and variable to hosts * - sync EndpointDetection on peerupdate - add EndpointDetection to env config * - endpoint detection always comes from the server - fixed ENDPOINT_DETECTION -> NETCLIENT_ENDPOINT_DETECTION --------- Co-authored-by: afeiszli <alex.feiszli@gmail.com>
This commit is contained in:
parent
834cc893ab
commit
94ca72e370
8 changed files with 78 additions and 54 deletions
|
@ -41,6 +41,7 @@ type ServerConfig struct {
|
|||
BrokerType string `yaml:"brokertype"`
|
||||
EmqxRestEndpoint string `yaml:"emqxrestendpoint"`
|
||||
NetclientAutoUpdate string `yaml:"netclientautoupdate"`
|
||||
NetclientEndpointDetection string `yaml:"netclientendpointdetection"`
|
||||
MasterKey string `yaml:"masterkey"`
|
||||
DNSKey string `yaml:"dnskey"`
|
||||
AllowedOrigin string `yaml:"allowedorigin"`
|
||||
|
|
|
@ -111,6 +111,7 @@ func CreateHost(h *models.Host) error {
|
|||
}
|
||||
h.HostPass = string(hash)
|
||||
h.AutoUpdate = servercfg.AutoUpdateEnabled()
|
||||
h.EndpointDetection = servercfg.EndpointDetectionEnabled()
|
||||
// if another server has already updated proxyenabled, leave it alone
|
||||
if !h.ProxyEnabledSet {
|
||||
log.Println("checking default proxy", servercfg.GetServerConfig().DefaultProxyMode)
|
||||
|
|
|
@ -167,6 +167,9 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
|
|||
HostNetworkInfo: models.HostInfoMap{},
|
||||
}
|
||||
|
||||
// endpoint detection always comes from the server
|
||||
hostPeerUpdate.Host.EndpointDetection = servercfg.EndpointDetectionEnabled()
|
||||
|
||||
logger.Log(1, "peer update for host", host.ID.String())
|
||||
peerIndexMap := make(map[string]int)
|
||||
for _, nodeID := range host.Nodes {
|
||||
|
|
|
@ -48,6 +48,7 @@ type Host struct {
|
|||
IPForwarding bool `json:"ipforwarding" yaml:"ipforwarding"`
|
||||
DaemonInstalled bool `json:"daemoninstalled" yaml:"daemoninstalled"`
|
||||
AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"`
|
||||
EndpointDetection bool `json:"endpointdetection" yaml:"endpointdetection"`
|
||||
HostPass string `json:"hostpass" yaml:"hostpass"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
OS string `json:"os" yaml:"os"`
|
||||
|
|
|
@ -438,7 +438,8 @@ func handleHostCheckin(h, currentHost *models.Host) bool {
|
|||
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) ||
|
||||
!h.EndpointIP.Equal(currentHost.EndpointIP) ||
|
||||
(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
|
||||
h.DefaultInterface != currentHost.DefaultInterface
|
||||
h.DefaultInterface != currentHost.DefaultInterface ||
|
||||
h.EndpointDetection != servercfg.EndpointDetectionEnabled()
|
||||
if ifaceDelta { // only save if something changes
|
||||
currentHost.EndpointIP = h.EndpointIP
|
||||
currentHost.Interfaces = h.Interfaces
|
||||
|
|
|
@ -19,6 +19,7 @@ NETMAKER_ACCOUNT_ID=
|
|||
LICENSE_KEY=
|
||||
SERVER_IMAGE_TAG=
|
||||
UI_IMAGE_TAG=
|
||||
NETCLIENT_ENDPOINT_DETECTION="disabled"
|
||||
# used for HA - identifies this server vs other servers
|
||||
NODE_ID="netmaker-server-1"
|
||||
METRICS_EXPORTER="off"
|
||||
|
|
|
@ -303,9 +303,9 @@ save_config() { (
|
|||
local toCopy=("SERVER_HOST" "MASTER_KEY" "TURN_USERNAME" "TURN_PASSWORD" "MQ_USERNAME" "MQ_PASSWORD"
|
||||
"INSTALL_TYPE" "NODE_ID" "METRICS_EXPORTER" "PROMETHEUS" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
|
||||
"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "STUN_PORT" "VERBOSITY"
|
||||
"DEFAULT_PROXY_MODE" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK"
|
||||
"TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" "FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER"
|
||||
"EXPORTER_API_PORT")
|
||||
"DEFAULT_PROXY_MODE" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND"
|
||||
"DISABLE_REMOTE_IP_CHECK" "NETCLIENT_ENDPOINT_DETECTION" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET"
|
||||
"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT")
|
||||
for name in "${toCopy[@]}"; do
|
||||
save_config_item $name "${!name}"
|
||||
done
|
||||
|
|
|
@ -51,6 +51,11 @@ func GetServerConfig() config.ServerConfig {
|
|||
} else {
|
||||
cfg.NetclientAutoUpdate = "disabled"
|
||||
}
|
||||
if EndpointDetectionEnabled() {
|
||||
cfg.NetclientEndpointDetection = "enabled"
|
||||
} else {
|
||||
cfg.NetclientEndpointDetection = "disabled"
|
||||
}
|
||||
if IsRestBackend() {
|
||||
cfg.RestBackend = "on"
|
||||
}
|
||||
|
@ -432,6 +437,17 @@ func AutoUpdateEnabled() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// EndpointDetectionEnabled returns a boolean indicating whether netclient endpoint detection is enabled or disabled
|
||||
// default is enabled
|
||||
func EndpointDetectionEnabled() bool {
|
||||
if os.Getenv("NETCLIENT_ENDPOINT_DETECTION") == "disabled" {
|
||||
return false
|
||||
} else if config.Config.Server.NetclientEndpointDetection == "disabled" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsDNSMode - should it run with DNS
|
||||
func IsDNSMode() bool {
|
||||
isdns := true
|
||||
|
|
Loading…
Add table
Reference in a new issue