Skip to content

feat: toggle the enabled state of workers - #731

Draft
NickJosevski wants to merge 2 commits into
nj/issue-311from
nj/issue-311-workers
Draft

NickJosevski wants to merge 2 commits into
nj/issue-311from
nj/issue-311-workers

Conversation

@NickJosevski

Copy link
Copy Markdown
Contributor

Stacked on #694 — merges into nj/issue-311, not main. Review #694 first.

Answers the "should workers get the same treatment?" question on #694: yes.

What changed

Refactor first — the enable/disable flow moves from pkg/cmd/target/shared/disabledstate.go into pkg/machinescommon, behind a Machine interface and a MachineKind that describes one machine repository. The noun in the prompt, the "already enabled" message and the "no ... to disable were found" error all come from the kind, so there is one copy of the flow instead of one per machine type. Deployment targets keep exactly the behaviour and output they had.

New commandsoctopus worker enable [<name> | <id>] and octopus worker disable [<name> | <id>], mirroring the deployment-target pair: prompts when no identifier is given (offering only workers not already in the requested state), short circuits without an update call when the worker is already in that state, errors under --no-prompt when no identifier is supplied.

New create flag--disabled on worker listening-tentacle create and worker ssh create (the two worker types with a create command), included in the generated automation command. Flag-only, no prompt — same as the target side.

--disabled's help text is now parameterised by noun, the way RegisterCreateTargetProxyFlags already is.

Test evidence

  • pkg/machinescommon/disabledstate_test.go — the prompt flow against a fake Machine, covering both nouns; replaces the old pkg/cmd/target/shared/disabledstate_test.go.
  • pkg/cmd/worker/enable/enable_test.go, pkg/cmd/worker/disable/disable_test.go — end-to-end through the root command against the mock HTTP server: named worker, already-in-state short circuit, interactive prompt. The PUT body is asserted to carry the flipped IsDisabled.
  • pkg/cmd/worker/worker_test.goenable/disable registered, and both worker create commands expose --disabled.
  • test/integration/worker_test.go — mirrors the deployment-target integration test, including that a toggle leaves the worker's other settings untouched.

go build ./... clean; go test ./pkg/... all pass. Both integration tests (TestWorkerEnableDisable and the existing TestDeploymentTargetEnableDisable, to check the refactor) run green against a local Octopus instance. gofmt/go vet report only pre-existing issues in files this PR does not touch.

🤖 Generated with Claude Code

NickJosevski and others added 2 commits September 15, 2026 17:26
Moves the shared enable/disable logic out of pkg/cmd/target/shared and into
pkg/machinescommon, behind a Machine interface and a MachineKind describing one
machine repository. Deployment targets keep the behaviour and output they had;
workers can now reuse it.

The noun in the prompt, the "already enabled" message and the "no ... to
disable were found" error all come from the kind, so there is one copy of the
flow rather than one per machine type.

Also parameterises the --disabled help text by noun, the way
RegisterCreateTargetProxyFlags already does.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Adds `octopus worker enable|disable [<name> | <id>]` and a `--disabled` flag on
`worker listening-tentacle create` and `worker ssh create`, mirroring the
deployment-target commands exactly: same prompt when no identifier is given,
same short circuit when the worker is already in the requested state, and the
flag is included in the generated automation command.

Test support: a worker fixture, and the Workers link on the fake root resource
so command tests can reach the workers endpoints.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant