generated from renoki-co/laravel-package-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from renoki-co/feature/scaling
[feature] Scaling for StatefulSet & Deployment
- Loading branch information
Showing
11 changed files
with
258 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace RenokiCo\PhpK8s\Contracts; | ||
|
||
interface Scalable | ||
{ | ||
/** | ||
* Get the path, prefixed by '/', that points to the resource scale. | ||
* | ||
* @return string | ||
*/ | ||
public function resourceScalePath(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace RenokiCo\PhpK8s\Kinds; | ||
|
||
use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; | ||
use RenokiCo\PhpK8s\Traits\HasSpec; | ||
|
||
class K8sScale extends K8sResource implements InteractsWithK8sCluster | ||
{ | ||
use HasSpec; | ||
|
||
/** | ||
* The resource Kind parameter. | ||
* | ||
* @var null|string | ||
*/ | ||
protected static $kind = 'Scale'; | ||
|
||
/** | ||
* The original scalable resource for this scale. | ||
* | ||
* @var \RenokiCo\PhpK8s\Kinds\K8sResource | ||
*/ | ||
protected $resource; | ||
|
||
/** | ||
* Wether the resource has a namespace. | ||
* | ||
* @var bool | ||
*/ | ||
protected static $namespaceable = true; | ||
|
||
/** | ||
* The default version for the resource. | ||
* | ||
* @var string | ||
*/ | ||
protected static $stableVersion = 'autoscaling/v1'; | ||
|
||
/** | ||
* Get the path, prefixed by '/', that points to the resources list. | ||
* | ||
* @return string | ||
*/ | ||
public function allResourcesPath(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* Get the path, prefixed by '/', that points to the specific resource. | ||
* | ||
* @return string | ||
*/ | ||
public function resourcePath(): string | ||
{ | ||
return $this->resource->resourceScalePath(); | ||
} | ||
|
||
/** | ||
* Set the desired replicas for the scale. | ||
* | ||
* @param int $replicas | ||
* @return $this | ||
*/ | ||
public function setReplicas(int $replicas) | ||
{ | ||
return $this->setSpec('replicas', $replicas); | ||
} | ||
|
||
/** | ||
* Get the defined replicas for the scale. | ||
* | ||
* @return int | ||
*/ | ||
public function getReplicas(): int | ||
{ | ||
return $this->getSpec('replicas', 0); | ||
} | ||
|
||
/** | ||
* Set the original scalable resource for this scale. | ||
* | ||
* @param \RenokiCo\PhpK8s\Kinds\K8sResource $resource | ||
* @return $this | ||
*/ | ||
public function setScalableResource(K8sResource $resource) | ||
{ | ||
$this->resource = $resource; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace RenokiCo\PhpK8s\Traits; | ||
|
||
trait CanScale | ||
{ | ||
/** | ||
* Scale the current resource to a specific number of replicas. | ||
* | ||
* @param int $replicas | ||
* @return \RenokiCo\PhpK8s\Kinds\K8sScale | ||
*/ | ||
public function scale(int $replicas) | ||
{ | ||
$scaler = $this->scaler(); | ||
|
||
$scaler->setReplicas($replicas)->update(); | ||
|
||
return $scaler; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters