Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a custom resource definition works on 1.7 and fails on 1.8 with 4.0 client #415

Closed
mildebrandt opened this issue Dec 12, 2017 · 5 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@mildebrandt
Copy link

I'm using python-client 4.0.0 and Kubernetes server 1.8.0 on minikube. I'm creating a custom resource definition using the kubernetes.client.ApiextensionsV1beta1Api.create_custom_resource_definition() API.

This calls the following rest endpoint:
https://192.168.64.34:8443/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions

with the following body:

{
  'apiVersion': 'apiextensions.k8s.io/v1beta1', 
  'kind': 'CustomResourceDefinition', 
  'metadata': {
    'name': 'alertmanagers.monitoring.coreos.com'
  }, 
  'spec': {
    'group': 'monitoring.coreos.com', 
    'version': 'v1', 
    'scope': 'Namespaced', 
    'names': {
      'plural': 'alertmanagers', 
      'singular': 'alertmanager', 
      'kind': 'AlertManager'
    }
  }
}

With Kubernetes 1.8.0, I get the following response:

{
    "kind": "CustomResourceDefinition",
    "apiVersion": "apiextensions.k8s.io/v1beta1",
    "metadata": {
        "name": "alertmanagers.monitoring.coreos.com",
        "selfLink": "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/alertmanagers.monitoring.coreos.com",
        "uid": "898234e4-df84-11e7-b925-6275c77a1d00",
        "resourceVersion": "6604",
        "generation": 1,
        "creationTimestamp": "2017-12-12T21:36:39Z"
    },
    "spec": {
        "group": "monitoring.coreos.com",
        "version": "v1",
        "names": {
            "plural": "alertmanagers",
            "singular": "alertmanager",
            "kind": "AlertManager",
            "listKind": "AlertManagerList"},
        "scope": "Namespaced"
    },
    "status": {
        "conditions": null,
        "acceptedNames": {"plural": "", "kind": ""}
    }
}

which generates the following error in the python client:

  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/apiextensions_v1beta1_api.py", line 57, in create_custom_resource_definition
    (data) = self.create_custom_resource_definition_with_http_info(body, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/apiextensions_v1beta1_api.py", line 136, in create_custom_resource_definition_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 321, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 163, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 620, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1beta1_custom_resource_definition_status.py", line 53, in __init__
    self.conditions = conditions
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1beta1_custom_resource_definition_status.py", line 101, in conditions
    raise ValueError("Invalid value for `conditions`, must not be `None`")
ValueError: Invalid value for `conditions`, must not be `None`

Kubernetes 1.7.5 returns the following:

{
    "kind": "CustomResourceDefinition",
    "apiVersion": "apiextensions.k8s.io/v1beta1",
    "metadata": {
        "name": "alertmanagers.monitoring.coreos.com",
        "selfLink": "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/alertmanagers.monitoring.coreos.com",
        "uid": "9c8a122b-df8b-11e7-b6e4-ca244fafa171",
        "resourceVersion": "1730",
        "creationTimestamp": "2017-12-12T22:27:17Z"
    },
    "spec": {
        "group": "monitoring.coreos.com",
        "version": "v1",
        "names": {
            "plural": "alertmanagers",
            "singular": "alertmanager",
            "kind": "AlertManager",
            "listKind": "AlertManagerList"},
        "scope": "Namespaced"
    },
    "status": {
        "conditions": [],
        "acceptedNames": {"plural": "", "kind": ""}
    }
}

This works just fine. The difference is in the return value of the conditions field

Now, there are a few things going on here:

  1. The server is returning a different value, [] for 1.7.5 and null for 1.8.0.
  2. The swagger doc says both of these fields are required, but the server returns empty values.
  3. If the swagger doc was correct (which I doubt it is), the code generation may be wrong. I suppose it's open to interpretation. I don't think an empty array fulfills a "required value". The same applies to the empty strings for the plural and kind members of the acceptedNames dict. This really indicates no value, but the swagger says it's required.

This could possibly be split into separate issues. Let me know what's best in this case. Thanks!

@mildebrandt
Copy link
Author

It looks like kubernetes 1.7 made the statement that nulls and empty arrays should be treated the same: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.7.md#known-issues

This also related to this open bug: #376

@rmb938
Copy link

rmb938 commented Jan 29, 2018

Is there an ETA on getting this fixed? It's still broken in 5.0.0b1 and I would like to be able to upgrade my clusters.

rmb938 added a commit to rmb938/python that referenced this issue Jan 29, 2018
@mildebrandt
Copy link
Author

We'd love to see a fix as well. For now, we've put in the following patch in our code:

@property
def accepted_names(self):
    return self._accepted_names


@accepted_names.setter
def accepted_names(self, accepted_names):
    self._accepted_names = accepted_names


@property
def conditions(self):
    return self._conditions


@conditions.setter
def conditions(self, conditions):
    self._conditions = conditions


# Patching the client to get around this issue:
# https://github.com/kubernetes-incubator/client-python/issues/415
V1beta1CustomResourceDefinitionStatus.accepted_names = accepted_names
V1beta1CustomResourceDefinitionStatus.conditions = conditions

@rmb938
Copy link

rmb938 commented Jan 29, 2018

That is a bit gross but I guess will have to do for now...

I did create a pr to fix it so hopefully it gets merged and released sometime soon.

@mbohlool
Copy link
Contributor

dup of #376

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants