Duplicate resource names
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 12
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Hi
Look like the id() method in python is not return unique value. It will cause 409 Conflict error when create items.
Code for reproduce
import yaml
from kubernetes import client, config
from kubecrd import KubeResourceBase
from apischema import schema
from dataclasses import dataclass, field
@dataclass
class Member(KubeResourceBase):
__group__ = "example.io"
__version__ = "v1"
id: int = field(
metadata=schema(
description="Member ID"
)
)
name: str = field(
metadata=schema(
description="Member name"
)
)
squad: str = field(
metadata=schema(
description="Member belong to squad"
)
)
def create_items(members: list, k8s_client):
for m in members:
name = m["name"]
squad = m["squad"]
member = Member(
id=m["id"],
name=name,
squad=squad)
member.save(k8s_client)
print(f"🚀 Added {name} in {squad}")
member_yaml = """
members:
- id: 1
name: Cola
squad: A
- id: 2
name: Ash
squad: A
- id: 3
name: Casey
squad: A
- id: 4
name: Oreo
squad: B
- id: 5
name: Mrs Muddy
squad: B
- id: 6
name: Mrs Peculiarpop
squad: B
"""
config.load_incluster_config()
k8s_client = client.ApiClient()
Member.install(k8s_client)
members = yaml.safe_load(member_yaml)
create_items(members["members"], k8s_client)
error message
python3 test2.py
🚀 Added Cola in Cola
🚀 Added Ash in Ash
🚀 Added Casey in Casey
Traceback (most recent call last):
File "/data/roster-reminder/test2.py", line 69, in <module>
create_items(members["members"], k8s_client)
File "/data/roster-reminder/test2.py", line 38, in create_items
member.save(k8s_client)
File "/usr/local/lib/python3.9/dist-packages/kubecrd/schemabase.py", line 219, in save
resp = api_instance.create_namespaced_custom_object(
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/api/custom_objects_api.py", line 225, in create_namespaced_custom_object
return self.create_namespaced_custom_object_with_http_info(group, version, namespace, plural, body, **kwargs) # noqa: E501
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/api/custom_objects_api.py", line 344, in create_namespaced_custom_object_with_http_info
return self.api_client.call_api(
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/api_client.py", line 348, in call_api
return self.__call_api(resource_path, method,
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/api_client.py", line 180, in __call_api
response_data = self.request(
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/api_client.py", line 391, in request
return self.rest_client.POST(url,
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/rest.py", line 275, in POST
return self.request("POST", url,
File "/usr/local/lib/python3.9/dist-packages/kubernetes/client/rest.py", line 234, in request
raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (409)
Reason: Conflict
HTTP response headers: HTTPHeaderDict({'Audit-Id': '3267083b-7bb1-469c-b79d-ed742c074343', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': '7b16e3db-c9ab-40ae-819a-1a4b90061a5f', 'X-Kubernetes-Pf-Prioritylevel-Uid': '4af6bed6-a525-4ea7-9599-5e3f481a867b', 'Date': 'Thu, 17 Nov 2022 01:20:26 GMT', 'Content-Length': '258'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"members.example.io \"member140400840708880\" already exists","reason":"AlreadyExists","details":{"name":"member140400840708880","group":"example.io","kind":"members"},"code":409}
kubectl get return:
apiVersion: v1
items:
- apiVersion: example.io/v1
kind: Member
metadata:
creationTimestamp: "2022-11-17T01:20:26Z"
generation: 1
name: member140400840708880
namespace: default
resourceVersion: "152738485"
uid: 6abe05e2-f3ac-4177-b4b9-acd959f50c3b
spec:
id: 2
name: Ash
squad: Ash
- apiVersion: example.io/v1
kind: Member
metadata:
creationTimestamp: "2022-11-17T01:20:26Z"
generation: 1
name: member140400840710368
namespace: default
resourceVersion: "152738484"
uid: 4944ac38-e210-4cd1-bbda-04eea2fd1cb0
spec:
id: 1
name: Cola
squad: Cola
- apiVersion: example.io/v1
kind: Member
metadata:
creationTimestamp: "2022-11-17T01:20:26Z"
generation: 1
name: member140400863499312
namespace: default
resourceVersion: "152738486"
uid: eaa875b9-a6c2-477c-af23-af3b5254f705
spec:
id: 3
name: Casey
squad: Casey
kind: List
metadata:
resourceVersion: ""
selfLink: ""
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in kubecrd/schemabase.py around the id() method at line 212, then run the provided Kubernetes custom-resource reproduction. Check how repeated Member objects derive their resource names; the issue is done when creating the listed members no longer produces a 409 AlreadyExists error and each resource has a unique name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100