From 45b074f49473adf7e0d047cfc45e28ed47b14dbb Mon Sep 17 00:00:00 2001 From: Michael Priest Date: Thu, 17 Mar 2022 02:33:08 +1030 Subject: [PATCH 01/31] Update dependencies and fix tests. --- client_test.json.example | 2 +- composer.json | 11 ++-- phpunit.xml | 58 ++++++++--------- tests/{ => src/Unit}/ClientTest.php | 63 +++++++++++-------- .../Serializer/BackupListSerializerTest.php | 2 +- .../Unit/Serializer/BackupSerializerTest.php | 6 +- .../Serializer/ConfigMapSerializerTest.php | 6 +- .../src/Unit/Serializer/HpaSerializerTest.php | 4 +- tests/src/Unit/Serializer/ListTestBase.php | 2 +- .../NetworkPolicySerializerTest.php | 4 +- .../Serializer/RestoreListSerializerTest.php | 2 +- .../Unit/Serializer/RestoreSerializerTest.php | 6 +- .../Unit/Serializer/RouteSerializerTest.php | 4 +- .../ScheduledBackupSerializerTest.php | 6 +- .../Serializer/StatefulSetSerializerTest.php | 6 +- .../Serializer/SyncListSerializerTest.php | 2 +- .../Unit/Serializer/SyncSerializerTest.php | 6 +- tests/{ => src}/fixtures/backup-list.json | 0 tests/{ => src}/fixtures/backup.json | 0 tests/{ => src}/fixtures/configmap.json | 0 tests/{ => src}/fixtures/hpa.json | 0 tests/{ => src}/fixtures/networkpolicy.json | 0 tests/{ => src}/fixtures/restore-list.json | 0 tests/{ => src}/fixtures/restore.json | 0 tests/{ => src}/fixtures/route.json | 0 tests/{ => src}/fixtures/schedule.json | 0 tests/{ => src}/fixtures/statefulset.json | 0 .../fixtures/statefulsetnormalized.json | 0 tests/{ => src}/fixtures/sync-list.json | 0 tests/{ => src}/fixtures/sync.json | 0 30 files changed, 99 insertions(+), 91 deletions(-) rename tests/{ => src/Unit}/ClientTest.php (91%) rename tests/{ => src}/fixtures/backup-list.json (100%) rename tests/{ => src}/fixtures/backup.json (100%) rename tests/{ => src}/fixtures/configmap.json (100%) rename tests/{ => src}/fixtures/hpa.json (100%) rename tests/{ => src}/fixtures/networkpolicy.json (100%) rename tests/{ => src}/fixtures/restore-list.json (100%) rename tests/{ => src}/fixtures/restore.json (100%) rename tests/{ => src}/fixtures/route.json (100%) rename tests/{ => src}/fixtures/schedule.json (100%) rename tests/{ => src}/fixtures/statefulset.json (100%) rename tests/{ => src}/fixtures/statefulsetnormalized.json (100%) rename tests/{ => src}/fixtures/sync-list.json (100%) rename tests/{ => src}/fixtures/sync.json (100%) diff --git a/client_test.json.example b/client_test.json.example index 3a90fb4..ef841f4 100644 --- a/client_test.json.example +++ b/client_test.json.example @@ -21,7 +21,7 @@ "from": { "kind": "DockerImage", "name": "uofa/s2i-shepherd-drupal:develop" - }, + } }, "envVars": [ { diff --git a/composer.json b/composer.json index 1a2b7ad..d64c531 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,14 @@ } ], "require": { - "guzzlehttp/guzzle" : "^6.2.1", - "symfony/serializer": "~3.4.0" + "guzzlehttp/guzzle" : "^6.5.5", + "symfony/serializer": "~4.4", + "symfony/phpunit-bridge": "^6.0" }, "require-dev": { - "phpunit/phpunit" : "~4.0", - "mockery/mockery" : "~0.9", - "satooshi/php-coveralls": "~1.0" + "phpunit/phpunit" : "~9.5", + "mockery/mockery" : "~1.5", + "php-coveralls/php-coveralls": "~2.5" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 1fc1eb5..6af8fb9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,35 +1,29 @@ - - - - - - - - - - - - ./tests/Unit - - - - + + + + ./src + + + ./ + ./ + + + + + + + + + + + + ./tests/src/Unit + + + + - - - - - ./src - - - ./ - ./ - - - + + diff --git a/tests/ClientTest.php b/tests/src/Unit/ClientTest.php similarity index 91% rename from tests/ClientTest.php rename to tests/src/Unit/ClientTest.php index ce2f918..ee27df0 100644 --- a/tests/ClientTest.php +++ b/tests/src/Unit/ClientTest.php @@ -24,7 +24,7 @@ class ClientTest extends TestCase { /** * Setup things required for the tests. */ - public function setUp() { + public function setUp(): void { global $argv, $argc; $this->assertEquals(6, $argc, 'Missing arguments'); @@ -41,7 +41,7 @@ public function setUp() { die("Unable to open specified file $argv[5]"); } - $this->client = new Client($this->host, $this->token, $this->namespace, TRUE); + $this->client = new Client($this->host, $this->token, $this->namespace, FALSE); $this->volumes = [ [ @@ -116,7 +116,8 @@ public function testGetSecret() { * Test creating an image stream. */ public function testCreateImageStream() { - $response = $this->client->createImageStream($this->json->clientTest->artifacts . '-stream'); + $response = $this->client->createImageStream( + $this->client->generateImageStreamConfig($this->json->clientTest->artifacts . '-stream')); $this->assertNotFalse( $response, @@ -135,8 +136,7 @@ public function testGetImageStream() { 'Unable to retrieve image stream.' ); - $this->assertInternalType( - 'array', + $this->assertIsArray( $response, 'Returned type for image stream incorrect.' ); @@ -151,7 +151,8 @@ public function testCreatePersistentVolumeClaim1() { $response = $this->client->createPersistentVolumeClaim( $this->json->clientTest->artifacts . '-private', 'ReadWriteMany', - '10Gi' + '10Gi', + 'mydeployment' ); $this->assertNotFalse( @@ -167,7 +168,8 @@ public function testCreatePersistentVolumeClaim2() { $response = $this->client->createPersistentVolumeClaim( $this->json->clientTest->artifacts . '-public', 'ReadWriteMany', - '10Gi' + '10Gi', + 'mydeployment' ); $this->assertNotFalse( @@ -192,10 +194,12 @@ public function testCreateBuildConfig() { ]; $response = $this->client->createBuildConfig( - $this->json->clientTest->artifacts . '-build', - $this->json->clientTest->buildSecret, - $this->json->clientTest->artifacts . '-stream:master', - $data + $this->client->generateBuildConfig( + $this->json->clientTest->artifacts . '-build', + $this->json->clientTest->buildSecret, + $this->json->clientTest->artifacts . '-stream:master', + $data + ) ); $this->assertNotFalse( @@ -215,10 +219,7 @@ public function testGetBuildConfig() { 'Unable to retrieve build config.' ); - $this->assertInternalType( - 'array', - $response - ); + $this->assertIsArray($response); } /** @@ -252,6 +253,9 @@ public function testCreateDeploymentConfig() { 'annotations' => [ 'test' => 'tester', ], + 'labels' => [ + 'app' => $this->json->clientTest->artifacts + ] ]; $name = $this->json->clientTest->artifacts . '-deploy'; @@ -259,11 +263,15 @@ public function testCreateDeploymentConfig() { $image_name = $this->json->clientTest->artifacts . '-image'; $response = $this->client->createDeploymentConfig( - $name, - $image_stream_tag, - $image_name, - $this->volumes, - $data + $this->client->generateDeploymentConfig( + $name, + $image_stream_tag, + $image_name, + FALSE, + $this->volumes, + $data, + [] + ) ); $this->assertNotFalse( @@ -305,6 +313,7 @@ public function testCreateCronJob() { $name, $image_name, '*/30 * * * *', + FALSE, $args, $this->volumes, $data @@ -327,10 +336,7 @@ public function testGetDeploymentConfig() { 'Unable to retrieve deploy config.' ); - $this->assertInternalType( - 'array', - $response - ); + $this->assertIsArray($response); } /** @@ -348,7 +354,13 @@ public function testCreateService() { $name = $this->json->clientTest->artifacts . '-service'; - $response = $this->client->createService($name, $data); + $response = $this->client->createService( + $name, + $this->json->clientTest->artifacts . '-deploy', + 8080, + 8080, + $this->json->clientTest->artifacts . '-deploy' + ); $this->assertNotFalse( $response, @@ -368,6 +380,7 @@ public function testCreateRoute() { $route = Route::create() ->setName($name) ->setHost($application_domain) + ->setPath('') ->setInsecureEdgeTerminationPolicy('Allow') ->setTermination('edge') ->setToKind('Service') diff --git a/tests/src/Unit/Serializer/BackupListSerializerTest.php b/tests/src/Unit/Serializer/BackupListSerializerTest.php index d40a31d..bb035c9 100644 --- a/tests/src/Unit/Serializer/BackupListSerializerTest.php +++ b/tests/src/Unit/Serializer/BackupListSerializerTest.php @@ -13,7 +13,7 @@ class BackupListSerializerTest extends ListTestBase { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/backup-list.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/backup-list.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\BackupList $backupList */ $backupList = $this->serializer->deserialize($jsonData, BackupList::class, 'json'); $this->assertTrue($backupList->hasBackups()); diff --git a/tests/src/Unit/Serializer/BackupSerializerTest.php b/tests/src/Unit/Serializer/BackupSerializerTest.php index f3468d9..fe91bbf 100644 --- a/tests/src/Unit/Serializer/BackupSerializerTest.php +++ b/tests/src/Unit/Serializer/BackupSerializerTest.php @@ -24,7 +24,7 @@ class BackupSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -33,7 +33,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/backup.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/backup.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\Backup $backup */ $backup = $this->serializer->deserialize($jsonData, Backup::class, 'json'); $this->assertEquals('test-123-backup', $backup->getName()); @@ -80,7 +80,7 @@ public function testNormalizer() { ->addDatabase($db) ->setLabel(Label::create('test-label', 'test label value')); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/backup.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/backup.json'), TRUE); unset($expected['status']); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, json_decode($this->serializer->serialize($backup, 'json'), TRUE)); diff --git a/tests/src/Unit/Serializer/ConfigMapSerializerTest.php b/tests/src/Unit/Serializer/ConfigMapSerializerTest.php index 43ac1ba..fa11ccc 100644 --- a/tests/src/Unit/Serializer/ConfigMapSerializerTest.php +++ b/tests/src/Unit/Serializer/ConfigMapSerializerTest.php @@ -22,7 +22,7 @@ class ConfigMapSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -31,7 +31,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/configmap.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/configmap.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\ConfigMap $configMap */ $configMap = $this->serializer->deserialize($jsonData, ConfigMap::class, 'json'); $this->assertEquals('test-config', $configMap->getName()); @@ -49,7 +49,7 @@ public function testNormalizer() { ->setLabel(Label::create('test-label', 'test label value')) ->setData(['foo' => 'bar', 'boo' => 'far']); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/configmap.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/configmap.json'), TRUE); unset($expected['status']); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, json_decode($this->serializer->serialize($configMap, 'json'), TRUE)); diff --git a/tests/src/Unit/Serializer/HpaSerializerTest.php b/tests/src/Unit/Serializer/HpaSerializerTest.php index 787b766..c1a75e2 100644 --- a/tests/src/Unit/Serializer/HpaSerializerTest.php +++ b/tests/src/Unit/Serializer/HpaSerializerTest.php @@ -21,7 +21,7 @@ class HpaSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -37,7 +37,7 @@ public function testNormalizer() { ->setTargetCpu(80) ->setName('test-hpa'); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/hpa.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/hpa.json'), TRUE); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, json_decode($this->serializer->serialize($hpa, 'json'), TRUE)); } diff --git a/tests/src/Unit/Serializer/ListTestBase.php b/tests/src/Unit/Serializer/ListTestBase.php index bc4a867..6064acd 100644 --- a/tests/src/Unit/Serializer/ListTestBase.php +++ b/tests/src/Unit/Serializer/ListTestBase.php @@ -21,7 +21,7 @@ abstract class ListTestBase extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } diff --git a/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php b/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php index 742f4b1..b826d66 100644 --- a/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php +++ b/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php @@ -21,7 +21,7 @@ class NetworkPolicySerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -37,7 +37,7 @@ public function testNormalizer() { ->setPort(11312) ->setName('test-np'); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/networkpolicy.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/networkpolicy.json'), TRUE); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, json_decode($this->serializer->serialize($np, 'json'), TRUE)); } diff --git a/tests/src/Unit/Serializer/RestoreListSerializerTest.php b/tests/src/Unit/Serializer/RestoreListSerializerTest.php index fe8ce8c..ff1e7a9 100644 --- a/tests/src/Unit/Serializer/RestoreListSerializerTest.php +++ b/tests/src/Unit/Serializer/RestoreListSerializerTest.php @@ -13,7 +13,7 @@ class RestoreListSerializerTest extends ListTestBase { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/restore-list.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/restore-list.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\RestoreList $restoreList */ $restoreList = $this->serializer->deserialize($jsonData, RestoreList::class, 'json'); $this->assertTrue($restoreList->hasRestores()); diff --git a/tests/src/Unit/Serializer/RestoreSerializerTest.php b/tests/src/Unit/Serializer/RestoreSerializerTest.php index 8d39cbc..ff4173f 100644 --- a/tests/src/Unit/Serializer/RestoreSerializerTest.php +++ b/tests/src/Unit/Serializer/RestoreSerializerTest.php @@ -24,7 +24,7 @@ class RestoreSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -33,7 +33,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/restore.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/restore.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\Restore $restore */ $restore = $this->serializer->deserialize($jsonData, Restore::class, 'json'); $this->assertEquals('test-restore', $restore->getName()); @@ -66,7 +66,7 @@ public function testNormalizer() { ->setDatabases([$db]) ->setLabel(Label::create('site_id', '123')); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/restore.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/restore.json'), TRUE); // We don't set status on normalization. unset($expected['status']); unset($expected['metadata']['creationTimestamp']); diff --git a/tests/src/Unit/Serializer/RouteSerializerTest.php b/tests/src/Unit/Serializer/RouteSerializerTest.php index 71f44c5..09833a6 100644 --- a/tests/src/Unit/Serializer/RouteSerializerTest.php +++ b/tests/src/Unit/Serializer/RouteSerializerTest.php @@ -21,7 +21,7 @@ class RouteSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -42,7 +42,7 @@ public function testNormalizer() { ->setToWeight(50) ->setWildcardPolicy('None'); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/route.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/route.json'), TRUE); $this->assertEquals($expected, json_decode($this->serializer->serialize($route, 'json'), TRUE)); } diff --git a/tests/src/Unit/Serializer/ScheduledBackupSerializerTest.php b/tests/src/Unit/Serializer/ScheduledBackupSerializerTest.php index ab426ab..29829d7 100644 --- a/tests/src/Unit/Serializer/ScheduledBackupSerializerTest.php +++ b/tests/src/Unit/Serializer/ScheduledBackupSerializerTest.php @@ -24,7 +24,7 @@ class ScheduledBackupSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -33,7 +33,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/schedule.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/schedule.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\ScheduledBackup $schedule */ $schedule = $this->serializer->deserialize($jsonData, ScheduledBackup::class, 'json'); $this->assertEquals(['test-label' => 'test label value'], $schedule->getLabels()); @@ -79,7 +79,7 @@ public function testNormalizer() { ->setRetention(7) ->setLabel(Label::create('test-label', 'test label value')); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/schedule.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/schedule.json'), TRUE); unset($expected['status']); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, $this->serializer->normalize($scheduled)); diff --git a/tests/src/Unit/Serializer/StatefulSetSerializerTest.php b/tests/src/Unit/Serializer/StatefulSetSerializerTest.php index 7f8ab88..19395da 100644 --- a/tests/src/Unit/Serializer/StatefulSetSerializerTest.php +++ b/tests/src/Unit/Serializer/StatefulSetSerializerTest.php @@ -23,7 +23,7 @@ class StatefulSetSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -32,7 +32,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/statefulset.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/statefulset.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\StatefulSet $ss */ $ss = $this->serializer->deserialize($jsonData, StatefulSet::class, 'json'); $this->assertEquals('test-ss', $ss->getName()); @@ -62,7 +62,7 @@ public function testNormalizer() { ], ]); - $expected = trim(file_get_contents(__DIR__ . '/../../../fixtures/statefulsetnormalized.json')); + $expected = trim(file_get_contents(__DIR__ . '/../../fixtures/statefulsetnormalized.json')); $actual = $this->serializer->serialize($ss, 'json'); // Use assertEquals here as the json assertions will not pick up on the // difference between an empty array and empty object. diff --git a/tests/src/Unit/Serializer/SyncListSerializerTest.php b/tests/src/Unit/Serializer/SyncListSerializerTest.php index a42c04b..e50644a 100644 --- a/tests/src/Unit/Serializer/SyncListSerializerTest.php +++ b/tests/src/Unit/Serializer/SyncListSerializerTest.php @@ -13,7 +13,7 @@ class SyncListSerializerTest extends ListTestBase { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/sync-list.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/sync-list.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\SyncList $syncList */ $syncList = $this->serializer->deserialize($jsonData, SyncList::class, 'json'); $this->assertCount(2, $syncList->getSyncs()); diff --git a/tests/src/Unit/Serializer/SyncSerializerTest.php b/tests/src/Unit/Serializer/SyncSerializerTest.php index 20a9aef..0d14e33 100644 --- a/tests/src/Unit/Serializer/SyncSerializerTest.php +++ b/tests/src/Unit/Serializer/SyncSerializerTest.php @@ -24,7 +24,7 @@ class SyncSerializerTest extends TestCase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp(): void { parent::setUp(); $this->serializer = OpenShiftSerializerFactory::create(); } @@ -33,7 +33,7 @@ public function setUp() { * @covers ::denormalize */ public function testDenormalize() { - $jsonData = file_get_contents(__DIR__ . '/../../../fixtures/sync.json'); + $jsonData = file_get_contents(__DIR__ . '/../../fixtures/sync.json'); /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\Sync $sync */ $sync = $this->serializer->deserialize($jsonData, Sync::class, 'json'); $this->assertEquals('test-123-sync', $sync->getName()); @@ -109,7 +109,7 @@ public function testNormalizer() { ->setRestoreDatabases([$restoreDb]) ->setLabel(Label::create('test-label', 'test label value')); - $expected = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/sync.json'), TRUE); + $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/sync.json'), TRUE); unset($expected['status']); unset($expected['metadata']['creationTimestamp']); $this->assertEquals($expected, json_decode($this->serializer->serialize($sync, 'json'), TRUE)); diff --git a/tests/fixtures/backup-list.json b/tests/src/fixtures/backup-list.json similarity index 100% rename from tests/fixtures/backup-list.json rename to tests/src/fixtures/backup-list.json diff --git a/tests/fixtures/backup.json b/tests/src/fixtures/backup.json similarity index 100% rename from tests/fixtures/backup.json rename to tests/src/fixtures/backup.json diff --git a/tests/fixtures/configmap.json b/tests/src/fixtures/configmap.json similarity index 100% rename from tests/fixtures/configmap.json rename to tests/src/fixtures/configmap.json diff --git a/tests/fixtures/hpa.json b/tests/src/fixtures/hpa.json similarity index 100% rename from tests/fixtures/hpa.json rename to tests/src/fixtures/hpa.json diff --git a/tests/fixtures/networkpolicy.json b/tests/src/fixtures/networkpolicy.json similarity index 100% rename from tests/fixtures/networkpolicy.json rename to tests/src/fixtures/networkpolicy.json diff --git a/tests/fixtures/restore-list.json b/tests/src/fixtures/restore-list.json similarity index 100% rename from tests/fixtures/restore-list.json rename to tests/src/fixtures/restore-list.json diff --git a/tests/fixtures/restore.json b/tests/src/fixtures/restore.json similarity index 100% rename from tests/fixtures/restore.json rename to tests/src/fixtures/restore.json diff --git a/tests/fixtures/route.json b/tests/src/fixtures/route.json similarity index 100% rename from tests/fixtures/route.json rename to tests/src/fixtures/route.json diff --git a/tests/fixtures/schedule.json b/tests/src/fixtures/schedule.json similarity index 100% rename from tests/fixtures/schedule.json rename to tests/src/fixtures/schedule.json diff --git a/tests/fixtures/statefulset.json b/tests/src/fixtures/statefulset.json similarity index 100% rename from tests/fixtures/statefulset.json rename to tests/src/fixtures/statefulset.json diff --git a/tests/fixtures/statefulsetnormalized.json b/tests/src/fixtures/statefulsetnormalized.json similarity index 100% rename from tests/fixtures/statefulsetnormalized.json rename to tests/src/fixtures/statefulsetnormalized.json diff --git a/tests/fixtures/sync-list.json b/tests/src/fixtures/sync-list.json similarity index 100% rename from tests/fixtures/sync-list.json rename to tests/src/fixtures/sync-list.json diff --git a/tests/fixtures/sync.json b/tests/src/fixtures/sync.json similarity index 100% rename from tests/fixtures/sync.json rename to tests/src/fixtures/sync.json From 250df2633927f2e6d15c7baba5aee7ad90d09b18 Mon Sep 17 00:00:00 2001 From: Michael Priest Date: Tue, 22 Mar 2022 01:38:06 +1030 Subject: [PATCH 02/31] Drupal core compatible version of the phpunit bridge. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d64c531..075f83e 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "guzzlehttp/guzzle" : "^6.5.5", "symfony/serializer": "~4.4", - "symfony/phpunit-bridge": "^6.0" + "symfony/phpunit-bridge": "^5.3" }, "require-dev": { "phpunit/phpunit" : "~9.5", From 161c8af9d3a94f88c4c32b319e3cd6577facd916 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 12 Apr 2022 13:28:16 +0930 Subject: [PATCH 03/31] Get Imagestream creation working. --- src/Client.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5228b9f..d3d38c3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -194,25 +194,25 @@ class Client implements ClientInterface { 'imagestream' => [ 'create' => [ 'action' => 'POST', - 'uri' => '/oapi/v1/namespaces/{namespace}/imagestreams', + 'uri' => '/apis/image.openshift.io/v1/namespaces/{namespace}/imagestreams', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/oapi/v1/namespaces/{namespace}/imagestreams/{name}', + 'uri' => '/apis/image.openshift.io/v1/namespaces/{namespace}/imagestreams/{name}', ], 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/imagestreams/{name}', + 'uri' => '/apis/image.openshift.io/v1/namespaces/{namespace}/imagestreams/{name}', ], 'update' => [ 'action' => 'PUT', - 'uri' => '/oapi/v1/namespaces/{namespace}/imagestreams/{name}', + 'uri' => '/apis/image.openshift.io/v1/namespaces/{namespace}/imagestreams/{name}', ], ], 'imagestreamtag' => [ 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/imagestreamtags/{name}', + 'uri' => '/apis/image.openshift.io/v1/namespaces/{namespace}/imagestreamtags/{name}', ], ], 'job' => [ @@ -920,7 +920,7 @@ public function getImageStream(string $name) { */ public function generateImageStreamConfig(string $name) { $imageStream = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'image.openshift.io/v1', 'kind' => 'ImageStream', 'metadata' => [ 'name' => $name, From 2aeb83cc22ce72b9e5d9751a40fc5fcebab5b893 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 13 Apr 2022 17:04:22 +0930 Subject: [PATCH 04/31] Update more endpoints for Openshift 4.x --- src/Client.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Client.php b/src/Client.php index d3d38c3..2d7e448 100644 --- a/src/Client.php +++ b/src/Client.php @@ -96,25 +96,25 @@ class Client implements ClientInterface { 'buildconfig' => [ 'create' => [ 'action' => 'POST', - 'uri' => '/oapi/v1/namespaces/{namespace}/buildconfigs', + 'uri' => '/apis/build.openshift.io/v1/namespaces/{namespace}/buildconfigs', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/oapi/v1/namespaces/{namespace}/buildconfigs/{name}', + 'uri' => '/apis/build.openshift.io/v1/namespaces/{namespace}/buildconfigs/{name}', ], 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/buildconfigs/{name}', + 'uri' => '/apis/build.openshift.io/v1/namespaces/{namespace}/buildconfigs/{name}', ], 'update' => [ 'action' => 'PUT', - 'uri' => '/oapi/v1/namespaces/{namespace}/buildconfigs/{name}', + 'uri' => '/apis/build.openshift.io/v1/namespaces/{namespace}/buildconfigs/{name}', ], ], 'builds' => [ 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/builds/{name}', + 'uri' => '/apis/build.openshift.io/v1/namespaces/{namespace}/builds', ], ], 'configmap' => [ @@ -148,29 +148,29 @@ class Client implements ClientInterface { 'deploymentconfig' => [ 'create' => [ 'action' => 'POST', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs/{name}', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs/{name}', ], 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs/{name}', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs/{name}', ], 'update' => [ 'action' => 'PUT', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs/{name}', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs/{name}', ], 'instantiate' => [ 'action' => 'POST', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs/{name}/instantiate', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs/{name}/instantiate', ], ], 'deploymentconfigs' => [ 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/deploymentconfigs', + 'uri' => '/apis/apps.openshift.io/v1/namespaces/{namespace}/deploymentconfigs', ], ], 'hpa' => [ @@ -316,19 +316,19 @@ class Client implements ClientInterface { 'route' => [ 'create' => [ 'action' => 'POST', - 'uri' => '/oapi/v1/namespaces/{namespace}/routes', + 'uri' => '/apis/route.openshift.io/v1/namespaces/{namespace}/routes', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/oapi/v1/namespaces/{namespace}/routes/{name}', + 'uri' => '/apis/route.openshift.io/v1/namespaces/{namespace}/routes/{name}', ], 'get' => [ 'action' => 'GET', - 'uri' => '/oapi/v1/namespaces/{namespace}/routes/{name}', + 'uri' => '/apis/route.openshift.io/v1/namespaces/{namespace}/routes/{name}', ], 'update' => [ 'action' => 'PUT', - 'uri' => '/oapi/v1/namespaces/{namespace}/routes/{name}', + 'uri' => '/apis/route.openshift.io/v1/namespaces/{namespace}/routes/{name}', ], ], 'schedule' => [ From b9bc140ba89602f7d58552f931f87def4de43d8d Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 13 Apr 2022 17:22:00 +0930 Subject: [PATCH 05/31] Remove unused variables and dead todo's. --- src/Client.php | 63 +++++++++----------------------------------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2d7e448..a2d4b47 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,13 +29,6 @@ */ class Client implements ClientInterface { - /** - * Api version. - * - * @var string - */ - private $apiVersion = 'v1'; - /** * Current working namespace. * @@ -43,13 +36,6 @@ class Client implements ClientInterface { */ private $namespace; - /** - * Base url to OpenShift. - * - * @var string - */ - private $host; - /** * Guzzle HTTP Client. * @@ -433,7 +419,6 @@ class Client implements ClientInterface { * {@inheritdoc} */ public function __construct($host, $token, $namespace, $verifyTls = TRUE) { - $this->host = $host; $this->namespace = $namespace; $this->guzzleClient = new GuzzleClient([ 'verify' => $verifyTls, @@ -447,30 +432,10 @@ public function __construct($host, $token, $namespace, $verifyTls = TRUE) { } /** - * Returns the api version. - * - * @return string - * The currently supported api version. - */ - public function getApiVersion() { - return $this->apiVersion; - } - - /** - * Set the api version number. - * - * @param string $apiVersion - * Api version number. - */ - public function setApiVersion(string $apiVersion) { - $this->apiVersion = $apiVersion; - } - - /** - * Returns the guzzle client. + * Return the Guzzle client. * * @return \GuzzleHttp\Client - * Return the guzzle client. + * Return the Guzzle client. */ public function getGuzzleClient() { return $this->guzzleClient; @@ -608,7 +573,6 @@ public function createSecret(string $name, array $data) { $data[$key] = base64_encode($value); } - // @todo - this should use model. $secret = [ 'kind' => 'Secret', 'metadata' => [ @@ -687,7 +651,6 @@ public function createService(string $name, string $deployment_name, int $port, ]; } - // @todo - use a model. $service = [ 'kind' => 'Service', 'metadata' => [ @@ -698,7 +661,6 @@ public function createService(string $name, string $deployment_name, int $port, 'ports' => [ // Defaults to TCP. [ - // @todo Does this have any impact when using non web ports? 'name' => 'web', 'port' => $port, 'targetPort' => $target_port, @@ -780,7 +742,7 @@ public function createRoute(Route $route) { * {@inheritdoc} */ public function updateRoute(string $name, string $service_name, string $application_domain) { - // TODO: Implement updateRoute() method. + // @todo Implement updateRoute() method. } /** @@ -866,7 +828,6 @@ public function generateBuildConfig(string $name, string $secret, string $image_ ], 'type' => 'Source', ], - // @todo - figure out github and other types of triggers 'triggers' => [ [ 'type' => 'ImageChange', @@ -974,14 +935,14 @@ public function getImageStreamTag(string $name) { * {@inheritdoc} */ public function createImageSteamTag(string $name) { - // TODO: Implement createImageSteamTag() method. + // @todo Implement createImageSteamTag() method. } /** * {@inheritdoc} */ public function updateImageSteamTag(string $name) { - // TODO: Implement updateImageSteamTag() method. + // @todo Implement updateImageSteamTag() method. } /** @@ -1035,7 +996,7 @@ public function createPersistentVolumeClaim(string $name, string $access_mode, s * {@inheritdoc} */ public function updatePersistentVolumeClaim(string $name, string $access_mode, string $storage) { - // TODO: Implement updatePersistentVolumeClaim() method. + // @todo Implement updatePersistentVolumeClaim() method. } /** @@ -1174,8 +1135,6 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, /** * Return a formatted securityContext for openshift. * - * TODO: Move uid/gid into a sub array and only pass that? - * * @param $data * The complete data array * @@ -1187,15 +1146,15 @@ protected function generateSecurityContext($data) { 'securityContext' => [ 'runAsUser' => $data['uid'], 'supplementalGroups' => array_key_exists('gid', $data) ? [$data['gid']] : [], - ] + ], ]; } /** * Return an array of probes. * - * @param $probes - * Array of probe configuration constructed from a project entity. + * @param array $probes + * Array of probe configuration constructed from a project entity. * * @return array * Probes array ready for API. @@ -1293,7 +1252,7 @@ public function instantiateDeploymentConfig(string $name) { public function updateDeploymentConfig(string $name, array $deployment_config, array $config) { $deployment_config = array_replace_recursive($deployment_config, $config); - // Just replace the entire env array as the replace screws it up. + // Replace the entire env array. if (isset($config['spec']['template']['spec']['containers'][0]['env'])) { $deployment_config['spec']['template']['spec']['containers'][0]['env'] = $config['spec']['template']['spec']['containers'][0]['env']; @@ -1497,7 +1456,7 @@ public function updateReplicationControllers($name, $label = NULL, $replica_coun $repControllers = $this->getReplicationControllers($name, $label); if ($replica_count === NULL) { - // @todo - err what ? + // @todo err what ? return $repControllers; } From 5a1f63b4d4fe5e7ed1c85526fb363d9b4e860081 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 27 Apr 2022 12:37:43 +0930 Subject: [PATCH 06/31] Remove old unused api variable and code. --- src/Client.php | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2d7e448..940fd05 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,13 +29,6 @@ */ class Client implements ClientInterface { - /** - * Api version. - * - * @var string - */ - private $apiVersion = 'v1'; - /** * Current working namespace. * @@ -446,26 +439,6 @@ public function __construct($host, $token, $namespace, $verifyTls = TRUE) { $this->serializer = OpenShiftSerializerFactory::create(); } - /** - * Returns the api version. - * - * @return string - * The currently supported api version. - */ - public function getApiVersion() { - return $this->apiVersion; - } - - /** - * Set the api version number. - * - * @param string $apiVersion - * Api version number. - */ - public function setApiVersion(string $apiVersion) { - $this->apiVersion = $apiVersion; - } - /** * Returns the guzzle client. * @@ -1067,7 +1040,7 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, $volume_config = $this->setVolumes($volumes); $deploymentConfig = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'apps.openshift.io/v1', 'kind' => 'DeploymentConfig', 'metadata' => [ 'name' => $name, @@ -1277,7 +1250,7 @@ public function instantiateDeploymentConfig(string $name) { ]); $instantiate = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'apps.openshift.io/v1', 'kind' => 'DeploymentRequest', 'name' => $name, 'latest' => TRUE, From 32b29651e993f8b604c37f2e31534ecb8a24f473 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 27 Apr 2022 12:38:03 +0930 Subject: [PATCH 07/31] Update the api version on the route. --- src/Serializer/RouteNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serializer/RouteNormalizer.php b/src/Serializer/RouteNormalizer.php index 1a4a7c4..641921c 100644 --- a/src/Serializer/RouteNormalizer.php +++ b/src/Serializer/RouteNormalizer.php @@ -30,7 +30,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) public function normalize($object, $format = NULL, array $context = []) { /** @var \UniversityOfAdelaide\OpenShift\Objects\Route $object */ $data = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'route.openshift.io/v1', 'kind' => 'Route', 'metadata' => [ 'name' => $object->getName(), From aa436eb41112abc3242ee10c591a2f325a23696e Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 4 May 2022 12:53:42 +0930 Subject: [PATCH 08/31] Update api response, don't suggest committing cache. --- .gitignore | 1 + tests/src/fixtures/route.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 264188c..291b3ce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.idea/ /client_test.json /client_test.yml +.phpunit.result.cache diff --git a/tests/src/fixtures/route.json b/tests/src/fixtures/route.json index 5a136f3..b4b0cc0 100644 --- a/tests/src/fixtures/route.json +++ b/tests/src/fixtures/route.json @@ -1,5 +1,5 @@ { - "apiVersion": "v1", + "apiVersion": "route.openshift.io/v1", "kind": "Route", "metadata": { "name": "route-test" From 35d8df41326158892fe00314d2948fb3724c84ac Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 4 May 2022 12:56:51 +0930 Subject: [PATCH 09/31] Skip long time non functional client tests for now. --- .github/workflows/openshift-client.yml | 7 +++++-- phpunit.xml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/openshift-client.yml b/.github/workflows/openshift-client.yml index d6692ba..dd9f8a6 100644 --- a/.github/workflows/openshift-client.yml +++ b/.github/workflows/openshift-client.yml @@ -33,5 +33,8 @@ jobs: - name: Install Composer dependencies run: | composer install --no-progress --prefer-dist - - name: Run Tests - run: vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/ + - name: Run Tests - Skip long time non functional client tests for now. + run: | + vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/BackupTest.php + vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/PhaseTest.php + vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/Serializer/ diff --git a/phpunit.xml b/phpunit.xml index 6af8fb9..f34ee3e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -23,7 +23,7 @@ - + From 44a6d969741feaab093591e2883eaf9971e3eaa8 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 4 May 2022 13:02:36 +0930 Subject: [PATCH 10/31] Move that test out of the way instead, simpler. --- .github/workflows/openshift-client.yml | 6 ++---- tests/src/{Unit => Disabled}/ClientTest.php | 0 2 files changed, 2 insertions(+), 4 deletions(-) rename tests/src/{Unit => Disabled}/ClientTest.php (100%) diff --git a/.github/workflows/openshift-client.yml b/.github/workflows/openshift-client.yml index dd9f8a6..37e852a 100644 --- a/.github/workflows/openshift-client.yml +++ b/.github/workflows/openshift-client.yml @@ -33,8 +33,6 @@ jobs: - name: Install Composer dependencies run: | composer install --no-progress --prefer-dist - - name: Run Tests - Skip long time non functional client tests for now. + - name: Run Tests run: | - vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/BackupTest.php - vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/PhaseTest.php - vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/Serializer/ + vendor/phpunit/phpunit/phpunit --coverage-text tests/src/Unit/ diff --git a/tests/src/Unit/ClientTest.php b/tests/src/Disabled/ClientTest.php similarity index 100% rename from tests/src/Unit/ClientTest.php rename to tests/src/Disabled/ClientTest.php From 548dccecef66dd62717371b6062715d9f91bd47c Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 9 May 2022 13:18:02 +0930 Subject: [PATCH 11/31] Missed committing these couple more api version changes. --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index a2d4b47..e5f026f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1028,7 +1028,7 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, $volume_config = $this->setVolumes($volumes); $deploymentConfig = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'apps.openshift.io/v1', 'kind' => 'DeploymentConfig', 'metadata' => [ 'name' => $name, @@ -1236,7 +1236,7 @@ public function instantiateDeploymentConfig(string $name) { ]); $instantiate = [ - 'apiVersion' => 'v1', + 'apiVersion' => 'apps.openshift.io/v1', 'kind' => 'DeploymentRequest', 'name' => $name, 'latest' => TRUE, From fd1b9405e6e1874fd1acc8859ce5c2e6c5225e90 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 24 May 2022 16:49:14 +0930 Subject: [PATCH 12/31] Switch to dynamically adding the auth token. --- src/Client.php | 35 ++++++++++++++++++++++++++++++++--- src/ClientInterface.php | 4 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index e5f026f..9847f49 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,10 @@ use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Handler\CurlHandler; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Middleware; +use Psr\Http\Message\RequestInterface; use UniversityOfAdelaide\OpenShift\Objects\Backups\Backup; use UniversityOfAdelaide\OpenShift\Objects\Backups\BackupList; use UniversityOfAdelaide\OpenShift\Objects\Backups\Restore; @@ -418,19 +422,33 @@ class Client implements ClientInterface { /** * {@inheritdoc} */ - public function __construct($host, $token, $namespace, $verifyTls = TRUE) { - $this->namespace = $namespace; + public function __construct($host, $verifyTls = TRUE) { + // Create a handler stack with sane defaults. + $stack = new HandlerStack(); + $stack->setHandler(new CurlHandler()); + + // Add our token variable checker so we can override the default token. + $stack->push($this->handleAuth()); + $this->guzzleClient = new GuzzleClient([ + 'handler' => $stack, 'verify' => $verifyTls, 'base_uri' => $host, 'headers' => [ - 'Authorization' => 'Bearer ' . $token, 'Accept' => 'application/json', ], ]); $this->serializer = OpenShiftSerializerFactory::create(); } + public function setNamespace($namespace) { + $this->namespace = $namespace; + } + + public function setToken($token) { + $this->token = $token; + } + /** * Return the Guzzle client. * @@ -441,6 +459,17 @@ public function getGuzzleClient() { return $this->guzzleClient; } + public function handleAuth() { + return function (callable $handler) { + return function (RequestInterface $r) use ($handler) { + if ($this->token) { + $r = $r->withHeader('Authorization', 'Bearer ' . $this->token); + return $r; + }; + }; + }; + } + /** * Recurse into the array and remove any keys with empty values. * diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 9dbf43b..d81fdbc 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -14,7 +14,7 @@ use UniversityOfAdelaide\OpenShift\Objects\StatefulSet; /** - * Interface OpenShiftClientInterface. + * The Interface for the OpenShiftClient. * * @package UnviersityofAdelaide\OpenShift. */ @@ -32,7 +32,7 @@ interface ClientInterface { * @param bool $verifyTls * TLS certificates are verified by default. */ - public function __construct($host, $token, $namespace, $verifyTls = TRUE); + public function __construct($host, $verifyTls = TRUE); /** * Sends a request via the guzzle http client. From aae647b8f21c7b68974af3b93306bd6d8660fc56 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 30 May 2022 13:03:46 +0930 Subject: [PATCH 13/31] Add in project api calls, some error handling. --- src/Client.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9847f49..a2fbf61 100644 --- a/src/Client.php +++ b/src/Client.php @@ -271,6 +271,16 @@ class Client implements ClientInterface { 'uri' => '/api/v1/namespaces/{namespace}/pods', ], ], + 'projects' => [ + 'create' => [ + 'action' => 'POST', + 'uri' => '/apis/project.openshift.io/v1/projects', + ], + 'get' => [ + 'action' => 'GET', + 'uri' => '/apis/project.openshift.io/v1/projects', + ], + ], 'replicationcontrollers' => [ 'get' => [ 'action' => 'GET', @@ -461,10 +471,10 @@ public function getGuzzleClient() { public function handleAuth() { return function (callable $handler) { - return function (RequestInterface $r) use ($handler) { + return function (RequestInterface $request, array $options) use ($handler) { if ($this->token) { - $r = $r->withHeader('Authorization', 'Bearer ' . $this->token); - return $r; + $request = $request->withHeader('Authorization', 'Bearer ' . $this->token); + return $handler($request, $options); }; }; }; @@ -540,6 +550,16 @@ public function request(string $method, string $uri, $body = NULL, array $query $e->hasResponse() ? $e->getResponse()->getBody() : '' ); } + + // If the response code is outside normal, throw some rage. + if (!in_array($response->getStatusCode(), [200, 201, 404])) { + $decoded_response = json_decode($response->getBody(), TRUE); + throw new ClientException( + $decoded_response['message'], + $decoded_response['code'], + ); + } + $contents = $response->getBody()->getContents(); return $decode_response ? json_decode($contents, TRUE) : $contents; } @@ -591,6 +611,32 @@ protected function createRequestUri(string $uri, array $params = []) { return $uri; } + /** + * Create a new project. + * + * @param string $name + * The project name to be created. + */ + public function createProject(string $name) { + $resourceMethod = $this->getResourceMethod(__METHOD__); + + $project = [ + 'kind' => 'Project', + 'metadata' => [ + 'name' => 'shp-' . $name, + ], + ]; + + return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); + } + + /** + * Retrieve a list of existing projects. + */ + public function getProjects() { + return $this->apiCall(__METHOD__, $name); + } + /** * {@inheritdoc} */ @@ -1794,6 +1840,7 @@ private function createSerializableObject($method, $object, array $params = []) $resourceMethod = $this->getResourceMethod($method); $uri = $this->createRequestUri($resourceMethod['uri'], $params); $serialized = $this->serializer->serialize($object, 'json'); + if (!$result = $this->request($resourceMethod['action'], $uri, $serialized, [], FALSE)) { return FALSE; } From e340acc1156f5fdcadb1cea64f0a32a2cf38bbd1 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 30 May 2022 16:35:08 +0930 Subject: [PATCH 14/31] Add in the project request method. --- src/Client.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index a2fbf61..dd5d772 100644 --- a/src/Client.php +++ b/src/Client.php @@ -271,7 +271,7 @@ class Client implements ClientInterface { 'uri' => '/api/v1/namespaces/{namespace}/pods', ], ], - 'projects' => [ + 'project' => [ 'create' => [ 'action' => 'POST', 'uri' => '/apis/project.openshift.io/v1/projects', @@ -281,6 +281,12 @@ class Client implements ClientInterface { 'uri' => '/apis/project.openshift.io/v1/projects', ], ], + 'projectrequest' => [ + 'create' => [ + 'action' => 'POST', + 'uri' => '/apis/project.openshift.io/v1/projectrequests', + ], + ], 'replicationcontrollers' => [ 'get' => [ 'action' => 'GET', @@ -622,14 +628,38 @@ public function createProject(string $name) { $project = [ 'kind' => 'Project', + 'apiVersion' => 'project.openshift.io/v1', 'metadata' => [ 'name' => 'shp-' . $name, + 'creationTimestamp' => NULL, ], ]; return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); } + /** + * Create a new project request. + * + * @param string $name + * The project name to be created. + */ + public function createProjectRequest(string $name) { + $resourceMethod = $this->getResourceMethod(__METHOD__); + + $project = [ + 'kind' => 'ProjectRequest', + 'apiVersion' => 'project.openshift.io/v1', + 'metadata' => [ + 'name' => 'shp-' . $name, + 'creationTimestamp' => NULL, + ], + ]; + + return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); + } + + /** * Retrieve a list of existing projects. */ From 37f6f3bda2e401940afbbb4761cf85c78ac18771 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 1 Jun 2022 12:46:10 +0930 Subject: [PATCH 15/31] Adding in roleinding support. --- src/Client.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index dd5d772..b773748 100644 --- a/src/Client.php +++ b/src/Client.php @@ -319,6 +319,20 @@ class Client implements ClientInterface { 'uri' => '/apis/extension.shepherd/v1/namespaces/{namespace}/restores', ], ], + 'rolebinding' => [ + 'get' => [ + 'action' => 'GET', + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}' + ], + 'list' => [ + 'action' => 'GET', + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings' + ], + 'create' => [ + 'action' => 'POST', + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings' + ], + ], 'route' => [ 'create' => [ 'action' => 'POST', @@ -630,7 +644,7 @@ public function createProject(string $name) { 'kind' => 'Project', 'apiVersion' => 'project.openshift.io/v1', 'metadata' => [ - 'name' => 'shp-' . $name, + 'name' => $name, 'creationTimestamp' => NULL, ], ]; @@ -651,7 +665,7 @@ public function createProjectRequest(string $name) { 'kind' => 'ProjectRequest', 'apiVersion' => 'project.openshift.io/v1', 'metadata' => [ - 'name' => 'shp-' . $name, + 'name' => $name, 'creationTimestamp' => NULL, ], ]; @@ -659,6 +673,42 @@ public function createProjectRequest(string $name) { return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); } + /** + * Give access to other users + */ + public function createRoleBinding(string $subjectUserName, string $roleBinding, string $roleBindingName, string $subjectProject = NULL) { + $resourceMethod = $this->getResourceMethod(__METHOD__); + + $request = [ + 'kind' => 'RoleBinding', + 'apiVersion' => 'rbac.authorization.k8s.io/v1', + 'metadata' => [ + 'name' => $roleBindingName, + 'namespace' => $this->namespace, + ], + 'subjects' => [ + [ + 'kind' => 'User', + 'apiGroup' => 'rbac.authorization.k8s.io', + 'name' => $subjectUserName, + ], + ], + 'roleRef' => [ + 'apiGroup'=> 'rbac.authorization.k8s.io', + 'kind'=> 'ClusterRole', + 'name'=> $roleBinding, + ], + ]; + + // This is a bit icky.. + if ($subjectProject) { + $subject[0]['kind'] = 'ServiceAccount'; + $subject[0]['namespace'] = $subjectProject; + unset($subject[0]['apiGroup']); + } + + return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $request); + } /** * Retrieve a list of existing projects. @@ -1205,6 +1255,7 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, 'from' => [ 'kind' => 'ImageStreamTag', 'name' => $image_stream_tag, + 'namespace' => 'shepherd', ], ], 'type' => 'ImageChange', From c86370cdf5717d97777fa2574e24307ab6b5a71e Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 1 Jun 2022 13:21:53 +0930 Subject: [PATCH 16/31] Make missing things respond like the api used to. --- src/Client.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Client.php b/src/Client.php index b773748..f9bc27f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -580,6 +580,11 @@ public function request(string $method, string $uri, $body = NULL, array $query ); } + // Reproduce what OpenShift 3.x did for 404 responses. + if ($response->getStatusCode() === 404) { + return FALSE; + } + $contents = $response->getBody()->getContents(); return $decode_response ? json_decode($contents, TRUE) : $contents; } From f80c715898fd2f610fbadc6040f7783e31c9254f Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Fri, 3 Jun 2022 15:15:39 +0930 Subject: [PATCH 17/31] Add support for project deletion. --- src/Client.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Client.php b/src/Client.php index f9bc27f..2bc97f8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -280,6 +280,10 @@ class Client implements ClientInterface { 'action' => 'GET', 'uri' => '/apis/project.openshift.io/v1/projects', ], + 'delete' => [ + 'action' => 'DELETE', + 'uri' => '/apis/project.openshift.io/v1/projects/{name}', + ], ], 'projectrequest' => [ 'create' => [ @@ -657,6 +661,16 @@ public function createProject(string $name) { return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); } + /** + * Delete a project. + * + * @param string $name + * The project name to be deleted. + */ + public function deleteProject(string $name) { + return $this->apiCall(__METHOD__, $name); + } + /** * Create a new project request. * From 11c099fcaf9bb921fc117bd7996e66e6f546d289 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Fri, 3 Jun 2022 15:42:29 +0930 Subject: [PATCH 18/31] Fix api layout issue. --- src/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2bc97f8..2e8d999 100644 --- a/src/Client.php +++ b/src/Client.php @@ -721,9 +721,9 @@ public function createRoleBinding(string $subjectUserName, string $roleBinding, // This is a bit icky.. if ($subjectProject) { - $subject[0]['kind'] = 'ServiceAccount'; - $subject[0]['namespace'] = $subjectProject; - unset($subject[0]['apiGroup']); + $request['subjects'][0]['kind'] = 'ServiceAccount'; + $request['subjects'][0]['namespace'] = $subjectProject; + unset($request['subjects'][0]['apiGroup']); } return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $request); From 13dba21719b1bc809552b2865eb49cb2d0265a13 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 14 Jun 2022 11:36:19 +0930 Subject: [PATCH 19/31] SAPP 2796 set pvc size (#58) * Add support for updating storage size. * Add missing token var, comments. --- src/Client.php | 51 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2e8d999..766a952 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,7 +6,6 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\HandlerStack; -use GuzzleHttp\Middleware; use Psr\Http\Message\RequestInterface; use UniversityOfAdelaide\OpenShift\Objects\Backups\Backup; use UniversityOfAdelaide\OpenShift\Objects\Backups\BackupList; @@ -38,7 +37,14 @@ class Client implements ClientInterface { * * @var string */ - private $namespace; + private string $namespace; + + /** + * Current working token. + * + * @var string + */ + private string $token; /** * Guzzle HTTP Client. @@ -326,15 +332,15 @@ class Client implements ClientInterface { 'rolebinding' => [ 'get' => [ 'action' => 'GET', - 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}' + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}', ], 'list' => [ 'action' => 'GET', - 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings' + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings', ], 'create' => [ 'action' => 'POST', - 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings' + 'uri' => '/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings', ], ], 'route' => [ @@ -475,11 +481,23 @@ public function __construct($host, $verifyTls = TRUE) { $this->serializer = OpenShiftSerializerFactory::create(); } - public function setNamespace($namespace) { + /** + * Set the namespace for future calls. + * + * @param string $namespace + * The namespace string. + */ + public function setNamespace(string $namespace) { $this->namespace = $namespace; } - public function setToken($token) { + /** + * Set the Token for future calls. + * + * @param string $token + * The token string. + */ + public function setToken(string $token) { $this->token = $token; } @@ -493,6 +511,12 @@ public function getGuzzleClient() { return $this->guzzleClient; } + /** + * Helper function called to handle token switching. + * + * @return \Closure + * Returns the closure that does the work. + */ public function handleAuth() { return function (callable $handler) { return function (RequestInterface $request, array $options) use ($handler) { @@ -559,7 +583,7 @@ public function request(string $method, string $uri, $body = NULL, array $query $response = $this->guzzleClient->request($method, $uri, $requestOptions); } catch (RequestException $e) { - // If the exception is a 'not found' response to a GET or DELETE, just return false. + // Early return for simple failures. if (($method === 'GET' || $method === 'DELETE') && $e->getCode() === 404) { return FALSE; } @@ -1170,7 +1194,16 @@ public function createPersistentVolumeClaim(string $name, string $access_mode, s * {@inheritdoc} */ public function updatePersistentVolumeClaim(string $name, string $access_mode, string $storage) { - // @todo Implement updatePersistentVolumeClaim() method. + $resourceMethod = $this->getResourceMethod(__METHOD__); + $uri = $this->createRequestUri($resourceMethod['uri'], ['name' => $name]); + + // Retrieve the existing settings. + $pvc = $this->getPersistentVolumeClaim($name); + + // We only support changing the size. + $pvc['spec']['resources']['requests']['storage'] = $storage; + + return $this->request($resourceMethod['action'], $uri, $pvc); } /** From 19b3a0f795bacd9773a8ed589ef88fdd300561b7 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 14 Jun 2022 11:36:37 +0930 Subject: [PATCH 20/31] Add labels functionality to route object. (#57) * Add labels functionality to route object. * Remove unneeded label code, add missing annotation class, update test. * Wrong one. * Dangling comma. * Remove duplicated annotations and put all in the ObjectBase. --- src/Objects/Annotation.php | 99 +++++++++++++++++++ src/Objects/Backups/Backup.php | 60 ----------- src/Objects/ObjectBase.php | 56 +++++++++++ src/Objects/Route.php | 46 --------- tests/src/Unit/BackupTest.php | 3 +- .../Unit/Serializer/BackupSerializerTest.php | 3 +- .../Unit/Serializer/RouteSerializerTest.php | 4 + tests/src/fixtures/route.json | 8 +- 8 files changed, 170 insertions(+), 109 deletions(-) create mode 100644 src/Objects/Annotation.php diff --git a/src/Objects/Annotation.php b/src/Objects/Annotation.php new file mode 100644 index 0000000..1599941 --- /dev/null +++ b/src/Objects/Annotation.php @@ -0,0 +1,99 @@ +setKey($key)->setValue($value); + return $instance; + } + + /** + * Gets the value of key. + * + * @return string + * Value of key. + */ + public function getKey(): string { + return $this->key; + } + + /** + * Sets the value of key. + * + * @param string $key + * The value for key. + * + * @return Annotation + * The calling class. + */ + public function setKey(string $key): Annotation { + $this->key = $key; + return $this; + } + + /** + * Gets the value of value. + * + * @return string + * Value of value. + */ + public function getValue(): string { + return $this->value; + } + + /** + * Sets the value of value. + * + * @param string $value + * The value for value. + * + * @return Annotation + * The calling class. + */ + public function setValue(string $value): Annotation { + $this->value = $value; + return $this; + } + + /** + * Turn the annotation into a string. + * + * @return string + * The string representation of the annotation. + */ + public function __toString() { + return sprintf('%s=%s', $this->getKey(), $this->getValue()); + } + +} diff --git a/src/Objects/Backups/Backup.php b/src/Objects/Backups/Backup.php index cc87b77..dd5958e 100644 --- a/src/Objects/Backups/Backup.php +++ b/src/Objects/Backups/Backup.php @@ -17,13 +17,6 @@ class Backup extends BackupObjectBase { */ const SYNC_LABEL = 'is-sync'; - /** - * An array of annotations to apply to this backup. - * - * @var array - */ - protected $annotations = []; - /** * The restic ID. * @@ -31,29 +24,6 @@ class Backup extends BackupObjectBase { */ protected $resticId; - /** - * Get a single annotation. - * - * @param string $key - * The key for the annotation. - * - * @return string|bool - * The annotation value or FALSE. - */ - public function getAnnotation(string $key): string { - return isset($this->getAnnotations()[$key]) ? $this->getAnnotations()[$key] : FALSE; - } - - /** - * Gets the value of annotations. - * - * @return array - * Value of annotations. - */ - public function getAnnotations(): array { - return $this->annotations; - } - /** * Check if this backup has any annotations. * @@ -64,36 +34,6 @@ public function hasAnnotations(): bool { return !empty($this->getAnnotations()); } - /** - * Set a single annotation. - * - * @param string $key - * The key for the annotation. - * @param string $value - * The value for the annotation. - * - * @return Backup - * The calling class. - */ - public function setAnnotation(string $key, string $value): Backup { - $this->annotations[$key] = $value; - return $this; - } - - /** - * Sets the value of annotations. - * - * @param array $annotations - * The value for annotations. - * - * @return Backup - * The calling class. - */ - public function setAnnotations(array $annotations): Backup { - $this->annotations = $annotations; - return $this; - } - /** * Gets the value of ResticId. * diff --git a/src/Objects/ObjectBase.php b/src/Objects/ObjectBase.php index 2cf3ed6..a24fc03 100644 --- a/src/Objects/ObjectBase.php +++ b/src/Objects/ObjectBase.php @@ -21,6 +21,13 @@ abstract class ObjectBase { */ protected $labels = []; + /** + * An arroy of annotations. + * + * @var array + */ + protected $annotations = []; + /** * The time the object was created. * @@ -113,6 +120,55 @@ public function getLabel(string $key): string { return isset($this->getLabels()[$key]) ? $this->getLabels()[$key] : FALSE; } + /** + * Gets the value of Annotations. + * + * @return array + */ + public function getAnnotations(): array { + return $this->annotations; + } + + /** + * Sets the value of Annotations. + * + * @param array $annotations + * + * @return $this + * The calling class. + */ + public function setAnnotations(array $annotations) { + $this->annotations = $annotations; + return $this; + } + + /** + * Sets a single Annotation. + * + * @param \UniversityOfAdelaide\OpenShift\Objects\Annotation $annotation + * The Annotation object. + * + * @return $this + * The calling class. + */ + public function setAnnotation(Annotation $annotation) { + $this->annotations[$annotation->getKey()] = $annotation->getValue(); + return $this; + } + + /** + * Get a single annotation. + * + * @param string $key + * The key for the annotation. + * + * @return string|bool + * The annotation value or FALSE. + */ + public function getAnnotation(string $key): string { + return isset($this->getAnnotations()[$key]) ? $this->getAnnotations()[$key] : FALSE; + } + /** * Gets the value of creationTimestamp. * diff --git a/src/Objects/Route.php b/src/Objects/Route.php index 1662ea1..550afc8 100644 --- a/src/Objects/Route.php +++ b/src/Objects/Route.php @@ -7,16 +7,6 @@ */ class Route extends ObjectBase { - /** - * Annotations - * - * E.g. - * ['some-name' => 'some-value'] - * - * @var array - */ - protected $annotations = []; - /** * Host. * @@ -77,42 +67,6 @@ class Route extends ObjectBase { */ protected $wildcardPolicy; - /** - * Gets the value of Annotations. - * - * @return array - */ - public function getAnnotations(): array { - return $this->annotations; - } - - /** - * Sets the value of Annotations. - * - * @param array $annotations - * - * @return Route - * The calling class. - */ - public function setAnnotations(array $annotations): Route { - $this->annotations = $annotations; - return $this; - } - - /** - * Sets a single Annotation. - * - * @param \UniversityOfAdelaide\OpenShift\Objects\Annotation $annotation - * The Annotation object. - * - * @return Route - * The calling class. - */ - public function setAnnotation(Annotation $annotation): Route { - $this->annotations[$annotation->getKey()] = $annotation->getValue(); - return $this; - } - /** * Gets the value of Host. * diff --git a/tests/src/Unit/BackupTest.php b/tests/src/Unit/BackupTest.php index 85796e1..ec4baed 100644 --- a/tests/src/Unit/BackupTest.php +++ b/tests/src/Unit/BackupTest.php @@ -3,6 +3,7 @@ namespace UniversityOfAdelaide\OpenShift\Tests\Unit; use PHPUnit\Framework\TestCase; +use UniversityOfAdelaide\OpenShift\Objects\Annotation; use UniversityOfAdelaide\OpenShift\Objects\Backups\Backup; use UniversityOfAdelaide\OpenShift\Objects\Backups\Phase; use UniversityOfAdelaide\OpenShift\Objects\Label; @@ -36,7 +37,7 @@ public function testGetFriendlyName() { $backup = new Backup(); $backup->setName('foo'); $this->assertEquals('foo', $backup->getFriendlyName()); - $backup->setAnnotation(Backup::FRIENDLY_NAME_ANNOTATION, 'bar'); + $backup->setAnnotation(Annotation::create(Backup::FRIENDLY_NAME_ANNOTATION, 'bar')); $this->assertEquals('bar', $backup->getFriendlyName()); } diff --git a/tests/src/Unit/Serializer/BackupSerializerTest.php b/tests/src/Unit/Serializer/BackupSerializerTest.php index fe91bbf..f0cfc2b 100644 --- a/tests/src/Unit/Serializer/BackupSerializerTest.php +++ b/tests/src/Unit/Serializer/BackupSerializerTest.php @@ -3,6 +3,7 @@ namespace UniversityOfAdelaide\OpenShift\Tests\Unit\Serializer; use PHPUnit\Framework\TestCase; +use UniversityOfAdelaide\OpenShift\Objects\Annotation; use UniversityOfAdelaide\OpenShift\Objects\Backups\Backup; use UniversityOfAdelaide\OpenShift\Objects\Backups\Database; use UniversityOfAdelaide\OpenShift\Objects\Backups\Phase; @@ -73,7 +74,7 @@ public function testNormalizer() { /** @var \UniversityOfAdelaide\OpenShift\Objects\Backups\Backup $backup */ $backup = Backup::create() ->setName('test-123-backup') - ->setAnnotation('some.annotation', 'test 123') + ->setAnnotation(Annotation::create('some.annotation', 'test 123')) ->setVolumes([ 'shared' => 'node-123-shared', ]) diff --git a/tests/src/Unit/Serializer/RouteSerializerTest.php b/tests/src/Unit/Serializer/RouteSerializerTest.php index 09833a6..ed4367b 100644 --- a/tests/src/Unit/Serializer/RouteSerializerTest.php +++ b/tests/src/Unit/Serializer/RouteSerializerTest.php @@ -3,6 +3,8 @@ namespace UniversityOfAdelaide\OpenShift\Tests\Unit\Serializer; use PHPUnit\Framework\TestCase; +use UniversityOfAdelaide\OpenShift\Objects\Annotation; +use UniversityOfAdelaide\OpenShift\Objects\Label; use UniversityOfAdelaide\OpenShift\Objects\Route; use UniversityOfAdelaide\OpenShift\Serializer\OpenShiftSerializerFactory; @@ -40,6 +42,8 @@ public function testNormalizer() { ->setToKind('Service') ->setToName('svc-test') ->setToWeight(50) + ->setLabel(Label::create('testing-label', 'label-testing')) + ->setAnnotation(Annotation::create('testing-annotation', 'annotation-testing')) ->setWildcardPolicy('None'); $expected = json_decode(file_get_contents(__DIR__ . '/../../fixtures/route.json'), TRUE); diff --git a/tests/src/fixtures/route.json b/tests/src/fixtures/route.json index b4b0cc0..4f7b260 100644 --- a/tests/src/fixtures/route.json +++ b/tests/src/fixtures/route.json @@ -2,7 +2,13 @@ "apiVersion": "route.openshift.io/v1", "kind": "Route", "metadata": { - "name": "route-test" + "name": "route-test", + "labels": { + "testing-label": "label-testing" + }, + "annotations": { + "testing-annotation": "annotation-testing" + } }, "spec": { "host": "route.host", From 9ad47fb82ff5a551f434e825d351555843ce74f0 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 5 Jul 2022 13:09:14 +0930 Subject: [PATCH 21/31] Fix spacing issues. --- src/Client.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 766a952..c5e6982 100644 --- a/src/Client.php +++ b/src/Client.php @@ -737,17 +737,18 @@ public function createRoleBinding(string $subjectUserName, string $roleBinding, ], ], 'roleRef' => [ - 'apiGroup'=> 'rbac.authorization.k8s.io', - 'kind'=> 'ClusterRole', - 'name'=> $roleBinding, + 'apiGroup' => 'rbac.authorization.k8s.io', + 'kind' => 'ClusterRole', + 'name' => $roleBinding, ], ]; - // This is a bit icky.. + // This is a bit icky. if ($subjectProject) { $request['subjects'][0]['kind'] = 'ServiceAccount'; $request['subjects'][0]['namespace'] = $subjectProject; unset($request['subjects'][0]['apiGroup']); + unset($request['metadata']['namespace']); } return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $request); From 8db244ddccf7457f0c4e0c199f37205c4eaf3103 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Tue, 9 Aug 2022 11:30:47 +0930 Subject: [PATCH 22/31] Allow choosing the namespace to pull the imagestream from. --- src/Client.php | 4 ++-- src/ClientInterface.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index c5e6982..fcf1bb7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1232,7 +1232,7 @@ public function getDeploymentConfigs(string $label = NULL) { /** * {@inheritdoc} */ - public function generateDeploymentConfig(string $name, string $image_stream_tag, string $image_name, bool $update_on_image_change = FALSE, array $volumes = [], array $data = [], array $probes = []) { + public function generateDeploymentConfig(string $name, string $image_stream_tag, string $image_name, string $image_stream_namespace, bool $update_on_image_change = FALSE, array $volumes = [], array $data = [], array $probes = []) { $volume_config = $this->setVolumes($volumes); $deploymentConfig = [ @@ -1308,7 +1308,7 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, 'from' => [ 'kind' => 'ImageStreamTag', 'name' => $image_stream_tag, - 'namespace' => 'shepherd', + 'namespace' => $image_stream_namespace, ], ], 'type' => 'ImageChange', diff --git a/src/ClientInterface.php b/src/ClientInterface.php index d81fdbc..e0eea92 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -597,6 +597,8 @@ public function getDeploymentConfig(string $label); * Image stream to manage the deployment. * @param string $image_name * Image name for deployment. + * @param string $image_stream_namespace + * The namespace to pull the image stream from. * @param bool $update_on_image_change * Automatically re-deploy pods on image change or not. * @param array $volumes @@ -609,7 +611,7 @@ public function getDeploymentConfig(string $label); * @return array * Returns the body response if successful. */ - public function generateDeploymentConfig(string $name, string $image_stream_tag, string $image_name, bool $update_on_image_change, array $volumes, array $data, array $probes); + public function generateDeploymentConfig(string $name, string $image_stream_tag, string $image_name, string $image_stream_namespace, bool $update_on_image_change, array $volumes, array $data, array $probes); /** * Updates and existing deployment config. From 2d22c5a6fb22d224d5c810b6ebc30dbe5fd28a2b Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Thu, 11 Aug 2022 12:38:55 +0930 Subject: [PATCH 23/31] Altering some build options needed for OpenShift 4.x. --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index fcf1bb7..0110a1a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1002,7 +1002,7 @@ public function generateBuildConfig(string $name, string $secret, string $image_ ], 'secrets' => [ [ - 'destinationDir' => '.', + 'destinationDir' => '/code', 'secret' => [ 'name' => $secret, ], @@ -1016,7 +1016,7 @@ public function generateBuildConfig(string $name, string $secret, string $image_ 'sourceStrategy' => [ 'env' => $data['env_vars'] ?? [], 'forcePull' => TRUE, - 'incremental' => TRUE, + 'incremental' => FALSE, 'from' => [ 'kind' => (string) $data['source']['type'], 'name' => (string) $data['source']['name'], From 8aeb92a30af0eb057d16c2d163c7ae80e1f8d8ee Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Thu, 18 Aug 2022 15:28:39 +0930 Subject: [PATCH 24/31] Provide more information on failures. --- src/Client.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 0110a1a..416405d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -603,7 +603,8 @@ public function request(string $method, string $uri, $body = NULL, array $query if (!in_array($response->getStatusCode(), [200, 201, 404])) { $decoded_response = json_decode($response->getBody(), TRUE); throw new ClientException( - $decoded_response['message'], + $decoded_response['message'] . "\n" . + json_encode($requestOptions), $decoded_response['code'], ); } @@ -717,7 +718,7 @@ public function createProjectRequest(string $name) { } /** - * Give access to other users + * Give access to other users. */ public function createRoleBinding(string $subjectUserName, string $roleBinding, string $roleBindingName, string $subjectProject = NULL) { $resourceMethod = $this->getResourceMethod(__METHOD__); From a524a31acfccd839437f9e33ba9f5feaf4da0449 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Fri, 19 Aug 2022 14:52:52 +0930 Subject: [PATCH 25/31] Make defaults saner, handle passed in values correctly. --- src/Client.php | 18 ++++++++++++++---- tests/src/Disabled/ClientTest.php | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 416405d..38ada9a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -981,12 +981,12 @@ public function generateBuildConfig(string $name, string $secret, string $image_ 'spec' => [ 'resources' => [ 'limits' => [ - 'cpu' => $data['cpu_limit'] ?? '0m', - 'memory' => $data['memory_limit'] ?? '1Gi', + 'cpu' => $data['cpu_limit'] ?? '256m', + 'memory' => $data['memory_limit'] ?? '256Mi', ], 'requests' => [ - 'cpu' => $data['cpu_request'] ?? '0m', - 'memory' => $data['memory_request'] ?? '0Mi', + 'cpu' => $data['cpu_request'] ?? '128m', + 'memory' => $data['memory_request'] ?? '128Mi', ], ], 'output' => [ @@ -1255,6 +1255,16 @@ public function generateDeploymentConfig(string $name, string $image_stream_tag, 'timeoutSeconds' => 600, 'updatePeriodSeconds' => 1, ], + 'resources' => [ + 'limits' => [ + 'cpu' => $data['cpu_limit'] ?? '256m', + 'memory' => $data['memory_limit'] ?? '256Mi', + ], + 'requests' => [ + 'cpu' => $data['cpu_request'] ?? '128m', + 'memory' => $data['memory_request'] ?? '128Mi', + ], + ], 'type' => 'Rolling', ], 'template' => [ diff --git a/tests/src/Disabled/ClientTest.php b/tests/src/Disabled/ClientTest.php index ee27df0..a71786d 100644 --- a/tests/src/Disabled/ClientTest.php +++ b/tests/src/Disabled/ClientTest.php @@ -183,6 +183,10 @@ public function testCreatePersistentVolumeClaim2() { */ public function testCreateBuildConfig() { $data = [ + 'cpu_limit' => '512m', + 'cpu_request' => '256m', + 'memory_limit' => '512Mi', + 'memory_request' => '256Mi', 'git' => [ 'uri' => $this->json->clientTest->source->git->uri, 'ref' => $this->json->clientTest->source->git->ref, From 7db467872bde484e19877b02b837771c9672f13f Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 29 Aug 2022 09:01:18 +0930 Subject: [PATCH 26/31] Networkpolicies changed the api endpoint. --- src/Client.php | 6 +++--- src/Serializer/NetworkPolicyNormalizer.php | 2 +- tests/src/fixtures/networkpolicy.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 38ada9a..549c1e6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -232,15 +232,15 @@ class Client implements ClientInterface { 'networkpolicy' => [ 'get' => [ 'action' => 'GET', - 'uri' => '/apis/extensions/v1beta1/namespaces/{namespace}/networkpolicies/{name}', + 'uri' => '/apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}', ], 'create' => [ 'action' => 'POST', - 'uri' => '/apis/extensions/v1beta1/namespaces/{namespace}/networkpolicies', + 'uri' => '/apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/apis/extensions/v1beta1/namespaces/{namespace}/networkpolicies/{name}', + 'uri' => '/apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}', ], ], 'persistentvolumeclaim' => [ diff --git a/src/Serializer/NetworkPolicyNormalizer.php b/src/Serializer/NetworkPolicyNormalizer.php index 981f621..9bf494f 100644 --- a/src/Serializer/NetworkPolicyNormalizer.php +++ b/src/Serializer/NetworkPolicyNormalizer.php @@ -30,7 +30,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) public function normalize($object, $format = NULL, array $context = []) { /** @var \UniversityOfAdelaide\OpenShift\Objects\NetworkPolicy $object */ $data = [ - 'apiVersion' => 'extensions/v1beta1', + 'apiVersion' => 'networking.k8s.io/v1', 'kind' => 'NetworkPolicy', 'metadata' => [ 'name' => $object->getName(), diff --git a/tests/src/fixtures/networkpolicy.json b/tests/src/fixtures/networkpolicy.json index 1880704..f69cef1 100644 --- a/tests/src/fixtures/networkpolicy.json +++ b/tests/src/fixtures/networkpolicy.json @@ -1,5 +1,5 @@ { - "apiVersion": "extensions/v1beta1", + "apiVersion": "networking.k8s.io/v1", "kind": "NetworkPolicy", "metadata": { "name": "test-np" From 738fd13cc563d4ef38c79a6b5b17282b2c74c5f3 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 5 Sep 2022 09:58:22 +0930 Subject: [PATCH 27/31] Support more matching on labels. --- src/Objects/NetworkPolicy.php | 53 +++++++++++++++---- src/Serializer/NetworkPolicyNormalizer.php | 5 +- .../NetworkPolicySerializerTest.php | 3 +- tests/src/fixtures/networkpolicy.json | 5 ++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/Objects/NetworkPolicy.php b/src/Objects/NetworkPolicy.php index 662491e..ee3b7a1 100644 --- a/src/Objects/NetworkPolicy.php +++ b/src/Objects/NetworkPolicy.php @@ -12,43 +12,74 @@ class NetworkPolicy extends ObjectBase { * * @var array */ - protected $ingressMatchLabels = []; + protected array $ingressPodMatchLabels = []; /** * The config map data. * * @var array */ - protected $podSelectorMatchLabels = []; + protected array $ingressNamespaceMatchLabels = []; + + /** + * The config map data. + * + * @var array + */ + protected array $podSelectorMatchLabels = []; /** * The port to allow. * * @var int */ - protected $port; + protected int $port; + + /** + * Gets the value of IngressPodMatchLabels. + * + * @return array + * Value of IngressPodMatchLabels. + */ + public function getIngressPodMatchLabels(): array { + return $this->ingressPodMatchLabels; + } + + /** + * Sets the value of IngressPodMatchLabels. + * + * @param array $ingressPodMatchLabels + * The value for IngressPodMatchLabels. + * + * @return NetworkPolicy + * The calling class. + */ + public function setIngressPodMatchLabels(array $ingressPodMatchLabels): NetworkPolicy { + $this->ingressPodMatchLabels = $ingressPodMatchLabels; + return $this; + } /** - * Gets the value of IngressMatchLabels. + * Gets the value of IngressNamespaceMatchLabels. * * @return array - * Value of IngressMatchLabels. + * Value of IngressNamespaceMatchLabels. */ - public function getIngressMatchLabels(): array { - return $this->ingressMatchLabels; + public function getIngressNamespaceMatchLabels(): array { + return $this->ingressNamespaceMatchLabels; } /** * Sets the value of IngressMatchLabels. * - * @param array $ingressMatchLabels - * The value for IngressMatchLabels. + * @param array $ingressNamespaceMatchLabels + * The value for IngressNamespaceMatchLabels. * * @return NetworkPolicy * The calling class. */ - public function setIngressMatchLabels(array $ingressMatchLabels): NetworkPolicy { - $this->ingressMatchLabels = $ingressMatchLabels; + public function setIngressNamespaceMatchLabels(array $ingressNamespaceMatchLabels): NetworkPolicy { + $this->ingressNamespaceMatchLabels = $ingressNamespaceMatchLabels; return $this; } diff --git a/src/Serializer/NetworkPolicyNormalizer.php b/src/Serializer/NetworkPolicyNormalizer.php index 9bf494f..522d0f3 100644 --- a/src/Serializer/NetworkPolicyNormalizer.php +++ b/src/Serializer/NetworkPolicyNormalizer.php @@ -41,7 +41,10 @@ public function normalize($object, $format = NULL, array $context = []) { 'from' => [ [ 'podSelector' => [ - 'matchLabels' => $object->getIngressMatchLabels(), + 'matchLabels' => $object->getIngressPodMatchLabels(), + ], + 'namespaceSelector' => [ + 'matchLabels' => $object->getIngressNamespaceMatchLabels(), ], ], ], diff --git a/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php b/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php index b826d66..74972f6 100644 --- a/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php +++ b/tests/src/Unit/Serializer/NetworkPolicySerializerTest.php @@ -32,7 +32,8 @@ protected function setUp(): void { public function testNormalizer() { /** @var \UniversityOfAdelaide\OpenShift\Objects\NetworkPolicy $np */ $np = NetworkPolicy::create() - ->setIngressMatchLabels(['app' => 'node-19']) + ->setIngressPodMatchLabels(['app' => 'node-19']) + ->setIngressNamespaceMatchLabels(['project' => 'project1']) ->setPodSelectorMatchLabels(['application' => 'datagrid-app']) ->setPort(11312) ->setName('test-np'); diff --git a/tests/src/fixtures/networkpolicy.json b/tests/src/fixtures/networkpolicy.json index f69cef1..78025ff 100644 --- a/tests/src/fixtures/networkpolicy.json +++ b/tests/src/fixtures/networkpolicy.json @@ -13,6 +13,11 @@ "matchLabels": { "app": "node-19" } + }, + "namespaceSelector": { + "matchLabels": { + "project": "project1" + } } } ], From 95487629116ae0f77f163fd8707dbb3f26acbd34 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 5 Sep 2022 10:21:05 +0930 Subject: [PATCH 28/31] Add ability to add labels to a namespace. --- src/Client.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Client.php b/src/Client.php index 549c1e6..953115f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -229,6 +229,16 @@ class Client implements ClientInterface { 'uri' => '/apis/batch/v1/namespaces/{namespace}/jobs/{name}', ], ], + 'namespace' => [ + 'get' => [ + 'action' => 'GET', + 'uri' => '/api/v1/namespaces/{namespace}', + ], + 'update' => [ + 'action' => 'PUT', + 'uri' => '/api/v1/namespaces/{namespace}', + ], + ], 'networkpolicy' => [ 'get' => [ 'action' => 'GET', @@ -717,6 +727,36 @@ public function createProjectRequest(string $name) { return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $project); } + /** + * Retrieve a namespace by name. + * + * @param string $name + * The project name to be retrieved. + */ + public function getNamespace(string $name) { + return $this->apiCall(__METHOD__, $name); + } + + /** + * Update namespace with a label. + * + * @param string $name + * The project name to be retrieved. + * @param array $labels + * The array of labels to be applied. + */ + public function updateNamespace(string $name, array $labels) { + if ($namespace = $this->getNamespace($name)) { + $namespace['metadata']['labels'] = array_merge( + $namespace['metadata']['labels'], + $labels + ); + + $resourceMethod = $this->getResourceMethod(__METHOD__); + return $this->request($resourceMethod['action'], $this->createRequestUri($resourceMethod['uri']), $namespace); + } + } + /** * Give access to other users. */ From 7f2ca941671e7a0eb06506ed1577bdb9b9fa8856 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 12 Sep 2022 10:38:41 +0930 Subject: [PATCH 29/31] Switch to nwe status fields. --- src/Serializer/SyncNormalizer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Serializer/SyncNormalizer.php b/src/Serializer/SyncNormalizer.php index 663eefe..adb8034 100644 --- a/src/Serializer/SyncNormalizer.php +++ b/src/Serializer/SyncNormalizer.php @@ -32,10 +32,10 @@ public function denormalize($data, $class, $format = NULL, array $context = []) ->setSite($data['spec']['site']) ->setBackupEnv($data['spec']['backupEnv']) ->setRestoreEnv($data['spec']['restoreEnv']) - ->setBackupPhase($data['status']['backupPhase'] ?? '') - ->setRestorePhase($data['status']['restorePhase'] ?? '') - ->setStartTimeStamp($data['status']['startTime'] ?? '') - ->setCompletionTimeStamp($data['status']['completionTime'] ?? ''); + ->setBackupPhase($data['status']['backup']['Phase'] ?? '') + ->setRestorePhase($data['status']['restore']['Phase'] ?? '') + ->setStartTimeStamp($data['status']['backup']['startTime'] ?? '') + ->setCompletionTimeStamp($data['status']['restore']['completionTime'] ?? ''); $backupDbs = []; foreach ($data['spec']['backupSpec']['mysql'] as $id => $dbSpec) { From 658e9b5f2b454608e1348985681a55ed268027e4 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Mon, 12 Sep 2022 10:52:05 +0930 Subject: [PATCH 30/31] Phase needs to be lowercase. --- src/Serializer/SyncNormalizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serializer/SyncNormalizer.php b/src/Serializer/SyncNormalizer.php index adb8034..9954923 100644 --- a/src/Serializer/SyncNormalizer.php +++ b/src/Serializer/SyncNormalizer.php @@ -32,8 +32,8 @@ public function denormalize($data, $class, $format = NULL, array $context = []) ->setSite($data['spec']['site']) ->setBackupEnv($data['spec']['backupEnv']) ->setRestoreEnv($data['spec']['restoreEnv']) - ->setBackupPhase($data['status']['backup']['Phase'] ?? '') - ->setRestorePhase($data['status']['restore']['Phase'] ?? '') + ->setBackupPhase($data['status']['backup']['phase'] ?? '') + ->setRestorePhase($data['status']['restore']['phase'] ?? '') ->setStartTimeStamp($data['status']['backup']['startTime'] ?? '') ->setCompletionTimeStamp($data['status']['restore']['completionTime'] ?? ''); From 997b0478d65a0454caa48689cf2713fd9fb20de5 Mon Sep 17 00:00:00 2001 From: Michael Priest Date: Fri, 20 Jan 2023 17:23:26 +1030 Subject: [PATCH 31/31] Move to stable cronjob batch api. --- src/Client.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 953115f..20985f9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -126,19 +126,19 @@ class Client implements ClientInterface { 'cronjob' => [ 'create' => [ 'action' => 'POST', - 'uri' => '/apis/batch/v1beta1/namespaces/{namespace}/cronjobs', + 'uri' => '/apis/batch/v1/namespaces/{namespace}/cronjobs', ], 'delete' => [ 'action' => 'DELETE', - 'uri' => '/apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}', + 'uri' => '/apis/batch/v1/namespaces/{namespace}/cronjobs/{name}', ], 'get' => [ 'action' => 'GET', - 'uri' => '/apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}', + 'uri' => '/apis/batch/v1/namespaces/{namespace}/cronjobs/{name}', ], 'update' => [ 'action' => 'PUT', - 'uri' => '/apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}', + 'uri' => '/apis/batch/v1/namespaces/{namespace}/cronjobs/{name}', ], ], 'deploymentconfig' => [ @@ -1556,7 +1556,7 @@ public function createCronJob(string $name, string $image_name, string $schedule $job_template = $this->jobTemplate($name, $image_name, $args, $volume_config, $data); $cronConfig = [ - 'apiVersion' => 'batch/v1beta1', + 'apiVersion' => 'batch/v1', 'kind' => 'CronJob', 'metadata' => [ 'name' => $name,