diff --git a/src/Helm.php b/src/Helm.php index 5151059..b710feb 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. * @@ -51,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 @@ -61,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. * @@ -91,18 +123,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 +153,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); + } } diff --git a/tests/HelmTest.php b/tests/HelmTest.php index 5995d5e..30eeef0 100644 --- a/tests/HelmTest.php +++ b/tests/HelmTest.php @@ -29,4 +29,51 @@ public function test_helm_repo_update() $this->assertTrue($process->isSuccessful()); } + + public function test_helm_repo_install() + { + Helm::addRepo('bitnami', 'https://charts.bitnami.com/bitnami')->run(); + Helm::repoUpdate()->run(); + + $process = Helm::install( + 'release-1', + 'bitnami/postgresql', + ['--debug' => true] + ); + + $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()->run(); + + $process = Helm::upgrade( + 'release-2', + 'bitnami/postgresql', + ['--install' => true, '--debug' => true] + ); + + $process->run(); + + dump($process->getCommandLine()); + dump($process->getOutput()); + + $this->assertTrue($process->isSuccessful()); + } + + public function test_helm_repo_macro() + { + Helm::macro('test', function ($var) { + return $var; + }); + + $this->assertEquals('123', Helm::test('123')); + } }