Skip to main content

ServiceInstance

Struct ServiceInstance 

Source
pub struct ServiceInstance {
    pub service_name: String,
    pub spec: ServiceSpec,
    /* private fields */
}
Expand description

Service instance manages a single service’s containers

Fields§

§service_name: String§spec: ServiceSpec

Implementations§

Source§

impl ServiceInstance

Source

pub fn new( service_name: String, spec: ServiceSpec, runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Option<Arc<RwLock<OverlayManager>>>, ) -> Self

Create a new service instance

Source

pub fn with_proxy( service_name: String, spec: ServiceSpec, runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Option<Arc<RwLock<OverlayManager>>>, proxy_manager: Arc<ProxyManager>, ) -> Self

Create a new service instance with proxy manager for health-aware load balancing

Source

pub fn set_node_id(&mut self, node_id: u64)

Set the local cluster node id. Used by ServiceManager to thread Cluster::node_id() down to container construction so new ContainerIds carry the owning node identity. Defaults to 0 (the single-node sentinel) when unset.

Source

pub fn set_deployment(&mut self, deployment: Option<String>)

Set the owning deployment name for service-discovery DNS scoping.

Idempotent with construction: the constructors already capture spec.deployment, but ServiceManager calls this so a deployment stamped after the fact (or via a different code path) is honored.

Source

pub fn set_ingress_enabled(&mut self, enabled: bool)

Set whether THIS node holds the standing HTTP/HTTPS ingress (mirrors NodeConfig.ingress). Threaded by ServiceManager so external service domains can be resolved to this node’s overlay IP when it is the funnel.

Source

pub fn set_cluster(&mut self, cluster: Arc<dyn Cluster>)

Set the cluster handle used to select an ingress-capable peer’s overlay IP when THIS node is not itself the ingress.

Source

pub fn dns_search_domain(&self, zone: &str) -> Option<String>

The per-deployment resolv.conf search domain list for containers in this service’s deployment, given the daemon’s global DNS zone (e.g. zlayer.local).

Returns a space-separated search value placing the deployment scope FIRST so a guest’s bare <svc> / <svc>.service query expands to THIS deployment’s record before anything else, with the bare zone last so cross-deployment by-FQDN names (<svc>.<otherdeployment>) still resolve:

search <deployment>.<zone> <zone>

When this instance has no deployment (standalone / single-deployment), returns None so callers fall back to the daemon’s global zone domain.

Source

pub fn role_for_replica(&self, replica_idx: u32) -> String

Derive the replica group role for a 1-based replica_idx.

When spec.replica_groups is unset, returns "default" (the implicit single-group case). Otherwise walks groups in declaration order, accumulating each group’s count until replica_idx falls within the current group’s range, and returns that group’s role.

Replicas beyond the declared total fall back to "default".

Source

pub fn with_dns(self, dns_server: Arc<DnsServer>) -> Self

Builder method to add DNS server for service discovery

Source

pub fn set_dns_server(&mut self, dns_server: Arc<DnsServer>)

Set the DNS server for service discovery

Source

pub fn set_container_dns(&mut self, container_dns: IpAddr)

Set the container-injectable overlay resolver IP and apply it to the instance’s spec.

When container_dns is set and the spec is eligible (not host-network, no user-supplied dns), this pre-populates spec.dns with the overlay resolver so containers resolve through <ip>:53 instead of inheriting the host’s /etc/resolv.conf.

Why this exists: on overlay-enabled hosts the netbird ~. systemd-resolved hijack swallows the host resolver, so a container that inherits the host resolv.conf cannot resolve anything. The overlay DNS server forwards non-overlay queries upstream, so pointing the container at it fixes resolution AND gives it service-name discovery.

Port-53 constraint: resolv.conf nameserver lines (and Docker’s --dns) carry no port — they are always port 53. The injected IP is therefore only useful because the daemon binds the overlay resolver on <ip>:53 (see daemon.rs Phase 4); the injected value is the bare IP, not a host:port.

User-supplied spec.dns is left untouched: an explicit resolver from the deployment spec always wins.

Source

pub fn set_proxy_manager(&mut self, proxy_manager: Arc<ProxyManager>)

