2019-08-01 14:04:18 +03:00
|
|
|
..
|
|
|
|
This work is licensed under a Creative Commons Attribution 3.0 Unported
|
|
|
|
License.
|
|
|
|
|
|
|
|
http://creativecommons.org/licenses/by/3.0/legalcode
|
|
|
|
|
|
|
|
Convention for heading levels in Neutron devref:
|
|
|
|
======= Heading 0 (reserved for the title in a document)
|
|
|
|
------- Heading 1
|
|
|
|
~~~~~~~ Heading 2
|
|
|
|
+++++++ Heading 3
|
|
|
|
''''''' Heading 4
|
|
|
|
(Avoid deeper levels because they do not render well.)
|
|
|
|
|
|
|
|
==================================
|
|
|
|
HowTo Update PodResources gRPC API
|
|
|
|
==================================
|
|
|
|
|
|
|
|
Purpose
|
|
|
|
-------
|
2019-11-12 15:36:47 +01:00
|
|
|
|
2019-08-01 14:04:18 +03:00
|
|
|
The purpose of this document is to describe how to update gRPC API files in
|
|
|
|
kuryr-kubernetes repository in case of upgrading to a new version of Kubernetes
|
|
|
|
PodResources API. These files are ``api_pb2_grpc.py``, ``api_pb2.py`` and
|
|
|
|
``api.proto`` from ``kuryr_kubernetes/pod_resources/`` directory.
|
|
|
|
|
|
|
|
``api.proto`` is a gRPC API definition file generated from the
|
|
|
|
``kubernetes/pkg/kubelet/apis/podresources/<version>/api.proto`` of the
|
|
|
|
Kubernetes source tree.
|
|
|
|
|
|
|
|
``api_pb2_grpc.py`` and ``api_pb2.py`` are python bindings for gRPC API.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
There are only 2 reasons for update:
|
|
|
|
|
|
|
|
#. Kubernetes released new version of PodResources API and the old one is no
|
|
|
|
longer supported. In this case, without update, we'll not be able to use
|
|
|
|
PodResources service.
|
|
|
|
#. ``protobuf`` version in ``lower-constraints.txt`` changed to lower
|
|
|
|
version (this is highly unlikely). In this case ``protobuf`` could fail
|
|
|
|
to use our python bindings.
|
|
|
|
|
2019-11-12 15:36:47 +01:00
|
|
|
|
2019-08-01 14:04:18 +03:00
|
|
|
Automated update
|
|
|
|
----------------
|
2019-11-12 15:36:47 +01:00
|
|
|
|
2019-08-01 14:04:18 +03:00
|
|
|
``contrib/regenerate_pod_resources_api.sh`` script could be used to re-generate
|
|
|
|
PodResources gRPC API files. By default, this script will download ``v1alpha1``
|
|
|
|
version of ``api.proto`` file from the Kubernetes GitHub repo and create
|
2019-11-12 21:40:03 +01:00
|
|
|
required kuryr-kubernetes files from it:
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
[kuryr-kubernetes]$ ./contrib/regenerate_pod_resources_api.sh
|
2019-08-01 14:04:18 +03:00
|
|
|
|
|
|
|
Alternatively, path to ``api.proto`` file could be specified in
|
2019-11-12 21:40:03 +01:00
|
|
|
``KUBERNETES_API_PROTO`` environment variable:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
$ export KUBERNETES_API_PROTO=/path/to/api.proto
|
2019-08-01 14:04:18 +03:00
|
|
|
|
|
|
|
Define ``API_VERSION`` environment variable to use specific version of
|
2019-11-12 21:40:03 +01:00
|
|
|
``api.proto`` from the Kubernetes GitHub:
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ export API_VERSION=v1alpha1
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 15:36:47 +01:00
|
|
|
|
2019-08-01 14:04:18 +03:00
|
|
|
Manual update steps
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
Preparing the new api.proto
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Copy the ``api.proto`` from K8s sources to ``kuryr_kubernetes/pod_resources/``
|
|
|
|
and remove all the lines that contains ``gogoproto`` since this is unwanted
|
2019-11-12 21:40:03 +01:00
|
|
|
dependency that is not needed for python bindings:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
$ sed '/gogoproto/d' \
|
|
|
|
../kubernetes/pkg/kubelet/apis/podresources/<version>/api.proto \
|
|
|
|
> kuryr_kubernetes/pod_resources/api.proto
|
2019-08-01 14:04:18 +03:00
|
|
|
|
|
|
|
Don't forget to update the file header that should point to the original
|
|
|
|
``api.proto`` and to this reference document::
|
|
|
|
|
|
|
|
// Generated from kubernetes/pkg/kubelet/apis/podresources/<version>/api.proto
|
|
|
|
// To regenerate api.proto, api_pb2.py and api_pb2_grpc.py follow instructions
|
|
|
|
// from doc/source/devref/updating_pod_resources_api.rst.
|
|
|
|
|
2019-11-12 15:36:47 +01:00
|
|
|
|
2019-08-01 14:04:18 +03:00
|
|
|
Generating the python bindings
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
* (Optional) Create the python virtual environment:
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
[kuryr-kubernetes]$ python3 -m venv venv
|
|
|
|
[kuryr-kubernetes]$ . ./venv/bin/activate
|
2019-08-01 14:04:18 +03:00
|
|
|
|
|
|
|
* To generate python bindings we need a ``protoc`` compiler and the
|
|
|
|
``gRPC plugin`` for it. The most simple way to get them is to install
|
2019-11-12 21:40:03 +01:00
|
|
|
``grpcio-tools``:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
(venv) [kuryr-kubernetes]$ pip install grpcio-tools==1.19
|
2019-08-01 14:04:18 +03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
We're installing specific version of ``grpcio-tools`` to get specific
|
|
|
|
version of ``protoc`` compiler. The version of ``protoc`` compiler should
|
|
|
|
be equal to the ``protobuf`` package version in ``lower-constraints.txt``.
|
|
|
|
This is because older ``protobuf`` might be not able to use files
|
|
|
|
generated by newer compiler. In case you need to use more recent compiler,
|
|
|
|
you need update ``requirements.txt`` and ``lower-constraints.txt``
|
|
|
|
accordingly.
|
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
To check version of compiler installed with ``grpcio-tools`` use:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
(venv) [kuryr-kubernetes]$ python -m grpc_tools.protoc --version
|
|
|
|
libprotoc 3.6.1
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
* Following command will generate ``api_pb2_grpc.py`` and ``api_pb2.py``:
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
.. code-block:: console
|
2019-08-01 14:04:18 +03:00
|
|
|
|
2019-11-12 21:40:03 +01:00
|
|
|
(venv) [kuryr-kubernetes]$ python -m grpc_tools.protoc -I./ \
|
|
|
|
--python_out=. --grpc_python_out=. \
|
|
|
|
kuryr_kubernetes/pod_resources/api.proto
|