Skip to content

Update dependencies and refactor test configurations #463

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
kubernetes: ['1.24.12', '1.25.8', '1.26.3']
laravel: ['9.*', '10.*', '11.*']
php: ['8.3', '8.4']
kubernetes: ['1.31.10', '1.32.6', '1.33.2']
laravel: ['11.*', '12.*']
prefer: [prefer-lowest, prefer-stable]
include:
- laravel: "9.*"
testbench: "7.*"
- laravel: "10.*"
testbench: "8.*"
- laravel: "11.*"
testbench: "9.*"
exclude:
- laravel: "11.*"
php: "8.1"
- laravel: "12.*"
testbench: "10.*"

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - K8s v${{ matrix.kubernetes }} --${{ matrix.prefer }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -48,16 +43,33 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, yaml
coverage: pcov

- uses: actions/cache@v3.0.5
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Prepare cache key
id: prep
run: |
PHP_VERSION=${{ matrix.php }}
LARAVEL_VERSION=${{ matrix.laravel }}
PREFER_VERSION=${{ matrix.prefer }}

# Remove any .* from the versions
LARAVEL_VERSION=${LARAVEL_VERSION//.*}

echo "cache-key=composer-php-$PHP_VERSION-$LARAVEL_VERSION-$PREFER_VERSION-${{ hashFiles('composer.json') }}" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
name: Cache dependencies
with:
path: ~/.composer/cache/files
key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }}
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ steps.prep.outputs.cache-key }}

- uses: medyagh/setup-minikube@latest
name: Setup Minikube
with:
minikube-version: 1.29.0
minikube-version: 1.36.0
driver: docker
container-runtime: containerd
kubernetes-version: v${{ matrix.kubernetes }}

Expand Down Expand Up @@ -86,6 +98,6 @@ jobs:
run: |
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

