Skip to content

Commit

Permalink
Switch to stable API extensions version
Browse files Browse the repository at this point in the history
This patch adds compatibility to k8s v1.22 / OpenShift 4.9.

In V1.22, apiextensions.k8s.io/v1beta1 is no longer available [1].
apiextensions.k8s.io/v1 requires a new versions field, thus
extending the current CRD definition [2].

python-kubernetes starts supporting these in 12.0, thus increasing the
dependency as well.

[1] https://kubernetes.io/docs/reference/using-api/deprecation-guide/
[2] https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/
  • Loading branch information
cschwede authored and Akrog committed Jan 18, 2022
1 parent b2ccaca commit b836012
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Ember-CSI has the following requirements:
- Fedora

- Container Orchestrator: Both Kubernetes and OpenShift are supported:
- Openshift: Recommended version 4.4 or newer. Supported from version 3.10 onward.
- Kubernetes: Recommended version 1.17 or newer. Supported from version 1.11 onward.
- Openshift: Recommended version 4.6 or newer. Supported from version 4.3 onward.
- Kubernetes: Recommended version 1.17 or newer. Supported from version 1.16 onward.

- Storage solution: Access and credentials to a `supported storage solution <index.html#supported_drivers>`_.

Expand Down
18 changes: 14 additions & 4 deletions ember_csi/cl_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,21 @@ def create_crd_definition(cls):
As well as with the individual names and shortcuts.
"""
crd = {'apiVersion': 'apiextensions.k8s.io/v1beta1',
crd = {'apiVersion': 'apiextensions.k8s.io/v1',
'kind': 'CustomResourceDefinition',
'metadata': {'name': cls.api_name},
'spec': {'group': cls.DOMAIN,
'version': cls.CRD_VERSION,
'versions': [{
'name': cls.CRD_VERSION,
'served': True,
'storage': True,
'schema': {
'openAPIV3Schema': {
'type': 'object',
'x-kubernetes-preserve-unknown-fields': True
}
}
}],
'scope': 'Namespaced',
'names': {'kind': cls.kind,
'singular': cls.singular,
Expand Down Expand Up @@ -473,11 +483,11 @@ def __init__(self):
k8s.config.load_incluster_config()
else:
k8s.config.load_kube_config()
config = k8s.client.Configuration()
config = k8s.client.Configuration().get_default_copy()
if config.host.startswith('https://'):
config.assert_hostname = False
self.api = k8s.client.api_client.ApiClient(configuration=config)
self.ext_api = k8s.client.ApiextensionsV1beta1Api(self.api)
self.ext_api = k8s.client.ApiextensionsV1Api(self.api)
self.crd_api = k8s.client.CustomObjectsApi(self.api)


Expand Down
6 changes: 3 additions & 3 deletions ember_csi/workarounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def k8s_issue_376():
That issue will raise a ValueError when creating a CRD because the status
returned by Kubernetes is set to None, which according to
V1beta1CustomResourceDefinitionStatus cannot be.
V1CustomResourceDefinitionStatus cannot be.
u'status': {u'acceptedNames': {u'kind': u'', u'plural': u''},
u'conditions': None}}
Expand All @@ -143,7 +143,7 @@ def set_conditions(self, conditions):
# Unlike the original one we accept None values
self._conditions = conditions

crd_status = k8s.client.models.v1beta1_custom_resource_definition_status
crd_status_cls = crd_status.V1beta1CustomResourceDefinitionStatus
crd_status = k8s.client.models.v1_custom_resource_definition_status
crd_status_cls = crd_status.V1CustomResourceDefinitionStatus
setattr(crd_status_cls, 'conditions',
property(fget=crd_status_cls.conditions.fget, fset=set_conditions))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run(self):
# GRPCIO v1.12.0 has broken dependencies, so we include them here
'protobuf>=3.5.0.post1',
# For the CRD persistent metadata plugin
'kubernetes>=7.0.0,<12.0.0',
'kubernetes>=12.0.0,<13.0.0.',
# If we install from PyPi we needed a newer setuptools because some
# Kubernetes dependencies use version in format of 4.*
# 'setuptools>=40.0.0',
Expand Down

0 comments on commit b836012

Please sign in to comment.