Skip to content

Commit cba2395

Browse files
Merge pull request #2664 from tamird/tamird/sync-job-delete-status-compat
Align synchronous resource deletion responses
2 parents 15a0705 + 213a5f4 commit cba2395

65 files changed

Lines changed: 622 additions & 557 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ updates:
3737
`await client.close()` or an async context manager. Interactive
3838
websocket streams use the generated `_without_preload_content`
3939
operations.
40-
- `CoreV1Api.delete_namespace` now returns a decoded dictionary rather
41-
than `V1Status`, since a successful deletion can return either a
42-
terminating Namespace or a Status.
40+
- Individual resource-deletion methods that previously returned
41+
`V1Status`, including `CoreV1Api.delete_namespace` and
42+
`BatchV1Api.delete_namespaced_job`, now return decoded dictionaries in
43+
both clients. A successful deletion can return either the deleted
44+
resource or a Status; access response fields with dictionary keys
45+
instead of model attributes.
4346

4447
See [kubernetes-client/python#2631][python-pr] and
4548
[kubernetes-client/gen#305][gen-pr].

examples/job_crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def delete_job(api_instance):
8888
body=client.V1DeleteOptions(
8989
propagation_policy='Foreground',
9090
grace_period_seconds=5))
91-
print(f"Job deleted. status='{str(api_response.status)}'")
91+
print(f"Job deleted. status='{str(api_response.get('status'))}'")
9292

9393

9494
def main():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c3d1f3292b01c5e3297240c5d49a69cd078653cd4a9f3d3482afa516a2d4c429
1+
fdf8e53487f406c1ebc282797e8c33f290c6ad9bf8df9cd13a776dd6f82eaadd

kubernetes/aio/e2e_test/test_batch.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ async def test_job_apis(self):
5555
self.assertEqual(name, resp.metadata.name)
5656

5757
resp = await api.delete_namespaced_job(
58-
name=name, body={}, namespace='default')
58+
name=name, body={'propagationPolicy': 'Background'},
59+
namespace='default')
60+
self.assertIsInstance(resp, dict)
61+
self.assertIn(resp['kind'], ('Job', 'Status'))
62+
if resp['kind'] == 'Job':
63+
self.assertEqual(name, resp['metadata']['name'])
64+
else:
65+
self.assertEqual('Success', resp['status'])
66+
if 'details' in resp:
67+
self.assertEqual(name, resp['details']['name'])

kubernetes/aio/test/test_generated_api.py

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def asyncSetUp(self):
4545
'metadata': {'resourceVersion': '1'},
4646
'items': [],
4747
}
48+
self.response_status = 200
4849
app = web.Application()
4950
app.router.add_route('*', '/{path:.*}', self._handle_request)
5051
self.runner = web.AppRunner(app)
@@ -90,7 +91,7 @@ async def _handle_request(self, request):
9091
}).encode() + b'\n')
9192
await response.write_eof()
9293
return response
93-
return web.json_response(self.response)
94+
return web.json_response(self.response, status=self.response_status)
9495

9596
async def test_bearer_alias_supports_synchronous_token_refresh(self):
9697
self.configuration.api_key['authorization'] = 'expired-token'
@@ -124,34 +125,57 @@ async def refresh(configuration):
124125

125126
async def test_delete_job_accepts_job_and_status_responses(self):
126127
responses = (
127-
{
128-
'apiVersion': 'batch/v1',
129-
'kind': 'Job',
130-
'metadata': {'name': 'sample'},
131-
'status': {'ready': 0},
132-
},
133-
{
134-
'apiVersion': 'v1',
135-
'kind': 'Status',
136-
'status': 'Success',
137-
'details': {'name': 'sample', 'kind': 'jobs'},
138-
},
128+
(
129+
{
130+
'apiVersion': 'batch/v1',
131+
'kind': 'Job',
132+
'metadata': {'name': 'sample'},
133+
'status': {'ready': 0},
134+
},
135+
'Job',
136+
{'ready': 0},
137+
),
138+
(
139+
{
140+
'apiVersion': 'v1',
141+
'kind': 'Status',
142+
'status': 'Success',
143+
'details': {'name': 'sample', 'kind': 'jobs'},
144+
},
145+
'Status',
146+
'Success',
147+
),
139148
)
140149

141-
for response in responses:
142-
with self.subTest(kind=response['kind']):
143-
self.response = response
144-
deleted = await BatchV1Api(
145-
self.api_client,
146-
).delete_namespaced_job(
147-
name='sample', namespace='default', body={},
148-
)
149-
150-
self.assertEqual(response, deleted)
151-
self.assertEqual(
152-
'/apis/batch/v1/namespaces/default/jobs/sample',
153-
self.requests[-1][0].path,
154-
)
150+
for response_status in (200, 202):
151+
for response, expected_kind, expected_status in responses:
152+
with self.subTest(
153+
status=response_status, kind=expected_kind
154+
):
155+
self.response_status = response_status
156+
self.response = response
157+
deleted = await BatchV1Api(
158+
self.api_client,
159+
).delete_namespaced_job(
160+
name='sample', namespace='default', body={},
161+
)
162+
163+
self.assertIsInstance(deleted, dict)
164+
self.assertIsNot(response, deleted)
165+
self.assertEqual(response, deleted)
166+
self.assertEqual(expected_kind, deleted['kind'])
167+
self.assertEqual(expected_status, deleted['status'])
168+
if expected_kind == 'Job':
169+
self.assertIsInstance(deleted['status'], dict)
170+
self.assertIsNot(response['status'], deleted['status'])
171+
else:
172+
self.assertIsInstance(deleted['status'], str)
173+
request, body = self.requests[-1]
174+
self.assertEqual({}, json.loads(body))
175+
self.assertEqual(
176+
'/apis/batch/v1/namespaces/default/jobs/sample',
177+
request.path,
178+
)
155179

156180
async def test_object_patches_use_strategic_merge(self):
157181
self.response = {

kubernetes/client/api/admissionregistration_v1_api.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ def delete_mutating_admission_policy(
43044304
_content_type: Optional[StrictStr] = None,
43054305
_headers: Optional[Dict[StrictStr, Any]] = None,
43064306
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
4307-
) -> V1Status:
4307+
) -> object:
43084308
"""delete_mutating_admission_policy
43094309

43104310
delete a MutatingAdmissionPolicy
@@ -4372,8 +4372,8 @@ def delete_mutating_admission_policy(
43724372
)
43734373

43744374
_response_types_map: Dict[str, Optional[str]] = {
4375-
'200': "V1Status",
4376-
'202': "V1Status",
4375+
'200': "object",
4376+
'202': "object",
43774377
'401': None,
43784378
}
43794379
return self.api_client._call_with_legacy_options(
@@ -4412,7 +4412,7 @@ def delete_mutating_admission_policy_with_http_info(
44124412
_content_type: Optional[StrictStr] = None,
44134413
_headers: Optional[Dict[StrictStr, Any]] = None,
44144414
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
4415-
) -> Tuple[V1Status, int, Any]:
4415+
) -> Tuple[object, int, Any]:
44164416
"""delete_mutating_admission_policy
44174417

44184418
delete a MutatingAdmissionPolicy
@@ -4480,8 +4480,8 @@ def delete_mutating_admission_policy_with_http_info(
44804480
)
44814481

44824482
_response_types_map: Dict[str, Optional[str]] = {
4483-
'200': "V1Status",
4484-
'202': "V1Status",
4483+
'200': "object",
4484+
'202': "object",
44854485
'401': None,
44864486
}
44874487
return self.api_client._call_with_legacy_options(
@@ -4620,7 +4620,7 @@ def delete_mutating_admission_policy_binding(
46204620
_content_type: Optional[StrictStr] = None,
46214621
_headers: Optional[Dict[StrictStr, Any]] = None,
46224622
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
4623-
) -> V1Status:
4623+
) -> object:
46244624
"""delete_mutating_admission_policy_binding
46254625

46264626
delete a MutatingAdmissionPolicyBinding
@@ -4688,8 +4688,8 @@ def delete_mutating_admission_policy_binding(
46884688
)
46894689

46904690
_response_types_map: Dict[str, Optional[str]] = {
4691-
'200': "V1Status",
4692-
'202': "V1Status",
4691+
'200': "object",
4692+
'202': "object",
46934693
'401': None,
46944694
}
46954695
return self.api_client._call_with_legacy_options(
@@ -4728,7 +4728,7 @@ def delete_mutating_admission_policy_binding_with_http_info(
47284728
_content_type: Optional[StrictStr] = None,
47294729
_headers: Optional[Dict[StrictStr, Any]] = None,
47304730
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
4731-
) -> Tuple[V1Status, int, Any]:
4731+
) -> Tuple[object, int, Any]:
47324732
"""delete_mutating_admission_policy_binding
47334733

47344734
delete a MutatingAdmissionPolicyBinding
@@ -4796,8 +4796,8 @@ def delete_mutating_admission_policy_binding_with_http_info(
47964796
)
47974797

47984798
_response_types_map: Dict[str, Optional[str]] = {
4799-
'200': "V1Status",
4800-
'202': "V1Status",
4799+
'200': "object",
4800+
'202': "object",
48014801
'401': None,
48024802
}
48034803
return self.api_client._call_with_legacy_options(
@@ -4936,7 +4936,7 @@ def delete_mutating_webhook_configuration(
49364936
_content_type: Optional[StrictStr] = None,
49374937
_headers: Optional[Dict[StrictStr, Any]] = None,
49384938
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
4939-
) -> V1Status:
4939+
) -> object:
49404940
"""delete_mutating_webhook_configuration
49414941

49424942
delete a MutatingWebhookConfiguration
@@ -5004,8 +5004,8 @@ def delete_mutating_webhook_configuration(
50045004
)
50055005

50065006
_response_types_map: Dict[str, Optional[str]] = {
5007-
'200': "V1Status",
5008-
'202': "V1Status",
5007+
'200': "object",
5008+
'202': "object",
50095009
'401': None,
50105010
}
50115011
return self.api_client._call_with_legacy_options(
@@ -5044,7 +5044,7 @@ def delete_mutating_webhook_configuration_with_http_info(
50445044
_content_type: Optional[StrictStr] = None,
50455045
_headers: Optional[Dict[StrictStr, Any]] = None,
50465046
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5047-
) -> Tuple[V1Status, int, Any]:
5047+
) -> Tuple[object, int, Any]:
50485048
"""delete_mutating_webhook_configuration
50495049

50505050
delete a MutatingWebhookConfiguration
@@ -5112,8 +5112,8 @@ def delete_mutating_webhook_configuration_with_http_info(
51125112
)
51135113

51145114
_response_types_map: Dict[str, Optional[str]] = {
5115-
'200': "V1Status",
5116-
'202': "V1Status",
5115+
'200': "object",
5116+
'202': "object",
51175117
'401': None,
51185118
}
51195119
return self.api_client._call_with_legacy_options(
@@ -5252,7 +5252,7 @@ def delete_validating_admission_policy(
52525252
_content_type: Optional[StrictStr] = None,
52535253
_headers: Optional[Dict[StrictStr, Any]] = None,
52545254
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5255-
) -> V1Status:
5255+
) -> object:
52565256
"""delete_validating_admission_policy
52575257

52585258
delete a ValidatingAdmissionPolicy
@@ -5320,8 +5320,8 @@ def delete_validating_admission_policy(
53205320
)
53215321

53225322
_response_types_map: Dict[str, Optional[str]] = {
5323-
'200': "V1Status",
5324-
'202': "V1Status",
5323+
'200': "object",
5324+
'202': "object",
53255325
'401': None,
53265326
}
53275327
return self.api_client._call_with_legacy_options(
@@ -5360,7 +5360,7 @@ def delete_validating_admission_policy_with_http_info(
53605360
_content_type: Optional[StrictStr] = None,
53615361
_headers: Optional[Dict[StrictStr, Any]] = None,
53625362
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5363-
) -> Tuple[V1Status, int, Any]:
5363+
) -> Tuple[object, int, Any]:
53645364
"""delete_validating_admission_policy
53655365

