Skip to content

Commit

Permalink
Fix KubeConfig temp certificate filename extension .pem
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankonig committed Jan 4, 2022
1 parent 990acd6 commit 236a771
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Traits/Cluster/LoadsFromKubeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected function writeTempFileForContext(
/** @var \RenokiCo\PhpK8s\KubernetesCluster $this */
$tempFolder = static::$tempFolder ?: sys_get_temp_dir();

$tempFilePath = $tempFolder.DIRECTORY_SEPARATOR.Str::slug("ctx-{$context}-{$userName}-{$url}-{$fileName}");
$tempFilePath = $tempFolder.DIRECTORY_SEPARATOR.Str::slug("ctx-{$context}-{$userName}-{$url}")."-{$fileName}";

if (file_exists($tempFilePath)) {
return $tempFilePath;
Expand Down
11 changes: 10 additions & 1 deletion tests/KubeConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

class KubeConfigTest extends TestCase
{
private $tempFolder;

/**
* {@inheritdoc}
*/
public function setUp(): void
{
parent::setUp();

KubernetesCluster::setTempFolder(__DIR__.DIRECTORY_SEPARATOR.'temp');
$this->tempFolder = __DIR__.DIRECTORY_SEPARATOR.'temp';
KubernetesCluster::setTempFolder($this->tempFolder);
}

/**
Expand All @@ -41,6 +44,12 @@ public function test_kube_config_from_yaml_file_with_base64_encoded_ssl()
'ssl_key' => $keyPath,
] = $cluster->getClient()->getConfig();

$tempFilePath = $this->tempFolder.DIRECTORY_SEPARATOR.'ctx-minikube-minikube-httpsminikube8443-';

$this->assertSame($tempFilePath.'ca-cert.pem', $caPath);
$this->assertSame($tempFilePath.'client-cert.pem', $certPath);
$this->assertSame($tempFilePath.'client-key.pem', $keyPath);

$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));
Expand Down

0 comments on commit 236a771

Please sign in to comment.