list_event_for_all_namespaces_with_http_info raises ValueError due to None value for event_time if there are events
还没有人认领这个 Issue。
评估
调研方向
从 EventsV1Api.list_event_for_all_namespaces_with_http_info()、Configuration 的默认值以及 events_v1_event.py 的 event_time setter 开始;通过 api_client.py 跟踪反序列化过程。将默认配置路径与报告中的 Kubernetes 事件 payload 进行比较,然后验证获取事件不再引发 ValueError,并确认配置行为是一致的。
由索引模型根据 Issue 内容生成。
描述
What happened (please include outputs or screenshots):
If you try to fetch events when there aren't any, the above mentioned method returns just fine. But if there are events, then an exception is raised in the internal setter for the 'event_time' property as the value being read in from K8s is None:
if self.local_vars_configuration.client_side_validation and event_time is None: # noqa: E501
raise ValueError("Invalid value for `event_time`, must not be `None`") # noqa: E501
or, as it happens:
File ".../python3.8/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
return self.__deserialize_model(data, klass)
File ".../lib/python3.8/site-packages/kubernetes/client/api_client.py", line 641, in __deserialize_model
instance = klass(**kwargs)
File ".../lib/python3.8/site-packages/kubernetes/client/models/events_v1_event.py", line 112, in __init__
self.event_time = event_time
File ".../lib/python3.8/site-packages/kubernetes/client/models/events_v1_event.py", line 291, in event_time
raise ValueError("Invalid value for `event_time`, must not be `None`") # noqa: E501
ValueError: Invalid value for `event_time`, must not be `None`
It may be the case that turning off client_side_validation will fix this, however there seem to be problems in this regard as well. In issue #1353 there was a mention of a breaking change (in release 1.12?) that involved setting up default config where client_side_validation can supposedly be turned off, but setting default configs don't seem to have any effect. Here's the code inside of the __init__() of EventsV1Api (local_vars_configuration is a parameter):
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
So if you don't pass in a value of local_vars_configuration, you get a brand-new Configuration object in which client_side_validation is True. One would have thought that the assignment to local_vars_configuration should have been:
local_vars_configuration = Configuration.get_default_copy()
which would have kind of lined up with the notes for release 12.0.1. More curiously, if you have a look into the __init__() for Configuration itself, you find this comment before setting client_side_validation:
# Disable client side validation
self.client_side_validation = True
So the comment implies that there shouldn't be any client side validation by default, but the code does the opposite.
This is kind of feeling like a regression.
What you expected to happen:
I was expecting that default behaviour wouldn't raise an exception for fetching regular event data from K8s (or in my case, k3s). My tests don't cover every resource type that could be fetched, so there may be other similar fields lurking within the library.
How to reproduce it (as minimally and precisely as possible):
from kubernetes.client import EventsV1Api
from kubernetes.client import CoreV1Api
from kubernetes import config
def tryit():
config.load_kube_config(config_file="/etc/rancher/k3s/k3s.yaml") # the config for k3s
# you need to first carry out some action that will result in an Event being reported, so we'll make a simple Pod
p = {'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {'labels': {'app': 'myapp'}, 'name': 'myapp-pod'},
'spec': {'containers': [{'command': ['sh',
'-c',
'echo Hello Kubernetes! && sleep 3600'],
'image': 'busybox',
'name': 'myapp-container'}]}}
api = CoreV1Api()
t0 = api.create_namespaced_pod_with_http_info(namespace='default', body=p)
ev = EventsV1Api()
t1 = ev.list_event_for_all_namespaces_with_http_info(async_req=False) # this craters
if __name__ == "__main__":
tryit()
Anything else we need to know?:
In my dev environment I use k3s, which may be the source for the empty event_time (versions below). Nonetheless, there's clearly something wrong in how default Configurations are being handled.
As this is impacting objects that are being built inside of the K8s Python client itself, it isn't clear that there's a feasible workaround that could involve the user supplying the config object since it appears the default config isn't used and there's no way to pass in a config into list_event_for_all_namespaces_with_http_info().
Environment:
- Kubernetes version (
kubectl version): Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.5+k3s1", GitCommit:"355fff3017b06cde44dbd879408a3a6826fa7125", GitTreeState:"clean", BuildDate:"2021-03-31T06:21:52Z", GoVersion:"go1.15.10", Compiler:"gc", Platform:"linux/amd64"} - OS (e.g., MacOS 10.13.6): Ubuntu 20.04.3 LTS
- Python version (
python --version): 3.810 - Python client version (
pip list | grep kubernetes): 19.15.0
- 主要语言
- Python
- 星标
- 7.7k
- 派生
- 3.5k
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 18
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
kubernetes-client/python 的其他 Issue
-
kind/bug
难度 1/5 1 小时以内 新手友好度 68/100
kubernetes-client/python#2280 · 16 条评论 · 9 个 reaction ·
-
Release 1.37 未关闭
kubernetes-client/python#2691 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
-
help wanted
难度 5/5 一周以上 新手友好度 35/100
kubernetes-client/python#2677 · 11 条评论 · 1 个 reaction ·
-
help wanted kind/feature
kubernetes-client/python#2602 · 6 条评论 · 已指派 1 人 ·
-
kind/bug
kubernetes-client/python#2596 · 11 条评论 · 2 个 reaction · 已指派 1 人 ·
查看 kubernetes-client/python 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·