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
No related branches found
No related tags found
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 {
$method,
$uri,
$query = [],
$body = [],
$body = NULL,
$namespace = TRUE,
$apiVersion = NULL,
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 {
if ($method === 'PUT' || $method === 'POST') {
// If the resource type is role or cluster role, the apiGroups maybe
// empty, and it cannot be removed.
if (!in_array($uri, ['/roles', '/clusterroles'], TRUE)) {
$array = $this->removeEmptyProperties(json_decode($body, TRUE));
$body = json_encode($array, JSON_PRETTY_PRINT);
}
// If the resource type is K8s role or cluster role, the apiGroups maybe
// empty, then it cannot be removed.
if (!empty($body)
&& in_array($method, ['PUT', 'POST'])
&& !in_array($uri, ['/roles', '/clusterroles'], TRUE)) {
$array = $this->removeEmptyProperties(json_decode($body, TRUE));
$body = json_encode($array, JSON_PRETTY_PRINT);
}
if (empty($this->namespace)) {
$namespace = FALSE;
}
// Fallback for namespace availability.
$namespace = !empty($this->namespace);
// Handling different response statuses.
$response = parent::sendRequest(
$method,
$uri,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment