Unable to patch groups returned in a list
larsks opened this issue · 1 comments
larsks commented
I am trying to remove a user from a list of groups. The code looks something like this:
groups = groupv1.get(label_selector='mylabel')
for group in groups.items:
try:
group.users.remove('some-user')
except (ValueError, AttributeError):
pass
else:
groupsv1.patch(body=group)
But this fails with:
File "/home/lars/.local/share/virtualenvs/acct-manager-qCJKB4-x/lib/python3.10/site-packages/openshift/dynamic/client.py", line 89, in serialize_body
return body.to_dict()
TypeError: 'NoneType' object is not callable
So okay, maybe I should try passing in a dict
instead:
groupsv1.patch(body=dict(group))
But this fails with:
[...]
File "/home/lars/.local/share/virtualenvs/acct-manager-qCJKB4-x/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 238, in sanitize_for_serialization
for attr, _ in six.iteritems(obj.openapi_types)
File "/home/lars/.local/share/virtualenvs/acct-manager-qCJKB4-x/lib/python3.10/site-packages/six.py", line 605, in iteritems
return iter(d.items(**kw))
AttributeError: 'NoneType' object has no attribute 'items'
So...maybe I should be patching the list all at once, rather than
individually:
groups = groupv1.get(label_selector='mylabel')
for group in groups.items:
try:
group.users.remove('some-user')
except (ValueError, AttributeError):
pass
groupsv1.patch(body=groups)
But this fails with:
File "/home/lars/.local/share/virtualenvs/acct-manager-qCJKB4-x/lib/python3.10/site-packages/openshift/dynamic/client.py", line 125, in patch
raise ValueError("name is required to patch {}.{}".format(resource.group_version, resource.kind))
ValueError: name is required to patch user.openshift.io/v1.Group
What's the correct way to patch these objects?
larsks commented
Ugh, I walked away to get coffee and came back, and now I can't reproduce the failure using dict(group)
, so I guess I'm closing this for now.