Skip to content

Commit d9bfc81

Browse files
committed
feat: return log responses as strings without JSON parsing
1 parent 09b0875 commit d9bfc81

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/KubernetesCluster.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function runOperation(Operation|string $operation, string $path, string|n
183183
Operation::APPLY => $this->applyPath($path, $payload, $query),
184184
Operation::JSON_PATCH => $this->jsonPatchPath($path, $payload, $query),
185185
Operation::JSON_MERGE_PATCH => $this->jsonMergePatchPath($path, $payload, $query),
186-
default => $this->makeRequest($operation->httpMethod(), $path, $payload, $query),
186+
default => $this->makeRequest($operation, $path, $payload, $query),
187187
};
188188
}
189189

@@ -351,7 +351,7 @@ protected function execPath(
351351
array $query = ['pretty' => 1, 'stdin' => 1, 'stdout' => 1, 'stderr' => 1, 'tty' => 1]
352352
): mixed {
353353
try {
354-
return $this->makeRequest(Operation::EXEC->httpMethod(), $path, '', $query);
354+
return $this->makeRequest(Operation::EXEC, $path, '', $query);
355355
} catch (KubernetesAPIException $e) {
356356
$payload = $e->getPayload();
357357

@@ -380,7 +380,7 @@ protected function attachPath(
380380
array $query = ['pretty' => 1, 'stdin' => 1, 'stdout' => 1, 'stderr' => 1, 'tty' => 1]
381381
): mixed {
382382
try {
383-
return $this->makeRequest(Operation::ATTACH->httpMethod(), $path, '', $query);
383+
return $this->makeRequest(Operation::ATTACH, $path, '', $query);
384384
} catch (KubernetesAPIException $e) {
385385
$payload = $e->getPayload();
386386

@@ -411,7 +411,7 @@ protected function applyPath(string $path, string $payload, array $query = ['pre
411411
],
412412
];
413413

414-
return $this->makeRequest(Operation::APPLY->httpMethod(), $path, $payload, $query, $options);
414+
return $this->makeRequest(Operation::APPLY, $path, $payload, $query, $options);
415415
}
416416

417417
/**
@@ -428,7 +428,7 @@ protected function jsonPatchPath(string $path, string $payload, array $query = [
428428
],
429429
];
430430

431-
return $this->makeRequest(Operation::JSON_PATCH->httpMethod(), $path, $payload, $query, $options);
431+
return $this->makeRequest(Operation::JSON_PATCH, $path, $payload, $query, $options);
432432
}
433433

434434
/**
@@ -445,7 +445,7 @@ protected function jsonMergePatchPath(string $path, string $payload, array $quer
445445
],
446446
];
447447

448-
return $this->makeRequest(Operation::JSON_MERGE_PATCH->httpMethod(), $path, $payload, $query, $options);
448+
return $this->makeRequest(Operation::JSON_MERGE_PATCH, $path, $payload, $query, $options);
449449
}
450450

451451
/**

src/Traits/Cluster/MakesHttpCalls.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\ClientException;
77
use GuzzleHttp\RequestOptions;
8+
use RenokiCo\PhpK8s\Enums\Operation;
89
use RenokiCo\PhpK8s\Exceptions\KubernetesAPIException;
910
use RenokiCo\PhpK8s\ResourcesList;
1011

@@ -146,18 +147,23 @@ public function call(string $method, string $path, string $payload = '', array $
146147
}
147148

148149
/**
149-
* Call the API with the specified method and path.
150+
* Call the API with the specified operation and path.
150151
*
151152
* @return mixed
152153
*
153154
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
154155
*/
155-
protected function makeRequest(string $method, string $path, string $payload = '', array $query = ['pretty' => 1], array $options = [])
156+
protected function makeRequest(Operation $operation, string $path, string $payload = '', array $query = ['pretty' => 1], array $options = [])
156157
{
157158
$resourceClass = $this->resourceClass;
158159

160+
$method = $operation->httpMethod();
159161
$response = $this->call($method, $path, $payload, $query, $options);
160162

163+
if ($operation === Operation::LOG) {
164+
return (string) $response->getBody();
165+
}
166+
161167
$json = @json_decode($response->getBody(), true);
162168

163169
// If the output is not JSONable, return the response itself.

0 commit comments

Comments
 (0)