|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\LKE\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\LKE\LKECluster; |
|
17
|
|
|
use Linode\LKE\LKEClusterRepositoryInterface; |
|
18
|
|
|
use Linode\LKE\LKENodeStatus; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
22
|
|
|
*/ |
|
23
|
|
|
class LKEClusterRepository extends AbstractRepository implements LKEClusterRepositoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public function createLKECluster(array $parameters = []): LKECluster |
|
26
|
|
|
{ |
|
27
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
28
|
|
|
$contents = $response->getBody()->getContents(); |
|
29
|
|
|
$json = json_decode($contents, true); |
|
30
|
|
|
|
|
31
|
|
|
return new LKECluster($this->client, $json); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function putLKECluster(int $clusterId, array $parameters = []): LKECluster |
|
35
|
|
|
{ |
|
36
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $clusterId), $parameters); |
|
37
|
|
|
$contents = $response->getBody()->getContents(); |
|
38
|
|
|
$json = json_decode($contents, true); |
|
39
|
|
|
|
|
40
|
|
|
return new LKECluster($this->client, $json); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function deleteLKECluster(int $clusterId): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $clusterId)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getLKEClusterDashboard(int $clusterId): string |
|
49
|
|
|
{ |
|
50
|
|
|
$response = $this->client->get(sprintf('%s/%s/dashboard', $this->getBaseUri(), $clusterId)); |
|
51
|
|
|
$contents = $response->getBody()->getContents(); |
|
52
|
|
|
$json = json_decode($contents, true); |
|
53
|
|
|
|
|
54
|
|
|
return $json['url']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function postLKEClusterRecycle(int $clusterId): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->client->post(sprintf('%s/%s/recycle', $this->getBaseUri(), $clusterId)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function postLKEClusterRegenerate(int $clusterId, bool $kubeconfig, bool $servicetoken): void |
|
63
|
|
|
{ |
|
64
|
|
|
$parameters = [ |
|
65
|
|
|
'kubeconfig' => $kubeconfig, |
|
66
|
|
|
'servicetoken' => $servicetoken, |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
$this->client->post(sprintf('%s/%s/regenerate', $this->getBaseUri(), $clusterId), $parameters); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function postLKECServiceTokenDelete(int $clusterId): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->client->delete(sprintf('%s/%s/servicetoken', $this->getBaseUri(), $clusterId)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getLKEClusterNode(int $clusterId, string $nodeId): LKENodeStatus |
|
78
|
|
|
{ |
|
79
|
|
|
$response = $this->client->get(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId)); |
|
80
|
|
|
$contents = $response->getBody()->getContents(); |
|
81
|
|
|
$json = json_decode($contents, true); |
|
82
|
|
|
|
|
83
|
|
|
return new LKENodeStatus($this->client, $json); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function deleteLKEClusterNode(int $clusterId, string $nodeId): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->client->delete(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function postLKEClusterNodeRecycle(int $clusterId, string $nodeId): void |
|
92
|
|
|
{ |
|
93
|
|
|
$this->client->post(sprintf('%s/%s/nodes/%s/recycle', $this->getBaseUri(), $clusterId, $nodeId)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getLKEClusterKubeconfig(int $clusterId): string |
|
97
|
|
|
{ |
|
98
|
|
|
$response = $this->client->get(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId)); |
|
99
|
|
|
$contents = $response->getBody()->getContents(); |
|
100
|
|
|
$json = json_decode($contents, true); |
|
101
|
|
|
|
|
102
|
|
|
return $json['kubeconfig']; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function deleteLKEClusterKubeconfig(int $clusterId): void |
|
106
|
|
|
{ |
|
107
|
|
|
$this->client->delete(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId)); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
protected function getBaseUri(): string |
|
111
|
|
|
{ |
|
112
|
|
|
return '/lke/clusters'; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
protected function getSupportedFields(): array |
|
116
|
|
|
{ |
|
117
|
|
|
return [ |
|
118
|
|
|
LKECluster::FIELD_ID, |
|
119
|
|
|
LKECluster::FIELD_LABEL, |
|
120
|
|
|
LKECluster::FIELD_REGION, |
|
121
|
|
|
LKECluster::FIELD_CREATED, |
|
122
|
|
|
LKECluster::FIELD_UPDATED, |
|
123
|
|
|
LKECluster::FIELD_K8S_VERSION, |
|
124
|
|
|
LKECluster::FIELD_TAGS, |
|
125
|
|
|
LKECluster::FIELD_CONTROL_PLANE, |
|
126
|
|
|
]; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
protected function jsonToEntity(array $json): Entity |
|
130
|
|
|
{ |
|
131
|
|
|
return new LKECluster($this->client, $json); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|