Repository navigation
fix(agent): read the Kairos version from kairos-release, not os-release twice - #4766
Conversation
…se twice config.Scan says it loads the version from the kairos-release file and then opens /etc/os-release, and the branch commented "Fallback into os-release" opens the same file again. kairos-init writes KAIROS_VERSION to /etc/kairos-release only, so the line that names the running system's version was never printed on an image it built, and the fallback could never fire. Both deferred closes captured the same variable, which the second Open reassigns, so the first handle was never closed: one leaked descriptor per scan. The error from Open was discarded too, and a failed Open went into godotenv.Parse, which is safe only because vfs.OSFS returns a typed-nil *os.File. Read the pair in the order sdk/utils.OSRelease already uses, close each file as soon as it is parsed, and skip a path that cannot be opened. Fixes kairos-io#4765 Signed-off-by: Ettore Di Giacinto <mudler@kairos.io>
Taking a look at this one: reviewing the diff and the tests. |
itxaka-agent
left a comment
There was a problem hiding this comment.
Automated triage agent (
kairos-triage-agent) running as@itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.
Looks good. kairosVersion now reads /etc/kairos-release first and falls back to /etc/os-release, each file is closed right after parsing, and a failed open is skipped. The new tests cover the precedence, the fallback and the descriptor count.
QA in progress: I'm testing this now. Results and proof will follow here. |
QA: pass at da47f93, details and proof: #4765 (comment) |
Fixes #4765
config.Scansays it loads the Kairos version from the kairos-release file, then opens/etc/os-release, and the branch commented "Fallback into os-release" opens the samefile a second time.
kairos-initwritesKAIROS_VERSIONto/etc/kairos-releaseonly,so the "Kairos System" log line was never printed on an image it built, and the fallback
could never fire.
Two more defects in the same block:
fvariable, which the secondOpenreassigns,so the handle from the first
Openwas never closed. A verbatim copy of the old blockrun 50 times grows the process from 8 open descriptors to 58.
Openwas discarded, both assignments flagged bywastedassign, and afailed
Openwent intogodotenv.Parse. That is safe today only becausevfs.OSFSreturns a typed-nil
*os.File, whose methods are nil-safe.The change reads the pair in the order
sdk/utils.OSReleasealready uses, kairos-releasefirst and os-release as the fallback, closes each file as soon as it is parsed, and skips
a path that cannot be opened.
Tests
Five ginkgo specs in
agent/pkg/config/scan_internal_test.go, over avfstfilesystemholding a real image's two files. Both halves were mutation-checked against this branch:
reads the version from kairos-releasef.Close()removedcloses what it opensgo test ./agent/pkg/config/...passes,golangci-lint run ./agent/pkg/config/...reports0 issues, and
wastedassignno longer fires on the package.Written by an AI agent. No human has read the code yet.