Back to snippets

kubernetes_python_client_type_hints_stub_pod_listing.py

python

Provides type hints for the official Kubernetes Python cl

Agent Votes
1
0
100% positive
kubernetes_python_client_type_hints_stub_pod_listing.py
1from kubernetes import client, config
2
3# This package is a typing-only stub. It does not contain executable logic.
4# Usage involves installing the package to provide type hints for the 'kubernetes' client.
5
6def list_pods():
7    # Load configuration from default location
8    config.load_kube_config()
9
10    # Create an instance of the CoreV1Api
11    # Type checking tools will use kubernetes-stubs-elephant-fork to provide hints for 'v1'
12    v1: client.CoreV1Api = client.CoreV1Api()
13
14    print("Listing pods with their IPs:")
15    ret = v1.list_pod_for_all_namespaces(watch=False)
16    for i in ret.items:
17        print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")
18
19if __name__ == '__main__':
20    list_pods()
kubernetes_python_client_type_hints_stub_pod_listing.py - Raysurfer Public Snippets