Set the proxy manager for health-aware load balancing

Source

pub fn set_health_states( &mut self, states: Arc<RwLock<HashMap<String, HealthState>>>, )

Set the shared health states map so health callbacks can bridge state back to ServiceManager

Source

pub async fn last_pulled_digest(&self) -> Option<String>

Get the last observed image digest (after the most recent successful pull). Returns None when no pull has happened yet, when the runtime does not expose digests, or when no matching ImageInfo was found.

Source

pub async fn scale_to(&self, replicas: u32) -> Result<()>

Scale to the desired number of replicas

This method uses short-lived locks to avoid blocking concurrent operations. I/O operations (pull, create, start, stop, remove) are performed without holding the containers lock to allow other operations to proceed.

§Errors

Returns an error if image pull, container creation, or container lifecycle operations fail.

Source

pub async fn replica_count(&self) -> usize

Get current number of replicas

Source

pub async fn container_ids(&self) -> Vec<ContainerId>

Get all container IDs

Source

pub async fn container_infos(&self) -> Vec<ContainerInfo>

Get per-container info (id, image, state, pid, overlay IP) for every live container in this instance.

Surfaces the REAL image reference each container was created from and its REAL lifecycle state (lowercased via ContainerState::as_str) so the API/ps no longer reports a hardcoded "running" with no image.

Source

pub fn containers(&self) -> &RwLock<HashMap<ContainerId, Container>>

Get read access to the containers map

This allows callers to access container overlay IPs and other metadata without copying the entire map.

Source

pub fn has_overlay_manager(&self) -> bool

Check if this service instance has an overlay manager configured

Source

pub fn has_proxy_manager(&self) -> bool

Check if this service instance has a proxy manager configured

Source

pub fn proxy_manager(&self) -> Option<&Arc<ProxyManager>>

Get the proxy manager for this instance, if configured.

Source

pub fn has_dns_server(&self) -> bool

Check if this service instance has a DNS server configured

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> OptionalSend for T
where T: Send + ?Sized,

Source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ServiceExt for T

Source§

fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>
where Self: Sized,

Propagate a header from the request to the response. Read more
Source§

fn add_extension<T>(self, value: T) -> AddExtension<Self, T>
where Self: Sized,

Add some shareable value to request extensions. Read more
Source§

fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>
where Self: Sized,

Apply a transformation to the request body. Read more
Source§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
Source§

fn compression(self) -> Compression<Self>
where Self: Sized,

Compresses response bodies. Read more
Source§

fn decompression(self) -> Decompression<Self>
where Self: Sized,

Decompress response bodies. Read more
Source§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
Source§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
Source§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

fn sensitive_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>
where Self: Sized,

Mark headers as sensitive on both requests and responses. Read more
Source§

fn sensitive_request_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<Self>
where Self: Sized,

Mark headers as sensitive on requests. Read more
Source§

fn sensitive_response_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveResponseHeaders<Self>
where Self: Sized,

Mark headers as sensitive on responses. Read more
Source§

fn override_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request. Read more
Source§

fn append_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Append a header into the request. Read more
Source§

fn insert_request_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request, if the header is not already present. Read more
Source§

fn override_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response. Read more
Source§

fn append_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Append a header into the response. Read more
Source§

fn insert_response_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response, if the header is not already present. Read more
Source§

fn set_request_id<M>( self, header_name: HeaderName, make_request_id: M, ) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension. Read more
Source§

fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension, using x-request-id as the header name. Read more
Source§

fn propagate_request_id( self, header_name: HeaderName, ) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses. Read more
Source§

fn propagate_x_request_id(self) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses, using x-request-id as the header name. Read more
Source§

fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>
where Self: Sized,

Catch panics and convert them into 500 Internal Server responses. Read more
Source§

fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>
where Self: Sized,

Intercept requests with over-sized payloads and convert them into 413 Payload Too Large responses. Read more
Source§

fn trim_trailing_slash(self) -> NormalizePath<Self>
where Self: Sized,

Remove trailing slashes from paths. Read more
Source§

fn append_trailing_slash(self) -> NormalizePath<Self>
where Self: Sized,

Append trailing slash to paths. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more