mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-08 21:05:54 +08:00
publish dns update on host name change
This commit is contained in:
parent
dbad8ac463
commit
5cac655f04
3 changed files with 44 additions and 4 deletions
|
@ -109,6 +109,19 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := mq.PublishPeerUpdate(); err != nil {
|
if err := mq.PublishPeerUpdate(); err != nil {
|
||||||
logger.Log(0, "fail to publish peer update: ", err.Error())
|
logger.Log(0, "fail to publish peer update: ", err.Error())
|
||||||
}
|
}
|
||||||
|
if newHost.Name != currHost.Name {
|
||||||
|
networks := logic.GetHostNetworks(currHost.ID.String())
|
||||||
|
if err := mq.PublishHostDNSUpdate(currHost, newHost, networks); err != nil {
|
||||||
|
var dnsError *mq.DNSError
|
||||||
|
if errors.Is(err, dnsError) {
|
||||||
|
for _, message := range err.(mq.DNSError).ErrorStrings {
|
||||||
|
logger.Log(0, message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Log(0, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
apiHostData := newHost.ConvertNMHostToAPI()
|
apiHostData := newHost.ConvertNMHostToAPI()
|
||||||
|
|
|
@ -4,15 +4,17 @@ package models
|
||||||
type DNSUpdateAction int
|
type DNSUpdateAction int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DNSDelete = iota
|
DNSDeleteByIP = iota
|
||||||
DNSDeleteByName
|
DNSDeleteByName
|
||||||
|
DNSReplaceName
|
||||||
|
DNSReplaceByIP
|
||||||
DNSInsert
|
DNSInsert
|
||||||
DNSReplace
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DNSUpdate struct {
|
type DNSUpdate struct {
|
||||||
Action DNSUpdateAction
|
Action DNSUpdateAction
|
||||||
Name string
|
Name string
|
||||||
|
NewName string
|
||||||
Address string
|
Address string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,7 @@ func PublishAllDNS(newnode *models.Node) error {
|
||||||
|
|
||||||
func PublishDNSDelete(node *models.Node, host *models.Host) error {
|
func PublishDNSDelete(node *models.Node, host *models.Host) error {
|
||||||
dns := models.DNSUpdate{
|
dns := models.DNSUpdate{
|
||||||
Action: models.DNSDelete,
|
Action: models.DNSDeleteByIP,
|
||||||
Name: host.Name + "." + node.Network,
|
Name: host.Name + "." + node.Network,
|
||||||
}
|
}
|
||||||
if node.Address.IP != nil {
|
if node.Address.IP != nil {
|
||||||
|
@ -260,7 +260,7 @@ func PublishDNSDelete(node *models.Node, host *models.Host) error {
|
||||||
|
|
||||||
func PublishReplaceDNS(oldNode, newNode *models.Node, host *models.Host) error {
|
func PublishReplaceDNS(oldNode, newNode *models.Node, host *models.Host) error {
|
||||||
dns := models.DNSUpdate{
|
dns := models.DNSUpdate{
|
||||||
Action: models.DNSReplace,
|
Action: models.DNSReplaceByIP,
|
||||||
Name: host.Name + "." + oldNode.Network,
|
Name: host.Name + "." + oldNode.Network,
|
||||||
}
|
}
|
||||||
if !oldNode.Address.IP.Equal(newNode.Address.IP) {
|
if !oldNode.Address.IP.Equal(newNode.Address.IP) {
|
||||||
|
@ -329,6 +329,31 @@ func PublishCustomDNS(entry *models.DNSEntry) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DNSError struct {
|
||||||
|
ErrorStrings []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e DNSError) Error() string {
|
||||||
|
return "error publishing dns update"
|
||||||
|
}
|
||||||
|
func PublishHostDNSUpdate(old, new *models.Host, networks []string) error {
|
||||||
|
errors := DNSError{}
|
||||||
|
for _, network := range networks {
|
||||||
|
dns := models.DNSUpdate{
|
||||||
|
Action: models.DNSReplaceName,
|
||||||
|
Name: old.Name + "." + network,
|
||||||
|
NewName: new.Name + "." + network,
|
||||||
|
}
|
||||||
|
if err := PublishDNSUpdate(network, dns); err != nil {
|
||||||
|
errors.ErrorStrings = append(errors.ErrorStrings, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(errors.ErrorStrings) > 0 {
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// function to collect and store metrics for server nodes
|
// function to collect and store metrics for server nodes
|
||||||
//func collectServerMetrics(networks []models.Network) {
|
//func collectServerMetrics(networks []models.Network) {
|
||||||
// if !servercfg.Is_EE {
|
// if !servercfg.Is_EE {
|
||||||
|
|
Loading…
Add table
Reference in a new issue