diff --git a/internal/app/cmd/create-runner-file_test.go b/internal/app/cmd/create-runner-file_test.go index e55a3d7..5afcda3 100644 --- a/internal/app/cmd/create-runner-file_test.go +++ b/internal/app/cmd/create-runner-file_test.go @@ -96,7 +96,7 @@ func Test_runCreateRunnerFile(t *testing.T) { // // Read back the runner file and verify its content // - reg, err := config.LoadRegistration(runnerFile) + reg, err := config.LoadRegistration(runnerFile, cfg.Runner.Labels) assert.NoError(t, err) assert.EqualValues(t, secret, reg.Token) assert.EqualValues(t, instance, reg.Address) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index f381b36..58919aa 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -37,7 +37,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, initLogging(cfg) log.Infoln("Starting runner daemon") - reg, err := config.LoadRegistration(cfg.Runner.File) + reg, err := config.LoadRegistration(cfg.Runner.File, cfg.Runner.Labels) if os.IsNotExist(err) { log.Error("registration file not found, please register the runner first") return err @@ -48,10 +48,6 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, cfg.Tune(reg.Address) lbls := reg.Labels - if len(cfg.Runner.Labels) > 0 { - lbls = cfg.Runner.Labels - } - ls := labels.Labels{} for _, l := range lbls { label, err := labels.Parse(l) diff --git a/internal/pkg/config/registration.go b/internal/pkg/config/registration.go index be66b4f..748d69d 100644 --- a/internal/pkg/config/registration.go +++ b/internal/pkg/config/registration.go @@ -22,7 +22,7 @@ type Registration struct { Labels []string `json:"labels"` } -func LoadRegistration(file string) (*Registration, error) { +func LoadRegistration(file string, labels []string) (*Registration, error) { f, err := os.Open(file) if err != nil { return nil, err @@ -34,6 +34,9 @@ func LoadRegistration(file string) (*Registration, error) { return nil, err } + if len(labels) > 0 { + reg.Labels = labels + } reg.Warning = "" return ®, nil