Skip to content

Commit

Permalink
Do not add namespace to Ingress hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
blake committed Jul 2, 2021
1 parent 1142194 commit 2693f40
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ func constructRecords(r resource.Resource) []string {
// Construct reverse IP
reverseIP := net.IPv4(ip[15], ip[14], ip[13], ip[12])

// Publish A records resources as <name>.<namespace>.local
// Ensure corresponding PTR records map to this hostname
records = append(records, fmt.Sprintf("%s.%s.local. %d IN A %s", r.Name, r.Namespace, recordTTL, ip))
records = append(records, fmt.Sprintf("%s.in-addr.arpa. %d IN PTR %s.%s.local.", reverseIP, recordTTL, r.Name, r.Namespace))

if r.Namespace == defaultNamespace || withoutNamespace {
// Publish services without the name in the namespace if any of the following
// criteria is satisfied:
// 1. The Service exists in the default namespace
// 2. The -without-namespace flag is equal to true
// 3. The record to be published is from an Ingress with a defined hostname
if r.Namespace == defaultNamespace || withoutNamespace || r.SourceType == "ingress" {
records = append(records, fmt.Sprintf("%s.local. %d IN A %s", r.Name, recordTTL, ip))
}

Expand Down
9 changes: 5 additions & 4 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const (

// Resource represents a resource to advertise over mDNS
type Resource struct {
Action string
IP string
Name string
Namespace string
SourceType string
Action string
IP string
Name string
Namespace string
}
9 changes: 5 additions & 4 deletions source/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func (i *IngressSource) buildRecords(obj interface{}, action string) ([]resource
hostname = parsedHost.Domain
}
advertiseObj := resource.Resource{
Action: action,
Name: hostname,
Namespace: ingress.Namespace,
IP: ipField,
SourceType: "ingress",
Action: action,
Name: hostname,
Namespace: ingress.Namespace,
IP: ipField,
}

records = append(records, advertiseObj)
Expand Down
3 changes: 2 additions & 1 deletion source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (s *ServiceSource) onUpdate(oldObj interface{}, newObj interface{}) {
func (s *ServiceSource) buildRecord(obj interface{}, action string) (resource.Resource, error) {

var advertiseObj = resource.Resource{
Action: action,
SourceType: "service",
Action: action,
}

service, ok := obj.(*corev1.Service)
Expand Down

0 comments on commit 2693f40

Please sign in to comment.