- .github
- devel
- doc
-
examples
-
dynamic-client
-
notebooks
-
watch
-
yaml_dir
- README.md
- __init__.py
- annotate_deployment.py
- api_discovery.py
- apply_from_dict.py
- apply_from_directory.py
- apply_from_single_file.py
- cluster_scoped_custom_object.py
- cronjob_crud.py
- deployment_create.py
- deployment_crud.py
- duration-gep2257.py
- in_cluster_config.py
- ingress_create.py
- job_crud.py
- multiple_clusters.py
- namespaced_custom_object.py
- node_labels.py
- out_of_cluster_config.py
- pick_kube_config_context.py
- pod_config_list.py
- pod_exec.py
- pod_portforward.py
- remote_cluster.py
- rollout-daemonset.py
- rollout-statefulset.py
-
dynamic-client
- kubernetes
- scripts
- .gitignore
- CHANGELOG.md
- CONTRIBUTING.md
- LICENSE
- MANIFEST.in
- OWNERS
- README.md
- SECURITY_CONTACTS
- code-of-conduct.md
- codecov.yml
- requirements.txt
- setup.cfg
- setup.py
- test-requirements.txt
- tox.ini
Explanation
This code defines a custom set of exceptions for interacting with the Kubernetes API using the kubernetes-client
Python library. It provides a way to handle API errors by mapping HTTP status codes to specific exception types.
api_exception
Function:Takes a
kubernetes.client.rest.ApiException
object (which represents an error response from the API).Maps the status code of the exception to a specific custom exception class defined in this file.
Returns an instance of the corresponding custom exception class, providing more context about the error (e.g., HTTP status code, reason, body, and original traceback).
DynamicApiError
Class:The base class for all custom API errors.
Inherits from
kubernetes.client.rest.ApiException
.Stores attributes like status code, reason, body, headers, and the original traceback.
Provides a
__str__
method for generating a detailed error message string.Provides a
summary
method that attempts to extract a meaningful error message from the API response body, falling back to a generic error message if the body isn’t available.Other Exception Classes:
ResourceNotFoundError: Indicates a resource was not found in the available Kubernetes APIs.
ResourceNotUniqueError: Indicates that the provided parameters matched multiple Kubernetes API resources.
KubernetesValidateMissing: Indicates that the
kubernetes-validate
tool is not installed.HTTP Error Classes:
Define specific exception classes for each common HTTP status code (e.g.,
BadRequestError
,UnauthorizedError
,NotFoundError
, etc.).These classes inherit from
DynamicApiError
, providing the same functionality for displaying detailed error messages and summaries.
Overall, this code provides a more refined and specific way to handle errors from the Kubernetes API, making it easier for developers to identify and debug issues during their interactions with the API.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph