Repository navigation
fix: send propagationPolicy at the top level of DeleteOptions #28
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
Open
abnegate
wants to merge
5
commits into
main
Choose a base branch
from
fix/delete-propagation-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd588c0
fix: send propagationPolicy at the top level of DeleteOptions
abnegate 029191f
Merge remote-tracking branch 'origin/main' into work/fix/delete-propa…
abnegate 75fd8d0
fix: accept the PropagationPolicy enum and wait out foreground deletes
abnegate 627db1a
test: assert the DeleteOptions that delete() puts on the wire
abnegate 2f269f4
test: keep one response queue per recording cluster
abnegate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace RenokiCo\PhpK8s\Enums; | ||
|
|
||
| /** | ||
| * Dependent deletion policies accepted by the Kubernetes DeleteOptions API. | ||
| */ | ||
| enum PropagationPolicy: string | ||
| { | ||
| case ORPHAN = 'Orphan'; | ||
| case BACKGROUND = 'Background'; | ||
| case FOREGROUND = 'Foreground'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| <?php | ||
|
|
||
| namespace RenokiCo\PhpK8s\Test; | ||
|
|
||
| use InvalidArgumentException; | ||
| use RenokiCo\PhpK8s\Enums\PropagationPolicy; | ||
|
|
||
| class DeleteOptionsTest extends TestCase | ||
| { | ||
| public function test_propagation_policy_is_a_top_level_delete_options_field() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $job->syncWith([ | ||
| 'metadata' => [ | ||
| 'name' => 'reap', | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| 'resourceVersion' => '12345', | ||
| ], | ||
| ]); | ||
|
|
||
| $options = $job->deleteOptions(null, 'Foreground'); | ||
|
|
||
| $this->assertSame('DeleteOptions', $options['kind']); | ||
| $this->assertSame('v1', $options['apiVersion']); | ||
| $this->assertSame('Foreground', $options['propagationPolicy']); | ||
| $this->assertSame(['uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900'], $options['preconditions']); | ||
| $this->assertArrayNotHasKey('propagationPolicy', $options['preconditions']); | ||
| $this->assertArrayNotHasKey('gracePeriodSeconds', $options['preconditions']); | ||
| $this->assertArrayNotHasKey('gracePeriodSeconds', $options); | ||
| } | ||
|
|
||
| public function test_grace_period_is_a_top_level_delete_options_field() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $job->syncWith([ | ||
| 'metadata' => [ | ||
| 'name' => 'reap', | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| ], | ||
| ]); | ||
|
|
||
| $options = $job->deleteOptions(30, 'Background'); | ||
|
|
||
| $this->assertSame('Background', $options['propagationPolicy']); | ||
| $this->assertSame(30, $options['gracePeriodSeconds']); | ||
| $this->assertSame(['uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900'], $options['preconditions']); | ||
| } | ||
|
|
||
| public function test_preconditions_are_omitted_without_a_resource_uid() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $options = $job->deleteOptions(null, 'Foreground'); | ||
|
|
||
| $this->assertSame('Foreground', $options['propagationPolicy']); | ||
| $this->assertArrayNotHasKey('preconditions', $options); | ||
| } | ||
|
|
||
| public function test_invalid_propagation_policy_is_rejected_before_the_request() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $this->expectException(InvalidArgumentException::class); | ||
| $this->expectExceptionMessage('Invalid propagation policy "foreground"'); | ||
|
|
||
| $job->deleteOptions(null, 'foreground'); | ||
| } | ||
|
|
||
| public function test_propagation_policy_accepts_the_enum() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $this->assertSame( | ||
| 'Orphan', | ||
| $job->deleteOptions(null, PropagationPolicy::ORPHAN)['propagationPolicy'] | ||
| ); | ||
| } | ||
|
|
||
| public function test_delete_sends_the_propagation_policy_at_the_top_level() | ||
| { | ||
| $cluster = (new RecordingCluster('http://127.0.0.1:8080')) | ||
| ->respondWith([ | ||
| ['kind' => 'Job', 'apiVersion' => 'batch/v1', 'metadata' => [ | ||
| 'name' => 'reap', | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| ]], | ||
| ['kind' => 'Status', 'apiVersion' => 'v1', 'status' => 'Success'], | ||
| ]); | ||
|
|
||
| $job = $cluster->job()->setName('reap'); | ||
| $job->syncWith([ | ||
| 'metadata' => [ | ||
| 'name' => 'reap', | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->assertTrue($job->delete(gracePeriod: 30, propagationPolicy: PropagationPolicy::BACKGROUND)); | ||
|
|
||
| $requests = $cluster->requests(); | ||
|
|
||
| $this->assertCount(2, $requests, 'delete() refreshes the resource, then deletes it'); | ||
| $this->assertSame('GET', $requests[0]->getMethod()); | ||
|
|
||
| $delete = $requests[1]; | ||
| $this->assertSame('DELETE', $delete->getMethod()); | ||
|
|
||
| $sent = json_decode((string) $delete->getBody(), true); | ||
|
|
||
| $this->assertSame('Background', $sent['propagationPolicy'] ?? null); | ||
| $this->assertSame(30, $sent['gracePeriodSeconds'] ?? null); | ||
| $this->assertSame( | ||
| ['uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900'], | ||
| $sent['preconditions'] ?? null, | ||
| 'only the uid belongs in preconditions' | ||
| ); | ||
| } | ||
|
|
||
| public function test_delete_options_payload_shape_matches_the_kubernetes_api() | ||
| { | ||
| $job = $this->cluster->job()->setName('reap'); | ||
|
|
||
| $job->syncWith([ | ||
| 'metadata' => [ | ||
| 'name' => 'reap', | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| ], | ||
| 'spec' => [ | ||
| 'template' => [ | ||
| 'spec' => [ | ||
| 'containers' => [], | ||
| ], | ||
| ], | ||
| ], | ||
| ]); | ||
|
|
||
| $payload = $job->deleteOptions(null, 'Foreground'); | ||
|
|
||
| $this->assertSame( | ||
| [ | ||
| 'apiVersion' => 'v1', | ||
| 'kind' => 'DeleteOptions', | ||
| 'propagationPolicy' => 'Foreground', | ||
| 'preconditions' => [ | ||
| 'uid' => 'aa11bb22-cc33-dd44-ee55-ff6677889900', | ||
| ], | ||
| ], | ||
| $payload | ||
| ); | ||
|
|
||
| $this->assertArrayNotHasKey('spec', $payload); | ||
| $this->assertArrayNotHasKey('metadata', $payload); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.