Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only set replicas when we have more than 1 #30

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ linters:
- goerr113
- goimports
- revive
- gomnd
- misspell
- noctx
- stylecheck
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func init() {
cmdRun.PersistentFlags().BoolVarP(&dryrun, "dry-run", "", false, "In dryrun mode, the worker actions the task without installing firmware")
cmdRun.PersistentFlags().BoolVarP(&useStatusKV, "use-kv", "", false, "when this is true, flasher writes status to a NATS KV store instead of sending reply messages")
cmdRun.PersistentFlags().BoolVarP(&faultInjection, "fault-injection", "", false, "Tasks can include a Fault attribute to allow fault injection for development purposes")
cmdRun.PersistentFlags().IntVarP(&replicas, "nats-replicas", "r", 1, "the default number of replicas to use for NATS data")
cmdRun.PersistentFlags().IntVarP(&replicas, "replica-count", "r", 3, "the number of replicas to use for NATS data")

if err := cmdRun.MarkPersistentFlagRequired("store"); err != nil {
log.Fatal(err)
Expand Down
13 changes: 12 additions & 1 deletion internal/worker/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"go.hollow.sh/toolbox/events"
"go.hollow.sh/toolbox/events/pkg/kv"
"go.hollow.sh/toolbox/events/registry"

"github.com/nats-io/nats.go"
Expand All @@ -14,6 +15,7 @@ import (
var (
once sync.Once
checkinCadence = 30 * time.Second
livenessTTL = 3 * time.Minute
)

// This starts a go-routine to peridocally check in with the NATS kv
Expand All @@ -26,7 +28,16 @@ func (w *Worker) startWorkerLivenessCheckin(ctx context.Context) {
return
}

if err := registry.InitializeActiveControllerRegistry(natsJS); err != nil {
opts := []kv.Option{
kv.WithTTL(livenessTTL),
}

// any setting of replicas (even 1) chokes NATS in non-clustered mode
if w.replicaCount != 1 {
opts = append(opts, kv.WithReplicas(w.replicaCount))
}

if err := registry.InitializeRegistryWithOptions(natsJS, opts...); err != nil {
w.logger.WithError(err).Error("unable to initialize active worker registry")
return
}
Expand Down
6 changes: 5 additions & 1 deletion internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ func (o *Worker) runTaskWithMonitor(ctx context.Context, task *model.Task, asset

func (o *Worker) getStatusPublisher() sm.Publisher {
if o.useStatusKV {
return NewStatusKVPublisher(o.stream, o.logger, kv.WithReplicas(o.replicaCount))
var opts []kv.Option
if o.replicaCount > 1 {
opts = append(opts, kv.WithReplicas(o.replicaCount))
}
return NewStatusKVPublisher(o.stream, o.logger, opts...)
}
return &statusEmitter{o.stream, o.logger}
}
Expand Down