Browse Source
admin: auto migrating master maintenance scripts to admin_script plugin config (#8509)
admin: auto migrating master maintenance scripts to admin_script plugin config (#8509)
* admin: seed admin_script plugin config from master maintenance scripts
When the admin server starts, fetch the maintenance scripts configuration
from the master via GetMasterConfiguration. If the admin_script plugin
worker does not already have a saved config, use the master's scripts as
the default value. This enables seamless migration from master.toml
[master.maintenance] to the admin script plugin worker.
Changes:
- Add maintenance_scripts and maintenance_sleep_minutes fields to
GetMasterConfigurationResponse in master.proto
- Populate the new fields from viper config in master_grpc_server.go
- On admin server startup, fetch the master config and seed the
admin_script plugin config if no config exists yet
- Strip lock/unlock commands from the master scripts since the admin
script worker handles locking automatically
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address review comments on admin_script seeding
- Replace TOCTOU race (separate Load+Save) with atomic
SaveJobTypeConfigIfNotExists on ConfigStore and Plugin
- Replace ineffective polling loop with single GetMaster call using
30s context timeout, since GetMaster respects context cancellation
- Add unit tests for SaveJobTypeConfigIfNotExists (in-memory + on-disk)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: apply maintenance script defaults in gRPC handler
The gRPC handler for GetMasterConfiguration read maintenance scripts
from viper without calling SetDefault, relying on startAdminScripts
having run first. If the admin server calls GetMasterConfiguration
before startAdminScripts sets the defaults, viper returns empty
strings and the seeding is silently skipped.
Apply SetDefault in the gRPC handler itself so it is self-contained.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Revert "fix: apply maintenance script defaults in gRPC handler"
This reverts commit 068a506330.
* fix: use atomic save in ensureJobTypeConfigFromDescriptor
ensureJobTypeConfigFromDescriptor used a separate Load + Save, racing
with seedAdminScriptFromMaster. If the descriptor defaults (empty
script) were saved first, SaveJobTypeConfigIfNotExists in the seeding
goroutine would see an existing config and skip, losing the master's
maintenance scripts.
Switch to SaveJobTypeConfigIfNotExists so both paths are atomic. Whichever
wins, the other is a safe no-op.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: fetch master scripts inline during config bootstrap, not in goroutine
Replace the seedAdminScriptFromMaster goroutine with a
ConfigDefaultsProvider callback. When the plugin bootstraps
admin_script defaults from the worker descriptor, it calls the
provider which fetches maintenance scripts from the master
synchronously. This eliminates the race between the seeding
goroutine and the descriptor-based config bootstrap.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* skip commented lock unlock
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
* reduce grpc calls
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pull/8490/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 368 additions and 39 deletions
-
101weed/admin/dash/admin_server.go
-
77weed/admin/dash/admin_server_seed_test.go
-
47weed/admin/plugin/config_store.go
-
75weed/admin/plugin/config_store_test.go
-
33weed/admin/plugin/plugin.go
-
2weed/cluster/maintenance/maintenance_config.go
-
3weed/pb/master.proto
-
42weed/pb/master_pb/master.pb.go
-
25weed/server/master_grpc_server.go
-
2weed/server/master_server.go
@ -0,0 +1,77 @@ |
|||
// MIGRATION: Tests for enrichConfigDefaults helpers. Remove after March 2027.
|
|||
package dash |
|||
|
|||
import "testing" |
|||
|
|||
func TestCleanMaintenanceScript(t *testing.T) { |
|||
tests := []struct { |
|||
name string |
|||
input string |
|||
expected string |
|||
}{ |
|||
{ |
|||
name: "empty", |
|||
input: "", |
|||
expected: "", |
|||
}, |
|||
{ |
|||
name: "only lock unlock", |
|||
input: " lock\n unlock\n", |
|||
expected: "", |
|||
}, |
|||
{ |
|||
name: "strips lock and unlock", |
|||
input: " lock\n ec.balance -apply\n volume.fix.replication -apply\n unlock\n", |
|||
expected: "ec.balance -apply\nvolume.fix.replication -apply", |
|||
}, |
|||
{ |
|||
name: "case insensitive lock", |
|||
input: "Lock\nec.balance -apply\nUNLOCK", |
|||
expected: "ec.balance -apply", |
|||
}, |
|||
{ |
|||
name: "preserves comments removal", |
|||
input: "lock\n# a comment\nec.balance -apply\nunlock", |
|||
expected: "ec.balance -apply", |
|||
}, |
|||
{ |
|||
name: "no lock unlock present", |
|||
input: "ec.balance -apply\nvolume.fix.replication -apply", |
|||
expected: "ec.balance -apply\nvolume.fix.replication -apply", |
|||
}, |
|||
{ |
|||
name: "windows line endings", |
|||
input: "lock\r\nec.balance -apply\r\nunlock\r\n", |
|||
expected: "ec.balance -apply", |
|||
}, |
|||
{ |
|||
name: "lock with inline comment", |
|||
input: "lock # migration\nec.balance -apply\nunlock # done", |
|||
expected: "ec.balance -apply", |
|||
}, |
|||
{ |
|||
name: "command with inline comment preserved", |
|||
input: "lock\nec.balance -apply # rebalance shards\nunlock", |
|||
expected: "ec.balance -apply", |
|||
}, |
|||
{ |
|||
name: "only inline comment after stripping", |
|||
input: "# full line comment\n # indented comment\n", |
|||
expected: "", |
|||
}, |
|||
{ |
|||
name: "typical master default", |
|||
input: "\n lock\n ec.encode -fullPercent=95 -quietFor=1h\n ec.rebuild -apply\n ec.balance -apply\n fs.log.purge -daysAgo=7\n volume.deleteEmpty -quietFor=24h -apply\n volume.balance -apply\n volume.fix.replication -apply\n s3.clean.uploads -timeAgo=24h\n unlock\n", |
|||
expected: "ec.encode -fullPercent=95 -quietFor=1h\nec.rebuild -apply\nec.balance -apply\nfs.log.purge -daysAgo=7\nvolume.deleteEmpty -quietFor=24h -apply\nvolume.balance -apply\nvolume.fix.replication -apply\ns3.clean.uploads -timeAgo=24h", |
|||
}, |
|||
} |
|||
|
|||
for _, tt := range tests { |
|||
t.Run(tt.name, func(t *testing.T) { |
|||
got := cleanMaintenanceScript(tt.input) |
|||
if got != tt.expected { |
|||
t.Errorf("cleanMaintenanceScript(%q) = %q, want %q", tt.input, got, tt.expected) |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue