Skip to content

Sync upstream changes from cuppett/php-k8s#14

Merged
ChiragAgg5k merged 7 commits intomainfrom
sync/upstream-main
Mar 5, 2026
Merged

Sync upstream changes from cuppett/php-k8s#14
ChiragAgg5k merged 7 commits intomainfrom
sync/upstream-main

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

Sync upstream changes from cuppett/php-k8s to bring in the latest features and fixes.

Changes included from upstream:

  1. Add HasFinalizers trait (6fb8a72) - Operator finalizer management support
  2. Add HasOwnerReferences trait (d1a76d4) - Resource hierarchy management
  3. Add Lease resource (e3bd7ef) - coordination.k8s.io/v1 for leader election
  4. Add status subresource support (45caa96) - updateStatus, jsonPatchStatus, jsonMergePatchStatus methods
  5. Fix integration tests (f23883d) - for operator enablement features
  6. Add comprehensive documentation (863e1de) - for operator enablement features
  7. Fix test failures (d23c5ae) - skip in-cluster test and remove invalid addWarning() call

Type of change

  • Feature
  • Documentation

Checklist

  • I have read CONTRIBUTING.md and AGENTS.md.
  • Unit tests added/updated where appropriate. (Included from upstream)
  • vendor/bin/phpunit passes locally (unit suite at minimum).
  • vendor/bin/psalm passes locally.
  • Backwards compatible (no breaking public API changes) or clearly documented.
  • Documentation updated (README.md and/or docs/), including examples if needed.
  • Changes are minimal and scoped (one concern per PR).
  • No tests depend on external secrets or network beyond the documented integration setup.

Integration tests (if applicable)

  • Tested against a local K8s (e.g., Minikube) with addons and CRDs installed, as outlined in AGENTS.md.
    • Kubernetes version:
    • PHP version:
    • Laravel/Testbench versions:

Breaking changes

None. All changes are additive and backwards compatible.

Notes for reviewers

This is a straightforward upstream sync. All commits have been reviewed and merged upstream at cuppett/php-k8s. The changes add operator-focused features including:

  • Finalizers support for resource cleanup
  • OwnerReferences for resource ownership tracking
  • Lease resource for distributed leader election
  • Status subresource operations for controllers

All tests and documentation are included from the upstream commits.

cuppett and others added 7 commits February 27, 2026 14:26
Implements finalizer support for all K8sResource instances:
- HasFinalizers trait with getFinalizers(), setFinalizers(), addFinalizer(),
  removeFinalizer(), and hasFinalizer() methods
- Added trait to K8sResource base class
- Unit tests for all finalizer operations
- Integration test demonstrating finalizer-based deletion workflow
- YAML fixture for testing ConfigMap with finalizer

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Implements owner reference support for all K8sResource instances:
- HasOwnerReferences trait with getOwnerReferences(), setOwnerReferences(),
  addOwnerReference(), removeOwnerReference(), hasOwnerReference(), and
  getControllerOwner() methods
- Added trait to K8sResource base class
- Owner references are idempotent (matched by UID)
- Support for controller and blockOwnerDeletion flags
- Unit tests for all owner reference operations
- Integration test demonstrating parent-child relationship persistence

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Implements full Lease resource support:
- K8sLease class with coordination.k8s.io/v1 API version
- HasSpec trait for spec management
- Implements InteractsWithK8sCluster and Watchable contracts
- Spec accessors: setHolderIdentity(), setLeaseDurationSeconds(),
  setAcquireTime(), setRenewTime(), getLeaseTransitions()
- Factory method in InitializesResources trait
- PHPDoc annotations in KubernetesCluster for IDE support
- Full test suite including build, YAML parsing, and API interaction tests
- YAML fixture for testing

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
…rgePatchStatus)

Implements status subresource operations for all resources:
- Modified HasStatus trait to add setStatus(), setStatusData(), and
  getStatusData() methods for local status manipulation
- Added resourceStatusPath() to construct /status subresource path
- Added updateStatus() for PUT operations to /status
- Added jsonPatchStatus() for JSON Patch (RFC 6902) operations
- Added jsonMergePatchStatus() for JSON Merge Patch (RFC 7396) operations
- All status methods reuse existing Operation enum values
- Unit tests for path construction and local status manipulation
- Integration test demonstrating status update API calls

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Fixes for all integration tests:
- Finalizer test: Use jsonMergePatch to remove finalizer during deletion
  (can't use update() on resources being deleted), add cleanup for
  leftover resources from previous runs
- Status test: Handle expected controller conflicts gracefully, wait for
  controller to initialize before patching
- Status patch methods: Fix to properly convert patch to JSON and handle
  runOperation return value by calling toArray() before syncWith()

All 25 integration tests now pass against live Kubernetes cluster.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Documentation for all four operator/controller features:

**Usage Guides (new section: Operators & Controllers):**
- Finalizers: Complete guide with operator patterns, best practices, cleanup
  examples, resource dependency management, and timeout protection
- Owner References: Parent-child relationships, controller ownership, garbage
  collection, multi-level ownership, reconciliation loops
- Status Updates: Status subresource operations, controller patterns, condition
  management, conflict handling, progressive updates

**Resource Documentation:**
- Lease: Leader election patterns, distributed locking, HA controllers,
  complete LeaderElection class example with acquire/renew logic

**Sidebar Updates:**
- Added "Operators & Controllers" section under Usage guide
- Added Lease to Cluster Resources section

All documentation includes:
- Comprehensive code examples with real-world use cases
- Best practices and common pitfalls
- Operator pattern implementations
- Attribution footer for fork

Documentation verified to build successfully with VitePress.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
…() call

Fixes two test failures that were not related to operator enablement:

1. KubeConfigTest::test_in_cluster_config - Skip test when not running in a
   Kubernetes cluster (service account files don't exist in local test env)

2. VerticalPodAutoscalerIntegrationTest::test_vpa_lifecycle_with_deployment -
   Remove call to addWarning() which doesn't exist in PHPUnit 11.x (replaced
   with comment noting the non-critical condition)

Both tests now pass successfully.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
@ChiragAgg5k ChiragAgg5k merged commit c93c003 into main Mar 5, 2026
42 checks passed
@ChiragAgg5k ChiragAgg5k deleted the sync/upstream-main branch March 5, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants