2
0

feat(runner): merge admin-added labels from server on declare

Adds MergeServerLabels method to sync labels added by admins in Gitea UI with runner's local configuration. Called after successful declare response to incorporate any server-side label changes. Skips duplicate labels and logs invalid entries. Enables dynamic label management without requiring runner restart or config file edits.
This commit is contained in:
2026-02-09 02:15:23 -05:00
parent 522ee44718
commit c9fce154c3
2 changed files with 25 additions and 2 deletions

View File

@@ -200,6 +200,8 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu
default:
log.Infof("runner: %s, with version: %s, with labels: %v, declare successfully",
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
// Merge any admin-added labels from the server
runner.MergeServerLabels(resp.Msg.Runner.Labels)
}
// Start periodic capabilities update goroutine

View File

@@ -308,10 +308,31 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
}
// Declare sends the runner's labels and capabilities to the server.
func (r *Runner) Declare(ctx context.Context, labels []string, capabilitiesJSON string) (*connect.Response[runnerv1.DeclareResponse], error) {
func (r *Runner) Declare(ctx context.Context, declareLabels []string, capabilitiesJSON string) (*connect.Response[runnerv1.DeclareResponse], error) {
return r.client.Declare(ctx, connect.NewRequest(&runnerv1.DeclareRequest{
Version: ver.Version(),
Labels: labels,
Labels: declareLabels,
CapabilitiesJson: capabilitiesJSON,
}))
}
// MergeServerLabels merges labels returned from the server (which may include admin-added labels)
// with the runner's existing labels. This allows admins to add labels via the Gitea UI.
func (r *Runner) MergeServerLabels(serverLabels []string) {
existing := make(map[string]bool)
for _, l := range r.labels {
existing[l.Name] = true
}
for _, labelStr := range serverLabels {
label, err := labels.Parse(labelStr)
if err != nil {
log.Warnf("ignoring invalid server label %q: %v", labelStr, err)
continue
}
if !existing[label.Name] {
r.labels = append(r.labels, label)
log.Infof("merged server label: %s", labelStr)
}
}
}