- .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 V1Variable
representing a variable within the Kubernetes API, specifically for the v1
version. It’s likely used in configurations or policy definitions where you need to set up dynamic values.
Here’s a breakdown:
Class Attributes:
openapi_types
: A dictionary mapping attribute names (expression
,name
) to their corresponding data types (str
). This is likely used for serialization/deserialization with the OpenAPI specification.attribute_map
: Another dictionary mapping attribute names to their JSON keys in the API response. This ensures consistency between Python objects and JSON data.Constructor (
__init__
):It takes
expression
,name
, andlocal_vars_configuration
(optional) as arguments.expression
is the CEL expression evaluated to determine the variable’s value.name
is the unique identifier for the variable, accessible within other expressions usingvariables.<name>
.local_vars_configuration
is likely used for configuration options related to client-side validation or other settings.Properties (
expression
andname
):Each attribute has a
@property
decorator, providing a getter and setter.The getters (
expression
andname
) are used to retrieve the values.The setters (
expression
andname
) are used to assign values. They also perform client-side validation by checking if the provided values areNone
.Utility Methods:
to_dict()
: Converts the object into a dictionary representation, suitable for serialization.to_str()
: Converts the object into a string representation usingpprint.pformat
.__repr__()
: Returns a string representation of the object for printing.__eq__()
: Defines equality comparison based on dictionary representation.__ne__()
: Defines inequality comparison based on dictionary representation.
Purpose:
This class likely represents a variable used in Kubernetes configurations or policies. Its purpose is:
- Dynamic Value Management: The variable’s value is determined by the CEL expression.
- Referencing in Other Expressions: The variable can be referenced using its unique name in other CEL expressions within the Kubernetes configuration.
Example Usage:
# Create a V1Variable with an expression and a name
variable = V1Variable(expression="10 + 20", name="my_value")
# Get the value of the variable (this would be evaluated at runtime)
print(variable.expression) # Output: "10 + 20"
# Access the variable in another CEL expression
another_expression = "variables.my_value * 2"
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph