runtime_operator

package module
v2.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Runtime Operator

NATS authentication

The operator and its hosts share one NATS control plane. On a NATS that requires authentication, the operator presents one of:

Flag Credential
-nats-creds a .creds file (user JWT and nkey seed)
-nats-nkey a file holding an nkey seed
-nats-token-file a file holding a token
-nats-user, -nats-password-file a user name, and a file holding its password

The operator refuses to start with more than one of these, and requires -nats-user and -nats-password-file together. The NATS client would send every credential it is given, and the server authenticates with only one.

Credentials, token, and password files are reread on every connect. When the server rejects the operator's credential, as when the server rotates a token before the kubelet refreshes the mounted Secret, the operator keeps reconnecting with whatever the file holds until the server accepts it. If the server is still refusing it after -nats-auth-failure-grace (five minutes by default, longer than the kubelet takes to refresh a Secret), liveness fails so Kubernetes restarts the operator and the refusal shows. Token and password files may end with one LF or CRLF line ending, which is removed. All other whitespace is preserved. Restart the operator after replacing a bare nkey seed: the NATS client caches its public key when building the connection options. Repeated auth rejections close a bare-nkey connection and fail liveness so Kubernetes can restart the operator with the new key. -nats-name sets the connection name, runtime-operator by default.

Helm Secret mounts

Set operator.volumes and operator.volumeMounts to mount an existing Kubernetes Secret, then pass the matching file flag in operator.extraArgs. For a Secret named operator-nats-auth with a token key:

operator:
  extraArgs:
    - "-nats-token-file=/nats-auth/token"
  volumes:
    - name: nats-auth
      secret:
        secretName: operator-nats-auth
  volumeMounts:
    - name: nats-auth
      mountPath: /nats-auth
      readOnly: true

Mount the Secret directory without subPath so Kubernetes can refresh its files. These mounts work with global.tls.enabled set to either value and coexist with the chart's TLS certificate mount. The Secret must exist in the operator's release namespace. Hosts need their own NATS credentials.

Host NATS authentication

Hosts authenticate their scheduler and data connections separately, with the same choice of one credential per connection:

Flag (scheduler or data) Credential
--<plane>-nats-creds a .creds file (user JWT and nkey seed)
--<plane>-nats-nkey a file holding an nkey seed
--<plane>-nats-token-file a file holding a token
--<plane>-nats-user, --<plane>-nats-password-file a user name, and a file holding its password

Each flag also reads WASH_<PLANE>_NATS_<NAME>, such as WASH_SCHEDULER_NATS_CREDS. Files are reread on every reconnect, and token and password files lose one LF or CRLF line ending. While a file stalls, fails to read, or does not parse, the host presents the last contents that parsed.

--<plane>-nats-jwt-as-token sends a .creds file's user JWT a second time, as the token. A NATS server without trusted operators drops the JWT before an auth callout sees it, so a callout that authorizes by JWT reads this copy.

Give each connection its own credential, so the data connection can be denied the control subjects under Permissions. Mount the Secret on a host group and pass the flags in its extraArgs. The Secret must exist in the host group's namespace:

runtime:
  hostGroups:
    - name: default
      extraArgs:
        - "--scheduler-nats-creds=/nats-auth/scheduler.creds"
        - "--data-nats-creds=/nats-auth/data.creds"
      volumes:
        - name: nats-auth
          secret:
            secretName: host-nats-auth
      volumeMounts:
        - name: nats-auth
          mountPath: /nats-auth
          readOnly: true

The host refuses workload volumes that expose these files.

Permissions

<id> is a host's id. A heartbeat's payload ID must match its subject's ID. An existing Host name cannot be claimed by a different ID; remove the old Host before reusing its name with a new ID. These checks rely on NATS permissions restricting each host to its own heartbeat subject.

The operator's replies arrive on its inbox prefix, _INBOX unless -nats-inbox-prefix sets another.

Client Publish Subscribe
Operator runtime.host.> runtime.operator.heartbeat.>, <inbox-prefix>.>
Host, scheduler connection runtime.host.<id>.__control.ready, runtime.operator.heartbeat.<id>, and replies (allow_responses with max: 1, or <inbox-prefix>.>) runtime.host.<id>.>

A host's scheduler connection must also receive its own messages, which is the NATS default. Its data connection carries workload traffic and needs none of the subjects above; deny it runtime.>.

Any client that may subscribe to _INBOX.> can read the replies hosts send the operator, and any client that may publish there can forge one. On a NATS shared with other clients, set -nats-inbox-prefix to a subject only the operator may subscribe to, such as runtime.operator.inbox, and allow hosts to reply there or by allow_responses.

Set wash host --host-id <id> or WASH_HOST_ID to match a credential's permitted host ID. IDs must contain 1–128 ASCII letters, digits, _ or - and must be unique among running hosts. The default remains a random UUID chosen at startup, which needs a credential issued for that ID. With one credential per host group, use * for <id>: those hosts can then read each other's commands and publish each other's heartbeats, though only the operator can send commands.

Logging

The operator and the gateway both configure Go's log/slog and controller-runtime's logr bridge through pkg/logging, so they accept the same flags. Logs go to stderr. Development mode defaults to text output, debug logging (controller verbosity 1), RFC3339 timestamps, and stack traces at warn and above. Use --dev-mode=false for JSON output, info logging, and stack traces at error and above. Text output uses slog's key=value format; JSON keeps ts, level, msg, logger, error, and stacktrace fields. User fields named time keep their name. Production logging is unsampled.

Kubernetes object pointers, passed directly or through logr.Marshaler, are logged as identity in every mode, including the default Helm deployment. Full contents, including Secret data, require an explicit --log-full-objects flag. Objects passed by value, or nested in slices, maps, or other structs, are not redacted.

Flag Values
--log-full-objects Include full Kubernetes objects; defaults to false
--log-format text, json
--log-level debug, info, warn, error, panic, or verbosity 1–127
--log-stacktrace-level info, warn, error, panic
--log-time-encoding epoch, millis, nanos, iso8601, rfc3339, rfc3339nano

Explicit logging flags override mode defaults regardless of argument order. --json-log overrides format and timestamp flags with JSON and numeric epoch seconds. The existing --zap-devel, --zap-encoder, --zap-log-level, --zap-stacktrace-level, and --zap-time-encoding flags remain aliases; --zap-encoder=console selects text output. If an alias and its new flag both appear, the last one wins. panic sets a threshold above error; logging does not itself panic. Controller records include a numeric v field. Standard library HTTP server diagnostics are logged at error without application stack traces. Application stack traces start at the log call. In text output a stack trace is a single escaped stacktrace="…\n\t…" value.

Development

You will need a local Kind cluster, NATS, and a Wash host.

For NATS, use:

docker run --rm --name wasmcloud-nats -p 4222:4222 nats -js

For Wash Host, use:

wash host --http-addr 127.0.0.1:8000

or from the top git directory:

cargo run -- host --http-addr 127.0.0.1:8000

For local kind cluster, refer to wash/README.md.

Install the CRDs into the cluster:

make install

Run the Builder / Watcher:

make devlog

You can apply development samples from the config/sample:

kubectl apply -f config/samples

Verify the Wash Host registered correctly with:

kubectl get host

Example:

❯ kubectl get host
NAME               HOSTID                                 HOSTGROUP   READY   AGE
exotic-toes-5866   14b0a1df-3f91-441c-b304-2aa56e9bef6e   default     True    52s

If you applied the samples, check if they deployed correctly:

❯ kubectl get workloaddeployment
NAME     REPLICAS   READY
blobby   1          True
hello    1          True

❯ curl -i hello.localhost.direct:8000
HTTP/1.1 200 OK
transfer-encoding: chunked
date: Tue, 25 Nov 2025 15:30:32 GMT

