Skip to content

Commit

Permalink
Merge branch 'feature/k8sReleases' into 'master'
Browse files Browse the repository at this point in the history
Add support for Kubernetes cluster upgrades

See merge request transip/restapi-php-library!242
  • Loading branch information
fvanmaldegem committed Aug 28, 2023
2 parents 3938095 + fb8ab0a commit 2df47dc
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CHANGELOG
=========
6.47.0
----
* Add resource to list available releases for upgrade of a Kubernetes cluster (experimental)
* Add resource action to upgrade a Kubernetes cluster (experimental)

6.46.0
----
* Fixed price information in Kubernetes products endpoint (experimental)
Expand Down
16 changes: 16 additions & 0 deletions src/Entity/Kubernetes/Cluster/Release.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Transip\Api\Library\Entity\Kubernetes\Cluster;

class Release extends \Transip\Api\Library\Entity\Kubernetes\Release
{
/**
* @var bool
*/
protected $isCompatibleUpgrade;

public function isCompatibleUpgrade(): bool
{
return $this->isCompatibleUpgrade;
}
}
55 changes: 55 additions & 0 deletions src/Repository/Kubernetes/Cluster/ReleaseRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Transip\Api\Library\Repository\Kubernetes\Cluster;

use Transip\Api\Library\Entity\Kubernetes\Cluster\Release as KubernetesRelease;
use Transip\Api\Library\Repository\ApiRepository;

class ReleaseRepository extends ApiRepository
{
public const RESOURCE_NAME = 'releases';
public const RESOURCE_PARAMETER_SINGULAR = 'release';
public const RESOURCE_PARAMETER_PLURAL = 'releases';

/**
* @return KubernetesRelease[]
*/
public function getAll(string $clusterName): array
{
return $this->getReleases($clusterName, []);
}

/**
* @return KubernetesRelease[]
*/
public function getCompatibleUpgrades(string $clusterName): array
{
return $this->getReleases($clusterName, ['isCompatibleUpgrade' => true]);
}

public function getByVersion(string $clusterName, string $version): KubernetesRelease
{
$response = $this->httpClient->get($this->getResourceUrl($clusterName, $version));

return new KubernetesRelease($this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_SINGULAR));
}

/**
* @param string $clusterName
* @param array<string, mixed> $query
* @return KubernetesRelease[]
*/
private function getReleases(string $clusterName, array $query = []): array
{
$releases = [];

$response = $this->httpClient->get($this->getResourceUrl($clusterName), $query);
$releasesArrays = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_PLURAL);

foreach ($releasesArrays as $releasesArray) {
$releases[] = new KubernetesRelease($releasesArray);
}

return $releases;
}
}
13 changes: 13 additions & 0 deletions src/Repository/Kubernetes/ClusterRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ public function reset(string $clusterName, string $confirmation): void
);
}

public function upgrade(string $clusterName, string $version): void
{
$parameters = [
'action' => 'upgrade',
'version' => $version
];

$this->httpClient->patch(
$this->getResourceUrl($clusterName),
$parameters
);
}

public function remove(string $clusterName): void
{
$this->httpClient->delete(
Expand Down
8 changes: 7 additions & 1 deletion src/TransipAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
use Transip\Api\Library\Repository\Kubernetes\Cluster\NodePools\TaintsRepository as KubernetesTaintsRepository;
use Transip\Api\Library\Repository\Kubernetes\Cluster\NodeRepository as KubernetesNodeRepository;
use Transip\Api\Library\Repository\Kubernetes\Cluster\Nodes\StatsRepository as KubernetesNodeStatsRepository;
use Transip\Api\Library\Repository\Kubernetes\Cluster\ReleaseRepository as KubernetesClusterReleaseRepository;
use Transip\Api\Library\Repository\Kubernetes\ClusterRepository as KubernetesClusterRepository;
use Transip\Api\Library\Repository\Kubernetes\ProductRepository as KubernetesProductRepository;
use Transip\Api\Library\Repository\Kubernetes\ReleaseRepository as KubernetesReleaseRepository;
Expand Down Expand Up @@ -95,7 +96,7 @@
class TransipAPI
{
public const TRANSIP_API_ENDPOINT = "https://api.transip.nl/v6";
public const TRANSIP_API_LIBRARY_VERSION = "6.46.0";
public const TRANSIP_API_LIBRARY_VERSION = "6.47.0";
public const TRANSIP_API_DEMO_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw";

/**
Expand Down Expand Up @@ -508,6 +509,11 @@ public function kubernetesReleases(): KubernetesReleaseRepository
return new KubernetesReleaseRepository($this->httpClient);
}

public function kubernetesClusterReleases(): KubernetesClusterReleaseRepository
{
return new KubernetesClusterReleaseRepository($this->httpClient);
}

public function openStackProjects(): OpenStackProjectRepository
{
return new OpenStackProjectRepository($this->httpClient);
Expand Down

0 comments on commit 2df47dc

Please sign in to comment.