pub struct K8sClient { /* private fields */ }Expand description
A namespaced kube client plus this process’s instance identity.
Implementations§
Source§impl K8sClient
impl K8sClient
Sourcepub async fn connect(namespace: impl Into<String>) -> Result<Self, K8sError>
pub async fn connect(namespace: impl Into<String>) -> Result<Self, K8sError>
Install the rustls CryptoProvider, connect a client from the
ambient config (in-cluster ServiceAccount or kubeconfig), and
scope it to namespace.
Sourcepub fn from_client(client: Client, namespace: String) -> Self
pub fn from_client(client: Client, namespace: String) -> Self
Wrap an already-constructed client (used by tests and callers that share a client across backends).
Sourcepub fn instance_id(&self) -> &str
pub fn instance_id(&self) -> &str
This process’s instance identity (fakecloud-<pid>), used for the
labels::INSTANCE label.
Sourcepub async fn create_pod(&self, pod: &Pod) -> Result<(), K8sError>
pub async fn create_pod(&self, pod: &Pod) -> Result<(), K8sError>
Create pod, first deleting any stale Pod with the same name left
behind by a previous process (which would otherwise make create
return 409 Conflict). Retries the create a few times while the
API server finishes deleting the old Pod.
Sourcepub async fn wait_for_pod_ip(
&self,
name: &str,
timeout: Duration,
) -> Result<String, K8sError>
pub async fn wait_for_pod_ip( &self, name: &str, timeout: Duration, ) -> Result<String, K8sError>
Poll until the Pod has a non-empty status.podIP and phase
Running, returning the IP. Errors if the Pod reaches a terminal
phase (Failed/Succeeded) during startup or if timeout
elapses first.
Sourcepub async fn wait_for_tcp(
ip: &str,
port: u16,
timeout: Duration,
) -> Result<(), K8sError>
pub async fn wait_for_tcp( ip: &str, port: u16, timeout: Duration, ) -> Result<(), K8sError>
TCP-handshake ip:port until it accepts a connection or timeout
elapses. A Pod being Running doesn’t guarantee the process
inside it is listening yet, so backends follow wait_for_pod_ip
with this.
Sourcepub async fn exec(
&self,
pod: &str,
container: Option<&str>,
cmd: &[&str],
) -> Result<ExecOutput, K8sError>
pub async fn exec( &self, pod: &str, container: Option<&str>, cmd: &[&str], ) -> Result<ExecOutput, K8sError>
Run cmd inside pod (in container, or the default container
when None) and collect stdout/stderr/exit-code. This is the k8s
equivalent of docker exec — used for operations like issuing
redis-cli commands or copying a file out of a Pod.
Sourcepub async fn exec_with_stdin(
&self,
pod: &str,
container: Option<&str>,
cmd: &[&str],
stdin: &[u8],
) -> Result<ExecOutput, K8sError>
pub async fn exec_with_stdin( &self, pod: &str, container: Option<&str>, cmd: &[&str], stdin: &[u8], ) -> Result<ExecOutput, K8sError>
Like exec but writes stdin to the command’s
standard input first (then closes it). Used for piping a SQL dump
into psql/mysql during a restore — the k8s equivalent of
docker exec -i ... < dump.
Sourcepub async fn pod_logs(
&self,
pod: &str,
container: Option<&str>,
) -> Result<String, K8sError>
pub async fn pod_logs( &self, pod: &str, container: Option<&str>, ) -> Result<String, K8sError>
Fetch a Pod container’s logs (the k8s equivalent of docker logs)
— used for log-marker readiness on engines that don’t expose a
connect-based probe (Oracle / SQL Server / Db2).
Sourcepub async fn delete_pod(&self, name: &str)
pub async fn delete_pod(&self, name: &str)
Delete a Pod by name. Idempotent — a 404 (already gone) is
treated as success; other errors are logged but not returned,
since teardown is best-effort.
Sourcepub async fn reap_stale(&self, service: &str) -> usize
pub async fn reap_stale(&self, service: &str) -> usize
Delete Pods of the given service left behind by a different
process. Lists Pods labelled with both labels::MANAGED_BY and
the service value, and deletes those whose labels::INSTANCE
differs from this process’s. Mirrors the Docker reaper so a
restart doesn’t leak the previous run’s Pods. Returns the count
reaped.
Sourcepub fn network_policies(&self) -> Api<NetworkPolicy>
pub fn network_policies(&self) -> Api<NetworkPolicy>
Namespaced NetworkPolicy API handle.
Sourcepub async fn apply_network_policy(&self, np: &NetworkPolicy)
pub async fn apply_network_policy(&self, np: &NetworkPolicy)
Create or replace a NetworkPolicy (delete-then-create, like
create_pod, so a re-apply with changed rules
always lands). Best-effort: errors are logged, not propagated, since a
failed policy apply must never fail the originating EC2 API call.
Sourcepub async fn prune_network_policies(&self, keep: &HashSet<String>)
pub async fn prune_network_policies(&self, keep: &HashSet<String>)
Delete every NetworkPolicy owned by this process (managed-by + this
instance label) whose name is not in keep. Prunes policies for
instances that have since terminated. Best-effort.
Sourcepub async fn cni_component_names(&self) -> Vec<String>
pub async fn cni_component_names(&self) -> Vec<String>
Best-effort detection of the cluster CNI from Pod names across the
namespaces CNIs commonly install into (e.g. calico-node-*, cilium-*,
kindnet-*). Returns the matched component names; the caller maps them
to a driver. An empty result (lists failed or no recognizable CNI) maps
to “unknown”.
Scans kube-system plus the operator namespaces Calico/Cilium use
(calico-system, tigera-operator, cilium) so a Tigera-operator or
dedicated-namespace install isn’t mis-reported as non-enforcing
(bug-hunt 2026-06-18 finding 1.6). Per-namespace list errors (RBAC /
absent namespace) are swallowed.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for K8sClient
impl !UnwindSafe for K8sClient
impl Freeze for K8sClient
impl Send for K8sClient
impl Sync for K8sClient
impl Unpin for K8sClient
impl UnsafeUnpin for K8sClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more