Skip to content

Commit 91e9859

Browse files
authored
Merge pull request #33 from renoki-co/feature/status
[feature] Status Checks
2 parents 52cf147 + ea02a8b commit 91e9859

31 files changed

+865
-58
lines changed

docs/kinds/Deployment.md

+20
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,23 @@ foreach ($dep->getPods() as $pod) {
110110
// $pod->logs()
111111
}
112112
```
113+
114+
### Deployment Status
115+
116+
The Status API is available to be accessed for fresh instances:
117+
118+
```php
119+
$dep->refresh();
120+
121+
$dep->getReadyReplicasCount();
122+
$dep->getDesiredReplicasCount();
123+
$dep->getUnavailableReplicasCount();
124+
```
125+
126+
You can check if all the pods within the Deployment are running:
127+
128+
```php
129+
if ($dep->allPodsAreRunning()) {
130+
//
131+
}
132+
```

docs/kinds/Job.md

+33
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,36 @@ foreach ($job->getPods() as $pod) {
135135
// $pod->logs()
136136
}
137137
```
138+
139+
### Job Status
140+
141+
The Status API is available to be accessed for fresh instances:
142+
143+
```php
144+
$job->refresh();
145+
146+
$job->getActivePodsCount();
147+
$job->getFailedPodsCount();
148+
$job->getSuccededPodsCount();
149+
```
150+
151+
You can check if the job completed:
152+
153+
```php
154+
if ($job->hasCompleted()) {
155+
//
156+
}
157+
```
158+
159+
You can retrieve the `null`/`\DateTime` instance for start and end times for the job:
160+
161+
```php
162+
$start = $job->getStartTime();
163+
$end = $job->getCompletionTime();
164+
```
165+
166+
You can also retrieve the amount of time the job ran for:
167+
168+
```php
169+
$seconds = $job->getDurationInSeconds();
170+
```

docs/kinds/Namespace.md

+20
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@ $ns = $cluster->namespace()
1717
```php
1818
$ns = $cluster->getNamespaceByName('staging');
1919
```
20+
21+
### Namespace Status
22+
23+
The Status API is available to be accessed for fresh instances:
24+
25+
```php
26+
$ns->refresh();
27+
28+
if ($ns->isActive()) {
29+
//
30+
}
31+
```
32+
33+
You can also check if the namespace is terminating:
34+
35+
```php
36+
if ($ns->isTerminating()) {
37+
//
38+
}
39+
```

docs/kinds/PersistentVolume.md

+20
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,23 @@ Dot notation is supported:
8585
```php
8686
$pv->getSpec('some.nested.path', []);
8787
```
88+
89+
### Persistent Volume Status
90+
91+
The Status API is available to be accessed for fresh instances:
92+
93+
```php
94+
$pv->refresh();
95+
96+
if ($pv->isAvailable()) {
97+
//
98+
}
99+
```
100+
101+
You can also check if the PV is bound:
102+
103+
```php
104+
if ($pv->isBound()) {
105+
//
106+
}
107+
```

docs/kinds/PersistentVolumeClaim.md

+20
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,23 @@ Dot notation is supported:
7474
```php
7575
$pvc->getSpec('some.nested.path', []);
7676
```
77+
78+
### Persistent Volume Claim Status
79+
80+
The Status API is available to be accessed for fresh instances:
81+
82+
```php
83+
$pvc->refresh();
84+
85+
if ($pvc->isAvailable()) {
86+
//
87+
}
88+
```
89+
90+
You can also check if the PVC is bound:
91+
92+
```php
93+
if ($pvc->isBound()) {
94+
//
95+
}
96+
```

docs/kinds/Pod.md

