mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-15325: Allowing to configure the device for detect the IP in HA clusters (#10917)
This commit is contained in:
@@ -46,10 +46,10 @@ func (o *ClusterDiscovery) AutoFillHostname() {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) AutoFillIpAddress() {
|
||||
func (o *ClusterDiscovery) AutoFillIpAddress(iface string) {
|
||||
// attempt to set the hostname to the first non-local IP address
|
||||
if len(o.Hostname) == 0 {
|
||||
o.Hostname = GetServerIpAddress()
|
||||
o.Hostname = GetServerIpAddress(iface)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestClusterDiscovery(t *testing.T) {
|
||||
o.Hostname = ""
|
||||
o.AutoFillHostname()
|
||||
|
||||
o.AutoFillIpAddress()
|
||||
o.AutoFillIpAddress("")
|
||||
o.Hostname = ""
|
||||
o.AutoFillIpAddress()
|
||||
o.AutoFillIpAddress("")
|
||||
}
|
||||
|
||||
@@ -672,6 +672,7 @@ type ClusterSettings struct {
|
||||
Enable *bool `restricted:"true"`
|
||||
ClusterName *string `restricted:"true"`
|
||||
OverrideHostname *string `restricted:"true"`
|
||||
NetworkInterface *string `restricted:"true"`
|
||||
UseIpAddress *bool `restricted:"true"`
|
||||
UseExperimentalGossip *bool `restricted:"true"`
|
||||
ReadOnlyConfig *bool `restricted:"true"`
|
||||
@@ -695,6 +696,10 @@ func (s *ClusterSettings) SetDefaults() {
|
||||
s.OverrideHostname = NewString("")
|
||||
}
|
||||
|
||||
if s.NetworkInterface == nil {
|
||||
s.NetworkInterface = NewString("")
|
||||
}
|
||||
|
||||
if s.UseIpAddress == nil {
|
||||
s.UseIpAddress = NewBool(true)
|
||||
}
|
||||
|
||||
@@ -302,10 +302,30 @@ func StringFromJson(data io.Reader) string {
|
||||
}
|
||||
}
|
||||
|
||||
func GetServerIpAddress() string {
|
||||
if addrs, err := net.InterfaceAddrs(); err != nil {
|
||||
func GetServerIpAddress(iface string) string {
|
||||
var addrs []net.Addr
|
||||
if len(iface) == 0 {
|
||||
var err error
|
||||
addrs, err = net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, i := range interfaces {
|
||||
if i.Name == iface {
|
||||
addrs, err = i.Addrs()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
|
||||
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() && !ip.IP.IsLinkLocalUnicast() && !ip.IP.IsLinkLocalMulticast() {
|
||||
@@ -314,7 +334,6 @@ func GetServerIpAddress() string {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ func TestIsValidAlphaNum(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetServerIpAddress(t *testing.T) {
|
||||
if len(GetServerIpAddress()) == 0 {
|
||||
if len(GetServerIpAddress("")) == 0 {
|
||||
t.Fatal("Should find local ip address")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user