feat(runner): merge admin-added labels from server on declare
Some checks failed
CI / build-and-test (push) Has been cancelled
Release / build (amd64, darwin) (push) Successful in 49s
Release / build (amd64, linux) (push) Successful in 1m4s
Release / build (amd64, windows) (push) Successful in 52s
Release / build (arm64, darwin) (push) Successful in 54s
Release / build (arm64, linux) (push) Successful in 47s
Release / release (push) Successful in 21s
Some checks failed
CI / build-and-test (push) Has been cancelled
Release / build (amd64, darwin) (push) Successful in 49s
Release / build (amd64, linux) (push) Successful in 1m4s
Release / build (amd64, windows) (push) Successful in 52s
Release / build (arm64, darwin) (push) Successful in 54s
Release / build (arm64, linux) (push) Successful in 47s
Release / release (push) Successful in 21s
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user