+64
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,67 @@ $pod->watchLogs(function ($line) {
135135
// with the given line.
136136
});
137137
```
138+
139+
### Pod Status
140+
141+
The Status API is available to be accessed for fresh instances:
142+
143+
```php
144+
$pod->refresh();
145+
146+
$pod->getPodIps();
147+
$pod->getHostIp();
148+
$pod->getQos();
149+
```
150+
151+
You can also check if the pod is running
152+
153+
```php
154+
if ($pod->isRunning()) {
155+
//
156+
}
157+
```
158+
159+
For [Job](Job.md) support, you may also check if the pod ran successfully:
160+
161+
```php
162+
foreach ($job->getPods() as $pod) {
163+
if ($pod->isSuccessful()) {
164+
//
165+
}
166+
}
167+
```
168+
169+
You can check the container statuses:
170+
171+
```php
172+
foreach ($pod->getContainerStatuses() as $container) {
173+
// $container->getName();
174+
}
175+
176+
foreach ($pod->getInitContainerStatuses() as $container) {
177+
// $container->getName();
178+
}
179+
```
180+
181+
You may also get a container by its name:
182+
183+
```php
184+
$mysql = $pod->getContainer('mysql');
185+
$busybox = $pod->getInitContainer('busybox');
186+
187+
// $mysql->getName();
188+
// $busybox->getName();
189+
```
190+
191+
Check if the containers are ready:
192+
193+
```php
194+
if ($pod->containersAreReady()) {
195+
//
196+
}
197+
198+
if ($pod->initContainersAreReady()) {
199+
//
200+
}
201+
```

docs/kinds/StatefulSet.md

+20
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,23 @@ foreach ($sts->getPods() as $pod) {
126126
// $pod->logs()
127127
}
128128
```
129+
130+
### StatefulSet Status
131+
132+
The Status API is available to be accessed for fresh instances:
133+
134+
```php
135+
$sts->refresh();
136+
137+
$sts->getCurrentReplicasCount();
138+
$sts->getReadyReplicasCount();
139+
$sts->getDesiredReplicasCount();
140+
```
141+
142+
You can check if all the pods within the StatefulSet are running:
143+
144+
```php
145+
if ($sts->allPodsAreRunning()) {
146+
//
147+
}
148+
```

src/Instances/Container.php

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public function addPort(int $containerPort, string $protocol = 'TCP', string $na
5353
return $this->setAttribute('ports', $ports);
5454
}
5555

56+
/**
57+
* Check if the container is ready.
58+
*
59+
* @return bool
60+
*/
61+
public function isReady(): bool
62+
{
63+
return $this->getAttribute('ready', false);
64+
}
65+
5666
/**
5767
* Get the instance as an array.
5868
*

src/Kinds/K8sDeployment.php

+64
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,68 @@ public function podsSelector(): array
109109
'deployment-name' => $this->getName(),
110110
];
111111
}
112+
113+
/**
114+
* Get the deployment conditions.
115+
*
116+
* @return array
117+
*/
118+
public function getConditions(): array
119+
{
120+
return $this->getAttribute('status.conditions', []);
121+
}
122+
123+
/**
124+
* Get the available replicas.
125+
*
126+
* @return int
127+
*/
128+
public function getAvailableReplicasCount(): int
129+
{
130+
return $this->getAttribute('status.availableReplicas', 0);
131+
}
132+
133+
/**
134+
* Get the ready replicas.
135+
*
136+
* @return int
137+
*/
138+
public function getReadyReplicasCount(): int
139+
{
140+
return $this->getAttribute('status.readyReplicas', 0);
141+
}
142+
143+
/**
144+
* Get the total desired replicas.
145+
*
146+
* @return int
147+
*/
148+
public function getDesiredReplicasCount(): int
149+
{
150+
return $this->getAttribute('status.replicas', 0);
151+
}
152+
153+
/**
154+
* Get the total unavailable replicas.
155+
*
156+
* @return int
157+
*/
158+
public function getUnavailableReplicasCount(): int
159+
{
160+
return $this->getAttribute('status.unavailableReplicas', 0);
161+
}
162+
163+
/**
164+
* Check if all scheduled pods are running.
165+
*
166+
* @return bool
167+
*/
168+
public function allPodsAreRunning(): bool
169+
{
170+
$pods = $this->getPods();
171+
172+
return $pods->count() > 0 && $pods->reject(function ($pod) {
173+
return $pod->isReady();
174+
})->isEmpty();
175+
}
112176
}

0 commit comments

Comments
 (0)