diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b937539..7acafb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,13 +3,17 @@ name: CI on: push: branches: - - "*" + - main tags: - "*" pull_request: branches: - "*" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + jobs: build: if: "!contains(github.event.head_commit.message, 'skip ci')" @@ -22,16 +26,9 @@ jobs: fail-fast: false matrix: php: ['8.3', '8.4', '8.5'] - kubernetes: ['1.33.10', '1.34.6', '1.35.3'] - laravel: ['12.*', '13.*'] - prefer: [prefer-lowest, prefer-stable] - include: - - laravel: "12.*" - testbench: "10.*" - - laravel: "13.*" - testbench: "11.*" + kubernetes: ['1.33.10'] - name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - K8s v${{ matrix.kubernetes }} --${{ matrix.prefer }} + name: PHP ${{ matrix.php }} - K8s v${{ matrix.kubernetes }} steps: - uses: actions/checkout@v6 @@ -43,27 +40,11 @@ jobs: extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, yaml coverage: pcov - - 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@v5 name: Cache dependencies with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ steps.prep.outputs.cache-key }} + path: ~/.composer/cache/files + key: composer-php-${{ matrix.php }}-${{ hashFiles('composer.json') }} - uses: medyagh/setup-minikube@latest name: Setup Minikube @@ -92,9 +73,7 @@ jobs: kubectl proxy --port=8080 --reject-paths="^/non-existent-path" & - 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 + run: composer update --prefer-stable --prefer-dist --no-interaction - name: Setup in-cluster config run: | diff --git a/composer.json b/composer.json index bb1c418..09fbbfc 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,10 @@ "ext-json": "*", "composer/semver": "^3.4", "guzzlehttp/guzzle": "^7.10", - "illuminate/macroable": "^12.0|^13.0", - "illuminate/support": "^12.0|^13.0", - "ratchet/pawl": "^0.4.1", - "symfony/process": "^7.3.4|^8.0" + "illuminate/macroable": "^12.0", + "illuminate/support": "^12.0", + "ratchet/pawl": "^0.4.3", + "symfony/process": "^7.4" }, "suggest": { "ext-yaml": "YAML extension is used to read or generate YAML from PHP K8s internal classes.", @@ -57,14 +57,13 @@ "test": "vendor/bin/phpunit" }, "require-dev": { - "laravel/pint": "dev-main", + "laravel/pint": "^1.29", "mockery/mockery": "^1.6", - "orchestra/testbench": "^10.9.0|^11.0", + "orchestra/testbench": "^10.9.0", "phpunit/phpunit": "^11.5", "vimeo/psalm": "^6.16.1" }, "config": { "sort-packages": true - }, - "minimum-stability": "dev" + } } diff --git a/src/Instances/Container.php b/src/Instances/Container.php index fadb71e..17e9139 100644 --- a/src/Instances/Container.php +++ b/src/Instances/Container.php @@ -4,6 +4,22 @@ class Container extends Instance { + /** + * Set the container name. + */ + public function setName(string $name): static + { + return $this->setAttribute('name', $name); + } + + /** + * Get the container name. + */ + public function getName(): ?string + { + return $this->getAttribute('name'); + } + /** * Set the image for the container. * @@ -14,6 +30,70 @@ public function setImage(string $image, string $tag = 'latest'): static return $this->setAttribute('image', $image.':'.$tag); } + /** + * Set the image pull policy. + */ + public function setImagePullPolicy(string $policy): static + { + return $this->setAttribute('imagePullPolicy', $policy); + } + + /** + * Get the image pull policy. + */ + public function getImagePullPolicy(): ?string + { + return $this->getAttribute('imagePullPolicy'); + } + + /** + * Set the command (entrypoint) for the container. + */ + public function setCommand(array $command): static + { + return $this->setAttribute('command', $command); + } + + /** + * Get the command (entrypoint) for the container. + */ + public function getCommand(): array + { + return $this->getAttribute('command', []); + } + + /** + * Set the args for the container. + */ + public function setArgs(array $args): static + { + return $this->setAttribute('args', $args); + } + + /** + * Get the args for the container. + */ + public function getArgs(): array + { + return $this->getAttribute('args', []); + } + + /** + * Set the working directory for the container. + */ + public function setWorkingDir(string $dir): static + { + return $this->setAttribute('workingDir', $dir); + } + + /** + * Get the working directory for the container. + */ + public function getWorkingDir(): ?string + { + return $this->getAttribute('workingDir'); + } + /** * Add a new port to the container list. * diff --git a/src/Kinds/K8sScale.php b/src/Kinds/K8sScale.php index e4da76c..d24cd02 100644 --- a/src/Kinds/K8sScale.php +++ b/src/Kinds/K8sScale.php @@ -89,7 +89,7 @@ public function refreshOriginal(array $query = ['pretty' => 1]): static * @throws KubernetesAPIException */ #[\Override] - public function create(array $query = ['pretty' => 1]): K8sResource + public function create(array $query = ['pretty' => 1]): static { return $this->cluster ->setResourceClass(get_class($this)) diff --git a/src/Kinds/K8sSecret.php b/src/Kinds/K8sSecret.php index 7d356e9..dfcf0f0 100644 --- a/src/Kinds/K8sSecret.php +++ b/src/Kinds/K8sSecret.php @@ -20,6 +20,22 @@ class K8sSecret extends K8sResource implements InteractsWithK8sCluster, Watchabl */ protected static bool $namespaceable = true; + /** + * Set the secret type. + */ + public function setType(string $type): static + { + return $this->setAttribute('type', $type); + } + + /** + * Get the secret type. + */ + public function getType(): ?string + { + return $this->getAttribute('type'); + } + /** * Get the data attribute. * Supports base64 decoding. diff --git a/src/Traits/RunsClusterOperations.php b/src/Traits/RunsClusterOperations.php index 4d3e623..89bd404 100644 --- a/src/Traits/RunsClusterOperations.php +++ b/src/Traits/RunsClusterOperations.php @@ -15,7 +15,6 @@ use RenokiCo\PhpK8s\Exceptions\KubernetesLogsException; use RenokiCo\PhpK8s\Exceptions\KubernetesScalingException; use RenokiCo\PhpK8s\Exceptions\KubernetesWatchException; -use RenokiCo\PhpK8s\Kinds\K8sResource; use RenokiCo\PhpK8s\Kinds\K8sScale; use RenokiCo\PhpK8s\KubernetesCluster; use RenokiCo\PhpK8s\Patches\JsonMergePatch; @@ -107,10 +106,8 @@ public function refreshResourceVersion(): static /** * Create or update the resource, wether the resource exists * or not within the cluster. - * - * @return $this */ - public function syncWithCluster(array $query = ['pretty' => 1]): K8sResource + public function syncWithCluster(array $query = ['pretty' => 1]): static { try { return $this->get($query); @@ -121,10 +118,8 @@ public function syncWithCluster(array $query = ['pretty' => 1]): K8sResource /** * Create or update the app based on existence. - * - * @return $this */ - public function createOrUpdate(array $query = ['pretty' => 1]): K8sResource + public function createOrUpdate(array $query = ['pretty' => 1]): static { if ($this->exists($query)) { $this->update($query); @@ -174,10 +169,9 @@ public function allNamespaces(array $query = ['pretty' => 1]): ResourcesList /** * Get a fresh instance from the cluster. * - * * @throws KubernetesAPIException */ - public function get(array $query = ['pretty' => 1]): K8sResource + public function get(array $query = ['pretty' => 1]): static { return $this->cluster ->setResourceClass(get_class($this)) @@ -192,10 +186,9 @@ public function get(array $query = ['pretty' => 1]): K8sResource /** * Create the resource. * - * * @throws KubernetesAPIException */ - public function create(array $query = ['pretty' => 1]): K8sResource + public function create(array $query = ['pretty' => 1]): static { return $this->cluster ->setResourceClass(get_class($this)) @@ -604,7 +597,7 @@ public function resourceStatusPath(): string /** * Update the status subresource. */ - public function updateStatus(array $query = ['pretty' => 1]): self + public function updateStatus(array $query = ['pretty' => 1]): static { $this->refreshOriginal(); $this->refreshResourceVersion(); @@ -622,9 +615,9 @@ public function updateStatus(array $query = ['pretty' => 1]): self /** * JSON Patch (RFC 6902) the status subresource. */ - public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty' => 1]): self + public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty' => 1]): static { - if (! $patch instanceof JsonPatch) { + if (is_array($patch)) { $patch = new JsonPatch($patch); } @@ -645,9 +638,9 @@ public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty' /** * JSON Merge Patch (RFC 7396) the status subresource. */ - public function jsonMergePatchStatus(JsonMergePatch|array $patch, array $query = ['pretty' => 1]): self + public function jsonMergePatchStatus(JsonMergePatch|array $patch, array $query = ['pretty' => 1]): static { - if (! $patch instanceof JsonMergePatch) { + if (is_array($patch)) { $patch = new JsonMergePatch($patch); }