From 7ccee2b2b4d0be35fa43360945ee793a5e15895c Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 31 Aug 2021 08:56:17 +0300 Subject: [PATCH 1/5] Added macro --- src/Helm.php | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Helm.php b/src/Helm.php index 5151059..27a0744 100644 --- a/src/Helm.php +++ b/src/Helm.php @@ -2,10 +2,15 @@ namespace RenokiCo\PhpHelm; +use Illuminate\Support\Traits\Macroable; use Symfony\Component\Process\Process; class Helm { + use Macroable { + __call as macroCall; + } + /** * The process instance to run Helm from. * @@ -91,18 +96,6 @@ public function __construct(string $action, array $params = [], array $flags = [ $this->process = new Process($command, null, $envs); } - /** - * Proxy the call to the process instance. - * - * @param string $method - * @param array $params - * @return mixed - */ - public function __call(string $method, array $params) - { - return $this->process->{$method}(...$params); - } - /** * Compile an array of flags to helm-supported flags. * @@ -133,4 +126,20 @@ protected function compileFlags(array $flags): array return $compiledFlags; } + + /** + * Proxy the call to the process instance. + * + * @param string $method + * @param array $params + * @return mixed + */ + public function __call(string $method, array $params) + { + if (static::hasMacro($method)) { + return $this->macroCall($method, $params); + } + + return $this->process->{$method}(...$params); + } } From bbb5638c73eac6b45018ad5b0e0ca1ce51eda5e8 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 31 Aug 2021 09:06:01 +0300 Subject: [PATCH 2/5] Added ::install and ::upgrade --- src/Helm.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Helm.php b/src/Helm.php index 27a0744..b710feb 100644 --- a/src/Helm.php +++ b/src/Helm.php @@ -56,7 +56,6 @@ public static function addRepo(string $name, string $url, array $extraFlags = [] /** * Initiate a helm repo update command. * - * @param array $extraArgs * @param array $extraFlags * @param array $envs * @return \RenokiCo\PhpHelm\Helm @@ -66,6 +65,34 @@ public static function repoUpdate(array $extraFlags = [], array $envs = []) return static::call('repo', ['update'], $extraFlags, $envs); } + /** + * Initiate a helm install command. + * + * @param string $releaseName + * @param string $chart + * @param array $extraFlags + * @param array $envs + * @return \RenokiCo\PhpHelm\Helm + */ + public static function install(string $releaseName, string $chart, array $extraFlags = [], array $envs = []) + { + return static::call('install', [$releaseName, $chart], $extraFlags, $envs); + } + + /** + * Initiate a helm upgrade command. + * + * @param string $releaseName + * @param string $chart + * @param array $extraFlags + * @param array $envs + * @return \RenokiCo\PhpHelm\Helm + */ + public static function upgrade(string $releaseName, string $chart, array $extraFlags = [], array $envs = []) + { + return static::call('upgrade', [$releaseName, $chart], $extraFlags, $envs); + } + /** * Change the default path for helm CLI. * From 853580aea27b77b2d19c04073ebf6bec40411cd3 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 31 Aug 2021 09:06:21 +0300 Subject: [PATCH 3/5] Testing --- tests/HelmTest.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/HelmTest.php b/tests/HelmTest.php index 5995d5e..282e35c 100644 --- a/tests/HelmTest.php +++ b/tests/HelmTest.php @@ -29,4 +29,41 @@ public function test_helm_repo_update() $this->assertTrue($process->isSuccessful()); } + + public function test_helm_repo_install() + { + $process = Helm::install( + 'test-release', + 'stable/chart-name', + ['--debug' => true] + ); + + $this->assertStringContainsString( + 'install test-release "stable/chart-name" --debug', + $process->getCommandLine() + ); + } + + public function test_helm_repo_upgrade() + { + $process = Helm::upgrade( + 'test-release', + 'stable/chart-name', + ['--debug' => true] + ); + + $this->assertStringContainsString( + 'upgrade test-release "stable/chart-name" --debug', + $process->getCommandLine() + ); + } + + public function test_helm_repo_macro() + { + Helm::macro('test', function ($var) { + return $var; + }); + + $this->assertEquals('123', Helm::test('123')); + } } From 41c79d6a0ca0eb0ad0957ecac27a9c39f8c7b7a6 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 31 Aug 2021 18:25:49 +0300 Subject: [PATCH 4/5] fixed tests --- tests/HelmTest.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/HelmTest.php b/tests/HelmTest.php index 282e35c..946b321 100644 --- a/tests/HelmTest.php +++ b/tests/HelmTest.php @@ -32,30 +32,40 @@ public function test_helm_repo_update() public function test_helm_repo_install() { + Helm::addRepo('bitnami', 'https://charts.bitnami.com/bitnami')->run(); + Helm::repoUpdate(); + $process = Helm::install( - 'test-release', - 'stable/chart-name', + 'release-1', + 'bitnami/postgresql', ['--debug' => true] ); - $this->assertStringContainsString( - 'install test-release "stable/chart-name" --debug', - $process->getCommandLine() - ); + $process->run(); + + dump($process->getCommandLine()); + dump($process->getOutput()); + + $this->assertTrue($process->isSuccessful()); } public function test_helm_repo_upgrade() { + Helm::addRepo('bitnami', 'https://charts.bitnami.com/bitnami')->run(); + Helm::repoUpdate(); + $process = Helm::upgrade( - 'test-release', - 'stable/chart-name', - ['--debug' => true] + 'release-2', + 'bitnami/postgresql', + ['--install' => true, '--debug' => true] ); - $this->assertStringContainsString( - 'upgrade test-release "stable/chart-name" --debug', - $process->getCommandLine() - ); + $process->run(); + + dump($process->getCommandLine()); + dump($process->getOutput()); + + $this->assertTrue($process->isSuccessful()); } public function test_helm_repo_macro() From d43d530a3b18ea146911314384451e8e581d74a8 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 31 Aug 2021 18:33:50 +0300 Subject: [PATCH 5/5] Run repoUpdate() --- tests/HelmTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/HelmTest.php b/tests/HelmTest.php index 946b321..30eeef0 100644 --- a/tests/HelmTest.php +++ b/tests/HelmTest.php @@ -33,7 +33,7 @@ public function test_helm_repo_update() public function test_helm_repo_install() { Helm::addRepo('bitnami', 'https://charts.bitnami.com/bitnami')->run(); - Helm::repoUpdate(); + Helm::repoUpdate()->run(); $process = Helm::install( 'release-1', @@ -52,7 +52,7 @@ public function test_helm_repo_install() public function test_helm_repo_upgrade() { Helm::addRepo('bitnami', 'https://charts.bitnami.com/bitnami')->run(); - Helm::repoUpdate(); + Helm::repoUpdate()->run(); $process = Helm::upgrade( 'release-2',