-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NET-1603: Manage DNS NM changes #3124
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0a68ddc
add switch for manage dns
yabinma 5b15521
manage DNS sync publish
yabinma 6d03431
add dns sync api
yabinma 6f4da26
add manageDNS field in peerUpdate
yabinma 04ed0c3
add default dns for extClent if manage dns enabled
yabinma 1e64cf4
add DEFAULT_DOMAIN for internal DNS lookup
yabinma e620270
move DNSSync to peerUpdate
yabinma f3c8e19
fix empty host in network issue
yabinma d7c1171
Merge branch 'develop' into NET-1603
yabinma 4de0fc1
sync up dns when custom dns add/delete
yabinma 715af30
fix custom DNS ip4/ipv6 validator issue
yabinma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
|
||
var batchSize = servercfg.GetPeerUpdateBatchSize() | ||
var batchUpdate = servercfg.GetBatchPeerUpdate() | ||
var manageDNSCache = map[string]int{} | ||
|
||
// PublishPeerUpdate --- determines and publishes a peer update to all the hosts | ||
func PublishPeerUpdate(replacePeers bool) error { | ||
|
@@ -249,3 +250,48 @@ func sendPeers() { | |
} | ||
} | ||
} | ||
|
||
func sendDNSSync() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this func should be simplified to all get all entries from the DB and push it to clients There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the cache in new commit. Please help review again. |
||
|
||
networks, err := logic.GetNetworks() | ||
if err == nil && len(networks) > 0 { | ||
for _, v := range networks { | ||
k, err := logic.GetDNS(v.NetID) | ||
if err == nil && len(k) > 0 { | ||
if manageDNSCache[v.NetID] != len(k) { | ||
err = PushSyncDNS(k) | ||
if err != nil { | ||
slog.Warn("error publishing dns entry data for network ", v.NetID, err.Error()) | ||
continue | ||
} | ||
manageDNSCache[v.NetID] = len(k) | ||
} | ||
continue | ||
} | ||
slog.Warn("error getting DNS entries for network ", v.NetID, err.Error()) | ||
} | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
func PushSyncDNS(dnsEntries []models.DNSEntry) error { | ||
logger.Log(2, "----> Pushing Sync DNS") | ||
data, err := json.Marshal(dnsEntries) | ||
if err != nil { | ||
return errors.New("failed to marshal DNS entries: " + err.Error()) | ||
} | ||
if mqclient == nil || !mqclient.IsConnectionOpen() { | ||
return errors.New("cannot publish ... mqclient not connected") | ||
} | ||
if token := mqclient.Publish(fmt.Sprintf("host/dns/sync/%s", dnsEntries[0].Network), 0, true, data); !token.WaitTimeout(MQ_TIMEOUT*time.Second) || token.Error() != nil { | ||
var err error | ||
if token.Error() == nil { | ||
err = errors.New("connection timeout") | ||
} else { | ||
err = token.Error() | ||
} | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package servercfg | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/matryer/is" | ||
) | ||
|
||
func TestValidateDomain(t *testing.T) { | ||
|
||
t.Run("", func(t *testing.T) { | ||
is := is.New(t) | ||
valid := validateDomain("netmaker.hosted") | ||
is.Equal(valid, true) | ||
}) | ||
|
||
t.Run("", func(t *testing.T) { | ||
is := is.New(t) | ||
valid := validateDomain("ipv4test1.hosted") | ||
is.Equal(valid, true) | ||
}) | ||
|
||
t.Run("", func(t *testing.T) { | ||
is := is.New(t) | ||
valid := validateDomain("ip_4?") | ||
is.Equal(valid, false) | ||
}) | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove periodic sync check, instead this can be published when peer update is pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to peerUpdate in new commit. please review again.