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

Merge branch '3458095-fix-the-compatibility' into '7.x'

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

See merge request !2305
parents 24eaf8ea 30c689f5
No related branches found
No related tags found
No related merge requests found
Pipeline #213377 canceled
diff --git a/CLOUD-6097 b/CLOUD-6097
new file mode 100644
index 000000000..0e9ba32d3
--- /dev/null
+++ b/CLOUD-6097
@@ -0,0 +1,102 @@
+diff --git a/CLOUD-6097 b/CLOUD-6097
+new file mode 100644
+index 000000000..b97b28c17
+--- /dev/null
++++ b/CLOUD-6097
+@@ -0,0 +1,48 @@
++diff --git a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
++index 7986849ee..2120c46b1 100644
++--- a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
+++++ b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
++@@ -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,
+diff --git a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
+index 7986849ee..2120c46b1 100644
+--- a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
++++ b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
+@@ -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,
diff --git a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
index 7986849ee..0f134f0ca 100644
--- a/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
+++ b/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php
@@ -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,
......@@ -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