From a24c29cf2e992c498db6f2b372992afbd120cc0f Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Tue, 21 Feb 2023 04:51:08 -0500 Subject: [PATCH 01/23] Bumping versions of minikube, k8s, laravel and php to current versions. * Setting Kubernetes versions to current * Adding Laravel 10 * Update location of sealed secrets CRD * Add PHP 8.2 * Ensuring we match the supported PHP versions for the versions of Laravel. See also: https://laravel.com/docs/10.x/releases#support-policy --- .github/workflows/ci.yml | 21 +++++++++++++++------ README.md | 6 +++--- composer.json | 10 +++++----- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68b272f3..4703f214 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,18 +22,27 @@ jobs: php: - '8.0' - '8.1' + - '8.2' kubernetes: - - '1.22.9' - - '1.23.6' - - '1.24.0' + - '1.23.16' + - '1.24.10' + - '1.25.6' laravel: - 9.* + - 10.* prefer: - 'prefer-lowest' - 'prefer-stable' include: + - laravel: 10.* + testbench: 8.* - laravel: 9.* testbench: 7.* + exclude: + - laravel: 10.* + php: '8.0' + - laravel: 9.* + php: '8.2' name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - K8s v${{ matrix.kubernetes }} --${{ matrix.prefer }} @@ -53,10 +62,10 @@ jobs: path: ~/.composer/cache/files key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }} - - uses: manusa/actions-setup-minikube@v2.6.1 + - uses: manusa/actions-setup-minikube@v2.7.2 name: Setup Minikube with: - minikube version: v1.25.2 + minikube version: v1.29.0 kubernetes version: "v${{ matrix.kubernetes }}" github token: "${{ secrets.GITHUB_TOKEN }}" @@ -79,7 +88,7 @@ jobs: - name: Setting CRDs for testing run: | - kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/sealedsecret-crd.yaml + kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/bitnami.com_sealedsecrets.yaml # - name: Run static analysis # run: | diff --git a/README.md b/README.md index 5017cd0c..f3bc5535 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ PHP K8s [![Total Downloads](https://poser.pugx.org/renoki-co/php-k8s/downloads)](https://packagist.org/packages/renoki-co/php-k8s) [![Monthly Downloads](https://poser.pugx.org/renoki-co/php-k8s/d/monthly)](https://packagist.org/packages/renoki-co/php-k8s) -![v1.22.9 K8s Version](https://img.shields.io/badge/K8s%20v1.22.9-Ready-%23326ce5?colorA=306CE8&colorB=green) -![v1.23.6 K8s Version](https://img.shields.io/badge/K8s%20v1.23.6-Ready-%23326ce5?colorA=306CE8&colorB=green) -![v1.24.0 K8s Version](https://img.shields.io/badge/K8s%20v1.24.0-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.23.16 K8s Version](https://img.shields.io/badge/K8s%20v1.23.16-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.24.10 K8s Version](https://img.shields.io/badge/K8s%20v1.24.10-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.25.6 K8s Version](https://img.shields.io/badge/K8s%20v1.25.6-Ready-%23326ce5?colorA=306CE8&colorB=green) [![Client Capabilities](https://img.shields.io/badge/Kubernetes%20Client-Silver-blue.svg?colorB=C0C0C0&colorA=306CE8)](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/csi-new-client-library-procedure.md#client-capabilities) [![Client Support Level](https://img.shields.io/badge/Kubernetes%20Client-stable-green.svg?colorA=306CE8)](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/csi-new-client-library-procedure.md#client-support-level) diff --git a/composer.json b/composer.json index df2ad327..83121152 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ ], "require": { "guzzlehttp/guzzle": "^6.5|^7.0", - "illuminate/macroable": "^9.0.1", - "illuminate/support": "^9.0.1", + "illuminate/macroable": "^9.0.1|^10.0.0", + "illuminate/support": "^9.0.1|^10.0.0", "ratchet/pawl": "^0.4.1", "symfony/process": "^5.4|^6.0", "vierbergenlars/php-semver": "^2.1|^3.0" @@ -37,9 +37,9 @@ }, "require-dev": { "mockery/mockery": "^1.5", - "orchestra/testbench": "^6.28|^7.0", - "orchestra/testbench-core": "^6.28|^7.0", - "phpunit/phpunit": "^9.5.20", + "orchestra/testbench": "^7.0|^8.0", + "orchestra/testbench-core": "^7.0|^8.0", + "phpunit/phpunit": "^9.5.20|^10.0", "vimeo/psalm": "^4.20" }, "config": { From f990c08ffeb88ded31a4e3fd8c08ccaffe022e87 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Tue, 21 Feb 2023 06:09:13 -0500 Subject: [PATCH 02/23] Updating test to check for our annotation only The actual number of annotations added by the system could vary. This test actually dependent on whether a feature gate is enabled or not. Just test for the presence of our target annotations and ignore the rest. See also: https://kubernetes.io/blog/2022/12/29/scalable-job-tracking-ga/#how-do-i-use-this-feature --- tests/JobTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/JobTest.php b/tests/JobTest.php index 97cb2e54..5a960dc6 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -110,10 +110,10 @@ public function runCreationTests() $this->assertEquals('pi', $job->getName()); $this->assertEquals(['tier' => 'backend'], $job->getLabels()); - if ($this->cluster->olderThan('1.23.0') || $this->cluster->newerThan('1.24.0')) { - $this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations()); - } else { - $this->assertEquals(['perl/annotation' => 'yes', 'batch.kubernetes.io/job-tracking' => ''], $job->getAnnotations()); + $annotations = $job->getAnnotations(); + foreach(['perl/annotation' => 'yes'] as $key => $value) { + $this->assertContains($key, array_keys($annotations), "Annotation $key missing"); + $this->assertEquals($value, $annotations[$key]); } $this->assertEquals($pod->getName(), $job->getTemplate()->getName()); @@ -187,10 +187,10 @@ public function runGetTests() $this->assertEquals('pi', $job->getName()); $this->assertEquals(['tier' => 'backend'], $job->getLabels()); - if ($this->cluster->olderThan('1.23.0') || $this->cluster->newerThan('1.24.0')) { - $this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations()); - } else { - $this->assertEquals(['perl/annotation' => 'yes', 'batch.kubernetes.io/job-tracking' => ''], $job->getAnnotations()); + $annotations = $job->getAnnotations(); + foreach(['perl/annotation' => 'yes'] as $key => $value) { + $this->assertContains($key, array_keys($annotations), "Annotation $key missing"); + $this->assertEquals($value, $annotations[$key]); } $this->assertInstanceOf(K8sPod::class, $job->getTemplate()); From f64897ad28eba2abca2233d2715b06c416a6a731 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Tue, 21 Feb 2023 19:44:14 -0500 Subject: [PATCH 03/23] Update: v1beta1/v2beta2 -> v1/v2 --- src/Kinds/K8sCronJob.php | 16 +++++++++------- src/Kinds/K8sHorizontalPodAutoscaler.php | 6 +++--- src/Kinds/K8sPodDisruptionBudget.php | 2 +- src/Kinds/K8sStatefulSet.php | 4 ++-- tests/CronJobTest.php | 10 +++++----- tests/HorizontalPodAutoscalerTest.php | 10 +++++----- tests/PodDisruptionBudgetTest.php | 12 ++++++------ tests/yaml/cronjob.yaml | 8 +------- tests/yaml/daemonset.yaml | 8 +++++--- tests/yaml/deployment.yaml | 7 +++++-- tests/yaml/hpa.yaml | 2 +- tests/yaml/job.yaml | 2 -- tests/yaml/pdb.yaml | 4 ++-- tests/yaml/statefulset.yaml | 5 +++++ 14 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/Kinds/K8sCronJob.php b/src/Kinds/K8sCronJob.php index 708effdb..701aad4c 100644 --- a/src/Kinds/K8sCronJob.php +++ b/src/Kinds/K8sCronJob.php @@ -4,6 +4,8 @@ use Carbon\Carbon; use Cron\CronExpression; +use DateTime; +use Illuminate\Support\Collection; use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Traits\Resource\HasSpec; @@ -26,7 +28,7 @@ class K8sCronJob extends K8sResource implements InteractsWithK8sCluster, Watchab * * @var string */ - protected static $defaultVersion = 'batch/v1beta1'; + protected static $defaultVersion = 'batch/v1'; /** * Wether the resource has a namespace. @@ -38,7 +40,7 @@ class K8sCronJob extends K8sResource implements InteractsWithK8sCluster, Watchab /** * Set the job template. * - * @param array|\RenokiCo\PhpK8s\Kinds\K8sJob $job + * @param array|K8sJob $job * @return $this */ public function setJobTemplate($job) @@ -54,7 +56,7 @@ public function setJobTemplate($job) * Get the template job. * * @param bool $asInstance - * @return array|\RenokiCo\PhpK8s\Kinds\K8sJob + * @return array|K8sJob */ public function getJobTemplate(bool $asInstance = true) { @@ -70,7 +72,7 @@ public function getJobTemplate(bool $asInstance = true) /** * Set the schedule for the cronjob. * - * @param \Cron\CronExpression|string $schedule + * @param CronExpression|string $schedule * @return $this */ public function setSchedule($schedule) @@ -86,7 +88,7 @@ public function setSchedule($schedule) * Retrieve the schedule. * * @param bool $asInstance - * @return \Cron\CronExpression|string + * @return CronExpression|string */ public function getSchedule(bool $asInstance = true) { @@ -102,7 +104,7 @@ public function getSchedule(bool $asInstance = true) /** * Get the last time a job was scheduled. * - * @return \DateTime|null + * @return DateTime|null */ public function getLastSchedule() { @@ -116,7 +118,7 @@ public function getLastSchedule() /** * Get the active jobs created by the cronjob. * - * @return \Illuminate\Support\Collection + * @return Collection */ public function getActiveJobs() { diff --git a/src/Kinds/K8sHorizontalPodAutoscaler.php b/src/Kinds/K8sHorizontalPodAutoscaler.php index 77a3f04b..db3929f0 100644 --- a/src/Kinds/K8sHorizontalPodAutoscaler.php +++ b/src/Kinds/K8sHorizontalPodAutoscaler.php @@ -28,7 +28,7 @@ class K8sHorizontalPodAutoscaler extends K8sResource implements InteractsWithK8s * * @var string */ - protected static $defaultVersion = 'autoscaling/v2beta2'; + protected static $defaultVersion = 'autoscaling/v2'; /** * Wether the resource has a namespace. @@ -40,7 +40,7 @@ class K8sHorizontalPodAutoscaler extends K8sResource implements InteractsWithK8s /** * Set the reference to the scaling resource. * - * @param \RenokiCo\PhpK8s\Contracts\Scalable $resource + * @param Scalable $resource * @return $this */ public function setResource(Scalable $resource) @@ -55,7 +55,7 @@ public function setResource(Scalable $resource) /** * Add a new metric. * - * @param \RenokiCo\PhpK8s\Instances\ResourceMetric $metric + * @param ResourceMetric $metric * @return $this */ public function addMetric(ResourceMetric $metric) diff --git a/src/Kinds/K8sPodDisruptionBudget.php b/src/Kinds/K8sPodDisruptionBudget.php index e5ae1fa7..67aee7b2 100644 --- a/src/Kinds/K8sPodDisruptionBudget.php +++ b/src/Kinds/K8sPodDisruptionBudget.php @@ -33,7 +33,7 @@ class K8sPodDisruptionBudget extends K8sResource implements InteractsWithK8sClus * * @var string */ - protected static $defaultVersion = 'policy/v1beta1'; + protected static $defaultVersion = 'policy/v1'; /** * Set the maximum unavailable pod budget and diff --git a/src/Kinds/K8sStatefulSet.php b/src/Kinds/K8sStatefulSet.php index 5d68df4b..1faca4a9 100644 --- a/src/Kinds/K8sStatefulSet.php +++ b/src/Kinds/K8sStatefulSet.php @@ -72,7 +72,7 @@ public function setUpdateStrategy(string $strategy, int $partition = 0) /** * Set the statefulset service. * - * @param \RenokiCo\PhpK8s\Kinds\K8sService|string $service + * @param K8sService|string $service * @return $this */ public function setService($service) @@ -97,7 +97,7 @@ public function getService() /** * Get the K8sService instance. * - * @return null|\RenokiCo\PhpK8s\Kinds\K8sService + * @return null|K8sService */ public function getServiceInstance() { diff --git a/tests/CronJobTest.php b/tests/CronJobTest.php index 29417221..67c6117e 100644 --- a/tests/CronJobTest.php +++ b/tests/CronJobTest.php @@ -39,7 +39,7 @@ public function test_cronjob_build() ->setJobTemplate($job) ->setSchedule(CronExpression::factory('* * * * *')); - $this->assertEquals('batch/v1beta1', $cronjob->getApiVersion()); + $this->assertEquals('batch/v1', $cronjob->getApiVersion()); $this->assertEquals('pi', $cronjob->getName()); $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); @@ -64,7 +64,7 @@ public function test_cronjob_from_yaml() $cronjob = $this->cluster->fromYamlFile(__DIR__.'/yaml/cronjob.yaml'); - $this->assertEquals('batch/v1beta1', $cronjob->getApiVersion()); + $this->assertEquals('batch/v1', $cronjob->getApiVersion()); $this->assertEquals('pi', $cronjob->getName()); $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); @@ -122,7 +122,7 @@ public function runCreationTests() $this->assertInstanceOf(K8sCronJob::class, $cronjob); - $this->assertEquals('batch/v1beta1', $cronjob->getApiVersion()); + $this->assertEquals('batch/v1', $cronjob->getApiVersion()); $this->assertEquals('pi', $cronjob->getName()); $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); @@ -175,7 +175,7 @@ public function runGetTests() $this->assertTrue($cronjob->isSynced()); - $this->assertEquals('batch/v1beta1', $cronjob->getApiVersion()); + $this->assertEquals('batch/v1', $cronjob->getApiVersion()); $this->assertEquals('pi', $cronjob->getName()); $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); @@ -195,7 +195,7 @@ public function runUpdateTests() $this->assertTrue($cronjob->isSynced()); - $this->assertEquals('batch/v1beta1', $cronjob->getApiVersion()); + $this->assertEquals('batch/v1', $cronjob->getApiVersion()); $this->assertEquals('pi', $cronjob->getName()); $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); $this->assertEquals([], $cronjob->getAnnotations()); diff --git a/tests/HorizontalPodAutoscalerTest.php b/tests/HorizontalPodAutoscalerTest.php index bd762807..57bcfdab 100644 --- a/tests/HorizontalPodAutoscalerTest.php +++ b/tests/HorizontalPodAutoscalerTest.php @@ -42,7 +42,7 @@ public function test_horizontal_pod_autoscaler_build() ->min(1) ->max(10); - $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); + $this->assertEquals('autoscaling/v2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); @@ -74,7 +74,7 @@ public function test_horizontal_pod_autoscaler_from_yaml() $hpa = $this->cluster->fromYamlFile(__DIR__.'/yaml/hpa.yaml'); - $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); + $this->assertEquals('autoscaling/v2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); @@ -141,7 +141,7 @@ public function runCreationTests() $this->assertInstanceOf(K8sDeployment::class, $dep); $this->assertInstanceOf(K8sHorizontalPodAutoscaler::class, $hpa); - $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); + $this->assertEquals('autoscaling/v2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); @@ -203,7 +203,7 @@ public function runGetTests() $cpuMetric = K8s::metric()->cpu()->averageUtilization(70); - $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); + $this->assertEquals('autoscaling/v2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); @@ -231,7 +231,7 @@ public function runUpdateTests() $cpuMetric = K8s::metric()->cpu()->averageUtilization(70); - $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); + $this->assertEquals('autoscaling/v2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); diff --git a/tests/PodDisruptionBudgetTest.php b/tests/PodDisruptionBudgetTest.php index c597a571..0474dcd4 100644 --- a/tests/PodDisruptionBudgetTest.php +++ b/tests/PodDisruptionBudgetTest.php @@ -20,7 +20,7 @@ public function test_pod_disruption_budget_build() ->setMinAvailable(1) ->setMaxUnavailable('25%'); - $this->assertEquals('policy/v1beta1', $pdb->getApiVersion()); + $this->assertEquals('policy/v1', $pdb->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb->getLabels()); @@ -33,7 +33,7 @@ public function test_pod_disruption_budget_from_yaml() { [$pdb1, $pdb2] = $this->cluster->fromYamlFile(__DIR__.'/yaml/pdb.yaml'); - $this->assertEquals('policy/v1beta1', $pdb1->getApiVersion()); + $this->assertEquals('policy/v1', $pdb1->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb1->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb1->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb1->getLabels()); @@ -41,7 +41,7 @@ public function test_pod_disruption_budget_from_yaml() $this->assertEquals('25%', $pdb1->getMaxUnavailable()); $this->assertEquals(null, $pdb1->getMinAvailable()); - $this->assertEquals('policy/v1beta1', $pdb2->getApiVersion()); + $this->assertEquals('policy/v1', $pdb2->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb2->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb2->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb2->getLabels()); @@ -107,7 +107,7 @@ public function runCreationTests() $this->assertInstanceOf(K8sDeployment::class, $dep); $this->assertInstanceOf(K8sPodDisruptionBudget::class, $pdb); - $this->assertEquals('policy/v1beta1', $pdb->getApiVersion()); + $this->assertEquals('policy/v1', $pdb->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb->getLabels()); @@ -142,7 +142,7 @@ public function runGetTests() $this->assertTrue($pdb->isSynced()); - $this->assertEquals('policy/v1beta1', $pdb->getApiVersion()); + $this->assertEquals('policy/v1', $pdb->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb->getLabels()); @@ -163,7 +163,7 @@ public function runUpdateTests() $this->assertTrue($pdb->isSynced()); - $this->assertEquals('policy/v1beta1', $pdb->getApiVersion()); + $this->assertEquals('policy/v1', $pdb->getApiVersion()); $this->assertEquals('mysql-pdb', $pdb->getName()); $this->assertEquals(['matchLabels' => ['tier' => 'backend']], $pdb->getSelectors()); $this->assertEquals(['tier' => 'backend'], $pdb->getLabels()); diff --git a/tests/yaml/cronjob.yaml b/tests/yaml/cronjob.yaml index 79083f24..831e3e70 100644 --- a/tests/yaml/cronjob.yaml +++ b/tests/yaml/cronjob.yaml @@ -1,4 +1,4 @@ -apiVersion: batch/v1beta1 +apiVersion: batch/v1 kind: CronJob metadata: name: pi @@ -12,8 +12,6 @@ spec: spec: ttlSecondsAfterFinished: 3600 template: - apiVersion: batch/v1 - kind: Job metadata: name: pi labels: @@ -29,7 +27,3 @@ spec: - Mbignum=bpi - -wle - print bpi(2000) - kind: Pod - apiVersion: v1 - apiVersion: batch/v1 - kind: Job diff --git a/tests/yaml/daemonset.yaml b/tests/yaml/daemonset.yaml index 2139a051..5729d4ee 100644 --- a/tests/yaml/daemonset.yaml +++ b/tests/yaml/daemonset.yaml @@ -5,9 +5,14 @@ metadata: labels: tier: backend spec: + selector: + matchLabels: + name: mysql-daemonset template: metadata: name: mysql + labels: + name: mysql-daemonset spec: containers: - name: mysql @@ -15,6 +20,3 @@ spec: ports: - name: mysql protocol: TCP - containerPort: 3306 - kind: Pod - apiVersion: v1 diff --git a/tests/yaml/deployment.yaml b/tests/yaml/deployment.yaml index bc936424..9159ea20 100644 --- a/tests/yaml/deployment.yaml +++ b/tests/yaml/deployment.yaml @@ -7,10 +7,15 @@ metadata: annotations: mysql/annotation: "yes" spec: + selector: + matchLabels: + name: mysql-deployment replicas: 3 template: metadata: name: mysql + labels: + name: mysql-deployment spec: containers: - name: mysql @@ -19,5 +24,3 @@ spec: - name: mysql protocol: TCP containerPort: 3306 - kind: Pod - apiVersion: v1 diff --git a/tests/yaml/hpa.yaml b/tests/yaml/hpa.yaml index fe2013a4..33c55e6e 100644 --- a/tests/yaml/hpa.yaml +++ b/tests/yaml/hpa.yaml @@ -1,4 +1,4 @@ -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: mysql-hpa diff --git a/tests/yaml/job.yaml b/tests/yaml/job.yaml index de445f98..232ae524 100644 --- a/tests/yaml/job.yaml +++ b/tests/yaml/job.yaml @@ -20,5 +20,3 @@ spec: - Mbignum=bpi - -wle - print bpi(2000) - kind: Pod - apiVersion: v1 diff --git a/tests/yaml/pdb.yaml b/tests/yaml/pdb.yaml index 9ba6939a..d6583b37 100644 --- a/tests/yaml/pdb.yaml +++ b/tests/yaml/pdb.yaml @@ -1,4 +1,4 @@ -apiVersion: policy/v1beta1 +apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: mysql-pdb @@ -12,7 +12,7 @@ spec: tier: backend maxUnavailable: 25% --- -apiVersion: policy/v1beta1 +apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: mysql-pdb diff --git a/tests/yaml/statefulset.yaml b/tests/yaml/statefulset.yaml index 8d59aadf..cdfae1c7 100644 --- a/tests/yaml/statefulset.yaml +++ b/tests/yaml/statefulset.yaml @@ -7,11 +7,16 @@ metadata: annotations: mysql/annotation: "yes" spec: + selector: + matchLabels: + name: mysql-statefulset replicas: 3 serviceName: mysql template: metadata: name: mysql + labels: + name: mysql-statefulset spec: containers: - name: mysql From ebd47c62a4894131ee451b82d476bee0caed12e7 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Tue, 21 Feb 2023 21:37:26 -0500 Subject: [PATCH 04/23] Fix: Tests should check image and version Ensuring the image and version are checked, but not necessarily the resolution or substituions due to full qualification. Saw the following error with KIND: --- Expected +++ Actual @@ @@ -'mysql:5.7' +'docker.io/library/mysql:5.7' --- tests/PodTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PodTest.php b/tests/PodTest.php index 866445c2..40d74826 100644 --- a/tests/PodTest.php +++ b/tests/PodTest.php @@ -217,8 +217,8 @@ public function runCreationTests() $pod->refresh(); - $this->assertEquals('busybox:latest', $pod->getInitContainer('busybox')->getImage()); - $this->assertEquals('mysql:5.7', $pod->getContainer('mysql')->getImage()); + $this->assertStringEndsWith('busybox:latest', $pod->getInitContainer('busybox')->getImage()); + $this->assertStringEndsWith('mysql:5.7', $pod->getContainer('mysql')->getImage()); $this->assertTrue($pod->containersAreReady()); $this->assertTrue($pod->initContainersAreReady()); From 2bc06d17d993418b2cc792567d17a93e237c67a8 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Tue, 21 Feb 2023 21:48:41 -0500 Subject: [PATCH 05/23] Resolving style issues --- src/Kinds/K8sCronJob.php | 4 ++-- src/Kinds/K8sHorizontalPodAutoscaler.php | 4 ++-- src/Kinds/K8sStatefulSet.php | 2 +- tests/JobTest.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Kinds/K8sCronJob.php b/src/Kinds/K8sCronJob.php index 701aad4c..ba1504b9 100644 --- a/src/Kinds/K8sCronJob.php +++ b/src/Kinds/K8sCronJob.php @@ -40,7 +40,7 @@ class K8sCronJob extends K8sResource implements InteractsWithK8sCluster, Watchab /** * Set the job template. * - * @param array|K8sJob $job + * @param array|K8sJob $job * @return $this */ public function setJobTemplate($job) @@ -72,7 +72,7 @@ public function getJobTemplate(bool $asInstance = true) /** * Set the schedule for the cronjob. * - * @param CronExpression|string $schedule + * @param CronExpression|string $schedule * @return $this */ public function setSchedule($schedule) diff --git a/src/Kinds/K8sHorizontalPodAutoscaler.php b/src/Kinds/K8sHorizontalPodAutoscaler.php index db3929f0..ac9d8bc3 100644 --- a/src/Kinds/K8sHorizontalPodAutoscaler.php +++ b/src/Kinds/K8sHorizontalPodAutoscaler.php @@ -40,7 +40,7 @@ class K8sHorizontalPodAutoscaler extends K8sResource implements InteractsWithK8s /** * Set the reference to the scaling resource. * - * @param Scalable $resource + * @param Scalable $resource * @return $this */ public function setResource(Scalable $resource) @@ -55,7 +55,7 @@ public function setResource(Scalable $resource) /** * Add a new metric. * - * @param ResourceMetric $metric + * @param ResourceMetric $metric * @return $this */ public function addMetric(ResourceMetric $metric) diff --git a/src/Kinds/K8sStatefulSet.php b/src/Kinds/K8sStatefulSet.php index 1faca4a9..ccb91f66 100644 --- a/src/Kinds/K8sStatefulSet.php +++ b/src/Kinds/K8sStatefulSet.php @@ -72,7 +72,7 @@ public function setUpdateStrategy(string $strategy, int $partition = 0) /** * Set the statefulset service. * - * @param K8sService|string $service + * @param K8sService|string $service * @return $this */ public function setService($service) diff --git a/tests/JobTest.php b/tests/JobTest.php index 5a960dc6..bf0d469e 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -111,7 +111,7 @@ public function runCreationTests() $this->assertEquals(['tier' => 'backend'], $job->getLabels()); $annotations = $job->getAnnotations(); - foreach(['perl/annotation' => 'yes'] as $key => $value) { + foreach (['perl/annotation' => 'yes'] as $key => $value) { $this->assertContains($key, array_keys($annotations), "Annotation $key missing"); $this->assertEquals($value, $annotations[$key]); } @@ -188,7 +188,7 @@ public function runGetTests() $this->assertEquals(['tier' => 'backend'], $job->getLabels()); $annotations = $job->getAnnotations(); - foreach(['perl/annotation' => 'yes'] as $key => $value) { + foreach (['perl/annotation' => 'yes'] as $key => $value) { $this->assertContains($key, array_keys($annotations), "Annotation $key missing"); $this->assertEquals($value, $annotations[$key]); } From b440d04ecff9115736c19655852e45a98b24cca4 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 12:21:58 -0500 Subject: [PATCH 06/23] Add: Timeout for each run of the suite Set timeout to 15. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4703f214..2a481086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: if: "!contains(github.event.head_commit.message, 'skip ci')" runs-on: ubuntu-latest + timeout-minutes: 15 strategy: fail-fast: false From 3a4197fb5caf4373c7b18b858b1f79ead5ad4dd7 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 12:24:24 -0500 Subject: [PATCH 07/23] Explicit registry for pulls Attempting public.ecr.aws to avoid rate limit on pulls --- tests/ContainerTest.php | 6 +++--- tests/CronJobTest.php | 6 +++--- tests/DaemonSetTest.php | 6 +++--- tests/DeploymentTest.php | 6 +++--- tests/EventTest.php | 2 +- tests/HorizontalPodAutoscalerTest.php | 6 +++--- tests/JobTest.php | 6 +++--- tests/PodDisruptionBudgetTest.php | 2 +- tests/PodTest.php | 16 ++++++++-------- tests/StatefulSetTest.php | 6 +++--- tests/VolumeTest.php | 10 +++++----- tests/yaml/cronjob.yaml | 2 +- tests/yaml/daemonset.yaml | 2 +- tests/yaml/deployment.yaml | 2 +- tests/yaml/job.yaml | 2 +- tests/yaml/pod.yaml | 4 ++-- tests/yaml/statefulset.yaml | 2 +- 17 files changed, 43 insertions(+), 43 deletions(-) diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 89657163..fb01309b 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -14,7 +14,7 @@ public function test_container_build() $volume = K8s::volume()->awsEbs('vol-1234', 'ext3'); - $container->setImage('nginx', '1.4') + $container->setImage('public.ecr.aws/docker/library/nginx', '1.23') ->setEnv(['key' => 'value']) ->addEnvs(['key2' => 'value2']) ->addSecretKeyRefs(['SECRET_ONE' => ['secret_ref_name', 'secret_ref_key']]) @@ -55,7 +55,7 @@ public function test_container_build() ->setSuccessThreshold(2) ); - $this->assertEquals('nginx:1.4', $container->getImage()); + $this->assertStringEndsWith('nginx:1.23', $container->getImage()); $this->assertEquals([ ['name' => 'key', 'value' => 'value'], ['name' => 'key2', 'value' => 'value2'], @@ -95,7 +95,7 @@ public function test_container_build() $container->removeEnv(); $this->assertFalse($container->isReady()); - $this->assertEquals('nginx:1.4', $container->getImage()); + $this->assertStringEndsWith('nginx:1.23', $container->getImage()); $this->assertEquals([], $container->getEnv([])); $this->assertEquals(['--test'], $container->getArgs()); $this->assertEquals([ diff --git a/tests/CronJobTest.php b/tests/CronJobTest.php index 67c6117e..3de6085d 100644 --- a/tests/CronJobTest.php +++ b/tests/CronJobTest.php @@ -16,7 +16,7 @@ public function test_cronjob_build() { $pi = K8s::container() ->setName('pi') - ->setImage('perl') + ->setImage('public.ecr.aws/docker/library/perl') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() @@ -53,7 +53,7 @@ public function test_cronjob_from_yaml() { $pi = K8s::container() ->setName('pi') - ->setImage('perl') + ->setImage('public.ecr.aws/docker/library/perl') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() @@ -89,7 +89,7 @@ public function runCreationTests() { $pi = K8s::container() ->setName('pi') - ->setImage('perl', '5.34.0') + ->setImage('public.ecr.aws/docker/library/perl', '5.36.0') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() diff --git a/tests/DaemonSetTest.php b/tests/DaemonSetTest.php index 83fe4565..4f99af64 100644 --- a/tests/DaemonSetTest.php +++ b/tests/DaemonSetTest.php @@ -14,7 +14,7 @@ public function test_daemon_set_build() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -43,7 +43,7 @@ public function test_daemon_set_from_yaml() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -77,7 +77,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/DeploymentTest.php b/tests/DeploymentTest.php index 2092c2c0..9fd09a9a 100644 --- a/tests/DeploymentTest.php +++ b/tests/DeploymentTest.php @@ -14,7 +14,7 @@ public function test_deployment_build() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -44,7 +44,7 @@ public function test_deployment_from_yaml() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -82,7 +82,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/EventTest.php b/tests/EventTest.php index 513b030f..0df2bafe 100644 --- a/tests/EventTest.php +++ b/tests/EventTest.php @@ -23,7 +23,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/HorizontalPodAutoscalerTest.php b/tests/HorizontalPodAutoscalerTest.php index 57bcfdab..44301edb 100644 --- a/tests/HorizontalPodAutoscalerTest.php +++ b/tests/HorizontalPodAutoscalerTest.php @@ -15,7 +15,7 @@ public function test_horizontal_pod_autoscaler_build() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -54,7 +54,7 @@ public function test_horizontal_pod_autoscaler_from_yaml() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -97,7 +97,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/JobTest.php b/tests/JobTest.php index bf0d469e..81c6cea7 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -14,7 +14,7 @@ public function test_job_build() { $pi = K8s::container() ->setName('pi') - ->setImage('perl') + ->setImage('public.ecr.aws/docker/library/perl') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() @@ -44,7 +44,7 @@ public function test_job_from_yaml() { $pi = K8s::container() ->setName('pi') - ->setImage('perl') + ->setImage('public.ecr.aws/docker/library/perl') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() @@ -80,7 +80,7 @@ public function runCreationTests() { $pi = K8s::container() ->setName('pi') - ->setImage('perl', '5.34.0') + ->setImage('public.ecr.aws/docker/library/perl', '5.36.0') ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); $pod = $this->cluster->pod() diff --git a/tests/PodDisruptionBudgetTest.php b/tests/PodDisruptionBudgetTest.php index 0474dcd4..5d09b93f 100644 --- a/tests/PodDisruptionBudgetTest.php +++ b/tests/PodDisruptionBudgetTest.php @@ -65,7 +65,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/PodTest.php b/tests/PodTest.php index 40d74826..6ff25a08 100644 --- a/tests/PodTest.php +++ b/tests/PodTest.php @@ -15,7 +15,7 @@ public function test_pod_build() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) @@ -24,7 +24,7 @@ public function test_pod_build() $busybox = K8s::container() ->setName('busybox') - ->setImage('busybox') + ->setImage('public.ecr.aws/docker/library/busybox') ->setCommand(['/bin/sh']); $pod = $this->cluster->pod() @@ -65,7 +65,7 @@ public function test_pod_from_yaml() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) @@ -74,7 +74,7 @@ public function test_pod_from_yaml() $busybox = K8s::container() ->setName('busybox') - ->setImage('busybox') + ->setImage('public.ecr.aws/docker/library/busybox') ->setCommand(['/bin/sh']); $pod = $this->cluster->fromYamlFile(__DIR__.'/yaml/pod.yaml'); @@ -112,7 +112,7 @@ public function test_pod_exec() { $busybox = K8s::container() ->setName('busybox-exec') - ->setImage('busybox') + ->setImage('public.ecr.aws/docker/library/busybox') ->setCommand(['/bin/sh', '-c', 'sleep 7200']); $pod = $this->cluster->pod() @@ -143,7 +143,7 @@ public function test_pod_attach() { $mysql = K8s::container() ->setName('mysql-attach') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) @@ -174,7 +174,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) @@ -183,7 +183,7 @@ public function runCreationTests() $busybox = K8s::container() ->setName('busybox') - ->setImage('busybox') + ->setImage('public.ecr.aws/docker/library/busybox') ->setCommand(['/bin/sh']); $pod = $this->cluster->pod() diff --git a/tests/StatefulSetTest.php b/tests/StatefulSetTest.php index f4da6bf9..ea0e213e 100644 --- a/tests/StatefulSetTest.php +++ b/tests/StatefulSetTest.php @@ -15,7 +15,7 @@ public function test_stateful_set_build() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -65,7 +65,7 @@ public function test_stateful_set_from_yaml() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]); @@ -120,7 +120,7 @@ public function runCreationTests() { $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->setPorts([ ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306], ]) diff --git a/tests/VolumeTest.php b/tests/VolumeTest.php index c9601d0b..8b3d4820 100644 --- a/tests/VolumeTest.php +++ b/tests/VolumeTest.php @@ -15,7 +15,7 @@ public function test_volume_empty_directory() $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->addMountedVolumes([$mountedVolume]) ->setMountedVolumes([$mountedVolume]); @@ -54,7 +54,7 @@ public function test_volume_config_map() $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->addMountedVolumes([$mountedVolume]); $pod = K8s::pod() @@ -92,7 +92,7 @@ public function test_volume_secret() $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->addMountedVolumes([$mountedVolume]); $pod = K8s::pod() @@ -123,7 +123,7 @@ public function test_volume_gce_pd() $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->addMountedVolumes([$mountedVolume]); $pod = K8s::pod() @@ -156,7 +156,7 @@ public function test_volume_aws_ebs() $mysql = K8s::container() ->setName('mysql') - ->setImage('mysql', '5.7') + ->setImage('public.ecr.aws/docker/library/mysql', '5.7') ->addMountedVolumes([$mountedVolume]); $pod = K8s::pod() diff --git a/tests/yaml/cronjob.yaml b/tests/yaml/cronjob.yaml index 831e3e70..9facee84 100644 --- a/tests/yaml/cronjob.yaml +++ b/tests/yaml/cronjob.yaml @@ -21,7 +21,7 @@ spec: spec: containers: - name: pi - image: perl:latest + image: public.ecr.aws/docker/library/perl:latest command: - perl - Mbignum=bpi diff --git a/tests/yaml/daemonset.yaml b/tests/yaml/daemonset.yaml index 5729d4ee..1fa4ced2 100644 --- a/tests/yaml/daemonset.yaml +++ b/tests/yaml/daemonset.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: mysql - image: mysql:5.7 + image: public.ecr.aws/docker/library/mysql:5.7 ports: - name: mysql protocol: TCP diff --git a/tests/yaml/deployment.yaml b/tests/yaml/deployment.yaml index 9159ea20..cde0d05f 100644 --- a/tests/yaml/deployment.yaml +++ b/tests/yaml/deployment.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: mysql - image: mysql:5.7 + image: public.ecr.aws/docker/library/mysql:5.7 ports: - name: mysql protocol: TCP diff --git a/tests/yaml/job.yaml b/tests/yaml/job.yaml index 232ae524..1e8f0d87 100644 --- a/tests/yaml/job.yaml +++ b/tests/yaml/job.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: pi - image: perl:latest + image: public.ecr.aws/docker/library/perl:latest command: - perl - Mbignum=bpi diff --git a/tests/yaml/pod.yaml b/tests/yaml/pod.yaml index 1daff0cd..8f5840c3 100644 --- a/tests/yaml/pod.yaml +++ b/tests/yaml/pod.yaml @@ -9,12 +9,12 @@ metadata: spec: initContainers: - name: busybox - image: busybox:latest + image: public.ecr.aws/docker/library/busybox:latest command: - /bin/sh containers: - name: mysql - image: mysql:5.7 + image: public.ecr.aws/docker/library/mysql:5.7 ports: - name: mysql protocol: TCP diff --git a/tests/yaml/statefulset.yaml b/tests/yaml/statefulset.yaml index cdfae1c7..024fb0f6 100644 --- a/tests/yaml/statefulset.yaml +++ b/tests/yaml/statefulset.yaml @@ -20,7 +20,7 @@ spec: spec: containers: - name: mysql - image: mysql:5.7 + image: public.ecr.aws/docker/library/mysql:5.7 ports: - name: mysql protocol: TCP From 9d8c821149dada0a81a7f77b3e0f0a5fd729b141 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 12:27:10 -0500 Subject: [PATCH 08/23] Updating phpunit.xml --- phpunit.xml | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 82794b74..ef9baef1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,25 +1,16 @@ - - - - tests - - - - - src/ - - - - - + + + + src/ + + + + + tests + + + + + From 50c3bd3ffa97a9b161f949a25ddf0a8c20a24602 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 13:26:28 -0500 Subject: [PATCH 09/23] Fix: error with too big number on newer perl Can't use an undefined value as an ARRAY reference at /usr/local/lib/perl5/5.36.0/Math/BigInt/Calc.pm line 1049. --- tests/CronJobTest.php | 6 +++--- tests/JobTest.php | 8 ++++---- tests/yaml/cronjob.yaml | 2 +- tests/yaml/job.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/CronJobTest.php b/tests/CronJobTest.php index 3de6085d..f9c44830 100644 --- a/tests/CronJobTest.php +++ b/tests/CronJobTest.php @@ -17,7 +17,7 @@ public function test_cronjob_build() $pi = K8s::container() ->setName('pi') ->setImage('public.ecr.aws/docker/library/perl') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') @@ -54,7 +54,7 @@ public function test_cronjob_from_yaml() $pi = K8s::container() ->setName('pi') ->setImage('public.ecr.aws/docker/library/perl') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') @@ -90,7 +90,7 @@ public function runCreationTests() $pi = K8s::container() ->setName('pi') ->setImage('public.ecr.aws/docker/library/perl', '5.36.0') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') diff --git a/tests/JobTest.php b/tests/JobTest.php index 81c6cea7..189fdd00 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -15,7 +15,7 @@ public function test_job_build() $pi = K8s::container() ->setName('pi') ->setImage('public.ecr.aws/docker/library/perl') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') @@ -45,7 +45,7 @@ public function test_job_from_yaml() $pi = K8s::container() ->setName('pi') ->setImage('public.ecr.aws/docker/library/perl') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') @@ -80,8 +80,8 @@ public function runCreationTests() { $pi = K8s::container() ->setName('pi') - ->setImage('public.ecr.aws/docker/library/perl', '5.36.0') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)']); + ->setImage('public.ecr.aws/docker/library/perl', '5.36') + ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); $pod = $this->cluster->pod() ->setName('perl') diff --git a/tests/yaml/cronjob.yaml b/tests/yaml/cronjob.yaml index 9facee84..4545bc50 100644 --- a/tests/yaml/cronjob.yaml +++ b/tests/yaml/cronjob.yaml @@ -26,4 +26,4 @@ spec: - perl - Mbignum=bpi - -wle - - print bpi(2000) + - print bpi(200) diff --git a/tests/yaml/job.yaml b/tests/yaml/job.yaml index 1e8f0d87..07b524e2 100644 --- a/tests/yaml/job.yaml +++ b/tests/yaml/job.yaml @@ -19,4 +19,4 @@ spec: - perl - Mbignum=bpi - -wle - - print bpi(2000) + - print bpi(200) From d0836a9b8ad468a3e940cf7e5982aee914023af2 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 13:55:23 -0500 Subject: [PATCH 10/23] Fix: Removing the --no-suggest option You are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a481086..b2b0d9e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest + composer update --${{ matrix.prefer }} --prefer-dist --no-interaction - name: Setup in-cluster config run: | From e5acaf597d86fe117e0d35ad697622a09ca6a09e Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Thu, 23 Feb 2023 14:13:19 -0500 Subject: [PATCH 11/23] Fix: Skipping some tests where the volumeBindingMode may not be Immediate On KIND, the standard storageclass is there, but the binding mode is WaitForFirstConsumer. This lets the test suite progress through this test without issue when we're working against hosts or clusters configured like that. --- tests/PersistentVolumeClaimTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/PersistentVolumeClaimTest.php b/tests/PersistentVolumeClaimTest.php index f6177a5d..7f4751f8 100644 --- a/tests/PersistentVolumeClaimTest.php +++ b/tests/PersistentVolumeClaimTest.php @@ -78,14 +78,16 @@ public function runCreationTests() $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); - while (! $pvc->isBound()) { - dump("Waiting for PVC {$pvc->getName()} to be bound..."); - sleep(1); - $pvc->refresh(); - } + if ($standard->getVolumeBindingMode() == 'Immediate') { + while (!$pvc->isBound()) { + dump("Waiting for PVC {$pvc->getName()} to be bound..."); + sleep(1); + $pvc->refresh(); + } - $this->assertFalse($pvc->isAvailable()); - $this->assertTrue($pvc->isBound()); + $this->assertFalse($pvc->isAvailable()); + $this->assertTrue($pvc->isBound()); + } } public function runGetAllTests() From d321c304882a2a1e296b0d29b4a6b7f1ca1c874a Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 03:38:39 -0400 Subject: [PATCH 12/23] Fix: Missing ext-yaml requirement in composer.json --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 83121152..9ff274ef 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,10 @@ "illuminate/support": "^9.0.1|^10.0.0", "ratchet/pawl": "^0.4.1", "symfony/process": "^5.4|^6.0", - "vierbergenlars/php-semver": "^2.1|^3.0" + "vierbergenlars/php-semver": "^2.1|^3.0", + "ext-yaml": "*" }, "suggest": { - "ext-yaml": "YAML extension is used to read or generate YAML from PHP K8s internal classes." }, "autoload": { "psr-4": { @@ -37,7 +37,6 @@ }, "require-dev": { "mockery/mockery": "^1.5", - "orchestra/testbench": "^7.0|^8.0", "orchestra/testbench-core": "^7.0|^8.0", "phpunit/phpunit": "^9.5.20|^10.0", "vimeo/psalm": "^4.20" From c78ffe671f58035f00d2510738c204313526d6c5 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 05:21:03 -0400 Subject: [PATCH 13/23] Fix: Unnecessary/error-prone check Annotations could get added by different admission plugins or API implementations. No reason to check for empty set here, createOrUpdate() with an empty annotation array won't actually remove any or guarantee that the array back after save is empty. --- tests/JobTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/JobTest.php b/tests/JobTest.php index 189fdd00..f928a44c 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -211,7 +211,6 @@ public function runUpdateTests() $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); $this->assertEquals(['tier' => 'backend'], $job->getLabels()); - $this->assertEquals([], $job->getAnnotations()); $this->assertInstanceOf(K8sPod::class, $job->getTemplate()); } From 70e9c024f1dad2d48fd45ad5eb797dc6b12eea95 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 04:08:22 -0400 Subject: [PATCH 14/23] Bump to 1.26, drop 1.23 * Replace manusa/actions-setup-minikube with medyagh/setup-minikube (from minikube documentation) * Explicit containerd runtime with dockershim removal * Updated README * Bump patch versions of current minor releases --- .github/workflows/ci.yml | 14 +++++++------- README.md | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2b0d9e1..51f27d20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,9 @@ jobs: - '8.1' - '8.2' kubernetes: - - '1.23.16' - - '1.24.10' - - '1.25.6' + - '1.24.12' + - '1.25.8' + - '1.26.3' laravel: - 9.* - 10.* @@ -63,12 +63,12 @@ jobs: path: ~/.composer/cache/files key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }} - - uses: manusa/actions-setup-minikube@v2.7.2 + - uses: medyagh/setup-minikube@latest name: Setup Minikube with: - minikube version: v1.29.0 - kubernetes version: "v${{ matrix.kubernetes }}" - github token: "${{ secrets.GITHUB_TOKEN }}" + minikube-version: 1.29.0 + container-runtime: containerd + kubernetes-version: "v${{ matrix.kubernetes }}" - name: Run Kubernetes Proxy run: | diff --git a/README.md b/README.md index f3bc5535..735264e8 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ PHP K8s [![Total Downloads](https://poser.pugx.org/renoki-co/php-k8s/downloads)](https://packagist.org/packages/renoki-co/php-k8s) [![Monthly Downloads](https://poser.pugx.org/renoki-co/php-k8s/d/monthly)](https://packagist.org/packages/renoki-co/php-k8s) -![v1.23.16 K8s Version](https://img.shields.io/badge/K8s%20v1.23.16-Ready-%23326ce5?colorA=306CE8&colorB=green) -![v1.24.10 K8s Version](https://img.shields.io/badge/K8s%20v1.24.10-Ready-%23326ce5?colorA=306CE8&colorB=green) -![v1.25.6 K8s Version](https://img.shields.io/badge/K8s%20v1.25.6-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.24.12 K8s Version](https://img.shields.io/badge/K8s%20v1.24.12-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.25.8 K8s Version](https://img.shields.io/badge/K8s%20v1.25.8-Ready-%23326ce5?colorA=306CE8&colorB=green) +![v1.26.3 K8s Version](https://img.shields.io/badge/K8s%20v1.26.3-Ready-%23326ce5?colorA=306CE8&colorB=green) [![Client Capabilities](https://img.shields.io/badge/Kubernetes%20Client-Silver-blue.svg?colorB=C0C0C0&colorA=306CE8)](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/csi-new-client-library-procedure.md#client-capabilities) [![Client Support Level](https://img.shields.io/badge/Kubernetes%20Client-stable-green.svg?colorA=306CE8)](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/csi-new-client-library-procedure.md#client-support-level) From 73acf9a3f25cee47e34413033b9aa79c98ab8e5b Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 06:19:47 -0400 Subject: [PATCH 15/23] Fix: PodDisruptionBudgetTest Consistent 409s Issue here likely due to speed of test versus timing in VM. Trying to eliminate this timing issue in this test. Unclear if 409s should be resolved in client code with a loop or in the library. --- tests/PodDisruptionBudgetTest.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/PodDisruptionBudgetTest.php b/tests/PodDisruptionBudgetTest.php index 5d09b93f..afe30047 100644 --- a/tests/PodDisruptionBudgetTest.php +++ b/tests/PodDisruptionBudgetTest.php @@ -153,13 +153,21 @@ public function runGetTests() public function runUpdateTests() { - $pdb = $this->cluster->getPodDisruptionBudgetByName('mysql-pdb'); - - $this->assertTrue($pdb->isSynced()); - - $pdb->setMinAvailable('25%'); - - $pdb->createOrUpdate(); + $backoff = 0; + do { + try { + $pdb = $this->cluster->getPodDisruptionBudgetByName('mysql-pdb')->setMinAvailable('25%')->createOrUpdate(); + } catch (KubernetesAPIException $e) { + if ($e->getCode() == 409) { + sleep(2*$backoff); + $backoff++; + } else { + throw $e; + } + if ($backoff > 3) + break; + } + } while (!isset($pdb)); $this->assertTrue($pdb->isSynced()); From ae6006a0427807e7f156f4f495d6728faeca20c6 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 07:29:59 -0400 Subject: [PATCH 16/23] Fix: PodTest inconsistent websocket values returned from exec() It cannot be guaranteed we get the returned values in the same lines. This test was fragile for where additional empty lines (non-lines) were emitted. Reducing to a single string of values and ensuring we get all the output. --- tests/PodTest.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/PodTest.php b/tests/PodTest.php index 6ff25a08..84fd69a7 100644 --- a/tests/PodTest.php +++ b/tests/PodTest.php @@ -127,14 +127,10 @@ public function test_pod_exec() } $messages = $pod->exec(['/bin/sh', '-c', 'echo 1 && echo 2 && echo 3'], 'busybox-exec'); - - $hasDesiredOutput = collect($messages)->where('channel', 'stdout')->filter(function ($message) { - return Str::contains($message['output'], '1') - && Str::contains($message['output'], '2') - && Str::contains($message['output'], '3'); - })->isNotEmpty(); - - $this->assertTrue($hasDesiredOutput); + $desiredOutput = collect($messages)->where('channel', 'stdout')->reduce(function(?string $carry, array $message) { + return $carry .= preg_replace('/\s+/', '', $message['output']); + }); + $this->assertEquals("123", $desiredOutput); $pod->delete(); } From 35fcf56b79893d3fbdef72f15d294e8d6b244357 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 09:40:00 -0400 Subject: [PATCH 17/23] Fix: K8sJob testing activepods instead of completiontime for completed() Also, selectors and queries for tier=backend would pick up MySQL pods from other tests. Updated annotation as "compute" instead of "backend" to keep this test separate. --- src/Kinds/K8sJob.php | 2 +- tests/JobTest.php | 21 ++++++++++----------- tests/yaml/job.yaml | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Kinds/K8sJob.php b/src/Kinds/K8sJob.php index cbb60bae..9ece4d7b 100644 --- a/src/Kinds/K8sJob.php +++ b/src/Kinds/K8sJob.php @@ -151,6 +151,6 @@ public function getDurationInSeconds(): int */ public function hasCompleted(): bool { - return $this->getActivePodsCount() === 0; + return !is_null($this->getCompletionTime()); } } diff --git a/tests/JobTest.php b/tests/JobTest.php index f928a44c..fe6d5912 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -25,14 +25,14 @@ public function test_job_build() $job = $this->cluster->job() ->setName('pi') - ->setLabels(['tier' => 'backend']) + ->setLabels(['tier' => 'compute']) ->setAnnotations(['perl/annotation' => 'yes']) ->setTTL(3600) ->setTemplate($pod); $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); - $this->assertEquals(['tier' => 'backend'], $job->getLabels()); + $this->assertEquals(['tier' => 'compute'], $job->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations()); $this->assertEquals($pod->getName(), $job->getTemplate()->getName()); $this->assertEquals('Never', $pod->getRestartPolicy()); @@ -57,7 +57,7 @@ public function test_job_from_yaml() $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); - $this->assertEquals(['tier' => 'backend'], $job->getLabels()); + $this->assertEquals(['tier' => 'compute'], $job->getLabels()); $this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations()); $this->assertEquals($pod->getName(), $job->getTemplate()->getName()); $this->assertEquals('Never', $pod->getRestartPolicy()); @@ -85,13 +85,13 @@ public function runCreationTests() $pod = $this->cluster->pod() ->setName('perl') - ->setLabels(['tier' => 'backend']) + ->setLabels(['tier' => 'compute']) ->setContainers([$pi]) ->neverRestart(); $job = $this->cluster->job() ->setName('pi') - ->setLabels(['tier' => 'backend']) + ->setLabels(['tier' => 'compute']) ->setAnnotations(['perl/annotation' => 'yes']) ->setTTL(3600) ->setTemplate($pod); @@ -108,7 +108,7 @@ public function runCreationTests() $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); - $this->assertEquals(['tier' => 'backend'], $job->getLabels()); + $this->assertEquals(['tier' => 'compute'], $job->getLabels()); $annotations = $job->getAnnotations(); foreach (['perl/annotation' => 'yes'] as $key => $value) { @@ -130,8 +130,7 @@ public function runCreationTests() K8sJob::selectPods(function ($job) { $this->assertInstanceOf(K8sJob::class, $job); - - return ['tier' => 'backend']; + return ['tier' => 'compute']; }); $pods = $job->getPods(); @@ -149,7 +148,7 @@ public function runCreationTests() $job->refresh(); while (! $completionTime = $job->getCompletionTime()) { - dump("Waiting for the competion time report of {$job->getName()}..."); + dump("Waiting for the completion time report of {$job->getName()}..."); sleep(1); $job->refresh(); } @@ -185,7 +184,7 @@ public function runGetTests() $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); - $this->assertEquals(['tier' => 'backend'], $job->getLabels()); + $this->assertEquals(['tier' => 'compute'], $job->getLabels()); $annotations = $job->getAnnotations(); foreach (['perl/annotation' => 'yes'] as $key => $value) { @@ -210,7 +209,7 @@ public function runUpdateTests() $this->assertEquals('batch/v1', $job->getApiVersion()); $this->assertEquals('pi', $job->getName()); - $this->assertEquals(['tier' => 'backend'], $job->getLabels()); + $this->assertEquals(['tier' => 'compute'], $job->getLabels()); $this->assertInstanceOf(K8sPod::class, $job->getTemplate()); } diff --git a/tests/yaml/job.yaml b/tests/yaml/job.yaml index 07b524e2..2d38d7e8 100644 --- a/tests/yaml/job.yaml +++ b/tests/yaml/job.yaml @@ -3,7 +3,7 @@ kind: Job metadata: name: pi labels: - tier: backend + tier: compute annotations: perl/annotation: "yes" spec: From b23f40837b6866c4c558d43da8be3c47988a2ee9 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 13:26:55 -0400 Subject: [PATCH 18/23] Fix: K8sCronJob needed to find active Job by name and also have running job Previous change to simpler Pi calculation exposed timing issue with test. Rather than make VM/CPU work harder or create potential for overflow again, sleep. Then, fixed lookup logic. --- src/Kinds/K8sCronJob.php | 2 +- tests/CronJobTest.php | 57 ++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/Kinds/K8sCronJob.php b/src/Kinds/K8sCronJob.php index ba1504b9..2a1b5754 100644 --- a/src/Kinds/K8sCronJob.php +++ b/src/Kinds/K8sCronJob.php @@ -123,7 +123,7 @@ public function getLastSchedule() public function getActiveJobs() { return collect($this->getStatus('active', []))->map(function ($job) { - return $this->cluster->job($job)->refresh(); + return $this->cluster->getJobByName($job['name'], $this->getNamespace()); }); } } diff --git a/tests/CronJobTest.php b/tests/CronJobTest.php index f9c44830..8961c420 100644 --- a/tests/CronJobTest.php +++ b/tests/CronJobTest.php @@ -10,7 +10,7 @@ use RenokiCo\PhpK8s\Kinds\K8sJob; use RenokiCo\PhpK8s\ResourcesList; -class CronCronJobTest extends TestCase +class CronJobTest extends TestCase { public function test_cronjob_build() { @@ -87,28 +87,28 @@ public function test_cronjob_api_interaction() public function runCreationTests() { - $pi = K8s::container() - ->setName('pi') - ->setImage('public.ecr.aws/docker/library/perl', '5.36.0') - ->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']); + $busybox = K8s::container() + ->setName('busybox-exec') + ->setImage('public.ecr.aws/docker/library/busybox') + ->setCommand(['/bin/sh', '-c', 'sleep 30']); $pod = $this->cluster->pod() - ->setName('perl') - ->setContainers([$pi]) + ->setName('sleep') + ->setContainers([$busybox]) ->restartOnFailure() ->neverRestart(); $job = $this->cluster->job() - ->setName('pi') - ->setLabels(['tier' => 'backend']) - ->setAnnotations(['perl/annotation' => 'yes']) + ->setName('sleeper') + ->setLabels(['tier' => 'useless']) + ->setAnnotations(['perl/annotation' => 'no']) ->setTTL(3600) ->setTemplate($pod); $cronjob = $this->cluster->cronjob() - ->setName('pi') - ->setLabels(['tier' => 'backend']) - ->setAnnotations(['perl/annotation' => 'yes']) + ->setName('periodic-sleep') + ->setLabels(['tier' => 'useless']) + ->setAnnotations(['perl/annotation' => 'no']) ->setJobTemplate($job) ->setSchedule(CronExpression::factory('* * * * *')); @@ -123,9 +123,9 @@ public function runCreationTests() $this->assertInstanceOf(K8sCronJob::class, $cronjob); $this->assertEquals('batch/v1', $cronjob->getApiVersion()); - $this->assertEquals('pi', $cronjob->getName()); - $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); - $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); + $this->assertEquals('periodic-sleep', $cronjob->getName()); + $this->assertEquals(['tier' => 'useless'], $cronjob->getLabels()); + $this->assertEquals(['perl/annotation' => 'no'], $cronjob->getAnnotations()); $this->assertEquals('Never', $pod->getRestartPolicy()); $this->assertInstanceOf(K8sJob::class, $cronjob->getJobTemplate()); @@ -135,6 +135,7 @@ public function runCreationTests() $activeJobs = $cronjob->getActiveJobs(); + // This check is sensitive to ensuring the jobs take some time to complete. while ($cronjob->getActiveJobs()->count() === 0) { dump("Waiting for the cronjob {$cronjob->getName()} to have active jobs..."); sleep(1); @@ -169,23 +170,23 @@ public function runGetAllTests() public function runGetTests() { - $cronjob = $this->cluster->getCronJobByName('pi'); + $cronjob = $this->cluster->getCronJobByName('periodic-sleep'); $this->assertInstanceOf(K8sCronJob::class, $cronjob); $this->assertTrue($cronjob->isSynced()); $this->assertEquals('batch/v1', $cronjob->getApiVersion()); - $this->assertEquals('pi', $cronjob->getName()); - $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); - $this->assertEquals(['perl/annotation' => 'yes'], $cronjob->getAnnotations()); + $this->assertEquals('periodic-sleep', $cronjob->getName()); + $this->assertEquals(['tier' => 'useless'], $cronjob->getLabels()); + $this->assertEquals(['perl/annotation' => 'no'], $cronjob->getAnnotations()); $this->assertInstanceOf(K8sJob::class, $cronjob->getJobTemplate()); } public function runUpdateTests() { - $cronjob = $this->cluster->getCronJobByName('pi'); + $cronjob = $this->cluster->getCronJobByName('periodic-sleep'); $this->assertTrue($cronjob->isSynced()); @@ -196,8 +197,8 @@ public function runUpdateTests() $this->assertTrue($cronjob->isSynced()); $this->assertEquals('batch/v1', $cronjob->getApiVersion()); - $this->assertEquals('pi', $cronjob->getName()); - $this->assertEquals(['tier' => 'backend'], $cronjob->getLabels()); + $this->assertEquals('periodic-sleep', $cronjob->getName()); + $this->assertEquals(['tier' => 'useless'], $cronjob->getLabels()); $this->assertEquals([], $cronjob->getAnnotations()); $this->assertInstanceOf(K8sJob::class, $cronjob->getJobTemplate()); @@ -205,7 +206,7 @@ public function runUpdateTests() public function runDeletionTests() { - $cronjob = $this->cluster->getCronJobByName('pi'); + $cronjob = $this->cluster->getCronJobByName('periodic-sleep'); $this->assertTrue($cronjob->delete()); @@ -216,13 +217,13 @@ public function runDeletionTests() $this->expectException(KubernetesAPIException::class); - $this->cluster->getCronJobByName('pi'); + $this->cluster->getCronJobByName('periodic-sleep'); } public function runWatchAllTests() { $watch = $this->cluster->cronjob()->watchAll(function ($type, $cronjob) { - if ($cronjob->getName() === 'pi') { + if ($cronjob->getName() === 'periodic-sleep') { return true; } }, ['timeoutSeconds' => 10]); @@ -232,8 +233,8 @@ public function runWatchAllTests() public function runWatchTests() { - $watch = $this->cluster->cronjob()->watchByName('pi', function ($type, $cronjob) { - return $cronjob->getName() === 'pi'; + $watch = $this->cluster->cronjob()->watchByName('periodic-sleep', function ($type, $cronjob) { + return $cronjob->getName() === 'periodic-sleep'; }, ['timeoutSeconds' => 10]); $this->assertTrue($watch); From c9ba63ff7704a82590ade35cf2a46cb6394e2694 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Sat, 25 Mar 2023 14:42:22 -0400 Subject: [PATCH 19/23] StyleCI fixups --- src/Kinds/K8sJob.php | 2 +- tests/JobTest.php | 1 + tests/PersistentVolumeClaimTest.php | 2 +- tests/PodDisruptionBudgetTest.php | 7 ++++--- tests/PodTest.php | 6 +++--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Kinds/K8sJob.php b/src/Kinds/K8sJob.php index 9ece4d7b..412fa622 100644 --- a/src/Kinds/K8sJob.php +++ b/src/Kinds/K8sJob.php @@ -151,6 +151,6 @@ public function getDurationInSeconds(): int */ public function hasCompleted(): bool { - return !is_null($this->getCompletionTime()); + return ! is_null($this->getCompletionTime()); } } diff --git a/tests/JobTest.php b/tests/JobTest.php index fe6d5912..72e7664c 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -130,6 +130,7 @@ public function runCreationTests() K8sJob::selectPods(function ($job) { $this->assertInstanceOf(K8sJob::class, $job); + return ['tier' => 'compute']; }); diff --git a/tests/PersistentVolumeClaimTest.php b/tests/PersistentVolumeClaimTest.php index 7f4751f8..2ba30c97 100644 --- a/tests/PersistentVolumeClaimTest.php +++ b/tests/PersistentVolumeClaimTest.php @@ -79,7 +79,7 @@ public function runCreationTests() $this->assertEquals('standard', $pvc->getStorageClass()); if ($standard->getVolumeBindingMode() == 'Immediate') { - while (!$pvc->isBound()) { + while (! $pvc->isBound()) { dump("Waiting for PVC {$pvc->getName()} to be bound..."); sleep(1); $pvc->refresh(); diff --git a/tests/PodDisruptionBudgetTest.php b/tests/PodDisruptionBudgetTest.php index afe30047..a6dcc67e 100644 --- a/tests/PodDisruptionBudgetTest.php +++ b/tests/PodDisruptionBudgetTest.php @@ -159,15 +159,16 @@ public function runUpdateTests() $pdb = $this->cluster->getPodDisruptionBudgetByName('mysql-pdb')->setMinAvailable('25%')->createOrUpdate(); } catch (KubernetesAPIException $e) { if ($e->getCode() == 409) { - sleep(2*$backoff); + sleep(2 * $backoff); $backoff++; } else { throw $e; } - if ($backoff > 3) + if ($backoff > 3) { break; + } } - } while (!isset($pdb)); + } while (! isset($pdb)); $this->assertTrue($pdb->isSynced()); diff --git a/tests/PodTest.php b/tests/PodTest.php index 84fd69a7..6cbd737c 100644 --- a/tests/PodTest.php +++ b/tests/PodTest.php @@ -127,10 +127,10 @@ public function test_pod_exec() } $messages = $pod->exec(['/bin/sh', '-c', 'echo 1 && echo 2 && echo 3'], 'busybox-exec'); - $desiredOutput = collect($messages)->where('channel', 'stdout')->reduce(function(?string $carry, array $message) { - return $carry .= preg_replace('/\s+/', '', $message['output']); + $desiredOutput = collect($messages)->where('channel', 'stdout')->reduce(function (?string $carry, array $message) { + return $carry .= preg_replace('/\s+/', '', $message['output']); }); - $this->assertEquals("123", $desiredOutput); + $this->assertEquals('123', $desiredOutput); $pod->delete(); } From ed884221c67df9d9d9e5083c43661e1b883e3576 Mon Sep 17 00:00:00 2001 From: rennokki Date: Sat, 1 Apr 2023 15:31:15 +0300 Subject: [PATCH 20/23] Updated packages --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 9ff274ef..eab3425a 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,13 @@ } ], "require": { + "ext-yaml": "*", "guzzlehttp/guzzle": "^6.5|^7.0", - "illuminate/macroable": "^9.0.1|^10.0.0", - "illuminate/support": "^9.0.1|^10.0.0", + "illuminate/macroable": "^9.35|^10.1", + "illuminate/support": "^9.35|^10.1", "ratchet/pawl": "^0.4.1", "symfony/process": "^5.4|^6.0", - "vierbergenlars/php-semver": "^2.1|^3.0", - "ext-yaml": "*" + "vierbergenlars/php-semver": "^2.1|^3.0" }, "suggest": { }, @@ -37,7 +37,7 @@ }, "require-dev": { "mockery/mockery": "^1.5", - "orchestra/testbench-core": "^7.0|^8.0", + "orchestra/testbench-core": "^7.23|^8.1", "phpunit/phpunit": "^9.5.20|^10.0", "vimeo/psalm": "^4.20" }, From 61954fa4a767e1e7941189e7749ad6368adbbdad Mon Sep 17 00:00:00 2001 From: rennokki Date: Sat, 1 Apr 2023 15:32:27 +0300 Subject: [PATCH 21/23] Update ci.yml --- .github/workflows/ci.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51f27d20..b33ecbdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,6 @@ jobs: fail-fast: false matrix: php: - - '8.0' - '8.1' - '8.2' kubernetes: @@ -35,15 +34,10 @@ jobs: - 'prefer-lowest' - 'prefer-stable' include: - - laravel: 10.* - testbench: 8.* - laravel: 9.* testbench: 7.* - exclude: - laravel: 10.* - php: '8.0' - - laravel: 9.* - php: '8.2' + testbench: 8.* name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - K8s v${{ matrix.kubernetes }} --${{ matrix.prefer }} From 343f9beaeafa6362a8cbb725147d1e093ab3be16 Mon Sep 17 00:00:00 2001 From: rennokki Date: Sat, 1 Apr 2023 15:33:26 +0300 Subject: [PATCH 22/23] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eab3425a..9229e9fa 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "require-dev": { "mockery/mockery": "^1.5", - "orchestra/testbench-core": "^7.23|^8.1", + "orchestra/testbench": "^7.23|^8.1", "phpunit/phpunit": "^9.5.20|^10.0", "vimeo/psalm": "^4.20" }, From 046c682aeb2485248e951001c9aeff666b167b20 Mon Sep 17 00:00:00 2001 From: rennokki Date: Tue, 4 Apr 2023 20:27:12 +0300 Subject: [PATCH 23/23] Moved `ext-yaml` to suggestions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9229e9fa..845befa3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ } ], "require": { - "ext-yaml": "*", "guzzlehttp/guzzle": "^6.5|^7.0", "illuminate/macroable": "^9.35|^10.1", "illuminate/support": "^9.35|^10.1", @@ -21,6 +20,7 @@ "vierbergenlars/php-semver": "^2.1|^3.0" }, "suggest": { + "ext-yaml": "YAML extension is used to read or generate YAML from PHP K8s internal classes." }, "autoload": { "psr-4": {