Hello @iabudiab. Thank you for your help.
I’ve added the logger, the code looks like this:
import SwiftkubeClient
import Logging
enum ApplicationError: Error {
case configError(String)
}
@main
struct MyCLI {
static func main() async throws {
var logger = Logger(label: String(describing: Self.self))
logger.logLevel = .debug
guard let client = KubernetesClient(logger: logger) else {
throw ApplicationError.configError("Cannot create k8s client")
}
defer {
print("closing client")
try? client.syncShutdown()
}
let ns = try await client.namespaces.list()
print("namespace count: \(ns.items.count)")
let task: SwiftkubeClientTask = try await client.pods.watch(
in: .allNamespaces,
retryStrategy: RetryStrategy(
policy: .maxAttempts(20),
backoff: .exponential(maximumDelay: 60, multiplier: 2.0),
initialDelay: 5.0,
jitter: 0.2
)
)
defer {
print("stopping task")
Task { await task.cancel() }
}
let stream = await task.start()
for try await event in stream {
let eventType = event.type
let name = event.resource.metadata?.name ?? "<unknown>"
print("\(eventType) - \(name)")
}
}
}
With kubectl config use-context cluster-B the output is below (I’ve redacted the IP address and the bearer token):
$ swift run
Building for debugging...
[7/7] Applying MyCLI
Build of product 'MyCLI' complete! (2.18s)
namespace count: 22
2025-10-31T09:54:56-0700 debug MyCLI: [SwiftkubeClient] Staring task for request: KubernetesRequest(url: https://35.205.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0A..., body: nil, deleteOptions: nil)
added - cert-manager-cainjector-5d6d6796fd-mcqdw
added - cert-manager-cf5b598f7-rm7tj
added - cert-manager-webhook-bf48cb58f-n2zd2
added - dragonfly-0
added - dragonfly-1
added - dragonfly-operator-controller-manager-54f8895cd-gh6l5
added - api-5d94b8b6bb-q4g2b
added - api-5d94b8b6bb-q5vcw
added - ingress-nginx-controller-65c58f694f-cj4kq
added - ingress-nginx-controller-65c58f694f-l6pqb
added - ingress-nginx-controller-65c58f694f-llfl5
added - ingress-nginx-controller-65c58f694f-qms5s
added - ingress-nginx-controller-65c58f694f-rbf6t
added - ingress-nginx-controller-65c58f694f-zjt4n
added - istio-ingressgateway-596b5d6874-8pm8r
added - istio-ingressgateway-596b5d6874-ghd4z
added - istiod-9c55c84b6-7j2q6
added - istiod-9c55c84b6-scqdn
2025-10-31T09:54:56-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://35.205.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0A...; resourceVersion: 1761670452064351017, body: nil, deleteOptions: nil) in 5.0 seconds
added - cert-manager-cainjector-5d6d6796fd-mcqdw
added - cert-manager-cf5b598f7-rm7tj
added - cert-manager-webhook-bf48cb58f-n2zd2
added - dragonfly-0
added - dragonfly-1
added - dragonfly-operator-controller-manager-54f8895cd-gh6l5
added - api-5d94b8b6bb-q4g2b
added - api-5d94b8b6bb-q5vcw
added - ingress-nginx-controller-65c58f694f-cj4kq
added - ingress-nginx-controller-65c58f694f-l6pqb
added - ingress-nginx-controller-65c58f694f-llfl5
added - ingress-nginx-controller-65c58f694f-qms5s
added - ingress-nginx-controller-65c58f694f-rbf6t
added - ingress-nginx-controller-65c58f694f-zjt4n
added - istio-ingressgateway-596b5d6874-8pm8r
added - istio-ingressgateway-596b5d6874-ghd4z
added - istiod-9c55c84b6-7j2q6
added - istiod-9c55c84b6-scqdn
2025-10-31T09:55:02-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://35.205.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0A...; resourceVersion: 1761670452064351017, body: nil, deleteOptions: nil) in 8.759008070837114 seconds
added - cert-manager-cainjector-5d6d6796fd-mcqdw
added - cert-manager-cf5b598f7-rm7tj
added - cert-manager-webhook-bf48cb58f-n2zd2
added - dragonfly-0
added - dragonfly-1
added - dragonfly-operator-controller-manager-54f8895cd-gh6l5
added - api-5d94b8b6bb-q4g2b
added - api-5d94b8b6bb-q5vcw
added - ingress-nginx-controller-65c58f694f-cj4kq
added - ingress-nginx-controller-65c58f694f-l6pqb
added - ingress-nginx-controller-65c58f694f-llfl5
added - ingress-nginx-controller-65c58f694f-qms5s
added - ingress-nginx-controller-65c58f694f-rbf6t
added - ingress-nginx-controller-65c58f694f-zjt4n
added - istio-ingressgateway-596b5d6874-8pm8r
added - istio-ingressgateway-596b5d6874-ghd4z
added - istiod-9c55c84b6-7j2q6
added - istiod-9c55c84b6-scqdn
2025-10-31T09:55:11-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://35.205.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0A...; resourceVersion: 1761670452064351017, body: nil, deleteOptions: nil) in 16.096752070899832 seconds
added - cert-manager-cainjector-5d6d6796fd-mcqdw
added - cert-manager-cf5b598f7-rm7tj
added - cert-manager-webhook-bf48cb58f-n2zd2
added - dragonfly-0
added - dragonfly-1
added - dragonfly-operator-controller-manager-54f8895cd-gh6l5
added - api-5d94b8b6bb-q4g2b
added - api-5d94b8b6bb-q5vcw
added - ingress-nginx-controller-65c58f694f-cj4kq
added - ingress-nginx-controller-65c58f694f-l6pqb
added - ingress-nginx-controller-65c58f694f-llfl5
added - ingress-nginx-controller-65c58f694f-qms5s
added - ingress-nginx-controller-65c58f694f-rbf6t
added - ingress-nginx-controller-65c58f694f-zjt4n
added - istio-ingressgateway-596b5d6874-8pm8r
added - istio-ingressgateway-596b5d6874-ghd4z
added - istiod-9c55c84b6-7j2q6
added - istiod-9c55c84b6-scqdn
2025-10-31T09:55:28-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://35.205.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0A...; resourceVersion: 1761670452064351017, body: nil, deleteOptions: nil) in 39.58572010879237 seconds
I am also noticing now that in the code we are asking to watch all pods across all namespaces. There are over 100 pods running in the cluster but the output above shows only 18 pods.
With kubectl config use-context cluster-A:
$ swift run
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build of product 'MyCLI' complete! (0.21s)
namespace count: 15
2025-10-31T10:01:54-0700 debug MyCLI: [SwiftkubeClient] Staring task for request: KubernetesRequest(url: https://34.82.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0AT..., body: nil, deleteOptions: nil)
2025-10-31T10:01:54-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://34.82.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0AT..., body: nil, deleteOptions: nil) in 5.0 seconds
2025-10-31T10:02:00-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://34.82.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0AT..., body: nil, deleteOptions: nil) in 10.78624777718268 seconds
2025-10-31T10:02:10-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://34.82.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0AT..., body: nil, deleteOptions: nil) in 17.290774437504712 seconds
2025-10-31T10:02:29-0700 debug MyCLI: [SwiftkubeClient] Will retry request: KubernetesRequest(url: https://34.82.xxx.xxx/api/v1/pods?watch=true, method: NIOHTTP1.HTTPMethod.GET, headers: Authorization: Bearer ya29.a0AT..., body: nil, deleteOptions: nil) in 43.502495158084876 seconds