Skip to content
Snippets Groups Projects

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

Merged Yas Naoi requested to merge issue/cloud-3458095:3458095-fix-the-compatibility-5.x into 5.x
1 file
+ 18
11
Compare changes
  • Side-by-side
  • Inline
@@ -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,
Loading