-
Notifications
You must be signed in to change notification settings - Fork 3
Improve k8s canonical DNS lookup #138
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||
|
|
||||||||||||||
| import re | ||||||||||||||
| import secrets | ||||||||||||||
| import socket | ||||||||||||||
| import string | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
@@ -82,3 +83,23 @@ def dotappend(string: str) -> str: | |||||||||||||
| if not string.endswith("."): | ||||||||||||||
| string += "." | ||||||||||||||
| return string | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def get_k8s_fqdn(name: str) -> str: | ||||||||||||||
| """Resolve the canonical FQDN for a Kubernetes service or pod name.""" | ||||||||||||||
| try: | ||||||||||||||
| info = socket.getaddrinfo( | ||||||||||||||
| name, | ||||||||||||||
| None, | ||||||||||||||
| family=socket.AF_UNSPEC, | ||||||||||||||
| flags=socket.AI_CANONNAME, | ||||||||||||||
| type=socket.SOCK_STREAM, | ||||||||||||||
| ) | ||||||||||||||
| except socket.gaierror as e: | ||||||||||||||
| raise RuntimeError(f"Failed to resolve canonical name for {name}") from e | ||||||||||||||
|
|
||||||||||||||
| for entry in info: | ||||||||||||||
| if canonname := entry[3]: | ||||||||||||||
| return canonname | ||||||||||||||
|
Comment on lines
+101
to
+103
Member
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. I don't sure that logic is robust enough with different DNS engines for kubernetes.
Contributor
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.
Member
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. I think we should add the following function and use it here
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| raise RuntimeError(f"Could not determine canonical name for {name}") | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.