Skip to content

K8sHttpClient

HTTP client support for talking to the Kubernetes API from code running inside a cluster. The module builds a K8sHttpClient service on top of the shared HTTP client, points requests at the in-cluster API endpoint, and uses the mounted service-account token when one is available.

6 exports Added in v4.0.0 Source

Constructors

Creates a scoped function that ensures a Kubernetes pod exists and waits until it is ready.

Details

The pod defaults to the default namespace and is deleted when the surrounding scope closes.

Signature

declare const makeCreatePod: Effect<(...args: [spec: Pod]) => Effect, never, K8sHttpClient>;

makeGetPods

Added in v4.0.0 Source

Creates a cached effect that fetches running Kubernetes pods.

Details

The request can be limited by namespace and label selector, and the result is a map keyed by pod IP address.

Signature

declare const makeGetPods: (options?: {
  readonly labelSelector?: string;
  readonly namespace?: string;
}) => Effect.Effect<
  Effect.Effect<Map<string, Pod>, HttpClientError.HttpClientError | Schema.SchemaError, never>,
  never,
  K8sHttpClient
>;

Layers

layer

Added in v4.0.0 Source

Layer that configures K8sHttpClient for the in-cluster Kubernetes API.

Details

It targets https://kubernetes.default.svc/api, adds the service-account bearer token when available, requires successful HTTP statuses, and retries transient failures.

Signature

declare const layer: Layer.Layer<
  K8sHttpClient,
  never,
  HttpClient.HttpClient | FileSystem.FileSystem
>;

Schemas

Pod

Added in v4.0.0 Source

Schema for Kubernetes Pod values used by cluster helpers.

Details

The model exposes readiness helpers derived from the pod status conditions.

Signature

declare class Pod extends {
  readonly status: PodStatus;
} {
  constructor(...args: [props: {
    readonly status: PodStatus;
  }, options?: MakeOptions]);
  isReady: boolean;
  isReadyOrInitializing: boolean;
}

PodStatus

Added in v4.0.0 Source

Schema for the subset of Kubernetes Pod status used by cluster helpers.

Signature

declare class PodStatus extends {
  readonly conditions: readonly Array<{
    readonly lastTransitionTime: string | null;
    readonly status: string;
    readonly type: string;
  }>;
  readonly hostIP: string;
  readonly phase: string;
  readonly podIP: string;
} {
  constructor(...args: [props: {
    readonly conditions: readonly Array<{
      readonly lastTransitionTime: string | null;
      readonly status: string;
      readonly type: string;
    }>;
    readonly hostIP: string;
    readonly phase: string;
    readonly podIP: string;
  }, options?: MakeOptions]);
}

Services

Service tag for the HTTP client used to call the Kubernetes API.

Signature

declare class K8sHttpClient extends Shape<"effect/cluster/K8sHttpClient", HttpClient, this> {
  constructor(_: never);
}