Merge pull request #390 from gravitl/hotfix_v0.8.5_client_adjustment

Hotfix v0.8.5 client adjustment
This commit is contained in:
dcarns 2021-10-27 15:27:11 -04:00 committed by GitHub
commit 9e9945bb1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 98 additions and 38 deletions

View file

@ -12,7 +12,7 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
restart: always restart: always
network_mode: host privileged: true
environment: environment:
SERVER_HOST: "SERVER_PUBLIC_IP" SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443" SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -29,11 +29,15 @@ services:
SERVER_GRPC_WIREGUARD: "off" SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*" CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite" DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui: netmaker-ui:
container_name: netmaker-ui container_name: netmaker-ui
depends_on: depends_on:
- netmaker - netmaker
image: gravitl/netmaker-ui:v0.8 image: gravitl/netmaker-ui:v0.8.5
links: links:
- "netmaker:api" - "netmaker:api"
ports: ports:

View file

@ -11,7 +11,7 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
restart: always restart: always
network_mode: host privileged: true
environment: environment:
SERVER_HOST: "SERVER_PUBLIC_IP" SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443" SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -28,11 +28,15 @@ services:
SERVER_GRPC_WIREGUARD: "off" SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*" CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite" DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui: netmaker-ui:
container_name: netmaker-ui container_name: netmaker-ui
depends_on: depends_on:
- netmaker - netmaker
image: gravitl/netmaker-ui:v0.8 image: gravitl/netmaker-ui:v0.8.5
links: links:
- "netmaker:api" - "netmaker:api"
ports: ports:

View file

@ -12,7 +12,7 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
restart: always restart: always
network_mode: host privileged: true
environment: environment:
SERVER_HOST: "SERVER_PUBLIC_IP" SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443" SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -29,11 +29,15 @@ services:
SERVER_GRPC_WIREGUARD: "off" SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*" CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite" DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui: netmaker-ui:
container_name: netmaker-ui container_name: netmaker-ui
depends_on: depends_on:
- netmaker - netmaker
image: gravitl/netmaker-ui:v0.8 image: gravitl/netmaker-ui:v0.8.5
links: links:
- "netmaker:api" - "netmaker:api"
ports: ports:

View file

@ -451,9 +451,11 @@ func isInterfacePresent(iface string, address string) (string, bool) {
} }
for _, addr := range currAddrs { for _, addr := range currAddrs {
if strings.Contains(addr.String(), address) && currIface.Name != iface { if strings.Contains(addr.String(), address) && currIface.Name != iface {
Log("found iface "+addr.String()+" "+currIface.Name, 2)
return currIface.Name, false return currIface.Name, false
} }
} }
} }
Log("failed to find iface "+iface, 2)
return "", true return "", true
} }

View file

