Create lock CRD as apiextensions.k8s.io/v1 object

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.

Change-Id: Icd518ab5cbb78e8b15f63d19c51b5f5b9a67e995
This commit is contained in:
Phil Sphicas 2022-02-09 10:04:38 -08:00
parent 790af88d61
commit c5d39f27ca
3 changed files with 22 additions and 31 deletions

View File

@ -57,8 +57,7 @@ class K8s(object):
self.batch_api = client.BatchV1Api(api_client) self.batch_api = client.BatchV1Api(api_client)
self.batch_v1beta1_api = client.BatchV1beta1Api(api_client) self.batch_v1beta1_api = client.BatchV1beta1Api(api_client)
self.custom_objects = client.CustomObjectsApi(api_client) self.custom_objects = client.CustomObjectsApi(api_client)
self.api_extensions = client.ApiextensionsV1beta1Api(api_client) self.api_extensions = client.ApiextensionsV1Api(api_client)
self.extension_api = client.ExtensionsV1beta1Api(api_client)
self.apps_v1_api = client.AppsV1Api(api_client) self.apps_v1_api = client.AppsV1Api(api_client)
def delete_job_action( def delete_job_action(
@ -369,10 +368,10 @@ class K8s(object):
:param crd: custom resource definition to create :param crd: custom resource definition to create
:type crd: kubernetes.client.V1beta1CustomResourceDefinition :type crd: kubernetes.client.V1CustomResourceDefinition
:return: new custom resource definition :return: new custom resource definition
:rtype: kubernetes.client.V1beta1CustomResourceDefinition :rtype: kubernetes.client.V1CustomResourceDefinition
""" """
return self.api_extensions.create_custom_resource_definition(crd) return self.api_extensions.create_custom_resource_definition(crd)

View File

@ -281,40 +281,32 @@ class LockConfig:
return lock return lock
def create_definition(self): def create_definition(self):
names = client.V1beta1CustomResourceDefinitionNames( names = client.V1CustomResourceDefinitionNames(
kind="Resource", plural=LOCK_PLURAL, singular=LOCK_SINGULAR) kind="Resource", plural=LOCK_PLURAL, singular=LOCK_SINGULAR)
metadata = client.V1ObjectMeta( metadata = client.V1ObjectMeta(
name="{}.{}".format(LOCK_PLURAL, LOCK_GROUP), name="{}.{}".format(LOCK_PLURAL, LOCK_GROUP),
resource_version=LOCK_VERSION) resource_version=LOCK_VERSION)
status = client.V1beta1CustomResourceDefinitionStatus( spec = client.V1CustomResourceDefinitionSpec(
accepted_names=names,
conditions=[],
stored_versions=[LOCK_VERSION])
spec = client.V1beta1CustomResourceDefinitionSpec(
group=LOCK_GROUP, group=LOCK_GROUP,
names=names, names=names,
scope="Namespaced", scope="Namespaced",
version=LOCK_VERSION) versions=[
crd = client.V1beta1CustomResourceDefinition( {
spec=spec, "name": LOCK_VERSION,
status=status, "schema": {
metadata=metadata, "openAPIV3Schema": {
kind="CustomResourceDefinition") "type": "object",
"x-kubernetes-preserve-unknown-fields": True
}
},
"served": True,
"storage": True,
}
])
crd = client.V1CustomResourceDefinition(
spec=spec, metadata=metadata, kind="CustomResourceDefinition")
try: try:
self.k8s.create_custom_resource_definition(crd) 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: except ApiException as err:
# If a 409 is received then the definition already exists # If a 409 is received then the definition already exists
if err.status != 409: if err.status != 409:

View File

@ -5,7 +5,7 @@ jsonschema>=3.0.1,<4
keystoneauth1>=3.18.0 keystoneauth1>=3.18.0
keystonemiddleware==5.3.0 keystonemiddleware==5.3.0
kombu<4.7,>=4.6.10 kombu<4.7,>=4.6.10
kubernetes>=12.0.0 kubernetes<23,>=17.0.0
Paste>=2.0.3 Paste>=2.0.3
PasteDeploy>=1.5.2 PasteDeploy>=1.5.2
pylibyaml~=0.1 pylibyaml~=0.1
@ -13,7 +13,7 @@ pyyaml~=5.1
requests requests
retry retry
setuptools>=40.4.3 setuptools>=40.4.3
prometheus_client>=0.7.0 prometheus_client<0.13.0,>=0.7.0
# API # API
falcon falcon