|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\Aent\K8SProvider; |
|
4
|
|
|
|
|
5
|
|
|
use TheAentMachine\Aent\Context\ContextInterface; |
|
6
|
|
|
use TheAentMachine\Aent\Payload\JsonPayloadInterface; |
|
7
|
|
|
use TheAentMachine\Aenthill\Aenthill; |
|
8
|
|
|
|
|
9
|
|
|
final class Provider implements ContextInterface, JsonPayloadInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public const RANCHER = 'Rancher'; |
|
12
|
|
|
public const GOOGLE_CLOUD = 'Google Cloud'; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
private $name; |
|
16
|
|
|
|
|
17
|
|
|
/** @var bool */ |
|
18
|
|
|
private $certManager; |
|
19
|
|
|
|
|
20
|
|
|
/** @var bool */ |
|
21
|
|
|
private $useNodePortForIngress; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $ingressClass; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Provider constructor. |
|
28
|
|
|
* @param string $name |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(string $name) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->name = $name; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return Provider |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function newRancherProvider(): self |
|
39
|
|
|
{ |
|
40
|
|
|
$self = new self(self::RANCHER); |
|
41
|
|
|
return $self; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return Provider |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function newGoogleCloudProvider(): self |
|
48
|
|
|
{ |
|
49
|
|
|
$self = new self(self::GOOGLE_CLOUD); |
|
50
|
|
|
return $self; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
public function toMetadata(): void |
|
57
|
|
|
{ |
|
58
|
|
|
Aenthill::update([ |
|
59
|
|
|
'PROVIDER_NAME' => $this->name, |
|
60
|
|
|
'CERT_MANAGER' => $this->certManager ? 'true' : 'false', |
|
61
|
|
|
'USE_NODE_PORT_FOR_INGRESS' => $this->useNodePortForIngress ? 'true' : 'false', |
|
62
|
|
|
'INGRESS_CLASS' => $this->ingressClass, |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return self |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function fromMetadata() |
|
70
|
|
|
{ |
|
71
|
|
|
$name = Aenthill::metadata('PROVIDER_NAME'); |
|
72
|
|
|
$certManager = Aenthill::metadata('CERT_MANAGER') === 'true'; |
|
73
|
|
|
$useNodePortForIngress = Aenthill::metadata('USE_NODE_PORT_FOR_INGRESS') === 'true'; |
|
74
|
|
|
$ingressClass = Aenthill::metadata('INGRESS_CLASS'); |
|
75
|
|
|
$self = new self($name); |
|
76
|
|
|
$self->certManager = $certManager; |
|
77
|
|
|
$self->useNodePortForIngress = $useNodePortForIngress; |
|
78
|
|
|
$self->ingressClass = $ingressClass; |
|
79
|
|
|
return $self; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return array<string,string> |
|
84
|
|
|
*/ |
|
85
|
|
|
public function toArray(): array |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
|
|
'PROVIDER_NAME' => $this->name, |
|
89
|
|
|
'CERT_MANAGER' => $this->certManager ? 'true' : 'false', |
|
90
|
|
|
'USE_NODE_PORT_FOR_INGRESS' => $this->useNodePortForIngress ? 'true' : 'false', |
|
91
|
|
|
'INGRESS_CLASS' => $this->ingressClass, |
|
92
|
|
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param array<string,string> $assoc |
|
97
|
|
|
* @return self |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function fromArray(array $assoc) |
|
100
|
|
|
{ |
|
101
|
|
|
$self = new self($assoc['PROVIDER_NAME']); |
|
102
|
|
|
$self->certManager = $assoc['CERT_MANAGER'] === 'true'; |
|
103
|
|
|
$self->useNodePortForIngress = $assoc['USE_NODE_PORT_FOR_INGRESS'] === 'true'; |
|
104
|
|
|
$self->ingressClass = $assoc['INGRESS_CLASS']; |
|
105
|
|
|
return $self; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getName(): string |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->name; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return bool |
|
118
|
|
|
*/ |
|
119
|
|
|
public function isCertManager(): bool |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->certManager; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param bool $certManager |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
|
|
public function setCertManager(bool $certManager): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->certManager = $certManager; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return bool |
|
135
|
|
|
*/ |
|
136
|
|
|
public function isUseNodePortForIngress(): bool |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->useNodePortForIngress; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param bool $useNodePortForIngress |
|
143
|
|
|
* @return void |
|
144
|
|
|
*/ |
|
145
|
|
|
public function setUseNodePortForIngress(bool $useNodePortForIngress): void |
|
146
|
|
|
{ |
|
147
|
|
|
$this->useNodePortForIngress = $useNodePortForIngress; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getIngressClass(): string |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->ingressClass; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param string $ingressClass |
|
160
|
|
|
* @return void |
|
161
|
|
|
*/ |
|
162
|
|
|
public function setIngressClass(string $ingressClass): void |
|
163
|
|
|
{ |
|
164
|
|
|
$this->ingressClass = $ingressClass; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|