@ -2,6 +2,7 @@ package logic
import ( import (
"errors" "errors"
"fmt"
"net" "net"
"os" "os"
"runtime" "runtime"
@ -108,6 +109,8 @@ func ServerJoin(network string, serverID string, privateKey string) error {
node.ListenPort, err = ncutils.GetFreePort(node.ListenPort) node.ListenPort, err = ncutils.GetFreePort(node.ListenPort)
if err != nil { if err != nil {
Log("Error retrieving port: "+err.Error(), 2) Log("Error retrieving port: "+err.Error(), 2)
} else {
Log("Set client port to "+fmt.Sprintf("%d", node.ListenPort)+" for network "+node.Network, 1)
} }
// safety check. If returned node from server is local, but not currently configured as local, set to local addr // safety check. If returned node from server is local, but not currently configured as local, set to local addr
@ -123,7 +126,7 @@ func ServerJoin(network string, serverID string, privateKey string) error {
if err = StorePrivKey(node.ID, privateKey); err != nil { if err = StorePrivKey(node.ID, privateKey); err != nil {
return err return err
} }
if err = ServerPush(node.MacAddress, node.Network); err != nil { if err = ServerPush(node); err != nil {
return err return err
} }
@ -151,7 +154,7 @@ func ServerCheckin(mac string, network string) error {
return err return err
} }
newNode, err = ServerPull(mac, network, false) newNode, err = ServerPull(&serverNode, false)
if isDeleteError(err) { if isDeleteError(err) {
return ServerLeave(mac, network) return ServerLeave(mac, network)
} else if err != nil { } else if err != nil {
@ -163,22 +166,16 @@ func ServerCheckin(mac string, network string) error {
return errors.New("node has been removed") return errors.New("node has been removed")
} }
return ServerPush(newNode.MacAddress, newNode.Network) return ServerPush(newNode)
} }
// ServerPull - pulls current config/peers for server // ServerPull - pulls current config/peers for server
func ServerPull(mac string, network string, onErr bool) (*models.Node, error) { func ServerPull(serverNode *models.Node, onErr bool) (*models.Node, error) {
var serverNode models.Node
var err error var err error
serverNode, err = GetNode(mac, network)
if err != nil {
return &serverNode, err
}
if serverNode.IPForwarding == "yes" { if serverNode.IPForwarding == "yes" {
if err = setIPForwardingLinux(); err != nil { if err = setIPForwardingLinux(); err != nil {
return &serverNode, err return serverNode, err
} }
} }
serverNode.OS = runtime.GOOS serverNode.OS = runtime.GOOS
@ -196,38 +193,31 @@ func ServerPull(mac string, network string, onErr bool) (*models.Node, error) {
Log("removed old interface "+oldIfaceName, 1) Log("removed old interface "+oldIfaceName, 1)
} }
serverNode.PullChanges = "no" serverNode.PullChanges = "no"
if err = setWGConfig(serverNode, network, false); err != nil { if err = setWGConfig(*serverNode, serverNode.Network, false); err != nil {
return &serverNode, err return serverNode, err
} }
// handle server side update // handle server side update
if err = UpdateNode(&serverNode, &serverNode); err != nil { if err = UpdateNode(serverNode, serverNode); err != nil {
return &serverNode, err return serverNode, err
} }
} else { } else {
if err = setWGConfig(serverNode, network, true); err != nil { if err = setWGConfig(*serverNode, serverNode.Network, true); err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return ServerPull(serverNode.MacAddress, serverNode.Network, true) return ServerPull(serverNode, true)
} else { } else {
return &serverNode, err return serverNode, err
} }
} }
} }
return &serverNode, nil return serverNode, nil
} }
// ServerPush - pushes config changes for server checkins/join // ServerPush - pushes config changes for server checkins/join
func ServerPush(mac string, network string) error { func ServerPush(serverNode *models.Node) error {
var serverNode models.Node
var err error
serverNode, err = GetNode(mac, network)
if err != nil /* && !ncutils.IsEmptyRecord(err) May not be necessary */ {
return err
}
serverNode.OS = runtime.GOOS serverNode.OS = runtime.GOOS
serverNode.SetLastCheckIn() serverNode.SetLastCheckIn()
return UpdateNode(&serverNode, &serverNode) return UpdateNode(serverNode, serverNode)
} }
// ServerLeave - removes a server node // ServerLeave - removes a server node

View file

@ -169,7 +169,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
} }
// set MTU of node interface // set MTU of node interface
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil { if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
Log("failed to create interface with mtu "+ifacename, 2) Log("failed to create interface with mtu "+strconv.Itoa(int(node.MTU))+" - "+ifacename, 2)
return err return err
} }

View file

