kubex.api¶
Auto-generated reference for the kubex.api module. Private descriptors (e.g. _LogsDescriptor) are excluded; they exist to wire the subresource accessors onto Api[T] and are not part of the public API.
Api class¶
kubex.api.api ¶
Api ¶
Api(
resource_type: Type[ResourceType],
client: BaseClient,
*,
namespace: ApiNamespaceTypes = Ellipsis,
)
Bases: Generic[ResourceType]
API for interacting with a Kubernetes resource type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_type
|
Type[ResourceType]
|
The resource model class to operate on, e.g. |
required |
client
|
BaseClient
|
The client used to send requests. |
required |
namespace
|
ApiNamespaceTypes
|
The default namespace for this API's calls; each method can
override it. If omitted, a namespace-scoped resource uses the client's
configured namespace (the kubeconfig context's namespace, or the pod's
own namespace in-cluster). Pass |
Ellipsis
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in kubex/api/api.py
create
async
¶
create(
data: ResourceType,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Create a resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ResourceType
|
The resource instance to create. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace to create the resource in. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the created resource instance, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace that is missing for
a namespace-scoped resource or given for a cluster-scoped one, or an
unknown option value (e.g. for |
Conflict
|
a resource with this name already exists. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
delete
async
¶
delete(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
grace_period_seconds: int | None = None,
propagation_policy: PropagationPolicyTypes = None,
preconditions: Precondition | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Status | ResourceType
Delete the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to delete. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to delete. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without deleting anything ( |
None
|
grace_period_seconds
|
int | None
|
The duration in seconds before the object should be
deleted, overriding its default grace period. |
None
|
propagation_policy
|
PropagationPolicyTypes
|
Whether and how dependents are garbage collected:
|
None
|
preconditions
|
Precondition | None
|
Conditions the object must meet to be deleted
( |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Status |
Status | ResourceType
|
the resource has been fully deleted. |
ResourceType |
Status | ResourceType
|
deletion has started, but the resource still exists (e.g.
it has finalizers or a termination grace period); the returned
object has |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
|
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
delete_collection
async
¶
delete_collection(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
dry_run: DryRunTypes = None,
grace_period_seconds: int | None = None,
propagation_policy: PropagationPolicyTypes = None,
preconditions: Precondition | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Status | ListEntity[ResourceType]
Delete collection of resources.
Deletes every resource matching the filters in a single call. Without
any selector, that is every resource of this type in the namespace (or,
with namespace=None, in all namespaces).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace to delete resources in. If not provided,
the namespace provided when creating the API will be used.
Pass |
Ellipsis
|
label_selector
|
str | None
|
Only delete resources whose labels match this selector. For details look at Label Selectors documentation. |
None
|
field_selector
|
str | None
|
Only delete resources whose fields match this selector. For details look at Field Selectors documentation. |
None
|
timeout_seconds
|
int | None
|
Server-side timeout (in seconds) for the call;
sent as the Kubernetes |
None
|
limit
|
int | None
|
Sent as the Kubernetes |
None
|
continue_token
|
str | None
|
Sent as the Kubernetes |
None
|
version_match
|
VersionMatchTypes
|
How the API server should interpret |
None
|
resource_version
|
ResourceVersionTypes
|
The resource version at which to select the resources,
as in |
None
|
dry_run
|
DryRunTypes
|
Validate the request without deleting anything ( |
None
|
grace_period_seconds
|
int | None
|
The duration in seconds before each object should be
deleted, overriding its default grace period. |
None
|
propagation_policy
|
PropagationPolicyTypes
|
Whether and how dependents are garbage collected:
|
None
|
preconditions
|
Precondition | None
|
Conditions each object must meet to be deleted
( |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Status |
Status | ListEntity[ResourceType]
|
the API server reported the result as a |
Status | ListEntity[ResourceType]
|
ListEntity[ResourceType]: the API server returned the list of deleted resources instead; which of the two you get depends on the Kubernetes version. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace given for a
cluster-scoped resource, or an unknown option value (e.g. for
|
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Read the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
resource_version
|
ResourceVersionTypes
|
The resource version to read. If not provided, the current resource version will be read. For details look at Resource Version Semantics documentation. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the resource instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
list
async
¶
list(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: Literal[RAISE, "raise"] = InvalidObjects.RAISE,
) -> ListEntity[ResourceType]
list(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: Literal[INCLUDE, "include"],
) -> ListWithInvalid[ResourceType]
list(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: InvalidObjectsTypes,
) -> ListEntity[ResourceType]
list(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: InvalidObjectsTypes = InvalidObjects.RAISE,
) -> ListEntity[ResourceType]
List objects of kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to list. If not provided,
the namespace provided when creating the API will be used.
Pass |
Ellipsis
|
label_selector
|
str | None
|
A selector to restrict the list of returned objects by their labels. For details look at Label Selectors documentation. |
None
|
field_selector
|
str | None
|
A selector to restrict the list of returned objects by their fields. For details look at Field Selectors documentation. |
None
|
timeout_seconds
|
int | None
|
Server-side timeout (in seconds) for the list/watch call;
sent as the Kubernetes |
None
|
limit
|
int | None
|
The maximum number of items to return. If more items match, the
returned list's |
None
|
continue_token
|
str | None
|
The |
None
|
version_match
|
VersionMatchTypes
|
How the API server should interpret |
None
|
resource_version
|
ResourceVersionTypes
|
The resource version to list. If not provided, the current resource version will be listed. For details look at Resource Version Semantics documentation. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
invalid
|
InvalidObjectsTypes
|
What to do with an object that does not fit the model.
|
RAISE
|
Returns:
| Type | Description |
|---|---|
ListEntity[ResourceType]
|
ListEntity[ResourceType]: the list of resources, with the list's
|
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace given for a
cluster-scoped resource, or an unknown option value (e.g. for
|
ValidationError
|
an object does not fit the model (unless
|
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Patch the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to patch. |
required |
patch
|
Patch
|
The patch to send: |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to patch. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the patched resource. An |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist (an |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
replace
async
¶
replace(
name: str,
data: ResourceType,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Replace the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to replace. |
required |
data
|
ResourceType
|
The complete new state of the resource. If its
|
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to replace. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the replaced resource, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
the resource has changed since the
|
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
watch
async
¶
watch(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
allow_bookmarks: bool | None = None,
send_initial_events: bool | None = None,
resource_version: ResourceVersionTypes = None,
timeout_seconds: int | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: Literal[RAISE, "raise"] = InvalidObjects.RAISE,
) -> AsyncGenerator[WatchEvent[ResourceType], None]
watch(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
allow_bookmarks: bool | None = None,
send_initial_events: bool | None = None,
resource_version: ResourceVersionTypes = None,
timeout_seconds: int | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: Literal[INCLUDE, "include"],
) -> AsyncGenerator[
WatchEvent[ResourceType] | InvalidWatchEvent, None
]
watch(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
allow_bookmarks: bool | None = None,
send_initial_events: bool | None = None,
resource_version: ResourceVersionTypes = None,
timeout_seconds: int | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: InvalidObjectsTypes,
) -> AsyncGenerator[
WatchEvent[ResourceType] | InvalidWatchEvent, None
]
watch(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
allow_bookmarks: bool | None = None,
send_initial_events: bool | None = None,
resource_version: ResourceVersionTypes = None,
timeout_seconds: int | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
invalid: InvalidObjectsTypes = InvalidObjects.RAISE,
) -> AsyncGenerator[
WatchEvent[ResourceType] | InvalidWatchEvent, None
]
Watch for changes to the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace to watch. If not provided,
the namespace provided when creating the API will be used.
Pass |
Ellipsis
|
label_selector
|
str | None
|
Only watch resources whose labels match this selector. For details look at Label Selectors documentation. |
None
|
field_selector
|
str | None
|
Only watch resources whose fields match this selector. For details look at Field Selectors documentation. |
None
|
allow_bookmarks
|
bool | None
|
Request periodic |
None
|
send_initial_events
|
bool | None
|
Start the stream with synthetic |
None
|
resource_version
|
ResourceVersionTypes
|
Only deliver changes made after this resource version,
e.g. the list |
None
|
timeout_seconds
|
int | None
|
Server-side timeout (in seconds); the server ends the stream cleanly after it. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
invalid
|
InvalidObjectsTypes
|
What to do with an |
RAISE
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[WatchEvent[ResourceType] | InvalidWatchEvent, None]
|
WatchEvent[ResourceType]: one event per change, with its |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace given for a
cluster-scoped resource, or |
ValidationError
|
an object does not fit the model (unless
|
Gone
|
the requested |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached, or the connection broke mid-stream. |
KubexTimeoutError
|
the request timed out on the client side, including mid-stream. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/api.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
create_api
async
¶
create_api(
resource_type: Type[ResourceType],
*,
client: BaseClient | None = None,
namespace: ApiNamespaceTypes = Ellipsis,
) -> Api[ResourceType]
Create an API for the specified resource type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_type
|
Type[ResourceType]
|
The resource type to create an API for. |
required |
client
|
BaseClient | None
|
The client to use for the API. If not provided, a new client will be created. |
None
|
namespace
|
ApiNamespaceTypes
|
The namespace to use for the API. If set all
operations will be performed in this namespace.
The Api namespace can be overridden by passing a
namespace to the individual methods. If omitted, a
namespace-scoped resource falls back to the client's
configured namespace (e.g. the in-cluster pod's own
namespace); pass |
Ellipsis
|
Returns:
| Type | Description |
|---|---|
Api[ResourceType]
|
An Api instance for the specified resource type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ConfigurationError
|
no |
ImportError
|
no |
Source code in kubex/api/api.py
Logs subresource¶
kubex.api._logs ¶
LogsAccessor ¶
LogsAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: Generic[ResourceType]
Accessor for logs subresource operations.
Source code in kubex/api/_logs.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
container: str | None = None,
limit_bytes: int | None = None,
pretty: bool | None = None,
previous: bool | None = None,
since_seconds: int | None = None,
since_time: datetime | None = None,
tail_lines: int | None = None,
timestamps: bool | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> str
Read logs of the specified resource.
since_seconds and since_time (a timezone-aware datetime, sent as
an RFC 3339 UTC sinceTime) are mutually exclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read logs of. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
container
|
str | None
|
The container to read logs of. Required when the Pod has more than one container; the API server rejects the request otherwise. |
None
|
limit_bytes
|
int | None
|
The maximum number of bytes of log output to return. |
None
|
pretty
|
bool | None
|
Ask the API server to pretty-print the output. |
None
|
previous
|
bool | None
|
Return logs of the previous, terminated instance of the container (e.g. after a crash). |
None
|
since_seconds
|
int | None
|
Only return logs newer than this many seconds. |
None
|
since_time
|
datetime | None
|
Only return logs newer than this timezone-aware instant.
A naive datetime raises |
None
|
tail_lines
|
int | None
|
Only return this many lines from the end of the log. |
None
|
timestamps
|
bool | None
|
Prefix each line with its RFC 3339 timestamp. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the log output, decoded as text. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
BadRequest
|
the API server rejected the arguments, e.g. |
NotFound
|
the pod does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_logs.py
stream
async
¶
stream(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
container: str | None = None,
limit_bytes: int | None = None,
pretty: bool | None = None,
previous: bool | None = None,
since_seconds: int | None = None,
since_time: datetime | None = None,
tail_lines: int | None = None,
timestamps: bool | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncGenerator[str, None]
Stream logs of the specified resource.
Follows the log (follow=true): the stream continues until the
container exits or the caller stops iterating. since_seconds and
since_time (a timezone-aware datetime, sent as an RFC 3339 UTC
sinceTime) are mutually exclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to stream logs of. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
container
|
str | None
|
The container to stream logs of. Required when the Pod has more than one container; the API server rejects the request otherwise. |
None
|
limit_bytes
|
int | None
|
The maximum number of bytes of log output to return. |
None
|
pretty
|
bool | None
|
Ask the API server to pretty-print the output. |
None
|
previous
|
bool | None
|
Return logs of the previous, terminated instance of the container (e.g. after a crash). |
None
|
since_seconds
|
int | None
|
Only return logs newer than this many seconds. |
None
|
since_time
|
datetime | None
|
Only return logs newer than this timezone-aware instant,
e.g. the timestamp of the last line processed before a reconnect.
A naive datetime raises |
None
|
tail_lines
|
int | None
|
Start with only this many lines from the end of the log. |
None
|
timestamps
|
bool | None
|
Prefix each line with its RFC 3339 timestamp. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Yields:
| Name | Type | Description |
|---|---|---|
str |
AsyncGenerator[str, None]
|
one log line at a time, without the trailing newline. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
BadRequest
|
the API server rejected the arguments, e.g. |
NotFound
|
the pod does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached, or the connection broke mid-stream. |
KubexTimeoutError
|
the request timed out on the client side, including mid-stream. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_logs.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
Scale subresource¶
kubex.api._scale ¶
ScaleAccessor ¶
ScaleAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: Generic[ResourceType]
Accessor for scale subresource operations.
Source code in kubex/api/_scale.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Scale
Read the scale of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Scale |
Scale
|
the resource's scale: |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_scale.py
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Scale
Patch the scale of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose scale to patch. |
required |
patch
|
Patch
|
The patch to send: |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Scale |
Scale
|
the scale after the patch. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_scale.py
replace
async
¶
replace(
name: str,
scale: Scale,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Scale
Replace the scale of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose scale to replace. |
required |
scale
|
Scale
|
The new scale, usually the |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Scale |
Scale
|
the updated scale. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
the resource has changed since the |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_scale.py
Status subresource¶
StatusAccessor.get/replace/patch are inherited from ResourceSubresourceAccessor
(shared with ResizeAccessor and EphemeralContainersAccessor), hence inherited_members below.
kubex.api._status ¶
StatusAccessor ¶
StatusAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: ResourceSubresourceAccessor[ResourceType]
Accessor for status subresource operations.
Source code in kubex/api/_subresource_accessor.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Read this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource, as returned by the subresource endpoint. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Patch this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to patch. |
required |
patch
|
Patch
|
The patch to send: |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the patch, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
replace
async
¶
replace(
name: str,
data: ResourceType,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Replace this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to replace. |
required |
data
|
ResourceType
|
The resource carrying the new subresource content. The API server
only persists the part this subresource covers (e.g. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the update, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
the resource has changed since the |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
Eviction subresource¶
kubex.api._eviction ¶
EvictionAccessor ¶
EvictionAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: Generic[ResourceType]
Accessor for eviction subresource operations.
Source code in kubex/api/_eviction.py
create
async
¶
create(
name: str,
eviction: Eviction,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> Status
Create an eviction for the specified resource.
Evicts the pod gracefully while respecting its PodDisruptionBudgets, the
mechanism behind kubectl drain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the pod to evict. |
required |
eviction
|
Eviction
|
The |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the pod to evict. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without evicting anything ( |
None
|
field_manager
|
str | None
|
Sent as the Kubernetes |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
Status |
Status
|
the API server's response once the eviction is accepted. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the pod does not exist. |
TooManyRequests
|
the eviction would violate a PodDisruptionBudget
(HTTP 429). Retry later; |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_eviction.py
Ephemeral containers subresource¶
kubex.api._ephemeral_containers ¶
EphemeralContainersAccessor ¶
EphemeralContainersAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: ResourceSubresourceAccessor[ResourceType]
Accessor for ephemeral containers subresource operations.
Source code in kubex/api/_subresource_accessor.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Read this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource, as returned by the subresource endpoint. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Patch this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to patch. |
required |
patch
|
Patch
|
The patch to send: |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the patch, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
replace
async
¶
replace(
name: str,
data: ResourceType,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Replace this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to replace. |
required |
data
|
ResourceType
|
The resource carrying the new subresource content. The API server
only persists the part this subresource covers (e.g. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the update, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
the resource has changed since the |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
Resize subresource¶
kubex.api._resize ¶
ResizeAccessor ¶
ResizeAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: ResourceSubresourceAccessor[ResourceType]
Accessor for resize subresource operations.
Source code in kubex/api/_subresource_accessor.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Read this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource, as returned by the subresource endpoint. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Patch this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to patch. |
required |
patch
|
Patch
|
The patch to send: |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the patch, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
replace
async
¶
replace(
name: str,
data: ResourceType,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ResourceType
Replace this subresource of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource whose subresource to replace. |
required |
data
|
ResourceType
|
The resource carrying the new subresource content. The API server
only persists the part this subresource covers (e.g. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ResourceType |
ResourceType
|
the full resource after the update, as stored by the API server. |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
Conflict
|
the resource has changed since the |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_subresource_accessor.py
Exec subresource¶
kubex.api._exec ¶
ExecAccessor ¶
ExecAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
channel_protocols: tuple[
ChannelProtocol, ...
] = DEFAULT_PROTOCOLS,
)
Bases: Generic[ResourceType]
Accessor for the Pod exec subresource.
.. warning::
Experimental. The WebSocket-based subresources (exec,
attach, portforward) are still under active development and
their API may change in future releases without notice.
Source code in kubex/api/_exec.py
run
async
¶
run(
name: str,
*,
command: Sequence[str],
container: str | None = None,
namespace: ApiNamespaceTypes = Ellipsis,
stdin: bytes | None = None,
stdout: bool = True,
stderr: bool = True,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ExecResult
Run a command and collect stdout/stderr until the channel closes.
.. warning::
Experimental. This WebSocket-based API is still under active development and may change in future releases without notice.
Unlike :meth:stream, the request_timeout bound (when provided)
applies to both the handshake (via the per-call HTTP timeout
propagated to the WebSocket upgrade) and the post-handshake command
execution + status collection (via a separate wall-clock cancel scope
that does not envelope teardown — see below). The wall-clock bound is
derived from Timeout.total if set, otherwise Timeout.read
(read's strict per-byte-inactivity semantics do not map cleanly onto
a long-lived WebSocket session, so it is treated as a call-level
upper bound here as a pragmatic approximation that prevents
indefinite hangs). Ellipsis defers to the client default for the
handshake without imposing an additional wall-clock bound; an
explicit None disables timeouts entirely.
stdin is sent in frames of at most 32 KiB and then half-closed. A
failure while sending it (e.g. the command exited without reading
all of it) is logged, not raised: the result reflects what the
server reported. Use :meth:ExecResult.raise_for_status to turn a
non-successful status into an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the Pod to run the command in. |
required |
command
|
Sequence[str]
|
The command and its arguments, e.g. |
required |
container
|
str | None
|
The container to run the command in. Required when the Pod has more than one container. |
None
|
namespace
|
ApiNamespaceTypes
|
The namespace of the Pod. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
stdin
|
bytes | None
|
Bytes to send to the command's stdin, which is then closed.
|
None
|
stdout
|
bool
|
Capture stdout. |
True
|
stderr
|
bool
|
Capture stderr. |
True
|
request_timeout
|
ApiRequestTimeoutTypes
|
Timeout override for this call, bounding both the
handshake and the command's run; see above. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
ExecResult |
ExecResult
|
the captured |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
TypeError
|
|
KubexApiError
|
the WebSocket handshake was rejected; the subclass matches
the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the WebSocket handshake or the command did not finish
within |
KubexClientException
|
the WebSocket handshake failed for another reason, or the connection closed abnormally. |
ConfigurationError
|
credentials could not be obtained, or the httpx
client is used without the |
Source code in kubex/api/_exec.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
stream
async
¶
stream(
name: str,
*,
command: Sequence[str],
container: str | None = None,
namespace: ApiNamespaceTypes = Ellipsis,
stdin: bool = False,
stdout: bool = True,
stderr: bool = True,
tty: bool = False,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncIterator[StreamSession]
Open a bidirectional exec session as an async context manager.
.. warning::
Experimental. This WebSocket-based API is still under active development and may change in future releases without notice.
Output is never dropped: a channel whose consumer falls behind pauses
the whole session (backpressure). Drain every enabled output channel
concurrently, or disable the ones you don't need (e.g.
stderr=False).
Leaving the async with block closes the session, even while the
command is still running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the Pod to run the command in. |
required |
command
|
Sequence[str]
|
The command and its arguments, e.g. |
required |
container
|
str | None
|
The container to run the command in. Required when the Pod has more than one container. |
None
|
namespace
|
ApiNamespaceTypes
|
The namespace of the Pod. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
stdin
|
bool
|
Open the stdin channel, for writing with |
False
|
stdout
|
bool
|
Open the stdout channel. |
True
|
stderr
|
bool
|
Open the stderr channel. Ignored with |
True
|
tty
|
bool
|
Allocate a pseudo-terminal. The kubelet then merges stderr into
stdout, so |
False
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for the WebSocket
handshake. A number is interpreted as the total timeout in
seconds. Pass |
Ellipsis
|
Yields:
| Name | Type | Description |
|---|---|---|
StreamSession |
AsyncIterator[StreamSession]
|
the open session, with |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
TypeError
|
|
KubexApiError
|
the WebSocket handshake was rejected; the subclass matches
the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the WebSocket handshake timed out. |
KubexClientException
|
the WebSocket handshake failed for another reason, or the connection closed abnormally. |
ConfigurationError
|
credentials could not be obtained, or the httpx
client is used without the |
Source code in kubex/api/_exec.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
ExecError ¶
Bases: KubexClientException
Raised by :meth:ExecResult.raise_for_status when a command did not succeed.
The message is the server's Status.message when there is one; the full
result (output, status, exit_code) is available as result.
Source code in kubex/api/_exec.py
ExecResult
dataclass
¶
Result of a one-shot ExecAccessor.run call.
exit_code
property
¶
Parse the exit code from status.
Returns 0 for a Success status, the integer parsed from
status.details.causes (where reason == "ExitCode") for a
non-zero exit, or None when status is missing or carries no
recognisable exit information. Note that None does not imply
success — for failures without a recognisable exit code (e.g. the
container could not start), inspect status directly, or call
:meth:raise_for_status.
raise_for_status ¶
Raise :class:ExecError unless the command reported Success.
Covers non-zero exits as well as failures without an exit code (e.g.
the binary does not exist) and a missing status. Returns self so
it can be chained: (await api.exec.run(...)).raise_for_status().
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
this result, unchanged, when the status is |
Raises:
| Type | Description |
|---|---|
ExecError
|
the status is missing or is not |
Source code in kubex/api/_exec.py
Attach subresource¶
kubex.api._attach ¶
AttachAccessor ¶
AttachAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
*,
channel_protocols: tuple[
ChannelProtocol, ...
] = DEFAULT_PROTOCOLS,
)
Bases: Generic[ResourceType]
Accessor for the Pod attach subresource.
.. warning::
Experimental. The WebSocket-based subresources (exec,
attach, portforward) are still under active development and
their API may change in future releases without notice.
Source code in kubex/api/_attach.py
stream
async
¶
stream(
name: str,
*,
container: str | None = None,
namespace: ApiNamespaceTypes = Ellipsis,
stdin: bool = False,
stdout: bool = True,
stderr: bool = True,
tty: bool = False,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncIterator[StreamSession]
Open a bidirectional attach session as an async context manager.
.. warning::
Experimental. This WebSocket-based API is still under active development and may change in future releases without notice.
Output is never dropped: a channel whose consumer falls behind pauses
the whole session (backpressure). Drain every enabled output channel
concurrently, or disable the ones you don't need (e.g.
stderr=False).
Attaches to the container's existing main process; no new command is
started. Leaving the async with block closes the session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the Pod to attach to. |
required |
container
|
str | None
|
The container to attach to. Required when the Pod has more than one container. |
None
|
namespace
|
ApiNamespaceTypes
|
The namespace of the Pod. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
stdin
|
bool
|
Attach to the process's stdin, for writing with |
False
|
stdout
|
bool
|
Attach to the process's stdout. |
True
|
stderr
|
bool
|
Attach to the process's stderr. Ignored with |
True
|
tty
|
bool
|
Attach as a terminal. The kubelet then merges stderr into stdout,
so |
False
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for the WebSocket
handshake. A number is interpreted as the total timeout in
seconds. Pass |
Ellipsis
|
Yields:
| Name | Type | Description |
|---|---|---|
StreamSession |
AsyncIterator[StreamSession]
|
the open session, with |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
KubexApiError
|
the WebSocket handshake was rejected; the subclass matches
the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the WebSocket handshake timed out. |
KubexClientException
|
the WebSocket handshake failed for another reason, or the connection closed abnormally. |
ConfigurationError
|
credentials could not be obtained, or the httpx
client is used without the |
Source code in kubex/api/_attach.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
Portforward subresource¶
kubex.api._portforward ¶
PortForwardStream ¶
PortForwardStream(
session: PortForwardSession,
port: int,
data_channel_id: int,
recv_stream: MemoryObjectReceiveStream[bytes],
)
Bases: ByteStream
Per-port bidirectional byte stream for the Kubernetes portforward subresource.
Wraps a PortForwardSession's data channel for a single port and implements
anyio.abc.ByteStream so it integrates naturally with anyio byte-stream consumers.
Outbound send() encodes the payload as a channel frame addressed to the
port's data channel. Inbound receive() reads from the session's per-port
memory stream, buffering excess bytes to satisfy max_bytes slicing.
aclose() half-closes the data channel (idempotent via the underlying
session helper) and prevents further send() calls. send_eof()
performs the same half-close without locking out receives. On the v4
portforward subprotocol — which the kubelet requires — half-close is a
local-only state change; the kubelet ignores wire CHANNEL_CLOSE frames
on v4 and tears down the channel only when the session WebSocket closes.
Source code in kubex/api/_portforward.py
aclose
async
¶
Close both directions of the stream.
The sending side is closed as by send_eof(). On the receiving side,
receive() raises anyio.EndOfStream once any bytes left over from a
partly read frame are returned, and data that arrives for this port
afterwards is discarded, so an unread port no longer stalls the others.
The session and its other ports stay open.
Source code in kubex/api/_portforward.py
receive
async
¶
Receive bytes from the remote port, waiting until some arrive.
A frame larger than max_bytes is returned over several calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_bytes
|
int
|
The maximum number of bytes to return. |
65536
|
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
between 1 and |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
EndOfStream
|
no more data will arrive: the kubelet closed the
port's data channel, the session ended, or this stream was closed
with |
Source code in kubex/api/_portforward.py
send
async
¶
Send item to the remote port, split into frames of at most 32 KiB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
bytes
|
The bytes to send. |
required |
Raises:
| Type | Description |
|---|---|
ClosedResourceError
|
|
KubexClientException
|
the session has already ended. |
Source code in kubex/api/_portforward.py
send_eof
async
¶
Close the sending side of the stream; receive() keeps working.
Later send() calls raise anyio.ClosedResourceError; calling this
again is a no-op. On the v4 portforward protocol (the only one the
kubelet supports) nothing is sent on the wire: the pod is not told about
the EOF and only sees the connection end when the session's WebSocket
closes.
Source code in kubex/api/_portforward.py
PortForwarder ¶
Holds an active portforward session and exposes per-port streams and errors.
streams[port] is a PortForwardStream (anyio.abc.ByteStream) for
sending and receiving raw bytes to/from the remote port.
errors[port] is an async iterator of error-text strings sent by the kubelet
on the error channel for that port.
All ports share one WebSocket and inbound data is never dropped: a port
whose stream (or error iterator) is not read stalls every port once its
queue is full. Read each forwarded port, or aclose() its stream.
Source code in kubex/api/_portforward.py
errors
property
¶
Per-port async iterators of kubelet error messages, keyed by remote port.
port_data_truncated
property
¶
Deprecated: always False for every port (data is no longer dropped).
port_error_truncated
property
¶
Deprecated: always False for every port (errors are no longer dropped).
streams
property
¶
Per-port byte streams (PortForwardStream), keyed by remote port.
PortforwardAccessor ¶
PortforwardAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
channel_protocols: tuple[
ChannelProtocol, ...
] = PORTFORWARD_PROTOCOLS,
)
Bases: Generic[ResourceType]
Accessor for the Pod portforward subresource.
.. warning::
Experimental. The WebSocket-based subresources (exec,
attach, portforward) are still under active development and
their API may change in future releases without notice.
Source code in kubex/api/_portforward.py
forward
async
¶
forward(
name: str,
*,
ports: Sequence[int],
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncIterator[PortForwarder]
Open portforward streams to the given ports as an async context manager.
.. warning::
Experimental. This WebSocket-based API is still under active development and may change in future releases without notice.
This is the low-level entry point: a single WebSocket multiplexes
all requested ports, and the caller drives I/O directly in Python via
per-port anyio.abc.ByteStream objects. No sockets are bound on the
host — bytes never leave the process. Use this when your own code
speaks to the pod (custom protocols, embedded clients, tests).
For the kubectl-style mode where external processes connect through
a real local TCP port, use :meth:listen instead (which is built on
top of this method).
Inbound data is never dropped; since the ports share one WebSocket, a
port that is not read stalls all ports once its queue fills. Read
every forwarded port (or aclose() the ones you don't need).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the pod. |
required |
ports
|
Sequence[int]
|
The pod ports to forward: 1 to 127 unique ports in 1..65535.
Each becomes a key of |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the pod. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for the WebSocket
handshake. A number is interpreted as the total timeout in
seconds. Pass |
Ellipsis
|
Yields:
| Name | Type | Description |
|---|---|---|
PortForwarder |
AsyncIterator[PortForwarder]
|
the per-port byte streams ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
TypeError
|
a port is not an |
KubexApiError
|
the WebSocket handshake was rejected; the subclass matches
the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the WebSocket handshake timed out. |
KubexClientException
|
the WebSocket handshake failed for another reason, or the connection closed abnormally. |
ConfigurationError
|
credentials could not be obtained, or the httpx
client is used without the |
Source code in kubex/api/_portforward.py
listen
async
¶
listen(
name: str,
*,
port_map: Mapping[int, int],
local_host: str = "127.0.0.1",
namespace: ApiNamespaceTypes = Ellipsis,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncIterator[None]
Open local TCP listeners and forward bytes bidirectionally to remote ports.
.. warning::
Experimental. This WebSocket-based API is still under active development and may change in future releases without notice.
This is the high-level, kubectl-style entry point: real OS sockets
are bound on local_host:local_port so that any process on the host
(curl, psql, a browser, …) can connect to the pod through a
local port. Each accepted local connection opens its own portforward
WebSocket session bound to that single remote port — one session per
connection, matching kubectl port-forward semantics. The method
itself yields None; you don't drive I/O through it.
For the low-level mode where your own Python code reads/writes bytes
directly without binding any sockets, use :meth:forward instead
(which this method is built on top of).
When the remote side finishes (or the kubelet reports an error), the
local connection is closed; a local half-close (EOF) keeps the
connection open until the remote response is complete. The v4
protocol cannot pass that EOF to the pod, so after a local client
disconnects its connection stays open until the pod closes it or
sends more data. Failures on individual connections (including a
rejected WebSocket handshake) are logged to the kubex.portforward
logger rather than raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the pod. |
required |
port_map
|
Mapping[int, int]
|
Maps each remote port (on the pod) to the local port
to listen on. Example: |
required |
local_host
|
str
|
The local address the listeners bind to. The default,
|
'127.0.0.1'
|
namespace
|
ApiNamespaceTypes
|
The namespace of the pod. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for the WebSocket
handshake of each accepted connection. A number is interpreted as
the total timeout in seconds. Pass |
Ellipsis
|
Yields:
| Name | Type | Description |
|---|---|---|
None |
AsyncIterator[None]
|
the listeners stay open while the |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
a port is not an |
Source code in kubex/api/_portforward.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
Metadata accessor¶
kubex.api._metadata ¶
MetadataAccessor ¶
MetadataAccessor(
client: BaseClient,
request_builder: RequestBuilder,
namespace: NamespaceTypes,
scope: Scope,
resource_type: Type[ResourceType],
)
Bases: Generic[ResourceType]
Accessor for metadata subresource operations.
Source code in kubex/api/_metadata.py
get
async
¶
get(
name: str,
*,
namespace: ApiNamespaceTypes = Ellipsis,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> PartialObjectMetadata
Read metadata of the specified resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to read. |
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to read. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
resource_version
|
ResourceVersionTypes
|
The resource version to read. If not provided, the current resource version will be read. For details look at Resource Version Semantics documentation. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
PartialObjectMetadata |
PartialObjectMetadata
|
the resource's |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist. |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_metadata.py
list
async
¶
list(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
timeout_seconds: int | None = None,
limit: int | None = None,
continue_token: str | None = None,
version_match: VersionMatchTypes = None,
resource_version: ResourceVersionTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> ListEntity[PartialObjectMetadata]
List metadata of resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resources to list. If not provided,
the namespace provided when creating the API will be used.
Pass |
Ellipsis
|
label_selector
|
str | None
|
A selector to restrict the list of returned objects by their labels. For details look at Label Selectors documentation. |
None
|
field_selector
|
str | None
|
A selector to restrict the list of returned objects by their fields. For details look at Field Selectors documentation. |
None
|
timeout_seconds
|
int | None
|
Server-side timeout (in seconds) for the list/watch call;
sent as the Kubernetes |
None
|
limit
|
int | None
|
The maximum number of items to return. If more items match, the
returned list's |
None
|
continue_token
|
str | None
|
The |
None
|
version_match
|
VersionMatchTypes
|
How the API server should interpret |
None
|
resource_version
|
ResourceVersionTypes
|
The resource version to list. If not provided, the current resource version will be listed. For details look at Resource Version Semantics documentation. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Type | Description |
|---|---|
ListEntity[PartialObjectMetadata]
|
ListEntity[PartialObjectMetadata]: the metadata of the matching resources,
with the list's |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace given for a
cluster-scoped resource, or an unknown option value (e.g. for
|
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_metadata.py
patch
async
¶
patch(
name: str,
patch: Patch,
*,
namespace: ApiNamespaceTypes = Ellipsis,
dry_run: DryRunTypes = None,
field_manager: str | None = None,
force: bool | None = None,
field_validation: FieldValidationTypes = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> PartialObjectMetadata
Patch metadata of the specified resource.
The patch is applied to the resource itself; only the response is reduced to its metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource to patch. |
required |
patch
|
Patch
|
The patch to send, typically changing labels or annotations:
|
required |
namespace
|
ApiNamespaceTypes
|
The namespace of the namespaced resource to patch. If not provided, the namespace provided when creating the API will be used. The namespace is required for namespaced resources. If namespace is provided for cluster-scoped resources, an error will be raised. |
Ellipsis
|
dry_run
|
DryRunTypes
|
Validate the request without persisting anything ( |
None
|
field_manager
|
str | None
|
The field manager name recorded in |
None
|
force
|
bool | None
|
Take over fields currently owned by another field manager instead
of failing with |
None
|
field_validation
|
FieldValidationTypes
|
How the API server handles unknown or duplicate fields in
the patch: |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Returns:
| Name | Type | Description |
|---|---|---|
PartialObjectMetadata |
PartialObjectMetadata
|
the patched resource's |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. an empty or malformed |
NotFound
|
the resource does not exist (an |
Conflict
|
an |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached. |
KubexTimeoutError
|
the request timed out on the client side. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_metadata.py
watch
async
¶
watch(
*,
namespace: ApiNamespaceTypes = Ellipsis,
label_selector: str | None = None,
field_selector: str | None = None,
allow_bookmarks: bool | None = None,
send_initial_events: bool | None = None,
resource_version: ResourceVersionTypes = None,
timeout_seconds: int | None = None,
request_timeout: ApiRequestTimeoutTypes = Ellipsis,
) -> AsyncGenerator[
WatchEvent[PartialObjectMetadata], None
]
Watch for metadata changes of resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace to watch. If not provided,
the namespace provided when creating the API will be used.
Pass |
Ellipsis
|
label_selector
|
str | None
|
Only watch resources whose labels match this selector. For details look at Label Selectors documentation. |
None
|
field_selector
|
str | None
|
Only watch resources whose fields match this selector. For details look at Field Selectors documentation. |
None
|
allow_bookmarks
|
bool | None
|
Request periodic |
None
|
send_initial_events
|
bool | None
|
Start the stream with synthetic |
None
|
resource_version
|
ResourceVersionTypes
|
Only deliver changes made after this resource version,
e.g. the list |
None
|
timeout_seconds
|
int | None
|
Server-side timeout (in seconds); the server ends the stream cleanly after it. |
None
|
request_timeout
|
ApiRequestTimeoutTypes
|
HTTP-level timeout override for this call. A number is
interpreted as the total timeout in seconds. Pass |
Ellipsis
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[WatchEvent[PartialObjectMetadata], None]
|
WatchEvent[PartialObjectMetadata]: one event per change, with its |
Raises:
| Type | Description |
|---|---|
ValueError
|
an argument is invalid, e.g. a namespace given for a
cluster-scoped resource, or |
Gone
|
the requested |
KubexApiError
|
the API server rejected the request; the subclass
matches the HTTP status (e.g. |
KubexConnectionError
|
the API server could not be reached, or the connection broke mid-stream. |
KubexTimeoutError
|
the request timed out on the client side, including mid-stream. |
ConfigurationError
|
credentials could not be obtained, e.g. an exec plugin or OIDC token refresh failed. |
Source code in kubex/api/_metadata.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
Stream session¶
kubex.api._stream_session ¶
StreamSession ¶
StreamSession(
connection: WebSocketConnection,
protocol: ChannelProtocol,
*,
stdin: bool = False,
stdout: bool = True,
stderr: bool = True,
tty: bool = False,
buffer_size: float = _DEFAULT_CHANNEL_BUFFER,
)
Bases: _BaseChannelSession
Multiplexes Kubernetes channel-protocol streams over a single :class:WebSocketConnection.
The session owns a background read loop that decodes incoming binary frames
and dispatches their payloads to per-channel queues. Outgoing writes
(stdin, resize, close_stdin) share a lock so concurrent callers
do not interleave bytes on the underlying WebSocket.
Inbound data is never dropped: when stdout or stderr has
buffer_size undelivered frames, the read loop waits for the consumer,
which also holds back every other channel (including the status). Drain
each enabled channel concurrently, disable the ones you don't need
(stderr=False), or close a receive stream (session.stderr.close())
to discard it. Leaving the async with block always tears the session
down promptly, even while the read loop is waiting.
Used by both the exec and attach subresource accessors.
Source code in kubex/api/_stream_session.py
stderr
property
¶
Stderr chunks as an async iterator; ends at once if disabled or with tty=True.
stderr_truncated
property
¶
Deprecated: always False. See :attr:stdout_truncated.
stdin
property
¶
Writer for stdin: await stdin.write(data), await stdin.close().
write() sends the data in frames of at most 32 KiB and raises
RuntimeError if stdin was not enabled or is already closed.
stdout
property
¶
Stdout chunks as an async iterator; ends when the channel closes.
stdout_truncated
property
¶
Deprecated: always False.
Output is no longer dropped when a consumer falls behind (the session applies backpressure instead), so there is nothing to report.
close_stdin
async
¶
Half-close stdin, signalling end-of-input to the process.
Idempotent, and a no-op when stdin was not enabled.
Raises:
| Type | Description |
|---|---|
KubexClientException
|
stdin is still open but the session has already ended. |
Source code in kubex/api/_stream_session.py
resize
async
¶
Send a terminal resize event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The new terminal width in columns; must be positive. |
required |
height
|
int
|
The new terminal height in rows; must be positive. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KubexClientException
|
the session has already ended. |
Source code in kubex/api/_stream_session.py
wait_for_status
async
¶
Wait for the terminal Status from the error channel.
Resolves once a complete Status document has arrived, or when the
connection closes; None means the server closed without sending
one. The status only arrives after earlier frames have been
delivered, so keep draining enabled output channels while waiting.
Returns:
| Type | Description |
|---|---|
Status | None
|
Status | None: the reported |
Source code in kubex/api/_stream_session.py
Portforward session¶
kubex.api._portforward_session ¶
PortForwardSession ¶
PortForwardSession(
connection: WebSocketConnection,
protocol: ChannelProtocol,
ports: Sequence[int],
*,
buffer_size: float = _DEFAULT_CHANNEL_BUFFER,
)
Bases: _BaseChannelSession
Port-aware WebSocket channel multiplexer for the Kubernetes portforward subresource.
Inherits lifecycle management (write lock, exit stack, task group) from
_BaseChannelSession. Each port gets a data MemoryObjectStream[bytes]
and an error MemoryObjectStream[str]. The first frame on each channel
carries a 2-byte little-endian port-number prefix which is stripped and
validated; subsequent frames are routed as raw bytes (data) or UTF-8 text
(error) without any prefix.
When a port's data (or error) queue holds buffer_size undelivered
frames the read loop waits for the consumer instead of dropping data.
Backpressure therefore reaches the remote side, but all ports share one
WebSocket: a port nobody reads stalls the others too (as with
kubectl port-forward). Read every forwarded port, or aclose() the
streams you don't need.
Source code in kubex/api/_portforward_session.py
close_port_data
async
¶
Half-close the data channel of port.
Idempotent: a second call for the same port is a no-op. On protocols
that support it (v5) this sends
protocol.encode(CHANNEL_CLOSE, bytes([data_channel_id])); on v4, the
only protocol the kubelet registers for portforward, the channel is only
marked closed locally, because the kubelet ignores close frames there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
A port forwarded by this session. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in kubex/api/_portforward_session.py
Protocol helpers¶
kubex.api._protocol ¶
ApiNamespaceTypes
module-attribute
¶
A per-call namespace argument: a namespace name, None (no namespace, or all
namespaces for calls that allow it), or ... (omitted: use the Api default).
ApiRequestTimeoutTypes
module-attribute
¶
A per-call HTTP timeout: a Timeout, a number of seconds, None (no timeout),
or ... (omitted: use the client default).
ApiProtocol ¶
Bases: Protocol[ResourceType]
The parts of Api that subresource descriptors read.
The descriptors' __get__ overloads match on ApiProtocol[T] to pick the
accessor type for resource type T, or SubresourceNotAvailable when
T lacks the matching marker interface.
CachedSubresourceDescriptor ¶
Base for non-data descriptors that guard on a marker interface and cache the accessor.
SubresourceNotAvailable ¶
Type of a subresource accessor whose resource type does not support it.
Type checkers see this for e.g. Api[Pod].scale: it has no attributes, so
any call on it is a type error. At runtime the attribute access raises
NotImplementedError instead.
ensure_optional_namespace ¶
ensure_optional_namespace(
namespace: ApiNamespaceTypes,
default: NamespaceTypes,
scope: Scope,
) -> NamespaceTypes
Resolve the namespace for a call that may span namespaces.
Used by list, watch and delete_collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace passed to the call, or |
required |
default
|
NamespaceTypes
|
The |
required |
scope
|
Scope
|
The resource's scope. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NamespaceTypes |
NamespaceTypes
|
the namespace to use, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
a namespace resolves for a cluster-scoped resource. |
Source code in kubex/api/_protocol.py
ensure_required_namespace ¶
ensure_required_namespace(
namespace: ApiNamespaceTypes,
default: NamespaceTypes,
scope: Scope,
) -> NamespaceTypes
Resolve the namespace for a call that targets a single object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace passed to the call, or |
required |
default
|
NamespaceTypes
|
The |
required |
scope
|
Scope
|
The resource's scope. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NamespaceTypes |
NamespaceTypes
|
the namespace to use; |
Raises:
| Type | Description |
|---|---|
ValueError
|
no namespace resolves for a namespace-scoped resource, or one resolves for a cluster-scoped resource. |
Source code in kubex/api/_protocol.py
get_namespace ¶
Resolve a per-call namespace argument against the Api default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
ApiNamespaceTypes
|
The namespace passed to the call, or |
required |
default
|
NamespaceTypes
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NamespaceTypes |
NamespaceTypes
|
|