Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@mildebrandt

Description

@mildebrandt

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions