All packages
Kubernetes API for Laravel
Error handling
Failed requests throw RoundlyConsulting\KubernetesApi\Exceptions\KubernetesException, which extends Laravel’s RequestException and carries the underlying Response so you can inspect the Kubernetes API error:
use RoundlyConsulting\KubernetesApi\Exceptions\KubernetesException;
try {
$cluster->deployments()
->setNamespace('shop')
->withName('checkout')
->find()
->setReplicas(5)
->update();
} catch (KubernetesException $e) {
$e->response->status(); // e.g. 404 or 409
$e->response->json('message'); // the Kubernetes error message
$e->response->json('reason'); // e.g. 'NotFound', 'Conflict'
$e->getMessage(); // the same message as the exception text
}Every exception
| Exception | Thrown when | Carries |
|---|---|---|
KubernetesException | The apiserver answers with a 4xx or 5xx. | ->response (the Laravel Response); the message is the apiserver’s. |
RateLimitExceededException | A request would wait longer than rate_limits.max_wait. | ->cluster (the registered cluster name, or the apiserver host for an ad-hoc client) and retryAfterSeconds(). |
KubeConfigException | fromKubeConfig() or inCluster() cannot load credentials — including a missing in-cluster CA certificate or an insecure-skip-tls-verify that isn’t a boolean. | A message naming what is missing or invalid. |
WebSocketException | exec() cannot connect or the WebSocket upgrade fails. | The connection or upgrade error. |
ClusterNotFoundException | cluster($name) gets a name that is neither configured nor registered. | The unknown cluster name. |
ClusterConfigurationException | A cluster has no URL, a definition closure returns no Cluster, a config source is unknown, a cluster or client setting is malformed or out of range, or a resource is used without a cluster. | Which cluster, config key or resource is misconfigured. |
NamespaceScopeException | A namespace-scoped client or resource is asked to leave its namespace. | ->scope (the pinned namespace). |
InvalidResourceException | registerResource() or the fake’s seed() gets a class that is not a resource or an unusable name, the resources config isn’t an array or names a non-resource class, or a request’s name, namespace, plural or apiVersion can’t be a single URL path segment (nothing is sent). | The offending class or name. |
InvalidConfigurationException | A rate_limits key or traefik.group is invalid — an unrecognised switch, a non-integer or out-of-range number, an unknown timespan or a non-string value. It comes from package-toolkit-for-laravel. | A message naming the key and the value given. |
A 404 from find() is the usual signal to create — existsOnCluster() and updateOrCreate() already handle it for you. A 409 from update() or updateOrCreate() means the object changed since you read it: re-read and retry.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.