Skip to content

Commit

Permalink
Restore support for single port services, document multi-port support
Browse files Browse the repository at this point in the history
  • Loading branch information
zonque committed May 11, 2023
1 parent aa87991 commit 35ca506
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ exposed as an mDNS service.
If a service is deleted or updated to not be exposed, the daemon will remove
the mDNS service.
## Kubernetes services with multiple ports
If a service has multiple ports, the port to be exposed as an mDNS service
has to be annotated with the same name as the mDNS service name, e.g.:
```yaml
metadata:
annotations:
kubelish/service-name: Example
kubelish/service-type: _example._tcp
kubelish/txt: Optional TXT record to be exposed along with the service on mDNS
...
spec:
...
ports:
- name: Example
nodePort: 10000
port: 9090
protocol: TCP
targetPort: 9090
```
## Running the daemon
The daemon must be run natively on a node of the cluster, outside of Kubernetes.
Expand Down
16 changes: 12 additions & 4 deletions pkg/k8s-watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ func (w *Watcher) meshDetails(svc *corev1.Service) *ServiceMDNS {
}
}

for _, port := range svc.Spec.Ports {
if port.Name == service.Annotations.ServiceName {
service.Port = int(port.Port)
break
if len(svc.Spec.Ports) == 1 {
service.Port = int(svc.Spec.Ports[0].Port)
} else {
for _, port := range svc.Spec.Ports {
if port.Name == service.Annotations.ServiceName {
service.Port = int(port.Port)
break
}
}
}

if service.Port == 0 {
return nil
}

return service
}

Expand Down

0 comments on commit 35ca506

Please sign in to comment.