@ -271,6 +271,7 @@ func GetFreePort(rangestart int32) (int32, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
for x := rangestart; x <= 65535; x++ { for x := rangestart; x <= 65535; x++ {
conflict := false conflict := false
for _, i := range devices { for _, i := range devices {
@ -397,6 +398,12 @@ func FileExists(f string) bool {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return false return false
} }
if err != nil && strings.Contains(err.Error(), "not a directory") {
return false
}
if err != nil {
Log("error reading file: " + f + ", " + err.Error())
}
return !info.IsDir() return !info.IsDir()
} }

View file

@ -12,6 +12,7 @@ import (
"github.com/gravitl/netmaker/config" "github.com/gravitl/netmaker/config"
) )
// SetHost - sets the host ip
func SetHost() error { func SetHost() error {
remoteip, err := GetPublicIP() remoteip, err := GetPublicIP()
if err != nil { if err != nil {
@ -20,6 +21,8 @@ func SetHost() error {
os.Setenv("SERVER_HOST", remoteip) os.Setenv("SERVER_HOST", remoteip)
return nil return nil
} }
// GetServerConfig - gets the server config into memory from file or env
func GetServerConfig() config.ServerConfig { func GetServerConfig() config.ServerConfig {
var cfg config.ServerConfig var cfg config.ServerConfig
cfg.APIConnString = GetAPIConnString() cfg.APIConnString = GetAPIConnString()
@ -76,6 +79,8 @@ func GetServerConfig() config.ServerConfig {
return cfg return cfg
} }
// GetFrontendURL - gets the frontend url
func GetFrontendURL() string { func GetFrontendURL() string {
var frontend = "" var frontend = ""
if os.Getenv("FRONTEND_URL") != "" { if os.Getenv("FRONTEND_URL") != "" {
@ -86,6 +91,7 @@ func GetFrontendURL() string {
return frontend return frontend
} }
// GetAPIConnString - gets the api connections string
func GetAPIConnString() string { func GetAPIConnString() string {
conn := "" conn := ""
if os.Getenv("SERVER_API_CONN_STRING") != "" { if os.Getenv("SERVER_API_CONN_STRING") != "" {
@ -95,6 +101,8 @@ func GetAPIConnString() string {
} }
return conn return conn
} }
// GetVersion - version of netmaker
func GetVersion() string { func GetVersion() string {
version := "0.8.5" version := "0.8.5"
if config.Config.Server.Version != "" { if config.Config.Server.Version != "" {
@ -102,6 +110,8 @@ func GetVersion() string {
} }
return version return version
} }
// GetDB - gets the database type
func GetDB() string { func GetDB() string {
database := "sqlite" database := "sqlite"
if os.Getenv("DATABASE") != "" { if os.Getenv("DATABASE") != "" {
@ -111,6 +121,8 @@ func GetDB() string {
} }
return database return database
} }
// GetAPIHost - gets the api host
func GetAPIHost() string { func GetAPIHost() string {
serverhost := "127.0.0.1" serverhost := "127.0.0.1"
remoteip, _ := GetPublicIP() remoteip, _ := GetPublicIP()
@ -127,6 +139,8 @@ func GetAPIHost() string {
} }
return serverhost return serverhost
} }
// GetPodIP - get the pod's ip
func GetPodIP() string { func GetPodIP() string {
podip := "127.0.0.1" podip := "127.0.0.1"
if os.Getenv("POD_IP") != "" { if os.Getenv("POD_IP") != "" {
@ -135,6 +149,7 @@ func GetPodIP() string {
return podip return podip
} }
// GetAPIPort - gets the api port
func GetAPIPort() string { func GetAPIPort() string {
apiport := "8081" apiport := "8081"
if os.Getenv("API_PORT") != "" { if os.Getenv("API_PORT") != "" {
@ -145,6 +160,7 @@ func GetAPIPort() string {
return apiport return apiport
} }
// GetCheckinInterval - get check in interval for nodes
func GetCheckinInterval() string { func GetCheckinInterval() string {
seconds := "15" seconds := "15"
if os.Getenv("CHECKIN_INTERVAL") != "" { if os.Getenv("CHECKIN_INTERVAL") != "" {
@ -155,6 +171,7 @@ func GetCheckinInterval() string {
return seconds return seconds
} }
// GetDefaultNodeLimit - get node limit if one is set
func GetDefaultNodeLimit() int32 { func GetDefaultNodeLimit() int32 {
var limit int32 var limit int32
limit = 999999999 limit = 999999999
@ -166,6 +183,8 @@ func GetDefaultNodeLimit() int32 {
} }
return limit return limit
} }
// GetGRPCConnString - get grpc conn string
func GetGRPCConnString() string { func GetGRPCConnString() string {
conn := "" conn := ""
if os.Getenv("SERVER_GRPC_CONN_STRING") != "" { if os.Getenv("SERVER_GRPC_CONN_STRING") != "" {
@ -176,6 +195,7 @@ func GetGRPCConnString() string {
return conn return conn
} }
// GetCoreDNSAddr - gets the core dns address
func GetCoreDNSAddr() string { func GetCoreDNSAddr() string {
addr, _ := GetPublicIP() addr, _ := GetPublicIP()
if os.Getenv("COREDNS_ADDR") != "" { if os.Getenv("COREDNS_ADDR") != "" {
@ -186,6 +206,7 @@ func GetCoreDNSAddr() string {
return addr return addr
} }
// GetGRPCHost - get the grpc host url
func GetGRPCHost() string { func GetGRPCHost() string {
serverhost := "127.0.0.1" serverhost := "127.0.0.1"
remoteip, _ := GetPublicIP() remoteip, _ := GetPublicIP()
@ -202,6 +223,8 @@ func GetGRPCHost() string {
} }
return serverhost return serverhost
} }
// GetGRPCPort - gets the grpc port
func GetGRPCPort() string { func GetGRPCPort() string {
grpcport := "50051" grpcport := "50051"
if os.Getenv("GRPC_PORT") != "" { if os.Getenv("GRPC_PORT") != "" {
@ -211,6 +234,8 @@ func GetGRPCPort() string {
} }
return grpcport return grpcport
} }
// GetMasterKey - gets the configured master key of server
func GetMasterKey() string { func GetMasterKey() string {
key := "secretkey" key := "secretkey"
if os.Getenv("MASTER_KEY") != "" { if os.Getenv("MASTER_KEY") != "" {
@ -220,6 +245,8 @@ func GetMasterKey() string {
} }
return key return key
} }
// GetAllowedOrigin - get the allowed origin
func GetAllowedOrigin() string { func GetAllowedOrigin() string {
allowedorigin := "*" allowedorigin := "*"
if os.Getenv("CORS_ALLOWED_ORIGIN") != "" { if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
@ -229,6 +256,8 @@ func GetAllowedOrigin() string {
} }
return allowedorigin return allowedorigin
} }
// IsRestBackend - checks if rest is on or off
func IsRestBackend() bool { func IsRestBackend() bool {
isrest := true isrest := true
if os.Getenv("REST_BACKEND") != "" { if os.Getenv("REST_BACKEND") != "" {
@ -242,6 +271,8 @@ func IsRestBackend() bool {
} }
return isrest return isrest
} }
// IsAgentBackend - checks if agent backed is on or off
func IsAgentBackend() bool { func IsAgentBackend() bool {
isagent := true isagent := true
if os.Getenv("AGENT_BACKEND") != "" { if os.Getenv("AGENT_BACKEND") != "" {
@ -255,6 +286,8 @@ func IsAgentBackend() bool {
} }
return isagent return isagent
} }
// IsClientMode - checks if it should run in client mode
func IsClientMode() string { func IsClientMode() string {
isclient := "on" isclient := "on"
if os.Getenv("CLIENT_MODE") != "" { if os.Getenv("CLIENT_MODE") != "" {
@ -274,6 +307,8 @@ func IsClientMode() string {
} }
return isclient return isclient
} }
// IsDNSMode - should it run with DNS
func IsDNSMode() bool { func IsDNSMode() bool {
isdns := true isdns := true
if os.Getenv("DNS_MODE") != "" { if os.Getenv("DNS_MODE") != "" {
@ -288,6 +323,7 @@ func IsDNSMode() bool {
return isdns return isdns
} }
// IsGRPCSSL - ssl grpc on or off
func IsGRPCSSL() bool { func IsGRPCSSL() bool {
isssl := false isssl := false
if os.Getenv("GRPC_SSL") != "" { if os.Getenv("GRPC_SSL") != "" {
@ -302,6 +338,7 @@ func IsGRPCSSL() bool {
return isssl return isssl
} }
// DisableRemoteIPCheck - disable the remote ip check
func DisableRemoteIPCheck() bool { func DisableRemoteIPCheck() bool {
disabled := false disabled := false
if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" { if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
@ -315,6 +352,8 @@ func DisableRemoteIPCheck() bool {
} }
return disabled return disabled
} }
// DisableDefaultNet - disable default net
func DisableDefaultNet() bool { func DisableDefaultNet() bool {
disabled := false disabled := false
if os.Getenv("DISABLE_DEFAULT_NET") != "" { if os.Getenv("DISABLE_DEFAULT_NET") != "" {
@ -328,6 +367,8 @@ func DisableDefaultNet() bool {
} }
return disabled return disabled
} }
// GetPublicIP - gets public ip
func GetPublicIP() (string, error) { func GetPublicIP() (string, error) {
endpoint := "" endpoint := ""
@ -354,6 +395,8 @@ func GetPublicIP() (string, error) {
} }
return endpoint, err return endpoint, err
} }
// GetVerbose - get the verbosity of server
func GetVerbose() int32 { func GetVerbose() int32 {
level, err := strconv.Atoi(os.Getenv("VERBOSITY")) level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
if err != nil || level < 0 { if err != nil || level < 0 {
@ -365,6 +408,7 @@ func GetVerbose() int32 {
return int32(level) return int32(level)
} }
// GetPlatform - get the system type of server
func GetPlatform() string { func GetPlatform() string {
platform := "linux" platform := "linux"
if os.Getenv("PLATFORM") != "" { if os.Getenv("PLATFORM") != "" {
@ -375,6 +419,7 @@ func GetPlatform() string {
return platform return platform
} }
// GetSQLConn - get the sql connection string
func GetSQLConn() string { func GetSQLConn() string {
sqlconn := "http://" sqlconn := "http://"
if os.Getenv("SQL_CONN") != "" { if os.Getenv("SQL_CONN") != "" {
@ -385,6 +430,7 @@ func GetSQLConn() string {
return sqlconn return sqlconn
} }
// IsSplitDNS - checks if split dns is on
func IsSplitDNS() bool { func IsSplitDNS() bool {
issplit := false issplit := false
if os.Getenv("IS_SPLIT_DNS") == "yes" { if os.Getenv("IS_SPLIT_DNS") == "yes" {
@ -395,6 +441,7 @@ func IsSplitDNS() bool {
return issplit return issplit
} }
// GetNodeID - gets the node id
func GetNodeID() string { func GetNodeID() string {
var id string var id string
id = getMacAddr() id = getMacAddr()
@ -406,6 +453,7 @@ func GetNodeID() string {
return id return id
} }
// GetServerCheckinInterval - gets the server check-in time
func GetServerCheckinInterval() int64 { func GetServerCheckinInterval() int64 {
var t = int64(5) var t = int64(5)
var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL")) var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL"))

View file

@ -107,9 +107,11 @@ func HandleContainedClient() error {
err = logic.ServerCheckin(servercfg.GetNodeID(), serverNet.NetID) err = logic.ServerCheckin(servercfg.GetNodeID(), serverNet.NetID)
if err != nil { if err != nil {
logic.Log("error occurred during server checkin: "+err.Error(), 1) logic.Log("error occurred during server checkin: "+err.Error(), 1)
} else {
logic.Log("completed peers check of network "+serverNet.NetID, 3)
} }
} }
logic.Log("completed a checkin call", 3) // logic.Log("completed a checkin call", 3)
} }
return nil return nil
} }
@ -168,7 +170,6 @@ func SyncNetworks(servernets []models.Network) error {
// AddNetwork - add a network to server in client mode // AddNetwork - add a network to server in client mode
func AddNetwork(network string) (bool, error) { func AddNetwork(network string) (bool, error) {
err := logic.ServerJoin(network, servercfg.GetNodeID(), "") var err = logic.ServerJoin(network, servercfg.GetNodeID(), "")
logic.Log("server added to network "+network, 2)
return true, err return true, err
} }