- uses: codecov/codecov-action@v3.1.0
- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: false
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ 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.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)
![v1.31.10 K8s Version](https://img.shields.io/badge/K8s%20v1.31.10-Ready-%23326ce5?colorA=306CE8&colorB=green)
![v1.32.6 K8s Version](https://img.shields.io/badge/K8s%20v1.32.6-Ready-%23326ce5?colorA=306CE8&colorB=green)
![v1.33.2 K8s Version](https://img.shields.io/badge/K8s%20v1.33.2-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)

Expand Down
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
}
],
"require": {
"guzzlehttp/guzzle": "^6.5|^7.0",
"illuminate/macroable": "^9.35|^10.1|^11.0",
"illuminate/support": "^9.35|^10.1|^11.0",
"php": "^8.3",
"guzzlehttp/guzzle": "^7.9",
"illuminate/macroable": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0",
"ratchet/pawl": "^0.4.1",
"symfony/process": "^5.4|^6.0|^7.0",
"vierbergenlars/php-semver": "^2.1|^3.0"
"symfony/process": "^7.3.0",
"composer/semver": "^3.4",
"ext-json": "*"
},
"suggest": {
"ext-yaml": "YAML extension is used to read or generate YAML from PHP K8s internal classes."
Expand All @@ -48,10 +50,10 @@
"test": "vendor/bin/phpunit"
},
"require-dev": {
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.23|^8.1|^9.0",
"phpunit/phpunit": "^9.5.20|^10.0",
"vimeo/psalm": "^4.20|^5.22"
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0|^10.0",
"phpunit/phpunit": "^10.0|^11.0",
"vimeo/psalm": "^6.12.0"
},
"config": {
"sort-packages": true
Expand Down
26 changes: 20 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
failOnWarning="false"
failOnDeprecation="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
<testsuites>
<testsuite name="Renoki Co Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<coverage>
<report>
<clover outputFile="coverage.xml"/>
<text outputFile="php://stdout"/>
</report>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
</php>
Expand Down
26 changes: 16 additions & 10 deletions src/Traits/Cluster/ChecksClusterVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

namespace RenokiCo\PhpK8s\Traits\Cluster;

use Composer\Semver\Comparator;
use Composer\Semver\VersionParser;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use JsonException;
use RenokiCo\PhpK8s\Exceptions\KubernetesAPIException;
use vierbergenlars\SemVer\version as Semver;

trait ChecksClusterVersion
{
/**
* The Kubernetes cluster version.
*
* @var \vierbergenlars\SemVer\version|null
*/
protected $kubernetesVersion;
protected string $kubernetesVersion;

/**
* Load the cluster version.
*
* @return void
*
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
* @throws KubernetesAPIException|GuzzleException|JsonException
*/
protected function loadClusterVersion(): void
{
if ($this->kubernetesVersion) {
if (isset($this->kubernetesVersion)) {
return;
}

Expand All @@ -42,9 +43,10 @@ protected function loadClusterVersion(): void
);
}

$json = @json_decode($response->getBody(), true);
$json = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

$this->kubernetesVersion = new Semver($json['gitVersion']);
$parser = new VersionParser();
$this->kubernetesVersion = $parser->normalize($json['gitVersion']);
}

/**
Expand All @@ -53,12 +55,14 @@ protected function loadClusterVersion(): void
*
* @param string $kubernetesVersion
* @return bool
*
* @throws KubernetesAPIException|GuzzleException|JsonException
*/
public function newerThan(string $kubernetesVersion): bool
{
$this->loadClusterVersion();

return Semver::gte(
return Comparator::greaterThanOrEqualTo(
$this->kubernetesVersion, $kubernetesVersion
);
}
Expand All @@ -69,12 +73,14 @@ public function newerThan(string $kubernetesVersion): bool
*
* @param string $kubernetesVersion
* @return bool
*
* @throws KubernetesAPIException|GuzzleException|JsonException
*/
public function olderThan(string $kubernetesVersion): bool
{
$this->loadClusterVersion();

return Semver::lt(
return Comparator::lessThan(
$this->kubernetesVersion, $kubernetesVersion
);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ChecksClusterVersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace RenokiCo\PhpK8s\Test;

class ChecksClusterVersionTest extends TestCase
{
public function test_check_cluster_version(): void
{
$this->assertFalse($this->cluster->olderThan('1.18.0'));
$this->assertTrue($this->cluster->newerThan('1.18.0'));
$this->assertFalse($this->cluster->newerThan('2.0.0'));
$this->assertTrue($this->cluster->olderThan('2.0.0'));
}
}
14 changes: 4 additions & 10 deletions tests/CronJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ class CronJobTest extends TestCase
{
public function test_cronjob_build()
{
$pi = K8s::container()
->setName('pi')
->setImage('public.ecr.aws/docker/library/perl')
->setCommand(['perl', '-Mbignum=bpi', '-wle', 'print bpi(200)']);
$pi = $this->createPerlContainer();

$pod = $this->cluster->pod()
->setName('perl')
Expand All @@ -37,7 +34,7 @@ public function test_cronjob_build()
->setLabels(['tier' => 'backend'])
->setAnnotations(['perl/annotation' => 'yes'])
->setJobTemplate($job)
->setSchedule(CronExpression::factory('* * * * *'));
->setSchedule(new CronExpression('* * * * *'));

$this->assertEquals('batch/v1', $cronjob->getApiVersion());
$this->assertEquals('pi', $cronjob->getName());
Expand All @@ -51,10 +48,7 @@ public function test_cronjob_build()

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(200)']);
$pi = $this->createPerlContainer();

$pod = $this->cluster->pod()
->setName('perl')
Expand Down Expand Up @@ -110,7 +104,7 @@ public function runCreationTests()
->setLabels(['tier' => 'useless'])
->setAnnotations(['perl/annotation' => 'no'])
->setJobTemplate($job)
->setSchedule(CronExpression::factory('* * * * *'));
->setSchedule(new CronExpression('* * * * *'));

$this->assertFalse($cronjob->isSynced());
$this->assertFalse($cronjob->exists());
Expand Down
Loading