Skip to content

Commit

Permalink
Merge pull request #141 from renoki-co/fix/encoding-in-exec-2.x
Browse files Browse the repository at this point in the history
[fix/2.x] Typos & urlencode the command in exec
  • Loading branch information
rennokki authored Oct 11, 2021
2 parents ce9b9cc + a045cc5 commit c9f66aa
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Instances/Probe.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getCommand()
*
* @param string $path
* @param int $port
* @param array $headers
* @param array $headers
* @param string $scheme
* @return $this
*/
Expand Down
1 change: 1 addition & 0 deletions src/Kinds/K8sEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function setResource(K8sResource $resource)
*
* @param array $query
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function emitOrUpdate(array $query = ['pretty' => 1])
Expand Down
2 changes: 1 addition & 1 deletion src/Kinds/K8sHorizontalPodAutoscaler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function addMetric(ResourceMetric $metric)
/**
* Add multiple metrics in one batch.
*
* @param array $metrics
* @param array $metrics
* @return $this
*/
public function addMetrics(array $metrics)
Expand Down
7 changes: 7 additions & 0 deletions src/Kinds/K8sResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function toJsonPayload(string $kind = null)
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
*/
public function watchByName(string $name, Closure $callback, array $query = ['pretty' => 1])
Expand All @@ -166,6 +167,7 @@ public function watchByName(string $name, Closure $callback, array $query = ['pr
* @param string $container
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand All @@ -181,6 +183,7 @@ public function containerLogs(string $container, array $query = ['pretty' => 1])
* @param Closure $callback
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand All @@ -197,6 +200,7 @@ public function logsByName(string $name, array $query = ['pretty' => 1])
* @param Closure $callback
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand All @@ -212,6 +216,7 @@ public function containerLogsByName(string $name, string $container, array $quer
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
*/
Expand All @@ -226,6 +231,7 @@ public function watchContainerLogs(string $container, Closure $callback, array $
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
*/
Expand All @@ -242,6 +248,7 @@ public function watchLogsByName(string $name, Closure $callback, array $query =
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Kinds/K8sScale.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function refresh(array $query = ['pretty' => 1])
}

/**
* Make a call to teh cluster to get fresh original values.
* Make a call to the cluster to get fresh original values.
*
* @param array $query
* @return $this
Expand Down
9 changes: 7 additions & 2 deletions src/KubernetesCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ protected function buildStreamContextOptions(): array
* @param string $payload
* @param array $query
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function call(string $method, string $path, string $payload = '', array $query = ['pretty' => 1])
Expand Down Expand Up @@ -299,6 +300,7 @@ public function call(string $method, string $path, string $payload = '', array $
* @param string $payload
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
protected function makeRequest(string $method, string $path, string $payload = '', array $query = ['pretty' => 1])
Expand Down Expand Up @@ -414,6 +416,7 @@ protected function makeWsRequest(string $path, Closure $callback = null, array $
* @param string|Closure $payload
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function runOperation(string $operation, string $path, $payload = '', array $query = ['pretty' => 1])
Expand All @@ -434,7 +437,7 @@ public function runOperation(string $operation, string $path, $payload = '', arr
/**
* Watch for the current resource or a resource list.
*
* @param string $path
* @param string $path
* @param Closure $callback
* @param array $query
* @return bool
Expand Down Expand Up @@ -467,7 +470,7 @@ protected function watchPath(string $path, Closure $callback, array $query = ['p
/**
* Watch for the logs for the resource.
*
* @param string $path
* @param string $path
* @param Closure $callback
* @param array $query
* @return bool
Expand Down Expand Up @@ -497,6 +500,7 @@ protected function watchLogsPath(string $path, Closure $callback, array $query =
* @param string $path
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
protected function execPath(
Expand Down Expand Up @@ -528,6 +532,7 @@ protected function execPath(
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
protected function attachPath(
Expand Down
1 change: 1 addition & 0 deletions src/Traits/Cluster/ChecksClusterVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ trait ChecksClusterVersion
* Load the cluster version.
*
* @return void
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
protected function loadClusterVersion(): void
Expand Down
3 changes: 3 additions & 0 deletions src/Traits/Cluster/LoadsFromKubeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function setTempFolder(string $tempFolder)
*
* @param string|null $context
* @return $this
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigClusterNotFound
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigContextNotFound
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigUserNotFound
Expand Down Expand Up @@ -104,6 +105,7 @@ public function fromKubeConfigYamlFile(string $path = '/.kube/config', string $c
* @param array $kubeconfig
* @param string $context
* @return void
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigClusterNotFound
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigContextNotFound
* @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigUserNotFound
Expand Down Expand Up @@ -175,6 +177,7 @@ protected function loadKubeConfigFromArray(array $kubeconfig, string $context):
* @param string $fileName
* @param string $contents
* @return string
*
* @throws \Exception
*/
protected function writeTempFileForContext(string $context, string $fileName, string $contents)
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function addRules(array $rules)
* Set the rules for the resource.
*
* @param array $rules
* @return $this
* @return $this
*/
public function setRules(array $rules)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasSubjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function addSubjects(array $subjects)
* Set the subjects for the resource.
*
* @param array $subjects
* @return $this
* @return $this
*/
public function setSubjects(array $subjects)
{
Expand Down
23 changes: 18 additions & 5 deletions src/Traits/RunsClusterOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function refresh(array $query = ['pretty' => 1])
}

/**
* Make a call to teh cluster to get fresh original values.
* Make a call to the cluster to get fresh original values.
*
* @param array $query
* @return $this
Expand All @@ -96,8 +96,8 @@ public function refreshOriginal(array $query = ['pretty' => 1])
}

/**
* Create or update the resource according
* to the cluster availability.
* Create or update the resource, wether the resource exists
* or not within the cluster.
*
* @param array $query
* @return $this
Expand Down Expand Up @@ -133,6 +133,7 @@ public function createOrUpdate(array $query = ['pretty' => 1])
*
* @param array $query
* @return \RenokiCo\PhpK8s\ResourcesList
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function all(array $query = ['pretty' => 1])
Expand All @@ -152,6 +153,7 @@ public function all(array $query = ['pretty' => 1])
*
* @param array $query
* @return \RenokiCo\PhpK8s\ResourcesList
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function allNamespaces(array $query = ['pretty' => 1])
Expand All @@ -167,10 +169,11 @@ public function allNamespaces(array $query = ['pretty' => 1])
}

/**
* Get a specific resource.
* Get a fresh instance from the cluster.
*
* @param array $query
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function get(array $query = ['pretty' => 1])
Expand All @@ -190,6 +193,7 @@ public function get(array $query = ['pretty' => 1])
*
* @param array $query
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function create(array $query = ['pretty' => 1])
Expand All @@ -209,6 +213,7 @@ public function create(array $query = ['pretty' => 1])
*
* @param array $query
* @return bool
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function update(array $query = ['pretty' => 1]): bool
Expand Down Expand Up @@ -241,6 +246,7 @@ public function update(array $query = ['pretty' => 1]): bool
* @param null|int $gracePeriod
* @param string $propagationPolicy
* @return bool
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
public function delete(array $query = ['pretty' => 1], $gracePeriod = null, string $propagationPolicy = 'Foreground'): bool
Expand Down Expand Up @@ -278,6 +284,7 @@ public function delete(array $query = ['pretty' => 1], $gracePeriod = null, stri
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
*/
public function watchAll(Closure $callback, array $query = ['pretty' => 1])
Expand All @@ -304,6 +311,7 @@ public function watchAll(Closure $callback, array $query = ['pretty' => 1])
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
*/
public function watch(Closure $callback, array $query = ['pretty' => 1])
Expand All @@ -329,6 +337,7 @@ public function watch(Closure $callback, array $query = ['pretty' => 1])
*
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand Down Expand Up @@ -356,6 +365,7 @@ public function logs(array $query = ['pretty' => 1])
* @param Closure $callback
* @param array $query
* @return mixed
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesWatchException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesLogsException
*/
Expand Down Expand Up @@ -390,6 +400,7 @@ public function watchLogs(Closure $callback, array $query = ['pretty' => 1])
* Get a specific resource scaling data.
*
* @return \RenokiCo\PhpK8s\Kinds\K8sScale
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesScalingException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand Down Expand Up @@ -422,6 +433,7 @@ public function scaler(): K8sScale
* @param string|null $container
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesExecException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand All @@ -442,7 +454,7 @@ public function exec(
KubernetesCluster::EXEC_OP,
$this->resourceExecPath(),
'',
['command' => $command, 'container' => $container] + $query
['command' => array_map('urlencode', $command), 'container' => $container] + $query
);
}

Expand All @@ -453,6 +465,7 @@ public function exec(
* @param string|null $container
* @param array $query
* @return string
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAttachException
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/PodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ public function test_pod_exec()
$pod->refresh();
}

$messages = $pod->exec(['/bin/sh', '-c', 'ls -al'], 'busybox');
$messages = $pod->exec(['/bin/sh', '-c', 'echo 1 && echo 2 && echo 3'], 'busybox');

$hasDesiredOutput = collect($messages)->where('channel', 'stdout')->filter(function ($message) {
return Str::contains($message['output'], '.dockerenv');
return Str::contains($message['output'], '1')
&& Str::contains($message['output'], '2')
&& Str::contains($message['output'], '3');
})->isNotEmpty();

$this->assertTrue($hasDesiredOutput);
Expand Down

0 comments on commit c9f66aa

Please sign in to comment.