From f1181cc62a0eeb2664d1d0d06623ff40dc6d8a9d Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Sat, 6 Apr 2024 20:09:56 +0200 Subject: [PATCH 1/5] after reading labels, load them into registration --- internal/app/cmd/daemon.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index e56a13f..8de19f4 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -64,6 +64,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, if len(ls) == 0 { log.Warn("no labels configured, runner may not be able to pick up jobs") } + reg.Labels = ls.ToStrings() if ls.RequireDocker() { dockerSocketPath, err := getDockerSocketPath(cfg.Container.DockerHost) From 7abbd84a8a3dbfe64332a9def3a7c7ad9cedda4e Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Tue, 9 Apr 2024 20:53:12 +0200 Subject: [PATCH 2/5] add label change post runner creation --- internal/app/cmd/daemon.go | 2 +- internal/app/run/runner.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index 8de19f4..8e47bf6 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -64,7 +64,6 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, if len(ls) == 0 { log.Warn("no labels configured, runner may not be able to pick up jobs") } - reg.Labels = ls.ToStrings() if ls.RequireDocker() { dockerSocketPath, err := getDockerSocketPath(cfg.Container.DockerHost) @@ -112,6 +111,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully", resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels) // if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified) + runner.Update(ctx, ls) reg.Labels = ls.ToStrings() if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { return fmt.Errorf("failed to save runner config: %w", err) diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index ee12165..ff54fa7 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -242,3 +242,7 @@ func (r *Runner) Declare(ctx context.Context, labels []string) (*connect.Respons Labels: labels, })) } + +func (r *Runner) Update(ctx context.Context, labels labels.Labels) { + r.labels = labels +} From 5660e21fb8cf58fa6c42b02d97afd26410ef312f Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Wed, 10 Apr 2024 22:39:55 +0200 Subject: [PATCH 3/5] added simple test to label update --- internal/app/run/runner_test.go | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 internal/app/run/runner_test.go diff --git a/internal/app/run/runner_test.go b/internal/app/run/runner_test.go new file mode 100644 index 0000000..cb40323 --- /dev/null +++ b/internal/app/run/runner_test.go @@ -0,0 +1,38 @@ +package run + +import ( + "context" + "testing" + + "gitea.com/gitea/act_runner/internal/pkg/labels" + "github.com/stretchr/testify/assert" +) + +func TestLabelUpdate(t *testing.T) { + ctx := context.Background() + ls := labels.Labels{} + + initialLabel, err := labels.Parse("testlabel:docker://alpine") + assert.Nil(t, err) + ls = append(ls, initialLabel) + + newLs := labels.Labels{} + + newLabel, err := labels.Parse("next label:host") + assert.Nil(t, err) + newLs = append(newLs, initialLabel) + newLs = append(newLs, newLabel) + + runner := Runner{ + labels: ls, + } + + assert.Contains(t, runner.labels, initialLabel) + assert.NotContains(t, runner.labels, newLabel) + + runner.Update(ctx, newLs) + + assert.Contains(t, runner.labels, initialLabel) + assert.Contains(t, runner.labels, newLabel) + +} From 599c75c16733d4a043151163b997259ec713841b Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Wed, 10 Apr 2024 23:20:34 +0200 Subject: [PATCH 4/5] replace Nil with NoError --- internal/app/run/runner_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/app/run/runner_test.go b/internal/app/run/runner_test.go index cb40323..0145c70 100644 --- a/internal/app/run/runner_test.go +++ b/internal/app/run/runner_test.go @@ -13,13 +13,13 @@ func TestLabelUpdate(t *testing.T) { ls := labels.Labels{} initialLabel, err := labels.Parse("testlabel:docker://alpine") - assert.Nil(t, err) + assert.NoError(t, err) ls = append(ls, initialLabel) newLs := labels.Labels{} newLabel, err := labels.Parse("next label:host") - assert.Nil(t, err) + assert.NoError(t, err) newLs = append(newLs, initialLabel) newLs = append(newLs, newLabel) @@ -34,5 +34,4 @@ func TestLabelUpdate(t *testing.T) { assert.Contains(t, runner.labels, initialLabel) assert.Contains(t, runner.labels, newLabel) - } From 5539ef727524efabab4e39b0c7c75800c4b845b4 Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Wed, 10 Apr 2024 23:52:10 +0200 Subject: [PATCH 5/5] add release notes --- RELEASE-NOTES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 6951540..bdcb071 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,5 +1,11 @@ # Release Notes +## 3.4.2 + +* [Fix label declaration](https://code.forgejo.org/forgejo/runner/pulls/176): Runner in daemon mode now takes labels found in config.yml into account when declaration was successful. +* [Fix the docker compose example](https://code.forgejo.org/forgejo/runner/pulls/175) to workaround the race on labels. +* [Fix the kubernetes dind example](https://code.forgejo.org/forgejo/runner/pulls/169). + ## 3.4.1 * Fixes a regression introduced in 3.4.0 by which a job with no image explicitly set would