Hi all,
Is it possible to listen to port-forward events in a cluster?
I tried to setup a simple watch that should print out any port-forward that gets created via kubectl, but this watch isn’t showing the port-forward I create.
Here’s how I set up the code :
Initialization/creation of client
await config.load_kube_config(config_file="~/.kube/config-auto")
configuration = client.Configuration().get_default_copy()
configuration.verify_ssl = False
my_client = client.ApiClient(configuration)
v1 = client.CoreV1Api(my_client)
The actual watch
while True:
w = watch.Watch()
stream = w.stream(
v1.connect_get_namespaced_pod_portforward,
)
for event in stream:
try:
print(event)
I tried to watch the other port forward resources listed in the core api client:
v1.connect_get_namespaced_pod_portforward_with_http_info,
v1.connect_post_namespaced_pod_portforward,
v1.connect_post_namespaced_pod_portforward_with_http_info
But that didn’t help either.
Am I doing something wrong or is it just not possible to watch for port-forward events?
My idea was if I can watch for port-forward events, then I could create a validating web hook that verifies whether a port-forward is allowed or not.
Thanks!