From 9c37292171aa9c35fbfb8c1ee2670150b9621190 Mon Sep 17 00:00:00 2001 From: Phil Sphicas Date: Wed, 9 Feb 2022 10:04:38 -0800 Subject: [PATCH 3/8] Create lock CRD as apiextensions.k8s.io/v1 object Cherry-pick https://review.opendev.org/c/airship/armada/+/845392 from upstream keeping the original commit message: ----- Kubernetes v1.22 stopped serving the apiextensions.k8s.io/v1beta1 API version of CustomResourceDefinition. This change ensures that the locks.armada.process CRD is created using the apiextensions.k8s.io/v1 API. The kubernetes client package is also updated to take advantage of the dynamic client. (cherry picked from commit c5d39f27cacaa953be43c7d3265bb693db0939d0) In addition to the clean cherry-pick add fixes for tests: - docs language - protobuf version - stestr missing Closes-Bug: 1978409 Change-Id: Icd518ab5cbb78e8b15f63d19c51b5f5b9a67e995 ----- On top of the upstream cherry-pick we need to enchance build env to add missing .yaml files. Change setup.py and add MANIFEST.in to allow proper contents of the image to be generated. Signed-off-by: Dan Voiculeasa --- MANIFEST.in | 2 ++ armada/handlers/k8s.py | 7 +++---- armada/handlers/lock.py | 42 +++++++++++++++++------------------------ doc/source/conf.py | 2 +- requirements.txt | 6 +++--- setup.py | 2 +- test-requirements.txt | 1 + 7 files changed, 28 insertions(+), 34 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..61709ba --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include *.yaml +recursive-include armada *.yaml diff --git a/armada/handlers/k8s.py b/armada/handlers/k8s.py index 31b00c7..56cbc26 100644 --- a/armada/handlers/k8s.py +++ b/armada/handlers/k8s.py @@ -57,8 +57,7 @@ class K8s(object): self.batch_api = client.BatchV1Api(api_client) self.batch_v1beta1_api = client.BatchV1beta1Api(api_client) self.custom_objects = client.CustomObjectsApi(api_client) - self.api_extensions = client.ApiextensionsV1beta1Api(api_client) - self.extension_api = client.ExtensionsV1beta1Api(api_client) + self.api_extensions = client.ApiextensionsV1Api(api_client) self.apps_v1_api = client.AppsV1Api(api_client) def delete_job_action( @@ -359,10 +358,10 @@ class K8s(object): :param crd: custom resource definition to create - :type crd: kubernetes.client.V1beta1CustomResourceDefinition + :type crd: kubernetes.client.V1CustomResourceDefinition :return: new custom resource definition - :rtype: kubernetes.client.V1beta1CustomResourceDefinition + :rtype: kubernetes.client.V1CustomResourceDefinition """ return self.api_extensions.create_custom_resource_definition(crd) diff --git a/armada/handlers/lock.py b/armada/handlers/lock.py index bd99d38..54e3eb0 100644 --- a/armada/handlers/lock.py +++ b/armada/handlers/lock.py @@ -281,40 +281,32 @@ class LockConfig: return lock def create_definition(self): - names = client.V1beta1CustomResourceDefinitionNames( + names = client.V1CustomResourceDefinitionNames( kind="Resource", plural=LOCK_PLURAL, singular=LOCK_SINGULAR) metadata = client.V1ObjectMeta( name="{}.{}".format(LOCK_PLURAL, LOCK_GROUP), resource_version=LOCK_VERSION) - status = client.V1beta1CustomResourceDefinitionStatus( - accepted_names=names, - conditions=[], - stored_versions=[LOCK_VERSION]) - spec = client.V1beta1CustomResourceDefinitionSpec( + spec = client.V1CustomResourceDefinitionSpec( group=LOCK_GROUP, names=names, scope="Namespaced", - version=LOCK_VERSION) - crd = client.V1beta1CustomResourceDefinition( - spec=spec, - status=status, - metadata=metadata, - kind="CustomResourceDefinition") + versions=[ + { + "name": LOCK_VERSION, + "schema": { + "openAPIV3Schema": { + "type": "object", + "x-kubernetes-preserve-unknown-fields": True + } + }, + "served": True, + "storage": True, + } + ]) + crd = client.V1CustomResourceDefinition( + spec=spec, metadata=metadata, kind="CustomResourceDefinition") try: self.k8s.create_custom_resource_definition(crd) - except ValueError as err: - # Because of an issue with the Kubernetes code, the API server - # may return `null` for the required field `conditions` in - # kubernetes.client.V1beta1CustomResourceDefinitionStatus - # This causes validation to fail which will raise the subsequent - # ValueError even though the CRD was created successfully - # https://github.com/kubernetes-client/gen/issues/52 - # TODO if this is fixed upstream this should be removed - known_msg = "Invalid value for `conditions`, must not be `None`" - known_err = ValueError(known_msg) - if err.args != known_err.args: - raise - LOG.debug("Encountered known issue while creating CRD, continuing") except ApiException as err: # If a 409 is received then the definition already exists if err.status != 409: diff --git a/doc/source/conf.py b/doc/source/conf.py index 6ed6273..b4826c7 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -78,7 +78,7 @@ author = 'The Airship Authors' # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/requirements.txt b/requirements.txt index 2d61ca3..c2f9ac2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,16 +6,16 @@ jsonschema>=3.0.1,<4 keystoneauth1>=3.18.0 keystonemiddleware==5.3.0 kombu<4.7,>=4.6.10 -kubernetes>=12.0.0 +kubernetes<23,>=17.0.0 Paste>=2.0.3 PasteDeploy>=1.5.2 -protobuf>=3.4.0 +protobuf>=3.4.0,<3.21 pylibyaml~=0.1 pyyaml~=5.1 requests retry setuptools>=40.4.3 -prometheus_client>=0.7.0 +prometheus_client<0.13.0,>=0.7.0 # API falcon diff --git a/setup.py b/setup.py index 7d9b694..8a5a815 100644 --- a/setup.py +++ b/setup.py @@ -5,4 +5,4 @@ try: except ImportError: pass -setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True) +setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True, include_package_data=True) diff --git a/test-requirements.txt b/test-requirements.txt index 3108c65..e9faa28 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -16,6 +16,7 @@ mock responses>=0.8.1 yapf==0.27.0 flake8-import-order==0.18.1 +stestr>=1.0.0 # Apache-2.0 grpcio-tools==1.16.0 typing-extensions==3.7.2 -- 2.34.1