Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Status Checks #33

Merged
merged 22 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/kinds/Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,23 @@ foreach ($dep->getPods() as $pod) {
// $pod->logs()
}
```

### Deployment Status

The Status API is available to be accessed for fresh instances:

```php
$dep->refresh();

$dep->getReadyReplicasCount();
$dep->getDesiredReplicasCount();
$dep->getUnavailableReplicasCount();
```

You can check if all the pods within the Deployment are running:

```php
if ($dep->allPodsAreRunning()) {
//
}
```
33 changes: 33 additions & 0 deletions docs/kinds/Job.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,36 @@ foreach ($job->getPods() as $pod) {
// $pod->logs()
}
```

### Job Status

The Status API is available to be accessed for fresh instances:

```php
$job->refresh();

$job->getActivePodsCount();
$job->getFailedPodsCount();
$job->getSuccededPodsCount();
```

You can check if the job completed:

```php
if ($job->hasCompleted()) {
//
}
```

You can retrieve the `null`/`\DateTime` instance for start and end times for the job:

```php
$start = $job->getStartTime();
$end = $job->getCompletionTime();
```

You can also retrieve the amount of time the job ran for:

```php
$seconds = $job->getDurationInSeconds();
```
20 changes: 20 additions & 0 deletions docs/kinds/Namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ $ns = $cluster->namespace()
```php
$ns = $cluster->getNamespaceByName('staging');
```

### Namespace Status

The Status API is available to be accessed for fresh instances:

```php
$ns->refresh();

if ($ns->isActive()) {
//
}
```

You can also check if the namespace is terminating:

```php
if ($ns->isTerminating()) {
//
}
```
20 changes: 20 additions & 0 deletions docs/kinds/PersistentVolume.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,23 @@ Dot notation is supported:
```php
$pv->getSpec('some.nested.path', []);
```

### Persistent Volume Status

The Status API is available to be accessed for fresh instances:

```php
$pv->refresh();

if ($pv->isAvailable()) {
//
}
```

You can also check if the PV is bound:

```php
if ($pv->isBound()) {
//
}
```
20 changes: 20 additions & 0 deletions docs/kinds/PersistentVolumeClaim.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ Dot notation is supported:
```php
$pvc->getSpec('some.nested.path', []);
```

### Persistent Volume Claim Status

The Status API is available to be accessed for fresh instances:

```php
$pvc->refresh();

if ($pvc->isAvailable()) {
//
}
```

You can also check if the PVC is bound:

```php
if ($pvc->isBound()) {
//
}
```
64 changes: 64 additions & 0 deletions docs/kinds/Pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,67 @@ $pod->watchLogs(function ($line) {
// with the given line.
});
```

### Pod Status

The Status API is available to be accessed for fresh instances:

```php
$pod->refresh();

$pod->getPodIps();
$pod->getHostIp();
$pod->getQos();
```

You can also check if the pod is running

```php
if ($pod->isRunning()) {
//
}
```

For [Job](Job.md) support, you may also check if the pod ran successfully:

```php
foreach ($job->getPods() as $pod) {
if ($pod->isSuccessful()) {
//
}
}
```

You can check the container statuses:

```php
foreach ($pod->getContainerStatuses() as $container) {
// $container->getName();
}

foreach ($pod->getInitContainerStatuses() as $container) {
// $container->getName();
}
```

You may also get a container by its name:

```php
$mysql = $pod->getContainer('mysql');
$busybox = $pod->getInitContainer('busybox');

// $mysql->getName();
// $busybox->getName();
```

Check if the containers are ready:

```php
if ($pod->containersAreReady()) {
//
}

if ($pod->initContainersAreReady()) {
//
}
```
20 changes: 20 additions & 0 deletions docs/kinds/StatefulSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ foreach ($sts->getPods() as $pod) {
// $pod->logs()
}
```

### StatefulSet Status

The Status API is available to be accessed for fresh instances:

```php
$sts->refresh();

$sts->getCurrentReplicasCount();
$sts->getReadyReplicasCount();
$sts->getDesiredReplicasCount();
```

You can check if all the pods within the StatefulSet are running:

```php
if ($sts->allPodsAreRunning()) {
//
}
```
10 changes: 10 additions & 0 deletions src/Instances/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function addPort(int $containerPort, string $protocol = 'TCP', string $na
return $this->setAttribute('ports', $ports);
}

/**
* Check if the container is ready.
*
* @return bool
*/
public function isReady(): bool
{
return $this->getAttribute('ready', false);
}

/**
* Get the instance as an array.
*
Expand Down
64 changes: 64 additions & 0 deletions src/Kinds/K8sDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,68 @@ public function podsSelector(): array
'deployment-name' => $this->getName(),
];
}

/**
* Get the deployment conditions.
*
* @return array
*/
public function getConditions(): array
{
return $this->getAttribute('status.conditions', []);
}

/**
* Get the available replicas.
*
* @return int
*/
public function getAvailableReplicasCount(): int
{
return $this->getAttribute('status.availableReplicas', 0);
}

/**
* Get the ready replicas.
*
* @return int
*/
public function getReadyReplicasCount(): int
{
return $this->getAttribute('status.readyReplicas', 0);
}

/**
* Get the total desired replicas.
*
* @return int
*/
public function getDesiredReplicasCount(): int
{
return $this->getAttribute('status.replicas', 0);
}

/**
* Get the total unavailable replicas.
*
* @return int
*/
public function getUnavailableReplicasCount(): int
{
return $this->getAttribute('status.unavailableReplicas', 0);
}

/**
* Check if all scheduled pods are running.
*
* @return bool
*/
public function allPodsAreRunning(): bool
{
$pods = $this->getPods();

return $pods->count() > 0 && $pods->reject(function ($pod) {
return $pod->isReady();
})->isEmpty();
}
}
Loading