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

Required arrays with null value #52

Open
mbohlool opened this issue Jan 31, 2018 · 20 comments
Open

Required arrays with null value #52

mbohlool opened this issue Jan 31, 2018 · 20 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@mbohlool
Copy link
Contributor

Looks like there is a problem with 1.8 spec going forward [TODO:ref issue] that an array that marked as required can be null. Assuming an empty array is an acceptable array in these situation (and it look like it is as kubernetes return empty array in some of those cases, TODO: add ref issues) we should consider fixing it in the main repo (TODO: create an issue) and also here as a quick fix until main repo issue has been fixed. This is my brain dump on the issue in case of anyone wants to work on this:

  • we should first research the problem and see if that is the case for all required arrays or a subset of them
  • as a quick fix, we can remove those arrays (or subset of them based on previous findings) from required list in a preprocessing step in this repo.
  • A regeneration of python (and other languages) clients should fix the issues (TODO: ref those issues)
  • Next, there should be a more permanent fix in the main repo.
@mbohlool mbohlool added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jan 31, 2018
@roycaihw
Copy link
Member

roycaihw commented Mar 26, 2018

Gathering known required API fields issues in python client:

The issue started in release-4.0. Although we had the required-field validation generated since release-1.0, the api_client would assign [] for the null fields before deserialize the model (before release-3.0). Since release-4.0 the generated api_client doesn't convert null to empty array anymore, and the ValueError gets raised.

Agree that the problem is in our API convention (can an required array be null?), and there should be a permanent fix in the main repo.

@ceridwen
Copy link
Contributor

ceridwen commented Mar 27, 2018

