hub: keep previous state when reload fails#635
Merged
Conversation
All eight YAML loaders (resourcedescriptors, resourceeditors, resourcedashboards, resourceoutlines, resourcetabledefinitions, resourceblockdefinitions, menuoutlines, clusterprofiles) wiped the package-global map at the start of every reload and panicked on any walk error. ReloadIfTriggered is invoked from init() (where panic is acceptable — embedded data must be valid) AND from every public lookup, so a hot-reloaded bad YAML dropped into /tmp/hub/<kind>/ — exactly the workflow documented in hub/README.md for live api-servers — would kill the running process from the next caller. Build into a temporary map per loader and swap atomically only when the walk succeeds. On reload failure, klog and keep the previous map. The first-load case (package globals still nil) still panics so init crashes loud if embedded data is bad. Signed-off-by: Tamal Saha <tamal@appscode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hub/resourcedescriptors/lib.go,resourceeditors/,resourcedashboards/,resourceoutlines/,resourcetabledefinitions/,resourceblockdefinitions/,menuoutlines/,clusterprofiles/) wiped the package-global map at the start of every reload andpaniced on any walk/unmarshal error.ReloadIfTriggeredis invoked frominit()(panic OK — embedded data is part of the build) and from every public lookup. The hot-reload mechanism documented inhub/README.md—kubectl cpa YAML into the pod's/tmp/hub/<kind>/, write to the trigger file — would therefore kill the running api-server from the first caller after a bad YAML was dropped.klog.ErrorSand keep the previous map. The first-load case (package globals still nil) still panics soinit()crashes loud if embedded data is malformed.Test plan
make unit-tests/tmp/hub/resourcedescriptors/, touch the trigger file, and confirm the api-server logs an error and keeps serving the previous descriptors instead of crashing.init()still panics when an embedded YAML is intentionally corrupted (usego build -tags faultstyle if needed).🤖 Generated with Claude Code