Hello from Rust!

Documentation

Index

Constants

View Source
const DefaultHeartbeatTTL = 60 * time.Second

DefaultHeartbeatTTL is how long a host may go unheard-from before it is considered unreachable: four missed heartbeats at the host's 15s interval.

View Source
const MinHeartbeatTTL = 30 * time.Second

MinHeartbeatTTL is the shortest TTL the operator honours. Hosts publish every 15s, so under two intervals a live fleet reads as unheard between ticks and no host is ever reaped.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbeddedOperator

type EmbeddedOperator struct {
	Bus      wasmbus.Bus
	NatsConn *nats.Conn
}

EmbeddedOperator is the main struct for the embedded operator. It allows embedding the Runtime Operator into other applications.

func NewEmbeddedOperator

func NewEmbeddedOperator(
	ctx context.Context,
	mgr manager.Manager,
	cfg EmbeddedOperatorConfig,
) (_ *EmbeddedOperator, err error)

NewEmbeddedOperator creates a new EmbeddedOperator.

type EmbeddedOperatorConfig

type EmbeddedOperatorConfig struct {
	// NATS connection string. Used to communicate with hosts.
	NatsURL string
	// NATS options. Used to configure the NATS connection.
	NatsOptions []nats.Option
	// Heartbeat TTL. Used to determine how long to wait before considering a
	// host unreachable. Unset means DefaultHeartbeatTTL; anything under
	// MinHeartbeatTTL is raised to it.
	HeartbeatTTL time.Duration
	// ReadyRequeueInterval overrides periodic polling for healthy workload
	// Deployments, ReplicaSets, and Workloads. Zero uses their defaults.
	ReadyRequeueInterval time.Duration
	// Host CPU threshold (percentage).
	// Used to calculate workload scheduling, avoiding hosts that are over this threshold.
	HostCPUThreshold float64
	// Host Memory threshold (percentage).
	// Used to calculate workload scheduling, avoiding hosts that are over this threshold.
	HostMemoryThreshold float64
	// Disable Artifact Controller. If set, Artifacts must be marked as 'Ready' elsewhere.
	// Useful when introducing a custom artifact management solution.
	DisableArtifactController bool
	// Namespace is the namespace the operator itself runs in. Every Host
	// CRD is created here regardless of where the underlying host pod
	// runs; tenant attribution is carried on the Host's Environment
	// field.
	Namespace string
	// HostNamespaces is the list of namespaces where host Pods run. The
	// operator's Pod informer cache and per-namespace Pod RBAC cover this
	// set so HostPodReconciler can manage finalizers on host Pods.
	HostNamespaces []string
	// AllowSharedHosts controls whether a WorkloadDeployment may schedule
	// onto a Host whose Environment differs from the workload's own
	// namespace (via WorkloadSpec.Environment). Default (true) preserves
	// legacy Cluster-scope scheduling semantics: with Environment unset
	// the scheduler imposes no Environment filter. When false, scheduling
	// is locked to the workload's own namespace and any non-matching
	// Environment is rejected with a Warning Event.
	AllowSharedHosts bool
}

Directories

Path Synopsis
api
condition
+kubebuilder:object:generate=true +kubebuilder:unservedversion
+kubebuilder:object:generate=true +kubebuilder:unservedversion
runtime/v1alpha1
Package v1alpha1 contains API Schema definitions for the runtime v1alpha1 API group.
Package v1alpha1 contains API Schema definitions for the runtime v1alpha1 API group.
internal
pkg
logging
Package logging configures log/slog, the standard log package, and controller-runtime's logr bridge from one set of command-line flags.
Package logging configures log/slog, the standard log package, and controller-runtime's logr bridge from one set of command-line flags.
natsclient
Package natsclient configures how a NATS client identifies itself from command-line flags, and reports when its connection cannot recover.
Package natsclient configures how a NATS client identifies itself from command-line flags, and reports when its connection cannot recover.
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL