-
Notifications
You must be signed in to change notification settings - Fork 11
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
[Discovery.KubernetesApi] add option to query pods in all namespaces #2421
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 |
---|---|---|
|
@@ -89,27 +89,17 @@ public override async Task<Resolved> Lookup(Lookup lookup, TimeSpan resolveTimeo | |
var labelSelector = _settings.PodLabelSelector(lookup.ServiceName); | ||
|
||
if(_log.IsInfoEnabled) | ||
_log.Info("Querying for pods with label selector: [{0}]. Namespace: [{1}]. Port: [{2}]", | ||
labelSelector, PodNamespace, lookup.PortName); | ||
_log.Info("Querying for pods with label selector: [{0}]. Namespace: [{1}]. AllNamespaces: [{2}]. Port: [{3}]", | ||
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. LGTM |
||
labelSelector, PodNamespace, _settings.AllNamespaces, lookup.PortName); | ||
|
||
var cts = new CancellationTokenSource(resolveTimeout); | ||
V1PodList podList; | ||
try | ||
{ | ||
#if !NET6_0_OR_GREATER | ||
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. So we moved the ifdefs down into these individual methods - got it |
||
var result = await _client.ListNamespacedPodWithHttpMessagesAsync( | ||
namespaceParameter: PodNamespace, | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token) | ||
.ConfigureAwait(false); | ||
podList = result.Body; | ||
#else | ||
var result = await _client.ListNamespacedPodAsync( | ||
namespaceParameter: PodNamespace, | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token); | ||
podList = result; | ||
#endif | ||
if(_settings.AllNamespaces) | ||
podList = await ListPodForAllNamespaces(labelSelector, cts); | ||
else | ||
podList = await ListNamespacedPod(labelSelector, cts); | ||
} | ||
catch (SerializationException e) | ||
{ | ||
|
@@ -177,7 +167,45 @@ public override async Task<Resolved> Lookup(Lookup lookup, TimeSpan resolveTimeo | |
|
||
return new Resolved(serviceName: lookup.ServiceName, addresses: addresses); | ||
} | ||
|
||
private async Task<V1PodList> ListNamespacedPod(string labelSelector, CancellationTokenSource cts) | ||
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. LGTM - basically what we had before |
||
{ | ||
V1PodList podList; | ||
#if !NET6_0_OR_GREATER | ||
var result = await _client.ListNamespacedPodWithHttpMessagesAsync( | ||
namespaceParameter: PodNamespace, | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token) | ||
.ConfigureAwait(false); | ||
podList = result.Body; | ||
#else | ||
var result = await _client.ListNamespacedPodAsync( | ||
namespaceParameter: PodNamespace, | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token); | ||
podList = result; | ||
#endif | ||
return podList; | ||
} | ||
|
||
private async Task<V1PodList> ListPodForAllNamespaces(string labelSelector, CancellationTokenSource cts) | ||
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. LGTM |
||
{ | ||
V1PodList podList; | ||
#if !NET6_0_OR_GREATER | ||
var result = await _client.ListPodForAllNamespacesWithHttpMessagesAsync( | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token) | ||
.ConfigureAwait(false); | ||
podList = result.Body; | ||
#else | ||
var result = await _client.ListPodForAllNamespacesAsync( | ||
labelSelector: labelSelector, | ||
cancellationToken: cts.Token); | ||
podList = result; | ||
#endif | ||
return podList; | ||
} | ||
|
||
// This uses blocking IO, and so should only be used to read configuration at startup. | ||
private string? ReadConfigVarFromFileSystem(string path, string name) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,11 @@ akka.discovery.kubernetes-api { | |
# Set this value to a specific string to override discovering the namespace using pod-namespace-path. | ||
pod-namespace = "<pod-namespace>" | ||
|
||
# Enable to query pods in all namespaces | ||
# | ||
# If this is set to true, the pod-namespace configuration is ignored. | ||
all-namespaces = true | ||
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. LGTM |
||
|
||
# Domain of the k8s cluster | ||
pod-domain = "cluster.local" | ||
|
||
|
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.
LGTM