Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
579dfcf
Bump minikube to 1.32
cuppett Aug 31, 2023
185da25
Fix: Explicitly set docker driver
cuppett Aug 31, 2023
44c65d9
Fix: Cache key with wildcard never hits
cuppett Aug 31, 2023
c61f0d2
Bumps for Kubernetes 1.27, 1.28, 1.29
cuppett Aug 31, 2023
a33394d
Bump actions/checkout from 3 to 4
dependabot[bot] Sep 11, 2023
096256e
Node.js 16 actions are deprecated.
cuppett Mar 22, 2024
edd53e0
Bump to PHP 8.3
cuppett Dec 2, 2023
a7980e3
Bump Kubernetes to 1.30.0
cuppett May 5, 2024
3786c38
Bump to k8s 1.31.0
cuppett Aug 24, 2024
55cb4d4
Fix: Deprecated vierbergenlars/php-semver -> composer/semver
cuppett Aug 31, 2023
a595279
Bump various composer levels
cuppett Aug 24, 2024
36693b9
Upgrade codecov action to v5
cuppett Jun 21, 2025
7506bab
Update CI workflow to latest versions (#7)
cuppett Jun 21, 2025
78ecfbe
Update symfony/process requirement from ^6.0|^7.0 to ^7.3.0 (#6)
dependabot[bot] Jun 21, 2025
4080584
Update guzzlehttp/guzzle requirement from ^6.5|^7.0 to ^7.9.3 (#3)
dependabot[bot] Jun 21, 2025
e1af0f5
Nit: Removing ineffective line since PHP 8.1
cuppett Jun 21, 2025
7076c87
Refactor test container configurations to eliminate duplication
cuppett Jun 21, 2025
bf949d9
Replacing mysql:5.7 with mariadb:11.8
cuppett Jun 21, 2025
190e194
Fix PHP 8.4 deprecation warnings for implicitly nullable parameters
kasperhendriks Sep 25, 2025
7283a7a
Add Kubernetes server-side apply support (#9)
cuppett Jun 21, 2025
b2c0f4a
Add request timeouts (#21)
kasperhendriks Jul 22, 2025
f8e077c
Add JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) support
cuppett Dec 6, 2025
54954f2
Add EndpointSlice (discovery.k8s.io/v1) API support (#8)
cuppett Jun 21, 2025
3df6738
Add Kubernetes Gateway API (gateway.networking.k8s.io/v1) support (#10)
cuppett Jun 21, 2025
a6a979a
Add VolumeSnapshot support for Kubernetes volume snapshots (#15)
cuppett Jul 6, 2025
d592160
Add ReplicaSet resource implementation with scale support
cuppett Dec 6, 2025
167860d
Add core Kubernetes policy and scheduling resources
cuppett Oct 1, 2025
a716017
Fix spelling: Wether -> Whether in resource classes
cuppett Oct 4, 2025
f4b83ea
Add VerticalPodAutoscaler support with comprehensive testing
cuppett Dec 6, 2025
8328a41
Improve test reliability: WebSocket coverage, watch timeouts, resourc…
cuppett Dec 6, 2025
856bdd3
Update dependencies: guzzle, symfony/process, testbench, psalm
cuppett Dec 6, 2025
d937fb1
Update CI: increase timeouts, upgrade actions/checkout to v6
cuppett Dec 6, 2025
36a3687
Fix for maximum PHP compatibility
cuppett Dec 6, 2025
d59a7c0
Apply Laravel Pint code style fixes
cuppett Dec 6, 2025
e4a1aa6
Fix remaining StyleCI violations
cuppett Dec 6, 2025
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
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ updates:
interval: weekly
open-pull-requests-limit: 10
versioning-strategy: increase
ignore:
- dependency-name: "phpunit/phpunit"
update-types: ["version-update:semver-major"]
90 changes: 73 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,56 @@ jobs:

runs-on: ubuntu-latest

timeout-minutes: 15
timeout-minutes: 25

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.2', '8.3', '8.4']
kubernetes: ['1.32.9', '1.33.5', '1.34.1']
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.*"
# PHP 8.5 only for Laravel 12
- php: '8.5'
kubernetes: '1.32.9'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-lowest
- php: '8.5'
kubernetes: '1.32.9'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-stable
- php: '8.5'
kubernetes: '1.33.5'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-lowest
- php: '8.5'
kubernetes: '1.33.5'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-stable
- php: '8.5'
kubernetes: '1.34.1'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-lowest
- php: '8.5'
kubernetes: '1.34.1'
laravel: '12.*'
testbench: "10.*"
prefer: prefer-stable

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -48,19 +74,48 @@ 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.37.0
driver: docker
container-runtime: containerd
kubernetes-version: v${{ matrix.kubernetes }}

- name: Enable VolumeSnapshots, CSI hostpath driver, and metrics-server
run: |
minikube addons enable volumesnapshots
minikube addons enable csi-hostpath-driver
minikube addons enable metrics-server

- name: Install VPA (VerticalPodAutoscaler)
run: |
git clone https://github.com/kubernetes/autoscaler.git /tmp/autoscaler
cd /tmp/autoscaler/vertical-pod-autoscaler
./hack/vpa-up.sh

- name: Run Kubernetes Proxy
run: |
kubectl proxy --port=8080 --reject-paths="^/non-existent-path" &
Expand All @@ -81,11 +136,12 @@ jobs:
- name: Setting CRDs for testing
run: |
kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/bitnami.com_sealedsecrets.yaml
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml

- name: Run tests
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor
composer.phar
composer.lock
coverage.xml
.DS_Store
.idea/
.phpunit.result.cache
.phpunit.result.cache
98 changes: 98 additions & 0 deletions PATCH_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# JSON Patch Support

This library now supports both JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) operations for Kubernetes resources.

## JSON Patch (RFC 6902)

JSON Patch allows you to apply a series of operations to modify a resource. It supports the following operations:

- `add` - Add a value at a specific path
- `remove` - Remove a value at a specific path
- `replace` - Replace a value at a specific path
- `move` - Move a value from one path to another
- `copy` - Copy a value from one path to another
- `test` - Test that a value at a path matches the expected value

### Usage

```php
use RenokiCo\PhpK8s\Patches\JsonPatch;

// Create a JSON Patch
$patch = new JsonPatch();
$patch
->test('/metadata/name', 'my-deployment')
->replace('/spec/replicas', 5)
->add('/metadata/labels/environment', 'production')
->remove('/metadata/labels/temporary');

// Apply to a resource
$deployment->jsonPatch($patch);

// Or use array format directly
$patchArray = [
['op' => 'replace', 'path' => '/spec/replicas', 'value' => 3],
['op' => 'add', 'path' => '/metadata/labels/app', 'value' => 'web'],
];
$deployment->jsonPatch($patchArray);
```

## JSON Merge Patch (RFC 7396)

JSON Merge Patch provides a simpler way to modify resources by merging a patch object with the target resource.

### Usage

```php
use RenokiCo\PhpK8s\Patches\JsonMergePatch;

// Create a JSON Merge Patch
$patch = new JsonMergePatch();
$patch
->set('spec.replicas', 5)
->set('metadata.labels.version', 'v2.0')
->remove('metadata.labels.deprecated'); // Sets to null for removal

// Apply to a resource
$deployment->jsonMergePatch($patch);

// Or use array format directly
$patchArray = [
'spec' => ['replicas' => 3],
'metadata' => [
'labels' => [
'version' => 'v2.0',
'deprecated' => null // Remove this label
]
]
];
$deployment->jsonMergePatch($patchArray);
```

## When to Use Which

- **JSON Patch** is more precise and allows for atomic operations with validation (via `test` operations). Use it when you need exact control over the changes.

- **JSON Merge Patch** is simpler and more intuitive for straightforward updates. Use it when you want to merge changes into a resource.

## HTTP Content Types

The library automatically sets the correct Content-Type headers:

- JSON Patch: `application/json-patch+json`
- JSON Merge Patch: `application/merge-patch+json`

## Examples

See `examples/patch_examples.php` for comprehensive examples of both patching approaches.

## Supported Resources

Both patch methods are available on all Kubernetes resources that extend `K8sResource` and use the `RunsClusterOperations` trait, including:

- Deployments
- Pods
- Services
- ConfigMaps
- Secrets
- And all other standard Kubernetes resources
8 changes: 5 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.32.9 K8s Version](https://img.shields.io/badge/K8s%20v1.32.9-Ready-%23326ce5?colorA=306CE8&colorB=green)
![v1.33.5 K8s Version](https://img.shields.io/badge/K8s%20v1.33.5-Ready-%23326ce5?colorA=306CE8&colorB=green)
![v1.34.1 K8s Version](https://img.shields.io/badge/K8s%20v1.34.1-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 Expand Up @@ -49,3 +50,4 @@ If you discover any security related issues, please email alex@renoki.org instea

- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)

21 changes: 12 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.2",
"guzzlehttp/guzzle": "^7.10",
"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.4",
"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,11 @@
"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"
"laravel/pint": "dev-main",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0|^10.6.0",
"phpunit/phpunit": "^10.0|^11.5",
"vimeo/psalm": "^6.13.1"
},
"config": {
"sort-packages": true
Expand Down
Loading