Skip to content

Commit 2949399

Browse files
authored
Merge pull request #181 from stefankonig/fromKubeConfigArray
Added ability to directly load a kubeconfig from an array
2 parents 68180b2 + 4f8d429 commit 2949399

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Traits/Cluster/LoadsFromKubeConfig.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ public static function fromKubeConfigYamlFile(string $path = '/.kube/config', st
9898
return (new static)->fromKubeConfigYaml(file_get_contents($path), $context);
9999
}
100100

101+
/**
102+
* Load configuration from an Array.
103+
*
104+
* @param array $kubeConfigArray
105+
* @param string|null $context
106+
* @return \RenokiCo\PhpK8s\KubernetesCluster
107+
*/
108+
public static function fromKubeConfigArray(array $kubeConfigArray, string $context = null)
109+
{
110+
$cluster = new static;
111+
112+
return $cluster->loadKubeConfigFromArray($kubeConfigArray, $context);
113+
}
114+
101115
/**
102116
* Load the Kube Config configuration from an array,
103117
* coming from a Kube Config file.

tests/KubeConfigTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,19 @@ public function environmentVariableContextProvider(): iterable
194194
yield ['minikube-2', 'minikube-2'];
195195
yield ['minikube-3', 'minikube-3'];
196196
}
197+
198+
public function test_kube_config_from_array_with_base64_encoded_ssl()
199+
{
200+
$cluster = KubernetesCluster::fromKubeConfigArray(yaml_parse_file(__DIR__.'/cluster/kubeconfig.yaml'), 'minikube');
201+
202+
[
203+
'verify' => $caPath,
204+
'cert' => $certPath,
205+
'ssl_key' => $keyPath,
206+
] = $cluster->getClient()->getConfig();
207+
208+
$this->assertEquals("some-ca\n", file_get_contents($caPath));
209+
$this->assertEquals("some-cert\n", file_get_contents($certPath));
210+
$this->assertEquals("some-key\n", file_get_contents($keyPath));
211+
}
197212
}

0 commit comments

Comments
 (0)