fc94326b0e
P00 — Re-architecture Foundation (deprecation/migration/test-infra/persona/docs). Deprecation sweep (REQ-068, REQ-072, REQ-089): - Add // Deprecated: doc comments to internal/daemon (R-001), internal/transport (REQ-073), internal/security/ca.go+csr.go (D-101/REQ-076), internal/engine/ dispatcher.go+peer.go (CLI-side scheduler), internal/cli/daemon.go. - orca daemon emits slog.Warn deprecation banner on every run (ungated); fires R-001 + v0.10-P05 drain-and-stop + v0.10-P14 deletion. - orca cert and orca node join (mTLS path) emit deprecation warnings; proxmox SSH path (the v0.9 replacement) does not warn. - Add --no-deprecation-warnings global flag on root command (PersistentPreRunE) for orca upgrade migrations. - 12 new daemon/cert/node deprecation tests in internal/cli/daemon_test.go (cli coverage 81.9%, warnDeprecated 100%). - Add DEPRECATED banners to v0.8 sections of ARCHITECTURE.md (verified the v0.9 supersession section + Supersession Table from prior turn are present). Bash tooling gate (grill C-06, C-15, C-16, C-17, C-18): - scripts/tests/test_helper.bash + example_test.bash — bats framework + helpers. - scripts/lib/orca-log.sh — slog-compatible JSON logging to syslog (C-17). - scripts/orca-verify-render.sh — render-contract validator skeleton (C-16). - scripts/tests/orca-log_test.bash + orca-verify-render_test.bash — 20 bats tests total (happy + failure paths per C-15). - .shellcheckrc — project shellcheck config. - Makefile: test-bash + lint-bash targets (graceful skip if tools missing); wired into test + lint targets. - internal/emit/contract.go + contract_test.go — versioned JSON render contract (orca.emit/v1) between Go emitters and bash appliers (C-16). - .ciagent/BASH_CAPABILITY_MAP_v0.9.md — maps shipped internal/transport capabilities to bash-side equivalents or accepted drops (C-18). - D-186 recorded in PROJECT.md: bash exempt from Go coverage gate; compensating control is bats + shellcheck + shfmt (C-06). verify-reqs: 90 requirements consistent. Build/test/lint/fmt all green. 20 bats tests pass. Go tests pass. No v0.8 code deleted — only marked deprecated (deletion deferred to v0.10-P14 per REQ-090 dual-write window). ---ci--- project: orca phase: P00 milestone: v0.9 status: execute ---/ci---
106 lines
3.6 KiB
Go
106 lines
3.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.cloudinit.dev/coreci/orca/internal/daemon"
|
|
"git.cloudinit.dev/coreci/orca/internal/engine"
|
|
"git.cloudinit.dev/coreci/orca/internal/store"
|
|
)
|
|
|
|
var (
|
|
daemonAddr string
|
|
pprofAddr string
|
|
)
|
|
|
|
var daemonCmd = &cobra.Command{
|
|
Use: "daemon",
|
|
Short: "Run the orca daemon (HTTP API + health checks)",
|
|
Long: `Start the orca daemon. Listens on the configured address for health, API, and dispatch requests.
|
|
|
|
Deprecated: v0.9 re-architecture replaces the orca daemon with SSH-push to
|
|
bare servers (R-001 — no orca binary on servers). The daemon is repurposed to
|
|
drain-and-stop in v0.10-P05 and scheduled for deletion in v0.10-P14. See
|
|
.ciagent/PRD_v0.9.md.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
warnDeprecated("orca daemon is deprecated in v0.9 and will be repurposed to 'drain-and-stop' in v0.10-P05; the v0.9 re-architecture (R-001) removes the orca binary from servers — see .ciagent/PRD_v0.9.md")
|
|
db, closer, err := openDB()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer closer()
|
|
|
|
log := newLogger()
|
|
addr := daemonAddr
|
|
if cfg := configFromCtx(cmd.Context()); cfg != nil && cfg.ListenAddr != "" && !cmd.Flags().Changed("addr") {
|
|
addr = cfg.ListenAddr
|
|
}
|
|
srv := daemon.NewServer(daemon.Options{
|
|
DB: db,
|
|
Log: log,
|
|
Addr: addr,
|
|
Actor: "daemon",
|
|
PprofAddr: pprofAddr,
|
|
})
|
|
|
|
// Wire the orca.v1.Dispatch service (v0.2 P02). The executor
|
|
// runs jobs locally; the dispatcher decides local vs peer.
|
|
executor := engine.NewExecutor(store.NewJobRepo(db), store.NewTaskRepo(db), log)
|
|
peers := engine.NewPeerRegistry()
|
|
dispatcher := engine.NewDispatcher(log, store.NewCapacityRepo(db), peers, executor)
|
|
srv.RegisterDispatch(daemon.NewDispatchHandlers(dispatcher, dispatcher.Dedupe()))
|
|
|
|
srv.MarkReady()
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
err := srv.Start()
|
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
errCh <- err
|
|
}
|
|
}()
|
|
|
|
fmt.Fprintf(cmd.OutOrStdout(), "✓ orca daemon listening on %s\n", daemonAddr)
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /healthz - liveness")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /readyz - readiness (db + ready flag)")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /v1/status - status JSON")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /v1/jobs - list jobs")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /v1/nodes - list nodes")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /v1/tasks - list tasks")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /orca.v1.Dispatch/Submit - cross-node job submit (P02)")
|
|
fmt.Fprintln(cmd.OutOrStdout(), " /orca.v1.Dispatch/Status - cross-node job status (P02)")
|
|
if pprofAddr != "" {
|
|
fmt.Fprintf(cmd.OutOrStdout(), " /debug/pprof/ (pprof) - %s\n", pprofAddr)
|
|
}
|
|
fmt.Fprintln(cmd.OutOrStdout(), " press Ctrl+C to stop")
|
|
|
|
ctx, stop := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
fmt.Fprintln(cmd.OutOrStdout(), "\nshutting down...")
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
return srv.Shutdown(shutdownCtx)
|
|
case err := <-errCh:
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
daemonCmd.Flags().StringVar(&daemonAddr, "addr", ":8080", "listen address")
|
|
daemonCmd.Flags().StringVar(&pprofAddr, "pprof", "", "enable pprof endpoint on <addr> (e.g. :6060); unauthenticated, operator-only")
|
|
rootCmd.AddCommand(daemonCmd)
|
|
}
|