Skip to content

Commit 7a6e601

Browse files
authored
Retornam/edits (#94)
* Update python packages * Update proto files
1 parent 0336fa8 commit 7a6e601

File tree

15 files changed

+7386
-2563
lines changed

15 files changed

+7386
-2563
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ container-runtime-interface-api = {editable = true, path = "."}
99
[dev-packages]
1010
build = "*"
1111
exceptiongroup = "*" # Required for Python versions < 3.11
12-
grpcio-tools = "~=1.47"
12+
grpcio-tools = "~=1.73"
1313
mypy = "*"
1414
mypy-protobuf = "*"
1515
pytest = "*"

bin/update-proto.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,22 @@ cd "$SCRIPT_DIR/../" || exit 1
88
# Commented out until 1.26 is fully supported
99
# git submodule update --init --recursive --remote --merge
1010

11-
pipenv run python -m grpc_tools.protoc \
12-
-I vendor \
13-
-I vendor/github.com/gogo/protobuf/ \
14-
-I vendor/cri-api/pkg/apis/runtime/ \
15-
--python_out=src/cri_api \
16-
--mypy_out=src/cri_api \
17-
--grpc_python_out=src/cri_api \
18-
v1/api.proto \
19-
vendor/github.com/gogo/protobuf/gogoproto/gogo.proto
2011

21-
pipenv run python -m grpc_tools.protoc \
12+
# find all prot files under the vendor/cri-api/pkg/apis/runtime/ directory
13+
# strip vendor/cri-api/pkg/apis/runtime/ leaving only the folder before
14+
# vendor/cri-api/pkg/apis/runtime/v1/api.proto becomes
15+
# v1/api.proto
16+
find vendor/cri-api/pkg/apis/runtime/ -name '*.proto' | sed 's|vendor/cri-api/pkg/apis/runtime/||' | \
17+
xargs pipenv run python -m grpc_tools.protoc \
2218
-I vendor \
2319
-I vendor/github.com/gogo/protobuf/ \
2420
-I vendor/cri-api/pkg/apis/runtime/ \
2521
--python_out=src/cri_api \
2622
--mypy_out=src/cri_api \
2723
--grpc_python_out=src/cri_api \
28-
v1alpha2/api.proto \
2924
vendor/github.com/gogo/protobuf/gogoproto/gogo.proto
3025

26+
27+
# replace from v1 or from github with cri_api
3128
find src/cri_api/ -type f -name '*.py' -print0 | xargs -0 -P 1 -I {} sed -i '' -Ee 's/from (v1|github)/from cri_api.\1/' {}
3229
pipenv run black .

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
packages=setuptools.find_namespace_packages(where="src"),
99
package_dir={"": "src"},
1010
include_package_data=True,
11-
install_requires=["grpcio~=1.39", "protobuf~=4.2"],
12-
version="2.0.0",
11+
install_requires=["grpcio~=1.73", "protobuf~=6.31"],
12+
version="2.0.1",
1313
author="Domino Data Lab",
1414
author_email="[email protected]",
1515
description="Python library for interaction with the Kubernetes container runtime interface API.", # noqa
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4-

src/cri_api/github/com/gogo/protobuf/gogoproto/gogo_pb2.py

Lines changed: 26 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cri_api/github/com/gogo/protobuf/gogoproto/gogo_pb2.pyi

Lines changed: 245 additions & 76 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = "1.73.1"
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
14+
_version_not_supported = first_version_is_lower(
15+
GRPC_VERSION, GRPC_GENERATED_VERSION
16+
)
17+
except ImportError:
18+
_version_not_supported = True
19+
20+
if _version_not_supported:
21+
raise RuntimeError(
22+
f"The grpc package installed is at version {GRPC_VERSION},"
23+
+ f" but the generated code in github.com/gogo/protobuf/gogoproto/gogo_pb2_grpc.py depends on"
24+
+ f" grpcio>={GRPC_GENERATED_VERSION}."
25+
+ f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}"
26+
+ f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}."
27+
)

src/cri_api/images.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .exceptions import ImageServiceException
1010
from .v1.api_pb2 import (
1111
AuthConfig,
12+
ImageFilter,
1213
ImageSpec,
1314
ImageStatusRequest,
1415
ListImagesRequest,
@@ -17,6 +18,7 @@
1718
)
1819
from .v1.api_pb2_grpc import ImageServiceStub
1920
from .v1alpha2.api_pb2 import AuthConfig as V1Alpha2AuthConfig
21+
from .v1alpha2.api_pb2 import ImageFilter as V1Alpha2ImageFilter
2022
from .v1alpha2.api_pb2 import ImageSpec as V1Alpha2ImageSpec
2123
from .v1alpha2.api_pb2 import ImageStatusRequest as V1Alpha2ImageStatusRequest
2224
from .v1alpha2.api_pb2 import ListImagesRequest as V1Alpha2ListImagesRequest
@@ -34,14 +36,35 @@ def __init__(self, channel: Channel) -> None:
3436
else V1Alpha2ImageServiceStub(channel.channel)
3537
)
3638

37-
# TODO filter?
38-
def list_images(self) -> List[dict]:
39+
def list_images(
40+
self, image_filter: Optional[Union[ImageFilter, V1Alpha2ImageFilter]] = None
41+
) -> List[dict]:
3942
try:
40-
response = self.stub.ListImages(
41-
ListImagesRequest()
42-
if self.channel.version == V1
43-
else V1Alpha2ListImagesRequest()
44-
)
43+
request: Union[ListImagesRequest, V1Alpha2ListImagesRequest]
44+
if self.channel.version == V1:
45+
# Only pass if it's the right type
46+
if image_filter is not None and not isinstance(
47+
image_filter, ImageFilter
48+
):
49+
raise TypeError("For V1, image_filter must be of type ImageFilter")
50+
request = (
51+
ListImagesRequest(filter=image_filter)
52+
if image_filter
53+
else ListImagesRequest()
54+
)
55+
else:
56+
if image_filter is not None and not isinstance(
57+
image_filter, V1Alpha2ImageFilter
58+
):
59+
raise TypeError(
60+
"For V1Alpha2, image_filter must be of type V1Alpha2ImageFilter"
61+
)
62+
request = (
63+
V1Alpha2ListImagesRequest(filter=image_filter)
64+
if image_filter
65+
else V1Alpha2ListImagesRequest()
66+
)
67+
response = self.stub.ListImages(request)
4568
return MessageToDict(response).get("images", [])
4669
except RpcError as e:
4770
raise ImageServiceException(e.code(), e.details()) from e
@@ -73,9 +96,11 @@ def pull_image(self, image_ref: str, auth_config: Optional[dict] = None) -> None
7396
else:
7497
request = V1Alpha2PullImageRequest(
7598
image=V1Alpha2ImageSpec(image=image_ref),
76-
auth=ParseDict(auth_config, V1Alpha2AuthConfig())
77-
if auth_config
78-
else None,
99+
auth=(
100+
ParseDict(auth_config, V1Alpha2AuthConfig())
101+
if auth_config
102+
else None
103+
),
79104
)
80105

81106
try:

src/cri_api/v1/api_pb2.py

Lines changed: 490 additions & 401 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)