Skip to content

[codex] Add container restart policy accessors#21

Merged
ChiragAgg5k merged 2 commits intomainfrom
codex/container-restart-policy
Apr 2, 2026
Merged

[codex] Add container restart policy accessors#21
ChiragAgg5k merged 2 commits intomainfrom
codex/container-restart-policy

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

Add a real restartPolicy API to Instances\Container so container-level restart policy can be expressed without relying on magic attribute setters.

What Changed

  • added Container::setRestartPolicy(RestartPolicy|string $policy): static
  • added Container::getRestartPolicy(): ?RestartPolicy
  • added a unit-test assertion in tests/ContainerTest.php covering restart policy round-tripping

Why

K8sPod already exposes a typed restart policy API, but Instances\Container did not. That gap forced downstream code to set the raw attribute directly even though restart policy is part of the container spec used by newer Kubernetes sidecar semantics.

This makes the container API explicit and typed, which also lets downstream projects remove local static-analysis workarounds.

Validation

Validation was not run locally in this checkout because /Users/chiragaggarwal/Desktop/appwrite/php-k8s/vendor is not installed yet.

Planned checks once dependencies are installed:

  • ./vendor/bin/pint --test src/Instances/Container.php tests/ContainerTest.php
  • vendor/bin/phpunit tests/ContainerTest.php

@ChiragAgg5k ChiragAgg5k marked this pull request as ready for review April 2, 2026 05:16
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 2, 2026

Greptile Summary

This PR adds typed setRestartPolicy / getRestartPolicy accessors to Instances\Container, closing a gap between K8sPod's existing restart-policy API and the container-level API needed for Kubernetes sidecar semantics. The implementation stores the policy as a raw string (consistent with other attribute-backed methods in the class) and uses RestartPolicy::tryFrom() for safe round-tripping back to the enum.

  • setRestartPolicy(RestartPolicy|string) normalises both union-type inputs to the backing string before storing, matching the pattern used elsewhere in the codebase.
  • getRestartPolicy() guards the null case before calling tryFrom, returning null for both unset and unrecognised string values — correct for the ?RestartPolicy return type.
  • The test additions cover the three meaningful paths: getter returns null when the attribute is absent, enum value round-trips correctly, and a raw 'Never' string round-trips to RestartPolicy::NEVER.

Confidence Score: 5/5

Safe to merge — the implementation is correct, prior review concerns have been fully addressed, and test coverage is thorough.

Both previously flagged issues (from vs tryFrom risk, and missing null/string-path test cases) are resolved in this revision. The implementation follows existing codebase patterns, doc comments end with periods per project style, and no new issues were introduced.

No files require special attention.

Important Files Changed

Filename Overview
src/Instances/Container.php Adds setRestartPolicy/getRestartPolicy accessors; correctly uses RestartPolicy::tryFrom() for safe enum conversion, consistent with existing method patterns in the class.
tests/ContainerTest.php Adds null-baseline assertion, enum round-trip, and string round-trip for the new restart policy accessors — covers all three meaningful code paths.

Reviews (2): Last reviewed commit: "Handle restart policy edge cases" | Re-trigger Greptile

Comment thread src/Instances/Container.php Outdated
Comment thread tests/ContainerTest.php
@ChiragAgg5k ChiragAgg5k merged commit 0ba9261 into main Apr 2, 2026
4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/container-restart-policy branch April 2, 2026 05:27
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.

1 participant