-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: SRV record on headless service #4055
Open
theloneexplorerquest
wants to merge
5
commits into
kubernetes-sigs:master
Choose a base branch
from
theloneexplorerquest:Support-SRV-records-for-ClusterIP-services-and-Load-Balancer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,6 @@ func (sc *serviceSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e | |
sc.setResourceLabel(svc, svcEndpoints) | ||
endpoints = append(endpoints, svcEndpoints...) | ||
} | ||
|
||
// this sorting is required to make merging work. | ||
// after we merge endpoints that have same DNS, we want to ensure that we end up with the same service being an "owner" | ||
// of all those records, as otherwise each time we update, we will end up with a different service that gets data merged in | ||
|
@@ -295,12 +294,35 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri | |
log.Errorf("Pod %s not found for address %v", address.TargetRef.Name, address) | ||
continue | ||
} | ||
for _, container := range pod.Spec.Containers { | ||
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. we would need to guard to enable if you need it. We can not create more than 50k records in a bigger cluster. |
||
for _, port := range container.Ports { | ||
// only create SRV if port have a name. | ||
if port.Name == "" { | ||
continue | ||
} | ||
serviceName := svc.ObjectMeta.Name | ||
protocol := strings.ToLower(string(port.Protocol)) | ||
if protocol == "" { | ||
protocol = "tcp" | ||
} | ||
// hostname.my-svc.my-namespace.svc.cluster-domain.example | ||
target := fmt.Sprintf("0 50 %d %s.%s.%s.svc.%s.", port.ContainerPort, pod.Spec.Hostname, serviceName, svc.Namespace, hostname) | ||
// _port-name._port-protocol.my-svc.my-namespace.svc.cluster-domain.example | ||
recordName := fmt.Sprintf("_%s._%s.%s.%s.svc.%s", port.Name, protocol, serviceName, svc.Namespace, hostname) | ||
var ep *endpoint.Endpoint | ||
if ttl.IsConfigured() { | ||
ep = endpoint.NewEndpointWithTTL(recordName, endpoint.RecordTypeSRV, ttl, target) | ||
} else { | ||
ep = endpoint.NewEndpoint(recordName, endpoint.RecordTypeSRV, target) | ||
} | ||
endpoints = append(endpoints, ep) | ||
} | ||
} | ||
|
||
headlessDomains := []string{hostname} | ||
if pod.Spec.Hostname != "" { | ||
headlessDomains = append(headlessDomains, fmt.Sprintf("%s.%s", pod.Spec.Hostname, hostname)) | ||
} | ||
|
||
for _, headlessDomain := range headlessDomains { | ||
targets := getTargetsFromTargetAnnotation(pod.Annotations) | ||
if len(targets) == 0 { | ||
|
@@ -339,6 +361,7 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri | |
for headlessKey := range targetsByHeadlessDomainAndType { | ||
headlessKeys = append(headlessKeys, headlessKey) | ||
} | ||
|
||
sort.Slice(headlessKeys, func(i, j int) bool { | ||
if headlessKeys[i].DNSName != headlessKeys[j].DNSName { | ||
return headlessKeys[i].DNSName < headlessKeys[j].DNSName | ||
|
Oops, something went wrong.
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.
this should be not added