There are a number of other API fields with this problem. From watching the issues in the two repositories in question, I have the following list. (This is just straight links, I don't have time right now to make the formatting pretty. I tried to avoid duplicates.)

Kubernetes

kubernetes-client/python#491
kubernetes-client/python#484
kubernetes-client/python#466
kubernetes-client/python#427
kubernetes-client/python#424

OpenShift

kubernetes-client/python#464
openshift/openshift-restclient-python#138

There are probably more that I haven't run into and that no one else has bothered to post an issue for yet.

@smiller171
Copy link

Looking at related issues (specifically #394) This has been an issue since at least November.

Is there any word on a fix or a workaround? As someone new to Kubernetes and even newer to the Python client, I have absolutely no idea how to move past this and make my application work.

@StephanX
Copy link

StephanX commented May 17, 2018

@smiller171 For good or ill, I've managed to work around this in my kubernetes-python module by commenting out the subject enforcement check at lines 184 & 185 of my /usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1beta1_cluster_role_binding.py file (the content being):

        if subjects is None:
            raise ValueError("Invalid value for `subjects`, must not be `None`")

@djmckinley
Copy link

I just came across this issue with the "limits" array in the LimitRangeSpec resource. If I write a LimitRange object with an empty array, when reading it back, I get the exception: "Invalid value for limits, must not be None". I worked around it by catching those exceptions and dealing with them - but I'm wondering if removing the test raising the exception like StephanX did would be better.

This seems to be a serious, pervasive issue with at least the 5.0.0 library. Is that accurate, or am I misunderstanding something?

Is there any fix in the works? Or suggested workaround other than dealing with each and every occurrence? So far, in my project, we've had to implement workarounds for this limits case, and the PodDisruptionBudget case (kubernetes-client/python#466). This issue (#52) makes it appear there could be many more problems lurking out there. Do we need to give up on 5.0.0, and go back to an earlier stable library release?

@roycaihw
Copy link
Member

Upstream PR fixing serverAddressByClientCIDRs: kubernetes/kubernetes#61963

@roycaihw
Copy link
Member

roycaihw commented Jun 12, 2018

Fixes for Conditions in CustomResourceDefinitionStatus kubernetes/kubernetes#64996
DisruptedPods in policy.v1beta1.PodDisruptionBudgetStatus kubernetes/kubernetes#65041

@lavalamp
Copy link
Member

Given that apiserver ignores the rule today, everything just works better if we adjust the specs to mark these fields as optional, no?

@lavalamp
Copy link
Member

Also, see kubernetes/kube-openapi#87

@mydockergit
Copy link

@roycaihw you can check v1beta1.CustomResourceDefinitionStatus requires conditions (kubernetes-client/python#447) because it is closed already.

@roycaihw
Copy link
Member

@mydockergit The field is still marked as required, as openapi spec shows:

   "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionStatus": {
    "description": "CustomResourceDefinitionStatus indicates the state of the CustomResourceDefinition",
    "required": [
     "conditions",
     "acceptedNames",
     "storedVersions"
    ],

I think kubernetes-client/python#447 was closed because we want to fix the API upstream

@agassner
Copy link

Any luck with this?

@ikflc
Copy link

ikflc commented Apr 2, 2019

Hi There, I am running python 3.7.2 and hit the same problem trying to deploy sql aag onto AKS, by running "python ./deploy-ag.py ...".
←[31m[ERROR] ←[0mCaught exception: Invalid value for conditions, must not be None
←[31m[ERROR] ←[0m<bound method ApiextensionsV1beta1Api.list_custom_resource_definition of <kubernetes.client.apis.apiextensions_v1beta1_api.ApiextensionsV1beta1Api object at 0x04178A10>> Could not complete successfully.

But the AKS is created. Is there anything i need to do to fix up the errors and how?

Thanks & regards,
Irene

@NKUCodingCat
Copy link

NKUCodingCat commented Apr 20, 2019

It seems caused by the issue of type hinting or some other similar
I can monkey patch it in my code but it is too tricky in product environment
Is there any other way to work around it ?

@ikflc here's a quick but dirty patch

from kubernetes import client

# ======== Hack for V1beta1CustomResourceDefinitionStatus bug ==================
# Things happened in /site-packages/kubernetes/client/api_client.py:635
# We should override models.V1beta1CustomResourceDefinitionStatus to avoid "Empty conditions" error
# Such issue relates to https://github.com/kubernetes-client/gen/issues/52
# I have nothing to do but monkey patch it

class Hack_Status_Conditions(client.api_client.models.V1beta1CustomResourceDefinitionStatus):
    
    def __init__(self, *args, **kwargs):
        super(Hack_Status_Conditions, self).__init__(*args, **kwargs)
        
    @property
    def conditions(self):
        return super(Hack_Status_Conditions, self).conditions

    @conditions.setter
    def conditions(self, cond):
        self._conditions = list() if cond == None else cond

client.api_client.models.V1beta1CustomResourceDefinitionStatus = Hack_Status_Conditions

# =================== DONE hacking here ================================================

Test passed in Python 3.7.2 / Kubeclient-Python v9.0.0 / Kubernetes 1.13.5

@lavalamp
Copy link
Member

@roycaihw looks like some of your fix PRs didn't get enough attention, maybe you can revisit them?

@zhangmingld
Copy link

@kubernetes/sig-api-machinery-bugs, we have the same problem
Can anyone help to look at this ?

roycaihw added a commit to roycaihw/client-python that referenced this issue Jul 19, 2019
@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 Jul 27, 2019
@roycaihw
Copy link
Member

/remove-lifecycle stale
/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jul 30, 2019
@kierenj
Copy link

kierenj commented Nov 6, 2019

Am I running into this here, or shall I raise a separate issue? Code straight from one of the examples:

deployment = client.AppsV1beta1Deployment()
/opt/conda/lib/python3.6/site-packages/kubernetes/client/models/apps_v1beta1_deployment_spec.py in __init__(self, min_ready_seconds, paused, progress_deadline_seconds, replicas, revision_history_limit, rollback_to, selector, strategy, template)
     87         if strategy is not None:
     88           self.strategy = strategy
---> 89         self.template = template
     90 
     91     @property

/opt/conda/lib/python3.6/site-packages/kubernetes/client/models/apps_v1beta1_deployment_spec.py in template(self, template)
    294         """
    295         if template is None:
--> 296             raise ValueError("Invalid value for `template`, must not be `None`")
    297 
    298         self._template = template

ValueError: Invalid value for `template`, must not be `None`

@dweineha
Copy link

I get similar results when calling list_api_service():
ValueError: Invalid value for service, must not be None

However, service is None whenever a service is Local (which is most of them).

And when calling list_controller_revision_for_all_namespaces():
ValueError: Invalid value for raw, must not be None

RuntimeRawExtension is explicitly listed as [optional] in the documentation for V1ControllerRevision, but is treated as mandatory by the bindings.

I've only tested with version 10.1.0 of the bindings, but checking the source code for 11.0.0 seems to indicate that the issue is still there.

diegodelemos pushed a commit to diegodelemos/reana-commons that referenced this issue Jul 3, 2020
* Gets raw data from Kubernetes and avoids OpenAPI deserialization which
  fails due to kubernetes-client/gen#52,
  even though [this fix](kubernetes/kubernetes#85728)
  exists, the Python Kubernetes library is still not compatible with it.
  More information at kubernetes-client/python#1174.
diegodelemos pushed a commit to diegodelemos/reana-commons that referenced this issue Jul 3, 2020
* Gets raw data from Kubernetes and avoids OpenAPI deserialization which
  fails due to kubernetes-client/gen#52,
  even though [this fix](kubernetes/kubernetes#85728)
  exists, the Python Kubernetes library is still not compatible with it.
  More information at kubernetes-client/python#1174.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests