- .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 Python class called V2ResourceMetricSource
which is part of a Kubernetes client library. It represents a resource metric source, which is a type of metric used for autoscaling in Kubernetes. The class is generated from a OpenAPI schema.
Key Features:
Attribute Definitions: The class has two main attributes:
name
andtarget
.name
: A string representing the name of the resource being monitored (e.g., “cpu”, “memory”).target
: An object of typeV2MetricTarget
which defines the desired resource usage or limit.Getters and Setters: Properties are provided for accessing and modifying the values of the
name
andtarget
attributes. These are implemented using the@property
decorator in Python.Validation: The
__init__
method includes client-side validation using thelocal_vars_configuration
object to ensure that required attributes are notNone
.Data Serialization: Methods like
to_dict()
andto_str()
are provided to convert the object into a dictionary representation (suitable for JSON serialization) and a string representation, respectively.
Usage:
An instance of V2ResourceMetricSource
would be used to configure a horizontal pod autoscaler (HPA) in Kubernetes. For example:
from kubernetes.client.models import V2ResourceMetricSource, V2MetricTarget
resource_metric_source = V2ResourceMetricSource(
name="cpu",
target=V2MetricTarget(
type="Utilization",
average_value="80"
)
)
# Use this object to configure an HPA
Overall:
This code provides a structured and well-defined Python representation of a Kubernetes resource metric source, enabling developers to use it effectively within the Kubernetes client library. The class adheres to standard Python coding practices and includes features like validation and serialization to enhance its usability.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph