Skip to content

Commit cd1203f

Browse files
committed
Removing url and port to use only URL.
1 parent 55873f6 commit cd1203f

7 files changed

+7
-40
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Can be written like this:
5757
use RenokiCo\PhpK8s\KubernetesCluster;
5858

5959
// Create a new instance of KubernetesCluster
60-
$cluster = new KubernetesCluster('http://127.0.0.1', 8080);
60+
$cluster = new KubernetesCluster('http://127.0.0.1:8080');
6161

6262
// Create a new NGINX service.
6363
$svc = $cluster->service()

docs/Cluster.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can initialize a Kubernetes Cluster class by doing so:
1111
```php
1212
use RenokiCo\PhpK8s\KubernetesCluster;
1313

14-
$cluster = new KubernetesCluster('http://127.0.0.1', 8080);
14+
$cluster = new KubernetesCluster('http://127.0.0.1:8080');
1515
```
1616

1717
### Attaching Bearer Token

src/KubernetesCluster.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ class KubernetesCluster
4545
* Create a new class instance.
4646
*
4747
* @param string $url
48-
* @param int $port
4948
* @return void
5049
*/
51-
public function __construct(string $url, int $port = 8080)
50+
public function __construct(string $url)
5251
{
5352
$this->url = $url;
54-
$this->port = $port;
5553
}
5654

5755
/**

src/Traits/Cluster/ChecksClusterVersion.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ protected function loadClusterVersion(): void
2727
return;
2828
}
2929

30-
$apiUrl = $this->getApiUrl();
31-
32-
$callableUrl = "{$apiUrl}/version";
30+
$callableUrl = "{$this->url}/version";
3331

3432
try {
3533
$response = $this->getClient()->request('GET', $callableUrl);

src/Traits/Cluster/LoadsFromKubeConfig.php

+1-20
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ protected function loadKubeConfigFromArray(array $kubeconfig, string $context):
8686
throw new KubeConfigUserNotFound("The user {$user} does not exist in the provided Kube Config file.");
8787
}
8888

89-
$extractedServer = $this->extract($clusterConfig['cluster']['server']);
90-
91-
$this->url = $extractedServer['url'];
92-
$this->port = $extractedServer['port'];
89+
$this->url = $clusterConfig['cluster']['server'];
9390

9491
if (isset($clusterConfig['cluster']['certificate-authority'])) {
9592
$this->withCaCertificate($clusterConfig['cluster']['certificate-authority']);
@@ -147,20 +144,4 @@ protected function writeTempFileForContext(string $context, string $fileName, st
147144

148145
return $tempFilePath;
149146
}
150-
151-
/**
152-
* Extract the given server address into URL and port.
153-
*
154-
* @param string $server
155-
* @return array
156-
*/
157-
protected function extract(string $server): array
158-
{
159-
$parts = parse_url($server);
160-
161-
return [
162-
'url' => ($parts['protocol'] ?? 'http').'//'.$parts['host'],
163-
'port' => $parts['port'] ?? 8080,
164-
];
165-
}
166147
}

src/Traits/Cluster/RunsClusterOperations.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ trait RunsClusterOperations
2828
self::WATCH_LOGS_OP => 'GET',
2929
];
3030

31-
/**
32-
* Get the API Cluster URL as string.
33-
*
34-
* @return string
35-
*/
36-
public function getApiUrl(): string
37-
{
38-
return "{$this->url}:{$this->port}";
39-
}
40-
4131
/**
4232
* Get the callable URL for a specific path.
4333
*
@@ -47,7 +37,7 @@ public function getApiUrl(): string
4737
*/
4838
public function getCallableUrl(string $path, array $query = ['pretty' => 1])
4939
{
50-
return $this->getApiUrl().$path.'?'.http_build_query($query);
40+
return $this->url.$path.'?'.http_build_query($query);
5141
}
5242

5343
/**

tests/TestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp(): void
2323
{
2424
parent::setUp();
2525

26-
$this->cluster = new KubernetesCluster('http://127.0.0.1');
26+
$this->cluster = new KubernetesCluster('http://127.0.0.1:8080');
2727

2828
$this->cluster->withoutSslChecks();
2929
}

0 commit comments

Comments
 (0)