generated from renoki-co/laravel-package-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathContainerTest.php
125 lines (109 loc) · 4.59 KB
/
ContainerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace RenokiCo\PhpK8s\Test;
use RenokiCo\PhpK8s\Instances\MountedVolume;
use RenokiCo\PhpK8s\Instances\Probe;
use RenokiCo\PhpK8s\K8s;
class ContainerTest extends TestCase
{
public function test_container_build()
{
$container = K8s::container();
$volume = K8s::volume()->awsEbs('vol-1234', 'ext3');
$container->setImage('public.ecr.aws/docker/library/nginx', '1.23')
->setEnv(['key' => 'value'])
->addEnvs(['key2' => 'value2'])
->addSecretKeyRefs(['SECRET_ONE' => ['secret_ref_name', 'secret_ref_key']])
->addConfigMapRefs(['SECRET_TWO' => ['cm_ref_name', 'cm_ref_key']])
->addFieldRefs(['NODE_NAME' => ['spec.nodeName']])
->setArgs(['--test'])
->addPort(80, 'TCP', 'http')
->addPort(443, 'TCP', 'https')
->setMountedVolumes([$volume->mountTo('/some/path')]);
$container->minMemory(1, 'Gi')->maxMemory(2, 'Gi')
->minCpu('500m')->maxCpu(1);
$container->setLivenessProbe(
K8s::probe()->command(['sh', 'test.sh'])
->setInitialDelaySeconds(10)
->setPeriodSeconds(60)
->setTimeoutSeconds(10)
->setFailureThreshold(3)
->setSuccessThreshold(2)
);
$container->setStartupProbe(
K8s::probe()->http('/health', 80, ['X-CSRF-TOKEN' => 'some-token'])
->setInitialDelaySeconds(10)
->setPeriodSeconds(60)
->setTimeoutSeconds(10)
->setFailureThreshold(3)
->setSuccessThreshold(2)
);
$container->setReadinessProbe(
K8s::probe()->tcp(3306, '10.0.0.0')
->setInitialDelaySeconds(10)
->setPeriodSeconds(60)
->setTimeoutSeconds(10)
->setFailureThreshold(3)
->setSuccessThreshold(2)
);
$this->assertStringEndsWith('nginx:1.23', $container->getImage());
$this->assertEquals([
['name' => 'key', 'value' => 'value'],
['name' => 'key2', 'value' => 'value2'],
[
'name' => 'SECRET_ONE',
'valueFrom' => [
'secretKeyRef' => [
'name' => 'secret_ref_name',
'key' => 'secret_ref_key',
],
],
],
[
'name' => 'SECRET_TWO',
'valueFrom' => [
'configMapKeyRef' => [
'name' => 'cm_ref_name',
'key' => 'cm_ref_key',
],
],
],
[
'name' => 'NODE_NAME',
'valueFrom' => [
'fieldRef' => [
'fieldPath' => 'spec.nodeName',
],
],
],
], $container->getEnv());
$this->assertEquals(['--test'], $container->getArgs());
$this->assertEquals([
['name' => 'http', 'protocol' => 'TCP', 'containerPort' => 80],
['name' => 'https', 'protocol' => 'TCP', 'containerPort' => 443],
], $container->getPorts());
$container->removeEnv();
$this->assertFalse($container->isReady());
$this->assertStringEndsWith('nginx:1.23', $container->getImage());
$this->assertEquals([], $container->getEnv([]));
$this->assertEquals(['--test'], $container->getArgs());
$this->assertEquals([
['name' => 'http', 'protocol' => 'TCP', 'containerPort' => 80],
['name' => 'https', 'protocol' => 'TCP', 'containerPort' => 443],
], $container->getPorts());
$this->assertEquals('1Gi', $container->getMinMemory());
$this->assertEquals('2Gi', $container->getMaxMemory());
$this->assertEquals('500m', $container->getMinCpu());
$this->assertEquals(1, $container->getMaxCpu());
$this->assertEquals(['sh', 'test.sh'], $container->getLivenessProbe()->getCommand());
$this->assertInstanceOf(Probe::class, $container->getLivenessProbe());
$this->assertInstanceOf(Probe::class, $container->getStartupProbe());
$this->assertInstanceOf(Probe::class, $container->getReadinessProbe());
foreach ($container->getMountedVolumes() as $volume) {
$this->assertInstanceOf(MountedVolume::class, $volume);
}
$this->assertEquals([
'name' => 'vol-1234-volume',
'mountPath' => '/some/path',
], $container->getMountedVolumes()[0]->toArray());
}
}