From e580f30dde3bc8fecaa7db7d94107a97786e865d Mon Sep 17 00:00:00 2001 From: Glenn Schmidt Date: Sat, 8 Jul 2017 18:14:31 +1000 Subject: [PATCH 1/2] Support for specifying options when deleting a resource --- src/Client.php | 10 +++++----- src/Models/DeleteOptions.php | 6 ++++++ src/Repositories/Repository.php | 18 +++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/Models/DeleteOptions.php diff --git a/src/Client.php b/src/Client.php index 908c7a2..48f6ef9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -267,11 +267,11 @@ public function sendRequest($method, $uri, $query = [], $body = [], $namespace = $requestUri = $baseUri . $uri; $requestOptions = []; - if ($method != 'DELETE') { - $requestOptions = [ - 'query' => is_array($query) ? $query : [], - 'body' => is_array($body) ? json_encode($body) : $body, - ]; + if (is_array($query) && !empty($query)) { + $requestOptions['query'] = $query; + } + if ($body !== null) { + $requestOptions['body'] = is_array($body) ? json_encode($body) : $body; } if (!$this->isUsingGuzzle6()) { diff --git a/src/Models/DeleteOptions.php b/src/Models/DeleteOptions.php new file mode 100644 index 0000000..4a35fd7 --- /dev/null +++ b/src/Models/DeleteOptions.php @@ -0,0 +1,6 @@ +deleteByName($model->getMetadata('name')); + return $this->deleteByName($model->getMetadata('name'), $options); } /** * Delete a model by name. * - * @param string $name + * @param string $name + * @param \Maclof\Kubernetes\Models\DeleteOptions $options * @return boolean */ - public function deleteByName($name) + public function deleteByName($name, DeleteOptions $options=null) { + $body = $options ? $options->getSchema() : null; if ($this->beta) { - $this->client->sendBetaRequest('DELETE', '/' . $this->uri . '/' . $name); + $this->client->sendBetaRequest('DELETE', '/' . $this->uri . '/' . $name, null, $body); } else { - $this->client->sendRequest('DELETE', '/' . $this->uri . '/' . $name); + $this->client->sendRequest('DELETE', '/' . $this->uri . '/' . $name, null, $body); } return true; } From 6d4f08b1cbb8405bbac69951a575b921e6fcb270 Mon Sep 17 00:00:00 2001 From: Glenn Schmidt Date: Sun, 9 Jul 2017 00:52:22 +1000 Subject: [PATCH 2/2] Add documentation about delete options --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index abbc9cc..dd18b0f 100644 --- a/README.md +++ b/README.md @@ -150,3 +150,16 @@ $replicationController = $client->replicationControllers()->setLabelSelector([ ])->first(); $client->replicationControllers()->delete($replicationController); ``` + +You can also specify options when performing a deletion, eg. to perform [cascading delete]( https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#setting-the-cascading-deletion-policy) + +```php +use Maclof\Kubernetes\Models\DeleteOptions; + +$client->replicationControllers()->delete($replicationController, + new DeleteOptions(['propagationPolicy' => 'Background'])); +``` + +See the API documentation for an explanation of the options: + +https://kubernetes.io/docs/api-reference/v1.6/#deleteoptions-v1-meta