53665366
delete a ValidatingAdmissionPolicy
@@ -5428,8 +5428,8 @@ def delete_validating_admission_policy_with_http_info(
54285428
)
54295429

54305430
_response_types_map: Dict[str, Optional[str]] = {
5431-
'200': "V1Status",
5432-
'202': "V1Status",
5431+
'200': "object",
5432+
'202': "object",
54335433
'401': None,
54345434
}
54355435
return self.api_client._call_with_legacy_options(
@@ -5568,7 +5568,7 @@ def delete_validating_admission_policy_binding(
55685568
_content_type: Optional[StrictStr] = None,
55695569
_headers: Optional[Dict[StrictStr, Any]] = None,
55705570
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5571-
) -> V1Status:
5571+
) -> object:
55725572
"""delete_validating_admission_policy_binding
55735573

55745574
delete a ValidatingAdmissionPolicyBinding
@@ -5636,8 +5636,8 @@ def delete_validating_admission_policy_binding(
56365636
)
56375637

56385638
_response_types_map: Dict[str, Optional[str]] = {
5639-
'200': "V1Status",
5640-
'202': "V1Status",
5639+
'200': "object",
5640+
'202': "object",
56415641
'401': None,
56425642
}
56435643
return self.api_client._call_with_legacy_options(
@@ -5676,7 +5676,7 @@ def delete_validating_admission_policy_binding_with_http_info(
56765676
_content_type: Optional[StrictStr] = None,
56775677
_headers: Optional[Dict[StrictStr, Any]] = None,
56785678
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5679-
) -> Tuple[V1Status, int, Any]:
5679+
) -> Tuple[object, int, Any]:
56805680
"""delete_validating_admission_policy_binding
56815681

56825682
delete a ValidatingAdmissionPolicyBinding
@@ -5744,8 +5744,8 @@ def delete_validating_admission_policy_binding_with_http_info(
57445744
)
57455745

57465746
_response_types_map: Dict[str, Optional[str]] = {
5747-
'200': "V1Status",
5748-
'202': "V1Status",
5747+
'200': "object",
5748+
'202': "object",
57495749
'401': None,
57505750
}
57515751
return self.api_client._call_with_legacy_options(
@@ -5884,7 +5884,7 @@ def delete_validating_webhook_configuration(
58845884
_content_type: Optional[StrictStr] = None,
58855885
_headers: Optional[Dict[StrictStr, Any]] = None,
58865886
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5887-
) -> V1Status:
5887+
) -> object:
58885888
"""delete_validating_webhook_configuration
58895889

58905890
delete a ValidatingWebhookConfiguration
@@ -5952,8 +5952,8 @@ def delete_validating_webhook_configuration(
59525952
)
59535953

59545954
_response_types_map: Dict[str, Optional[str]] = {
5955-
'200': "V1Status",
5956-
'202': "V1Status",
5955+
'200': "object",
5956+
'202': "object",
59575957
'401': None,
59585958
}
59595959
return self.api_client._call_with_legacy_options(
@@ -5992,7 +5992,7 @@ def delete_validating_webhook_configuration_with_http_info(
59925992
_content_type: Optional[StrictStr] = None,
59935993
_headers: Optional[Dict[StrictStr, Any]] = None,
59945994
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
5995-
) -> Tuple[V1Status, int, Any]:
5995+
) -> Tuple[object, int, Any]:
59965996
"""delete_validating_webhook_configuration
59975997

59985998
delete a ValidatingWebhookConfiguration
@@ -6060,8 +6060,8 @@ def delete_validating_webhook_configuration_with_http_info(
60606060
)
60616061

60626062
_response_types_map: Dict[str, Optional[str]] = {
6063-
'200': "V1Status",
6064-
'202': "V1Status",
6063+
'200': "object",
6064+
'202': "object",
60656065
'401': None,
60666066
}
60676067
return self.api_client._call_with_legacy_options(

0 commit comments

Comments
 (0)