-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdns.go
54 lines (45 loc) · 1.21 KB
/
mdns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package phases
import (
"fmt"
"net"
"github.com/pion/mdns"
"github.com/pkg/errors"
"golang.org/x/net/ipv4"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
)
func NewMDnsPublishPhase() workflow.Phase {
return workflow.Phase{
Name: "mdns-publish",
Short: "Publish the cluster domain with mdns.",
Run: runMDnsPublish,
}
}
// runPrepare executes the node initialization process.
func runMDnsPublish(c workflow.RunData) error {
data, ok := c.(IkniteInitData)
if !ok {
return fmt.Errorf("prepare phase invoked with an invalid data struct. ")
}
ikniteConfig := data.IkniteCluster().Spec
if !ikniteConfig.EnableMDNS {
return nil
}
addr, err := net.ResolveUDPAddr("udp", mdns.DefaultAddress)
if err != nil {
return errors.Wrap(err, "Cannot resolve default address")
}
l, err := net.ListenUDP("udp4", addr)
if err != nil {
return errors.Wrap(err, "Cannot Listen on default address")
}
var conn *mdns.Conn
fmt.Println("[mdns-publish] Starting the mdns reponder...")
conn, err = mdns.Server(ipv4.NewPacketConn(l), &mdns.Config{
LocalNames: []string{ikniteConfig.DomainName},
})
if err != nil {
return errors.Wrap(err, "Cannot create server")
}
data.SetMDnsConn(conn)
return nil
}