diff --git a/src/Traits/Cluster/LoadsFromKubeConfig.php b/src/Traits/Cluster/LoadsFromKubeConfig.php index 070d47e7..5be5a831 100644 --- a/src/Traits/Cluster/LoadsFromKubeConfig.php +++ b/src/Traits/Cluster/LoadsFromKubeConfig.php @@ -98,6 +98,20 @@ public static function fromKubeConfigYamlFile(string $path = '/.kube/config', st return (new static)->fromKubeConfigYaml(file_get_contents($path), $context); } + /** + * Load configuration from an Array. + * + * @param array $kubeConfigArray + * @param string|null $context + * @return \RenokiCo\PhpK8s\KubernetesCluster + */ + public static function fromKubeConfigArray(array $kubeConfigArray, string $context = null) + { + $cluster = new static; + + return $cluster->loadKubeConfigFromArray($kubeConfigArray, $context); + } + /** * Load the Kube Config configuration from an array, * coming from a Kube Config file. diff --git a/tests/KubeConfigTest.php b/tests/KubeConfigTest.php index bb2de664..0702b129 100644 --- a/tests/KubeConfigTest.php +++ b/tests/KubeConfigTest.php @@ -194,4 +194,19 @@ public function environmentVariableContextProvider(): iterable yield ['minikube-2', 'minikube-2']; yield ['minikube-3', 'minikube-3']; } + + public function test_kube_config_from_array_with_base64_encoded_ssl() + { + $cluster = KubernetesCluster::fromKubeConfigArray(yaml_parse_file(__DIR__.'/cluster/kubeconfig.yaml'), 'minikube'); + + [ + 'verify' => $caPath, + 'cert' => $certPath, + 'ssl_key' => $keyPath, + ] = $cluster->getClient()->getConfig(); + + $this->assertEquals("some-ca\n", file_get_contents($caPath)); + $this->assertEquals("some-cert\n", file_get_contents($certPath)); + $this->assertEquals("some-key\n", file_get_contents($keyPath)); + } }