Skip to content
Snippets Groups Projects
Commit a107a605 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #3458095 by yas, zterry95: Fix compatibility with Maclof\Kubernetes\Client

parent 445b5218
Branches
Tags
1 merge request!2309Issue #3458095 by yas, zterry95: Fix compatibility with Maclof\Kubernetes\Client
Pipeline #215109 passed
...@@ -26,25 +26,32 @@ class K8sClient extends Client { ...@@ -26,25 +26,32 @@ class K8sClient extends Client {
$method, $method,
$uri, $uri,
$query = [], $query = [],
$body = [], $body = NULL,
$namespace = TRUE, $namespace = TRUE,
$apiVersion = NULL, $apiVersion = NULL,
array $requestOptions = [], array $requestOptions = [],
) { ) {
// Normalize $body to either NULL or a non-empty string if appropriate.
$body = empty($body) && !is_bool($body) && !is_numeric($body) ? NULL : $body;
if (!is_null($body) && !is_string($body)) {
throw new \InvalidArgumentException('A variable $body must be a string, array, or NULL');
}
try { try {
if ($method === 'PUT' || $method === 'POST') { // If the resource type is K8s role or cluster role, the apiGroups maybe
// If the resource type is role or cluster role, the apiGroups maybe // empty, then it cannot be removed.
// empty, and it cannot be removed. if (!empty($body)
if (!in_array($uri, ['/roles', '/clusterroles'], TRUE)) { && in_array($method, ['PUT', 'POST'])
$array = $this->removeEmptyProperties(json_decode($body, TRUE)); && !in_array($uri, ['/roles', '/clusterroles'], TRUE)) {
$body = json_encode($array, JSON_PRETTY_PRINT); $array = $this->removeEmptyProperties(json_decode($body, TRUE));
} $body = json_encode($array, JSON_PRETTY_PRINT);
} }
if (empty($this->namespace)) { // Fallback for namespace availability.
$namespace = FALSE; $namespace = !empty($this->namespace);
}
// Handling different response statuses.
$response = parent::sendRequest( $response = parent::sendRequest(
$method, $method,
$uri, $uri,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment