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

get_api_group() raises ValueError: Invalid value for server_address_by_client_cid_rs, must not be None #394

Closed
ceridwen opened this issue Nov 17, 2017 · 12 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@ceridwen
Copy link

When I call get_api_group() with the 4.0 beta client against Kubernetes 1.7 or 1.8, I get an error:

  File "~/test_automation/test_automation/kubernetes_.py", line 353, in __init__
    api_groups.append(a.get_api_group())
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/apis/admissionregistration_api.py", line 55, in get_api_group
    (data) = self.get_api_group_with_http_info(**kwargs)
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/apis/admissionregistration_api.py", line 124, in get_api_group_with_http_info
    collection_formats=collection_formats)
  File "~/virtualenvs/kubernetes1.8/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 "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 163, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/models/v1_api_group.py", line 71, in __init__
    self.server_address_by_client_cid_rs = server_address_by_client_cid_rs
  File "~/virtualenvs/kubernetes1.8/lib/python3.6/site-packages/kubernetes/client/models/v1_api_group.py", line 189, in server_address_by_client_cid_rs
    raise ValueError("Invalid value for `server_address_by_client_cid_rs`, must not be `None`")
ValueError: Invalid value for `server_address_by_client_cid_rs`, must not be `None`

Not sure if this is a misconfiguration issue or something deeper.

@tomplus
Copy link
Member

tomplus commented Nov 23, 2017

Hi @ceridwen New version is more strict - fields "name", "versions", "serverAddressByClientCIDRs" are required by Kubernetes and there are additional checks for it.

See also: #401

@mbohlool
Copy link
Contributor

@ceridwen I assume your problem is fixed by @tomplus answer. Please re-open if you still need this.

@ceridwen
Copy link
Author

I'm still confused. When I look at the documentation for get_api_group() at https://github.com/kubernetes-incubator/client-python/blob/master/kubernetes/docs/ApiextensionsApi.md#get_api_group ,

try: 
    api_response = api_instance.get_api_group()
    pprint(api_response)
except ApiException as e:
    print("Exception when calling ApiextensionsApi->get_api_group: %s\n" % e)

It shows get_api_group() being called with no arguments, exactly like I called it. Where are these fields supposed to be set? Is the documentation wrong, or something else going on?

The way configurations are done in the documentation is now different from the way it's done in the examples under the main tree.

Documentation:

# Configure API key authorization: BearerToken
configuration = kubernetes.client.Configuration()
configuration.api_key['authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['authorization'] = 'Bearer'

# create an instance of the API class
api_instance = kubernetes.client.ApiextensionsApi(kubernetes.client.ApiClient(configuration))

Examples:

config.load_kube_config()

v1 = client.CoreV1Api()

I haven't changed any of my configuration code, it uses the method given in the examples, which is the same as for 3.0. Does this no longer work?

@ceridwen
Copy link
Author

ceridwen commented Dec 19, 2017

After taking a look at this in the debugger, this is either a bug or a configuration problem on the Kubernetes side. In the other issue that @tomplus mentioned, they're constructing a pod by instantiating the model classes directly. I'm not hand-creating V1APIGroup at all, I'm making a call against get_api_group(). The client receives the HTTP response and decodes it into a Python dict using the json module inside deserialize():

231  	        try:
232  	            data = json.loads(response.data)
233  	        except ValueError:
234  	            data = response.data
235
236  ->	        return self.__deserialize(data, response_type)

Here, response_data is:

'{"kind":"APIGroup","apiVersion":"v1","name":"admissionregistration.k8s.io","versions":[{"groupVersion":"admissionregistration.k8s.io/v1alpha1","version":"v1alpha1"}],"preferredVersion":{"groupVersion":"admissionregistration.k8s.io/v1alpha1","version":"v1alpha1"},"serverAddressByClientCIDRs":null}\n'

json.loads turns this into:

{'kind': 'APIGroup', 'apiVersion': 'v1', 'name': 'admissionregistration.k8s.io', 'versions': [{'groupVersion': 'admissionregistration.k8s.io/v1alpha1', 'version': 'v1alpha1'}], 'preferredVersion': {'groupVersion': 'admissionregistration.k8s.io/v1alpha1', 'version': 'v1alpha1'}, 'serverAddressByClientCIDRs': None}

It sets serverAddressByClientCIDRs which is null in the HTTP response to None. After a couple more steps, __deserialize_model() then tries to instantiate V1APIGroup with that dict and the client crashes.

Are all Kubernetes clusters required to have serverAddressByClientCIDRs set to a non-null value? This cluster is freshly installed with 1.8 using Kubespray. I can't reopen this issue, could you please reopen it?

@tomplus
Copy link
Member

tomplus commented Dec 19, 2017

The question is why Kubernetes returns None, this field is mandatory.

There is a notice that "The server returns only those CIDRs that it thinks that the client can match." (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#apigroup-v1-meta). Maybe it works only from the cluster (when an application is deployed to cluster)...

@fabianvf
Copy link
Contributor

I think this may be an issue of the translation to python by swagger. It's possible that the field is required, and that null is a valid value for it. However, swagger translates that required to a None check in python, and the field will be None in both the case that it is provided and explicitly set to null, and the case that it was not provided and is an invalid object.

I'm not sure if other languages will see the same issue, but it may be a limitation of the spec, and we may need to figure out a better way to handle it. I think we need to be able to differentiate between the case that it is null and the case that it is not provided.

@fabianvf
Copy link
Contributor

@mbohlool ^

@roycaihw
Copy link
Member

Umbrella issue: kubernetes-client/gen#52

@roycaihw roycaihw reopened this Mar 26, 2018
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 23, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 23, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

7 participants