@kici-dev/orchestrator 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +1 -6
- package/dist/__test-helpers__/mock-db.d.ts +103 -0
- package/dist/__test-helpers__/mock-ws.d.ts +13 -0
- package/dist/agent/dispatcher.d.ts +231 -0
- package/dist/agent/ownership-tracker.d.ts +46 -0
- package/dist/agent/registry.d.ts +255 -0
- package/dist/agent/token-store.d.ts +96 -0
- package/dist/app.d.ts +234 -0
- package/dist/audit/access-log.d.ts +92 -0
- package/dist/audit/sampling-rate-limiter.d.ts +41 -0
- package/dist/cache/build-coordinator.d.ts +42 -0
- package/dist/cache/dep-cache.d.ts +51 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/pending-builds.d.ts +14 -0
- package/dist/cache/pending-dynamics.d.ts +15 -0
- package/dist/cache/pending-inits.d.ts +19 -0
- package/dist/cache/pending-tracker.d.ts +65 -0
- package/dist/cache/source-cache.d.ts +30 -0
- package/dist/cli/api-client.d.ts +411 -0
- package/dist/cli/commands/access-log.d.ts +30 -0
- package/dist/cli/commands/agent-service/index.d.ts +15 -0
- package/dist/cli/commands/agent-service/install.d.ts +9 -0
- package/dist/cli/commands/agent-service/logs.d.ts +9 -0
- package/dist/cli/commands/agent-service/restart.d.ts +8 -0
- package/dist/cli/commands/agent-service/start.d.ts +8 -0
- package/dist/cli/commands/agent-service/status.d.ts +10 -0
- package/dist/cli/commands/agent-service/stop.d.ts +8 -0
- package/dist/cli/commands/agent-service/uninstall.d.ts +9 -0
- package/dist/cli/commands/agent-service/upgrade.d.ts +11 -0
- package/dist/cli/commands/agent.d.ts +10 -0
- package/dist/cli/commands/api-key.d.ts +12 -0
- package/dist/cli/commands/audit.d.ts +9 -0
- package/dist/cli/commands/backend.d.ts +17 -0
- package/dist/cli/commands/cold-store-impl.d.ts +101 -0
- package/dist/cli/commands/cold-store.d.ts +30 -0
- package/dist/cli/commands/config.d.ts +16 -0
- package/dist/cli/commands/db.d.ts +19 -0
- package/dist/cli/commands/debug-bundle.d.ts +16 -0
- package/dist/cli/commands/diagnose.d.ts +15 -0
- package/dist/cli/commands/environment.d.ts +24 -0
- package/dist/cli/commands/event-dlq.d.ts +19 -0
- package/dist/cli/commands/event-log.d.ts +27 -0
- package/dist/cli/commands/event.d.ts +4 -0
- package/dist/cli/commands/execution.d.ts +17 -0
- package/dist/cli/commands/inspect-bundle.d.ts +16 -0
- package/dist/cli/commands/maintenance.d.ts +4 -0
- package/dist/cli/commands/orchestrator-service/index.d.ts +12 -0
- package/dist/cli/commands/orchestrator-service/install.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/logs.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/restart.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/start.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/status.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/stop.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/uninstall.d.ts +9 -0
- package/dist/cli/commands/orchestrator-service/upgrade.d.ts +12 -0
- package/dist/cli/commands/org-settings.d.ts +17 -0
- package/dist/cli/commands/peer.d.ts +13 -0
- package/dist/cli/commands/queue.d.ts +16 -0
- package/dist/cli/commands/registration.d.ts +18 -0
- package/dist/cli/commands/rotate.d.ts +9 -0
- package/dist/cli/commands/runs.d.ts +34 -0
- package/dist/cli/commands/secret.d.ts +12 -0
- package/dist/cli/commands/shared/db.d.ts +16 -0
- package/dist/cli/commands/shared/versioned-upgrade.d.ts +38 -0
- package/dist/cli/commands/source.d.ts +24 -0
- package/dist/cli/commands/token.d.ts +10 -0
- package/dist/cli/commands/workflow.d.ts +31 -0
- package/dist/cli/join.d.ts +14 -0
- package/dist/cli/kici-admin.d.ts +13 -0
- package/dist/cli/lazy-deps/cache.d.ts +17 -0
- package/dist/cli/lazy-deps/downloader.d.ts +33 -0
- package/dist/cli/lazy-deps/registry.d.ts +43 -0
- package/dist/cli/service/compose.d.ts +25 -0
- package/dist/cli/service/index.d.ts +24 -0
- package/dist/cli/service/launchd.d.ts +34 -0
- package/dist/cli/service/platform-detect.d.ts +59 -0
- package/dist/cli/service/systemd.d.ts +41 -0
- package/dist/cli/service/types.d.ts +91 -0
- package/dist/cli/service/windows.d.ts +20 -0
- package/dist/cli/wizard/agent-wizard.d.ts +24 -0
- package/dist/cli/wizard/orchestrator-wizard.d.ts +38 -0
- package/dist/cli/wizard/prompts.d.ts +23 -0
- package/dist/cli.js +11435 -0
- package/dist/cluster/cluster-identity.d.ts +59 -0
- package/dist/cluster/coordinator.d.ts +204 -0
- package/dist/cluster/health-api.d.ts +30 -0
- package/dist/cluster/index.d.ts +24 -0
- package/dist/cluster/join-client.d.ts +75 -0
- package/dist/cluster/join-handler.d.ts +58 -0
- package/dist/cluster/join-token.d.ts +94 -0
- package/dist/cluster/orphan-recovery.d.ts +67 -0
- package/dist/cluster/peer-client.d.ts +190 -0
- package/dist/cluster/peer-credentials.d.ts +108 -0
- package/dist/cluster/peer-crypto.d.ts +57 -0
- package/dist/cluster/peer-handler.d.ts +97 -0
- package/dist/cluster/peer-registry.d.ts +186 -0
- package/dist/cluster/raft-state.d.ts +36 -0
- package/dist/cluster/raft.d.ts +140 -0
- package/dist/cold-store/load-access-log-range.d.ts +73 -0
- package/dist/cold-store/load-event-log-range.d.ts +62 -0
- package/dist/cold-store/load-secret-audit-log-range.d.ts +38 -0
- package/dist/cold-store/orchestrator-cold-store.d.ts +58 -0
- package/dist/cold-store/tables/access-log.d.ts +80 -0
- package/dist/cold-store/tables/event-log.d.ts +70 -0
- package/dist/cold-store/tables/execution-jobs.d.ts +63 -0
- package/dist/cold-store/tables/execution-runs.d.ts +81 -0
- package/dist/cold-store/tables/execution-steps.d.ts +65 -0
- package/dist/cold-store/tables/secret-audit-log.d.ts +77 -0
- package/dist/concurrency/dispatch-next-queued.d.ts +63 -0
- package/dist/concurrency/group-tracker.d.ts +51 -0
- package/dist/concurrency/index.d.ts +3 -0
- package/dist/concurrency/queue-manager.d.ts +68 -0
- package/dist/concurrency/waiters.d.ts +58 -0
- package/dist/config/encryption.d.ts +82 -0
- package/dist/config/env-overlay.d.ts +45 -0
- package/dist/config/index.d.ts +16 -0
- package/dist/config/loader.d.ts +26 -0
- package/dist/config/reload.d.ts +113 -0
- package/dist/config/resolver.d.ts +47 -0
- package/dist/config/schema.d.ts +210 -0
- package/dist/config/shared-store.d.ts +142 -0
- package/dist/config/types.d.ts +218 -0
- package/dist/config.d.ts +249 -0
- package/dist/cron/cron-scheduler.d.ts +78 -0
- package/dist/cron/cron-store.d.ts +38 -0
- package/dist/dashboard/handler.d.ts +243 -0
- package/dist/db/client.d.ts +13 -0
- package/dist/db/migration-provider.d.ts +9 -0
- package/dist/db/migrations/001_initial.d.ts +8 -0
- package/dist/db/migrations/002_config_versions_key_version.d.ts +16 -0
- package/dist/db/migrations/003_access_log.d.ts +26 -0
- package/dist/db/migrations/004_rename_bundle_to_source.d.ts +19 -0
- package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +19 -0
- package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +38 -0
- package/dist/db/migrations/007_audit_logs_archived_at.d.ts +42 -0
- package/dist/db/migrations/008_event_log_archived_at.d.ts +40 -0
- package/dist/db/migrations/009_access_log_trigram.d.ts +15 -0
- package/dist/db/migrations/010_cold_store_chunks.d.ts +34 -0
- package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +21 -0
- package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +28 -0
- package/dist/db/migrations/013_execution_log_bytes.d.ts +21 -0
- package/dist/db/migrations/014_kici_events_lease_retry.d.ts +36 -0
- package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +30 -0
- package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +15 -0
- package/dist/db/migrations/017_org_id_widen.d.ts +4 -0
- package/dist/db/migrations/018_org_id_prefix_backfill.d.ts +4 -0
- package/dist/db/migrator.d.ts +32 -0
- package/dist/db/types.d.ts +1266 -0
- package/dist/diagnostics/bundle-reader.d.ts +48 -0
- package/dist/diagnostics/bundle-writer.d.ts +57 -0
- package/dist/diagnostics/checks/agents.d.ts +10 -0
- package/dist/diagnostics/checks/certs.d.ts +9 -0
- package/dist/diagnostics/checks/config.d.ts +10 -0
- package/dist/diagnostics/checks/db.d.ts +9 -0
- package/dist/diagnostics/checks/disk.d.ts +9 -0
- package/dist/diagnostics/checks/index.d.ts +17 -0
- package/dist/diagnostics/checks/ws.d.ts +9 -0
- package/dist/diagnostics/index.d.ts +13 -0
- package/dist/diagnostics/runner.d.ts +23 -0
- package/dist/diagnostics/types.d.ts +38 -0
- package/dist/entry-helpers.d.ts +93 -0
- package/dist/environments/binding-store.d.ts +27 -0
- package/dist/environments/environment-store.d.ts +74 -0
- package/dist/environments/held-runs.d.ts +64 -0
- package/dist/environments/index.d.ts +10 -0
- package/dist/environments/protection/branch-gate.d.ts +5 -0
- package/dist/environments/protection/concurrency-gate.d.ts +7 -0
- package/dist/environments/protection/pipeline.d.ts +18 -0
- package/dist/environments/protection/reviewer-gate.d.ts +7 -0
- package/dist/environments/protection/trust-gate.d.ts +7 -0
- package/dist/environments/protection/wait-timer-gate.d.ts +7 -0
- package/dist/environments/variable-store.d.ts +39 -0
- package/dist/events/circuit-breaker.d.ts +33 -0
- package/dist/events/event-emitter.d.ts +55 -0
- package/dist/events/event-retry-scanner.d.ts +52 -0
- package/dist/events/event-router.d.ts +183 -0
- package/dist/events/event-store.d.ts +157 -0
- package/dist/events/trust-store.d.ts +54 -0
- package/dist/events/types.d.ts +61 -0
- package/dist/helpers/ip-extraction.d.ts +29 -0
- package/dist/helpers/rate-limiter.d.ts +23 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +772 -0
- package/dist/lockfile-cache.d.ts +39 -0
- package/dist/metrics/agent-metrics-aggregator.d.ts +116 -0
- package/dist/metrics/metrics-reporter.d.ts +40 -0
- package/dist/metrics/prometheus.d.ts +261 -0
- package/dist/metrics/scheduled-jobs.d.ts +20 -0
- package/dist/orchestrator-core.d.ts +193 -0
- package/dist/pipeline/dispatch-matched-workflow.d.ts +102 -0
- package/dist/pipeline/inline-eval.d.ts +28 -0
- package/dist/pipeline/install-secrets-resolver.d.ts +73 -0
- package/dist/pipeline/manual-schedule.d.ts +21 -0
- package/dist/pipeline/needs-scheduler.d.ts +85 -0
- package/dist/pipeline/process-webhook.d.ts +38 -0
- package/dist/pipeline/processor.d.ts +326 -0
- package/dist/pipeline/rerun.d.ts +79 -0
- package/dist/pipeline/test-pipeline.d.ts +110 -0
- package/dist/provider-registry.d.ts +122 -0
- package/dist/providers/generic/index.d.ts +23 -0
- package/dist/providers/generic/normalizer.d.ts +112 -0
- package/dist/providers/generic/verification.d.ts +47 -0
- package/dist/providers/github/auth.d.ts +60 -0
- package/dist/providers/github/changed-files.d.ts +51 -0
- package/dist/providers/github/check-status-poster.d.ts +35 -0
- package/dist/providers/github/contributor-resolver.d.ts +30 -0
- package/dist/providers/github/index.d.ts +20 -0
- package/dist/providers/github/lock-file.d.ts +32 -0
- package/dist/providers/github/normalizer.d.ts +103 -0
- package/dist/providers/github/repo-url.d.ts +35 -0
- package/dist/providers/internal/index.d.ts +32 -0
- package/dist/providers/internal/lock-file-fetcher.d.ts +34 -0
- package/dist/providers/internal/normalizer.d.ts +89 -0
- package/dist/providers/internal/repo-url-builder.d.ts +42 -0
- package/dist/providers/universal-git/changed-files.d.ts +42 -0
- package/dist/providers/universal-git/clone-token.d.ts +83 -0
- package/dist/providers/universal-git/config.d.ts +192 -0
- package/dist/providers/universal-git/index.d.ts +55 -0
- package/dist/providers/universal-git/lock-file.d.ts +71 -0
- package/dist/providers/universal-git/normalizer.d.ts +90 -0
- package/dist/providers/universal-git/repo-url.d.ts +50 -0
- package/dist/providers/universal-git/ssh-auth.d.ts +94 -0
- package/dist/queue/bootstrap.d.ts +50 -0
- package/dist/queue/cleanup.d.ts +41 -0
- package/dist/queue/depth-refresher.d.ts +65 -0
- package/dist/queue/job-queue.d.ts +343 -0
- package/dist/queue/scheduled-job.d.ts +91 -0
- package/dist/registration/extractor.d.ts +44 -0
- package/dist/registration/registration-index.d.ts +162 -0
- package/dist/registration/registration-store.d.ts +111 -0
- package/dist/reporting/check-run-summary.d.ts +102 -0
- package/dist/reporting/commit-status.d.ts +382 -0
- package/dist/reporting/execution-tracker.d.ts +538 -0
- package/dist/reporting/fs-log-storage.d.ts +41 -0
- package/dist/reporting/log-pull-handler.d.ts +35 -0
- package/dist/reporting/log-storage.d.ts +70 -0
- package/dist/reporting/log-writer.d.ts +45 -0
- package/dist/reporting/s3-log-storage.d.ts +42 -0
- package/dist/reporting/step-log-buffer.d.ts +57 -0
- package/dist/routes/admin-access-log.d.ts +34 -0
- package/dist/routes/admin-backends.d.ts +28 -0
- package/dist/routes/admin-config.d.ts +57 -0
- package/dist/routes/admin-db.d.ts +20 -0
- package/dist/routes/admin-environments.d.ts +42 -0
- package/dist/routes/admin-errors.d.ts +4 -0
- package/dist/routes/admin-event-dlq.d.ts +39 -0
- package/dist/routes/admin-event-log.d.ts +42 -0
- package/dist/routes/admin-events.d.ts +46 -0
- package/dist/routes/admin-maintenance.d.ts +22 -0
- package/dist/routes/admin-org-settings.d.ts +29 -0
- package/dist/routes/admin-queue-execution.d.ts +27 -0
- package/dist/routes/admin-registrations.d.ts +37 -0
- package/dist/routes/admin-runs.d.ts +57 -0
- package/dist/routes/admin-scheduled-jobs.d.ts +36 -0
- package/dist/routes/admin-sources.d.ts +18 -0
- package/dist/routes/admin.d.ts +103 -0
- package/dist/routes/capabilities.d.ts +24 -0
- package/dist/routes/diagnostics.d.ts +16 -0
- package/dist/routes/health.d.ts +20 -0
- package/dist/routes/test-trigger.d.ts +41 -0
- package/dist/routes/uploads.d.ts +38 -0
- package/dist/routes/webhooks.d.ts +36 -0
- package/dist/scaler/bare-metal-backend.d.ts +107 -0
- package/dist/scaler/config.d.ts +303 -0
- package/dist/scaler/container-backend.d.ts +125 -0
- package/dist/scaler/file-tail.d.ts +23 -0
- package/dist/scaler/firecracker-api.d.ts +100 -0
- package/dist/scaler/firecracker-backend.d.ts +263 -0
- package/dist/scaler/index.d.ts +24 -0
- package/dist/scaler/ip-allocator.d.ts +177 -0
- package/dist/scaler/label-matcher.d.ts +73 -0
- package/dist/scaler/log-forwarder.d.ts +54 -0
- package/dist/scaler/machine-ledger.d.ts +160 -0
- package/dist/scaler/manager.d.ts +338 -0
- package/dist/scaler/nftables.d.ts +85 -0
- package/dist/scaler/types.d.ts +388 -0
- package/dist/scaler/warm-pool.d.ts +81 -0
- package/dist/secrets/audit-logger.d.ts +65 -0
- package/dist/secrets/backend-health.d.ts +60 -0
- package/dist/secrets/backend-registry.d.ts +68 -0
- package/dist/secrets/backend-sync.d.ts +40 -0
- package/dist/secrets/cleanup.d.ts +40 -0
- package/dist/secrets/config.d.ts +51 -0
- package/dist/secrets/crypto.d.ts +49 -0
- package/dist/secrets/ephemeral-keys.d.ts +49 -0
- package/dist/secrets/index.d.ts +17 -0
- package/dist/secrets/pg-secret-store.d.ts +105 -0
- package/dist/secrets/rbac.d.ts +47 -0
- package/dist/secrets/secret-output-store.d.ts +46 -0
- package/dist/secrets/secret-resolver.d.ts +137 -0
- package/dist/secrets/source-credentials.d.ts +61 -0
- package/dist/secrets/token-manager.d.ts +63 -0
- package/dist/secrets/vault-secret-store.d.ts +85 -0
- package/dist/security/comment-handler.d.ts +67 -0
- package/dist/security/contributor-cache.d.ts +75 -0
- package/dist/security/global-workflow-policy.d.ts +72 -0
- package/dist/security/lock-source.d.ts +34 -0
- package/dist/security/trust-resolver.d.ts +108 -0
- package/dist/security/workflow-diff.d.ts +26 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +48055 -0
- package/dist/sources/index.d.ts +10 -0
- package/dist/sources/source-manager.d.ts +63 -0
- package/dist/sources/source-store.d.ts +79 -0
- package/dist/sources/source-validator.d.ts +16 -0
- package/dist/stale-detector/stale-run-detector.d.ts +109 -0
- package/dist/standalone.d.ts +20 -0
- package/dist/standalone.js +41546 -0
- package/dist/storage/blob-routes.d.ts +20 -0
- package/dist/storage/filesystem.d.ts +60 -0
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/s3.d.ts +68 -0
- package/dist/storage/sign-url.d.ts +45 -0
- package/dist/storage/types.d.ts +98 -0
- package/dist/webhook/dedup.d.ts +44 -0
- package/dist/webhook/event-log.d.ts +83 -0
- package/dist/webhook/generic-sources.d.ts +169 -0
- package/dist/webhook/handler.d.ts +23 -0
- package/dist/webhook/relay-buffer.d.ts +96 -0
- package/dist/webhook/verify-inbound.d.ts +78 -0
- package/dist/worker/in-memory-execution-tracker.d.ts +94 -0
- package/dist/worker/in-memory-job-queue.d.ts +74 -0
- package/dist/worker/static-agent-token-store.d.ts +58 -0
- package/dist/worker/worker-status.d.ts +36 -0
- package/dist/worker-core.d.ts +74 -0
- package/dist/ws/agent-api-registry.d.ts +49 -0
- package/dist/ws/agent-handler.d.ts +176 -0
- package/dist/ws/agent-heartbeat.d.ts +45 -0
- package/dist/ws/dashboard-backends-handler.d.ts +51 -0
- package/dist/ws/dashboard-diagnostics-handler.d.ts +56 -0
- package/dist/ws/dashboard-env-handler.d.ts +107 -0
- package/dist/ws/dashboard-global-workflows-handler.d.ts +72 -0
- package/dist/ws/dashboard-registrations-handler.d.ts +84 -0
- package/dist/ws/event-buffer.d.ts +16 -0
- package/dist/ws/observer-handler.d.ts +42 -0
- package/dist/ws/observer-registry.d.ts +88 -0
- package/dist/ws/platform-client.d.ts +270 -0
- package/dist/ws/server-options.d.ts +15 -0
- package/package.json +87 -6
- package/sbom.spdx.json +14370 -0
- package/index.js +0 -3
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firecracker scaler backend implementation.
|
|
3
|
+
*
|
|
4
|
+
* Manages ephemeral agent microVMs using the Firecracker VMM via the jailer.
|
|
5
|
+
* Handles full VM lifecycle: prepare chroot, hardlink rootfs+kernel, create overlay drive,
|
|
6
|
+
* invoke jailer, inject MMDS metadata, and destroy with cleanup.
|
|
7
|
+
*
|
|
8
|
+
* Log capture: Firecracker backend handles log forwarding internally.
|
|
9
|
+
* The jailer is spawned as a non-daemonized detached child with stdout redirected to a
|
|
10
|
+
* serial console log file and VMM logs captured via --log-path. Both files are tailed
|
|
11
|
+
* using fs.watchFile() and forwarded with distinct logsSource tags ('firecracker-serial',
|
|
12
|
+
* 'firecracker-vmm'). The serial-console path is best-effort only: Firecracker's Rust
|
|
13
|
+
* BufWriter around stdout + jailer's uid drop make sparse userspace writes unreliable,
|
|
14
|
+
* so it's treated as defense-in-depth. The canonical agent log path is WS agent.log
|
|
15
|
+
* (attached unconditionally by the agent; see packages/agent/src/server.ts step 6).
|
|
16
|
+
*
|
|
17
|
+
* Follows the Docker backend pattern closely for consistency.
|
|
18
|
+
*/
|
|
19
|
+
import { type ToolRequirement } from '@kici-dev/shared';
|
|
20
|
+
import type { IpAllocator, IpAllocationResult } from './ip-allocator.js';
|
|
21
|
+
import type { AgentTokenStore } from '../agent/token-store.js';
|
|
22
|
+
import type { ScalerBackend, ScalerEntry, ManagedAgent, LabelSetConfig, ScalerEventCallback, ValidationResult, EffectiveLimits } from './types.js';
|
|
23
|
+
/**
|
|
24
|
+
* Infrastructure interfaces that share the `kici-` prefix but must NEVER be
|
|
25
|
+
* deleted by the orphan sweep. Bridges (kici-br0/kici-br1) carry all VM
|
|
26
|
+
* traffic; kici-m01 is the staging metadata interface. Losing any of these
|
|
27
|
+
* kills all running VMs.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PROTECTED_INTERFACES: readonly string[];
|
|
30
|
+
/** Extended ManagedAgent that includes the allocated IP for cleanup */
|
|
31
|
+
export interface FirecrackerManagedAgent extends ManagedAgent {
|
|
32
|
+
/** Allocated IP address for TAP/IP release during destroy */
|
|
33
|
+
ip: string;
|
|
34
|
+
/** TAP device name for cleanup */
|
|
35
|
+
tapDevice: string;
|
|
36
|
+
}
|
|
37
|
+
export interface FirecrackerScalerBackendOptions {
|
|
38
|
+
/** Human-readable name for this scaler */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Label sets this backend can provision */
|
|
41
|
+
labelSets: LabelSetConfig[];
|
|
42
|
+
/** Maximum concurrent agents */
|
|
43
|
+
maxAgents: number;
|
|
44
|
+
/** Shared IP allocator instance */
|
|
45
|
+
ipAllocator: IpAllocator;
|
|
46
|
+
/** Path to firecracker binary */
|
|
47
|
+
firecrackerPath: string;
|
|
48
|
+
/** Path to jailer binary */
|
|
49
|
+
jailerPath: string;
|
|
50
|
+
/** Default kernel image path */
|
|
51
|
+
kernelPath: string;
|
|
52
|
+
/** Jailer chroot base directory @default '/srv/jailer' */
|
|
53
|
+
chrootBaseDir?: string;
|
|
54
|
+
/** Jailer uid */
|
|
55
|
+
uid: number;
|
|
56
|
+
/** Jailer gid */
|
|
57
|
+
gid: number;
|
|
58
|
+
/** Default vCPU count @default 2 */
|
|
59
|
+
vcpuCount?: number;
|
|
60
|
+
/** Default memory in MiB @default 512 */
|
|
61
|
+
memSizeMib?: number;
|
|
62
|
+
/** Bridge interface name for TAP attachment */
|
|
63
|
+
bridgeName: string;
|
|
64
|
+
/** Gateway IP for guest networking */
|
|
65
|
+
gateway: string;
|
|
66
|
+
/** Netmask for guest networking */
|
|
67
|
+
netmask: string;
|
|
68
|
+
/** Token store for creating ephemeral agent auth tokens. Optional -- when undefined, no token is injected. */
|
|
69
|
+
tokenStore?: AgentTokenStore;
|
|
70
|
+
/** TTL for ephemeral agent tokens in ms. Default: 1 hour. */
|
|
71
|
+
tokenTtlMs?: number;
|
|
72
|
+
/** Agent roles for this scaler. undefined = all, [] = execution only. */
|
|
73
|
+
roles?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Wrap privileged commands (`ip`, `chown`) with `sudo -n`. Required when the
|
|
76
|
+
* orchestrator runs as a non-root user (e.g. user-mode systemd on edge worker
|
|
77
|
+
* nodes) and operators have set up a sudoers NOPASSWD rule for those binaries.
|
|
78
|
+
* On hosts where the orchestrator already runs as root, leave this false.
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
requireSudo?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare class FirecrackerScalerBackend implements ScalerBackend {
|
|
84
|
+
readonly type: "firecracker";
|
|
85
|
+
readonly maxAgents: number;
|
|
86
|
+
readonly logsSource = "firecracker-serial";
|
|
87
|
+
/** AbortControllers for file tailing per managed VM (keyed by agent ID) */
|
|
88
|
+
private readonly tailAbortControllers;
|
|
89
|
+
private _labelSets;
|
|
90
|
+
private readonly name;
|
|
91
|
+
private readonly ipAllocator;
|
|
92
|
+
private readonly firecrackerPath;
|
|
93
|
+
private readonly jailerPath;
|
|
94
|
+
private readonly kernelPath;
|
|
95
|
+
private readonly chrootBaseDir;
|
|
96
|
+
private readonly uid;
|
|
97
|
+
private readonly gid;
|
|
98
|
+
private readonly vcpuCount;
|
|
99
|
+
private readonly memSizeMib;
|
|
100
|
+
private readonly bridgeName;
|
|
101
|
+
private readonly gateway;
|
|
102
|
+
private readonly netmask;
|
|
103
|
+
private readonly tokenStore?;
|
|
104
|
+
private readonly tokenTtlMs;
|
|
105
|
+
private readonly roles;
|
|
106
|
+
private readonly requireSudo;
|
|
107
|
+
/** Tracks all managed VM agents by ManagedAgent.id */
|
|
108
|
+
private readonly agents;
|
|
109
|
+
/** Periodic orphan sweep timer (null when stopped). */
|
|
110
|
+
private orphanSweepTimer;
|
|
111
|
+
/** Guard against re-entrant sweeps if a single run takes longer than the interval. */
|
|
112
|
+
private orphanSweepInFlight;
|
|
113
|
+
constructor(options: FirecrackerScalerBackendOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Declare required tools for a firecracker scaler entry.
|
|
116
|
+
*/
|
|
117
|
+
static getRequiredTools(entry: ScalerEntry): ToolRequirement[];
|
|
118
|
+
get labelSets(): LabelSetConfig[];
|
|
119
|
+
getActiveCount(): number;
|
|
120
|
+
spawn(labelSet: string[], agentId: string, orchestratorUrl: string, onEvent?: ScalerEventCallback, effectiveLimits?: EffectiveLimits): Promise<ManagedAgent>;
|
|
121
|
+
getScalerContext(agentId: string): Record<string, unknown> | undefined;
|
|
122
|
+
destroy(managedId: string): Promise<void>;
|
|
123
|
+
shutdownAll(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Clear MMDS data for an agent after receiving config.ack via WS.
|
|
126
|
+
* Belt-and-suspenders: even though MMDS only contains orchestrator URL,
|
|
127
|
+
* clearing it reduces the attack surface to zero post-startup.
|
|
128
|
+
*
|
|
129
|
+
* Note: Wiring from agent-handler is done in Plan 04.
|
|
130
|
+
*
|
|
131
|
+
* @param agentId - The agent ID whose VM MMDS should be cleared
|
|
132
|
+
*/
|
|
133
|
+
clearAgentMmds(agentId: string): Promise<void>;
|
|
134
|
+
reload(labelSets: LabelSetConfig[]): ValidationResult;
|
|
135
|
+
/**
|
|
136
|
+
* Clean up orphaned VMs.
|
|
137
|
+
*
|
|
138
|
+
* Safe to call both at startup AND periodically while the backend is active
|
|
139
|
+
* (see startPeriodicOrphanSweep): each pass explicitly skips VMs that are
|
|
140
|
+
* currently tracked in-memory (spawning / running / destroying), and Pass 3
|
|
141
|
+
* re-reads DB allocations after listing host interfaces to close the spawn
|
|
142
|
+
* race (allocate → ip tuntap add is not atomic).
|
|
143
|
+
*
|
|
144
|
+
* Three passes:
|
|
145
|
+
* 1. DB allocations: check if VM process is still running, clean dead ones
|
|
146
|
+
* 2. Filesystem: scan chroot dir for directories not in DB allocations
|
|
147
|
+
* 3. Network: scan host interfaces for orphan TAP devices
|
|
148
|
+
*
|
|
149
|
+
* Returns the count of cleaned orphans.
|
|
150
|
+
*/
|
|
151
|
+
cleanupOrphans(): Promise<number>;
|
|
152
|
+
/**
|
|
153
|
+
* Default interval for periodic orphan sweeps (15 minutes).
|
|
154
|
+
*
|
|
155
|
+
* Long-running orchestrators need in-process orphan sweeps because the
|
|
156
|
+
* external kici-leak-sweep timer skips TAP cleanup while a staging
|
|
157
|
+
* orchestrator is active (to avoid racing spawns). Without this, leaked
|
|
158
|
+
* TAPs accumulate until the orchestrator restarts — which can be weeks.
|
|
159
|
+
*/
|
|
160
|
+
private static readonly ORPHAN_SWEEP_INTERVAL_MS;
|
|
161
|
+
/**
|
|
162
|
+
* Start a periodic orphan sweep. Idempotent — calling twice has no effect
|
|
163
|
+
* beyond the first call. Use stopPeriodicOrphanSweep() to stop.
|
|
164
|
+
*
|
|
165
|
+
* @param intervalMs override the default interval (primarily for tests)
|
|
166
|
+
*/
|
|
167
|
+
startPeriodicOrphanSweep(intervalMs?: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Stop the periodic orphan sweep started by startPeriodicOrphanSweep().
|
|
170
|
+
* Safe to call when the sweep was never started.
|
|
171
|
+
*/
|
|
172
|
+
stopPeriodicOrphanSweep(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Build the merged forwarded-env map for an agent's MMDS payload.
|
|
175
|
+
*
|
|
176
|
+
* Mirrors bare-metal/container precedence: KICI_AGENT_ENV_*-prefixed vars from the
|
|
177
|
+
* orchestrator's process.env (prefix stripped) are seeded first, then scalers.yaml
|
|
178
|
+
* `env:` overlays them (yaml wins on conflict).
|
|
179
|
+
*
|
|
180
|
+
* Two safety filters apply:
|
|
181
|
+
* - Keys must match POSIX_ENV_NAME_PATTERN. Otherwise rejected to keep MMDS path
|
|
182
|
+
* construction safe inside the VM and to prevent the guest from being asked to
|
|
183
|
+
* `export` something the shell can't represent.
|
|
184
|
+
* - The cumulative byte cost (key + value + 2-byte overhead per entry) must stay
|
|
185
|
+
* under MMDS_FORWARDED_ENV_BUDGET_BYTES. Once exceeded, remaining entries are
|
|
186
|
+
* skipped and warnings logged. This protects the ~51 KiB MMDS data store cap
|
|
187
|
+
* from being blown by an accidentally-huge env value.
|
|
188
|
+
*/
|
|
189
|
+
buildForwardedEnv(matchedLabelSet: LabelSetConfig, agentId: string): Record<string, string>;
|
|
190
|
+
/**
|
|
191
|
+
* Build the Firecracker VM configuration JSON.
|
|
192
|
+
*
|
|
193
|
+
* Resolution order for vcpu_count and mem_size_mib:
|
|
194
|
+
* 1. effectiveLimits (resolved by ScalerManager from job/scaler/global caps) — wins if set.
|
|
195
|
+
* 2. label-set's vcpuCount/memSizeMib.
|
|
196
|
+
* 3. backend-level default vcpuCount/memSizeMib.
|
|
197
|
+
*
|
|
198
|
+
* Firecracker requires integer vCPUs and integer MiB. We round CPUs UP via
|
|
199
|
+
* Math.ceil to never under-provision (a 0.5-CPU request still gets a whole vCPU)
|
|
200
|
+
* and floor-divide bytes -> MiB. A debug log is emitted when rounding actually
|
|
201
|
+
* changes the value, so operators can spot frequent fractional requests.
|
|
202
|
+
*/
|
|
203
|
+
buildVmConfig(alloc: IpAllocationResult, labelSet: LabelSetConfig, effectiveLimits?: EffectiveLimits): Record<string, unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Create a sparse ext4 overlay drive for per-VM writable layer.
|
|
206
|
+
* The file is sparse (allocates no disk blocks until written) and
|
|
207
|
+
* pre-formatted as ext4 so the guest can mount it immediately.
|
|
208
|
+
*/
|
|
209
|
+
private createOverlayDrive;
|
|
210
|
+
/**
|
|
211
|
+
* Promisified execFile wrapper with 30s timeout.
|
|
212
|
+
*/
|
|
213
|
+
private execAsync;
|
|
214
|
+
/**
|
|
215
|
+
* Get the API socket path for an agent's Firecracker VM.
|
|
216
|
+
*/
|
|
217
|
+
getSocketPath(agentId: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* Get the chroot directory path for an agent.
|
|
220
|
+
*/
|
|
221
|
+
getChrootDir(agentId: string): string;
|
|
222
|
+
/**
|
|
223
|
+
* Check if a VM process is still alive by reading its PID file and sending signal 0.
|
|
224
|
+
*/
|
|
225
|
+
private isVmProcessAlive;
|
|
226
|
+
/**
|
|
227
|
+
* Wait for a VM's jailer process to exit within a timeout.
|
|
228
|
+
*/
|
|
229
|
+
private waitForProcessExit;
|
|
230
|
+
/**
|
|
231
|
+
* Clean up resources after a failed spawn attempt.
|
|
232
|
+
*/
|
|
233
|
+
private cleanupFailedSpawn;
|
|
234
|
+
/**
|
|
235
|
+
* Start tailing serial console and VMM log files, forwarding lines directly
|
|
236
|
+
* via forwardLine() with distinct logsSource tags.
|
|
237
|
+
*
|
|
238
|
+
* Also monitors the jailer child process for early exit (boot failure detection).
|
|
239
|
+
* Forwarding is handled internally (not through ScalerManager/AgentLogForwarder)
|
|
240
|
+
* because Firecracker has two distinct log sources per VM.
|
|
241
|
+
*/
|
|
242
|
+
private startLogTailing;
|
|
243
|
+
/**
|
|
244
|
+
* Tail a single log file and forward each line via forwardLine().
|
|
245
|
+
* For serial console lines: non-JSON lines (kernel boot output) are wrapped
|
|
246
|
+
* as debug-level JSON; failure patterns (kernel panic, init failure) are elevated to error.
|
|
247
|
+
*/
|
|
248
|
+
private tailAndForward;
|
|
249
|
+
/**
|
|
250
|
+
* Check if a serial console line matches known boot failure patterns.
|
|
251
|
+
*/
|
|
252
|
+
private isFailurePattern;
|
|
253
|
+
/**
|
|
254
|
+
* Read the serial console log file and detect the type of boot failure.
|
|
255
|
+
*/
|
|
256
|
+
private detectFailureType;
|
|
257
|
+
/**
|
|
258
|
+
* Read and forward any remaining log file content for an orphaned/dead VM.
|
|
259
|
+
* Called during cleanupOrphans() before deleting the chroot directory.
|
|
260
|
+
*/
|
|
261
|
+
private forwardRemainingLogs;
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=firecracker-backend.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent auto-scaler module.
|
|
3
|
+
*
|
|
4
|
+
* Provides pluggable backend-agnostic agent provisioning for the orchestrator.
|
|
5
|
+
* Supports Docker, bare-metal, and Firecracker backends with YAML configuration,
|
|
6
|
+
* label-set matching, and warm pool management.
|
|
7
|
+
*/
|
|
8
|
+
export type { ResourceLimits, LabelSetConfig, ManagedAgent, ScaleResult, ValidationResult, ScalerBackend, ScalerConfig, ScalerEntry, WarmPoolConfig, FirecrackerNetworkConfig, } from './types.js';
|
|
9
|
+
export { loadScalerConfig, scalerFileSchema, firecrackerNetworkSchema, parseMemoryString, } from './config.js';
|
|
10
|
+
export { normalizeLabelSet, labelSetsMatch, detectLabelSetOverlaps, findBackendForLabels, } from './label-matcher.js';
|
|
11
|
+
export { ContainerScalerBackend, detectRuntime } from './container-backend.js';
|
|
12
|
+
export type { ContainerScalerBackendOptions, DetectedRuntime } from './container-backend.js';
|
|
13
|
+
export { BareMetalScalerBackend } from './bare-metal-backend.js';
|
|
14
|
+
export type { BareMetalScalerBackendOptions } from './bare-metal-backend.js';
|
|
15
|
+
export { FirecrackerScalerBackend } from './firecracker-backend.js';
|
|
16
|
+
export type { FirecrackerScalerBackendOptions, FirecrackerManagedAgent, } from './firecracker-backend.js';
|
|
17
|
+
export { FirecrackerApi, FirecrackerApiError } from './firecracker-api.js';
|
|
18
|
+
export { ScalerManager } from './manager.js';
|
|
19
|
+
export type { ScalerStatus } from './manager.js';
|
|
20
|
+
export { WarmPoolManager } from './warm-pool.js';
|
|
21
|
+
export type { WarmPoolCallbacks } from './warm-pool.js';
|
|
22
|
+
export { DbIpAllocator, InMemoryIpAllocator, parseCidr, ipToNumber, numberToIp, generateMac, generateTapName, } from './ip-allocator.js';
|
|
23
|
+
export type { IpAllocator, IpAllocationResult, IpAllocationRecord, CidrRange, } from './ip-allocator.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CIDR IP allocator for Firecracker VM networking.
|
|
3
|
+
*
|
|
4
|
+
* Two implementations behind a shared interface:
|
|
5
|
+
*
|
|
6
|
+
* - `DbIpAllocator` — persists allocations to PostgreSQL. Used by
|
|
7
|
+
* coordinators where the cluster Postgres is reachable. Allocations
|
|
8
|
+
* survive orchestrator restarts so a long-lived VM keeps its IP across
|
|
9
|
+
* coord bounces.
|
|
10
|
+
*
|
|
11
|
+
* - `InMemoryIpAllocator` — Map-backed, no persistence. Used by worker
|
|
12
|
+
* peers where the cluster DB is not reachable. The firecracker backend's
|
|
13
|
+
* existing `cleanupOrphans()` Pass-2/Pass-3 walks the jailer chroot
|
|
14
|
+
* tree + host TAP devices on every spawn and during the leak sweep, so
|
|
15
|
+
* any worker-orch restart starts the allocator empty and the next
|
|
16
|
+
* cleanup pass reaps the leftover chroots and TAPs naturally — no
|
|
17
|
+
* recovery state needs to live in the allocator itself.
|
|
18
|
+
*
|
|
19
|
+
* Each orch has its own bridge with its own subnet (coord A: `kici`,
|
|
20
|
+
* coord B: `kici_b`, Pi worker: `kici-br0`), so allocator state is
|
|
21
|
+
* per-orch by design. No two orchs share an IP space.
|
|
22
|
+
*/
|
|
23
|
+
import type { Kysely } from 'kysely';
|
|
24
|
+
import type { Database } from '../db/types.js';
|
|
25
|
+
/**
|
|
26
|
+
* Result of a successful IP allocation.
|
|
27
|
+
*/
|
|
28
|
+
export interface IpAllocationResult {
|
|
29
|
+
/** Allocated IP address */
|
|
30
|
+
ip: string;
|
|
31
|
+
/** Gateway IP for guest networking */
|
|
32
|
+
gateway: string;
|
|
33
|
+
/** Subnet mask for guest networking */
|
|
34
|
+
netmask: string;
|
|
35
|
+
/** Deterministic MAC address derived from IP */
|
|
36
|
+
mac: string;
|
|
37
|
+
/** TAP device name on the host */
|
|
38
|
+
tapDevice: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parsed CIDR range.
|
|
42
|
+
*/
|
|
43
|
+
export interface CidrRange {
|
|
44
|
+
/** Network address as a 32-bit number */
|
|
45
|
+
networkAddress: number;
|
|
46
|
+
/** Prefix length (e.g. 24 for /24) */
|
|
47
|
+
prefixLength: number;
|
|
48
|
+
/** First usable IP (network address + 1) as a 32-bit number */
|
|
49
|
+
startIp: number;
|
|
50
|
+
/** Last usable IP (broadcast - 1) as a 32-bit number */
|
|
51
|
+
endIp: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse an IPv4 address string to a 32-bit unsigned integer.
|
|
55
|
+
*/
|
|
56
|
+
export declare function ipToNumber(ip: string): number;
|
|
57
|
+
/**
|
|
58
|
+
* Convert a 32-bit unsigned integer back to an IPv4 address string.
|
|
59
|
+
*/
|
|
60
|
+
export declare function numberToIp(n: number): string;
|
|
61
|
+
/**
|
|
62
|
+
* Parse a CIDR notation string into a CidrRange.
|
|
63
|
+
*
|
|
64
|
+
* @example parseCidr('10.0.0.0/24')
|
|
65
|
+
* // => { networkAddress: 167772160, prefixLength: 24, startIp: 167772161, endIp: 167772414 }
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseCidr(cidr: string): CidrRange;
|
|
68
|
+
/**
|
|
69
|
+
* Generate a deterministic MAC address from an IP address.
|
|
70
|
+
*
|
|
71
|
+
* Uses the locally-administered unicast prefix 06:00:AC followed by
|
|
72
|
+
* the last 3 octets of the IP address encoded as hex.
|
|
73
|
+
*
|
|
74
|
+
* @example generateMac('10.0.0.5') // => '06:00:AC:00:00:05'
|
|
75
|
+
* @example generateMac('10.0.1.42') // => '06:00:AC:00:01:2A'
|
|
76
|
+
*/
|
|
77
|
+
export declare function generateMac(ip: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Generate a TAP device name from a VM ID.
|
|
80
|
+
* Linux interface names are limited to 15 characters (IFNAMSIZ).
|
|
81
|
+
* Format: kici-XXXXXXXX (5 + 8 = 13 chars, well within limit).
|
|
82
|
+
*
|
|
83
|
+
* Uses the LAST 8 characters of the vmId to avoid collisions.
|
|
84
|
+
* VM IDs have format "scaler-firecracker-XXXXXXXX" where the unique
|
|
85
|
+
* random suffix is at the end. Using slice(0, 8) would always produce
|
|
86
|
+
* "scaler-f" for all Firecracker VMs.
|
|
87
|
+
*/
|
|
88
|
+
export declare function generateTapName(vmId: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Shape of one row returned by `IpAllocator.getAllocations()` /
|
|
91
|
+
* `getAllocationForVm()`. Matches the `ip_allocations` table columns so
|
|
92
|
+
* the firecracker-backend's `cleanupOrphans()` can read both impls
|
|
93
|
+
* uniformly.
|
|
94
|
+
*/
|
|
95
|
+
export interface IpAllocationRecord {
|
|
96
|
+
ip: string;
|
|
97
|
+
vm_id: string;
|
|
98
|
+
scaler_name: string;
|
|
99
|
+
tap_device: string;
|
|
100
|
+
mac_address: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Per-orch CIDR IP allocator interface.
|
|
104
|
+
*
|
|
105
|
+
* Two implementations: `DbIpAllocator` (Postgres, coordinator) and
|
|
106
|
+
* `InMemoryIpAllocator` (Map-backed, worker). The firecracker-backend
|
|
107
|
+
* depends only on this interface — never on the concrete class — so a
|
|
108
|
+
* single backend implementation works in both deploy modes.
|
|
109
|
+
*/
|
|
110
|
+
export interface IpAllocator {
|
|
111
|
+
allocate(vmId: string, scalerName: string): Promise<IpAllocationResult>;
|
|
112
|
+
release(vmId: string): Promise<void>;
|
|
113
|
+
releaseByIp(ip: string): Promise<void>;
|
|
114
|
+
getAllocations(): Promise<IpAllocationRecord[]>;
|
|
115
|
+
getAllocationForVm(vmId: string): Promise<IpAllocationRecord | null>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* DB-backed CIDR IP allocator.
|
|
119
|
+
*
|
|
120
|
+
* Allocates IPs from a configurable range, skipping the gateway.
|
|
121
|
+
* All allocations are persisted in PostgreSQL — used by coordinators
|
|
122
|
+
* where the cluster DB is reachable. Allocations survive orch restarts
|
|
123
|
+
* so a long-lived VM keeps its IP across coord bounces.
|
|
124
|
+
*/
|
|
125
|
+
export declare class DbIpAllocator implements IpAllocator {
|
|
126
|
+
private readonly db;
|
|
127
|
+
private readonly range;
|
|
128
|
+
private readonly gateway;
|
|
129
|
+
private readonly gatewayNum;
|
|
130
|
+
private readonly netmask;
|
|
131
|
+
constructor(opts: {
|
|
132
|
+
db: Kysely<Database>;
|
|
133
|
+
cidr: string;
|
|
134
|
+
gateway: string;
|
|
135
|
+
netmask: string;
|
|
136
|
+
});
|
|
137
|
+
allocate(vmId: string, scalerName: string): Promise<IpAllocationResult>;
|
|
138
|
+
release(vmId: string): Promise<void>;
|
|
139
|
+
releaseByIp(ip: string): Promise<void>;
|
|
140
|
+
getAllocations(): Promise<IpAllocationRecord[]>;
|
|
141
|
+
getAllocationForVm(vmId: string): Promise<IpAllocationRecord | null>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* In-memory CIDR IP allocator.
|
|
145
|
+
*
|
|
146
|
+
* Used by worker peers where the cluster Postgres is not reachable. State
|
|
147
|
+
* lives in a `Map<vmId, IpAllocationRecord>` for the lifetime of the
|
|
148
|
+
* orch process; on restart the allocator starts empty and the
|
|
149
|
+
* firecracker-backend's existing `cleanupOrphans()` Pass-2/Pass-3 walks
|
|
150
|
+
* the jailer chroot tree + host TAP devices (matching `VM_TAP_PATTERN`)
|
|
151
|
+
* to reap any leftover state. No persistence and no chroot recovery
|
|
152
|
+
* inside the allocator — the filesystem is the source of truth, and the
|
|
153
|
+
* cleanup pass already consults it.
|
|
154
|
+
*
|
|
155
|
+
* Each orch has its own bridge with its own subnet, so per-process
|
|
156
|
+
* state is by design. No locking needed: every method is synchronous on
|
|
157
|
+
* the in-memory Map and only awaits to satisfy the async interface.
|
|
158
|
+
*/
|
|
159
|
+
export declare class InMemoryIpAllocator implements IpAllocator {
|
|
160
|
+
private readonly range;
|
|
161
|
+
private readonly gateway;
|
|
162
|
+
private readonly gatewayNum;
|
|
163
|
+
private readonly netmask;
|
|
164
|
+
private readonly byVmId;
|
|
165
|
+
private readonly allocatedIps;
|
|
166
|
+
constructor(opts: {
|
|
167
|
+
cidr: string;
|
|
168
|
+
gateway: string;
|
|
169
|
+
netmask: string;
|
|
170
|
+
});
|
|
171
|
+
allocate(vmId: string, scalerName: string): Promise<IpAllocationResult>;
|
|
172
|
+
release(vmId: string): Promise<void>;
|
|
173
|
+
releaseByIp(ip: string): Promise<void>;
|
|
174
|
+
getAllocations(): Promise<IpAllocationRecord[]>;
|
|
175
|
+
getAllocationForVm(vmId: string): Promise<IpAllocationRecord | null>;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=ip-allocator.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Label-set matching and overlap detection for the scaler module.
|
|
3
|
+
*
|
|
4
|
+
* Label sets are normalized (sorted, deduplicated, lowercased) for
|
|
5
|
+
* deterministic comparison.
|
|
6
|
+
*
|
|
7
|
+
* findBackendForLabels uses subset matching: a job requiring ['macos']
|
|
8
|
+
* matches a scaler with ['macos', 'darwin', 'bare-metal']. This is
|
|
9
|
+
* consistent with peer routing (findPeersWithCapacity) and allows
|
|
10
|
+
* workflows to target broad labels like 'macos' without listing every
|
|
11
|
+
* label the scaler defines.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Normalize a label set for comparison.
|
|
15
|
+
* Sorts alphabetically, deduplicates, and lowercases all labels.
|
|
16
|
+
* Produces a deterministic string key for comparison.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* normalizeLabelSet(['Docker', 'linux', 'linux']) // => "docker,linux"
|
|
20
|
+
* normalizeLabelSet([]) // => ""
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeLabelSet(labels: string[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Check if two label sets are exactly equal after normalization.
|
|
25
|
+
* Subsets do NOT match -- ["linux"] does not match ["linux", "docker"].
|
|
26
|
+
*/
|
|
27
|
+
export declare function labelSetsMatch(a: string[], b: string[]): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Detect overlapping label sets across different scalers.
|
|
30
|
+
* Returns all pairs of scalers that share the same normalized label set.
|
|
31
|
+
*
|
|
32
|
+
* Intra-scaler duplicates are allowed (same scaler, duplicate label sets).
|
|
33
|
+
* Only cross-scaler overlaps are flagged.
|
|
34
|
+
*
|
|
35
|
+
* Used at startup to reject configs with ambiguous routing.
|
|
36
|
+
*/
|
|
37
|
+
export declare function detectLabelSetOverlaps(scalers: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
labelSets: Array<{
|
|
40
|
+
labels: string[];
|
|
41
|
+
}>;
|
|
42
|
+
}>): Array<{
|
|
43
|
+
labels: string;
|
|
44
|
+
scaler1: string;
|
|
45
|
+
scaler2: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Find which scaler backend handles a given set of labels.
|
|
49
|
+
* Returns the scaler name and label-set index, or null if no match.
|
|
50
|
+
*
|
|
51
|
+
* Uses subset matching: job labels must be a subset of the scaler's label set.
|
|
52
|
+
* ['macos'] matches ['macos', 'darwin', 'bare-metal']. This is consistent
|
|
53
|
+
* with peer routing (findPeersWithCapacity) which uses the same semantics.
|
|
54
|
+
*
|
|
55
|
+
* In addition, every label declared in a scaler's `mandatoryLabels` must be
|
|
56
|
+
* present in the job's `runsOn`. This is the Kubernetes-taint-style opt-in
|
|
57
|
+
* gate: a scaler with `mandatoryLabels: ['gpu']` only accepts jobs that
|
|
58
|
+
* explicitly include `gpu` in `runsOn`.
|
|
59
|
+
*
|
|
60
|
+
* When multiple backends match, the one with the smallest label set wins
|
|
61
|
+
* (most specific match).
|
|
62
|
+
*/
|
|
63
|
+
export declare function findBackendForLabels(labels: string[], scalers: Array<{
|
|
64
|
+
name: string;
|
|
65
|
+
labelSets: Array<{
|
|
66
|
+
labels: string[];
|
|
67
|
+
}>;
|
|
68
|
+
mandatoryLabels?: string[];
|
|
69
|
+
}>, excludeLabels?: string[]): {
|
|
70
|
+
scalerName: string;
|
|
71
|
+
labelSetIndex: number;
|
|
72
|
+
} | null;
|
|
73
|
+
//# sourceMappingURL=label-matcher.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent log forwarding: enriches agent log lines with metadata and writes
|
|
3
|
+
* them to a writable stream (typically orchestrator stdout for ELK ingestion).
|
|
4
|
+
*
|
|
5
|
+
* Handles both JSON and non-JSON log lines:
|
|
6
|
+
* - JSON lines are parsed, enriched with agent/context metadata, and re-serialized.
|
|
7
|
+
* - Non-JSON lines are wrapped as info-level JSON objects.
|
|
8
|
+
*
|
|
9
|
+
* The `service` field identifies the originating tier for forwarded logs that flow
|
|
10
|
+
* through orchestrator stdout (where `kici.service` from container name would say
|
|
11
|
+
* `orchestrator`). This is NOT a rename of `app.source` -- it serves the different
|
|
12
|
+
* purpose of identifying forwarded log origin for scaler-managed agents only.
|
|
13
|
+
*/
|
|
14
|
+
import type { LogCapture } from './types.js';
|
|
15
|
+
/** Context fields merged into each forwarded log line. */
|
|
16
|
+
interface ForwardContext {
|
|
17
|
+
runId?: string;
|
|
18
|
+
requestId?: string;
|
|
19
|
+
jobId?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Enrich and forward a single log line to an output stream.
|
|
23
|
+
*
|
|
24
|
+
* Standalone function for use in the WS agent.log path (agent-handler).
|
|
25
|
+
*
|
|
26
|
+
* @param line - Raw log line from the agent
|
|
27
|
+
* @param agentId - The agent that produced the line
|
|
28
|
+
* @param output - Writable stream to write enriched JSON to
|
|
29
|
+
* @param context - Optional trace context fields
|
|
30
|
+
* @param logsSource - Optional log source identifier (e.g. 'docker', 'podman', 'bare-metal', 'firecracker-serial')
|
|
31
|
+
*/
|
|
32
|
+
export declare function forwardLine(line: string, agentId: string, output: NodeJS.WritableStream, context?: ForwardContext, logsSource?: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Consumes a LogCapture stream and forwards enriched log lines to an output stream.
|
|
35
|
+
*
|
|
36
|
+
* Used by scaler backends (container, bare-metal, Firecracker) to forward
|
|
37
|
+
* agent stdout/stderr to orchestrator stdout for ELK ingestion.
|
|
38
|
+
*/
|
|
39
|
+
export declare class AgentLogForwarder {
|
|
40
|
+
private readonly agentId;
|
|
41
|
+
private readonly output;
|
|
42
|
+
constructor(agentId: string, output?: NodeJS.WritableStream);
|
|
43
|
+
/**
|
|
44
|
+
* Forward all lines from a LogCapture to the output stream.
|
|
45
|
+
* Resolves when the capture's async iterable ends.
|
|
46
|
+
*
|
|
47
|
+
* @param capture - LogCapture to consume
|
|
48
|
+
* @param context - Optional trace context fields
|
|
49
|
+
* @param logsSource - Optional log source identifier (e.g. 'docker', 'podman', 'bare-metal')
|
|
50
|
+
*/
|
|
51
|
+
forward(capture: LogCapture, context?: ForwardContext, logsSource?: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=log-forwarder.d.ts.map
|