feat: toggle the enabled state of deployment targets - #694
Draft
NickJosevski wants to merge 1 commit into
Draft
Conversation
Adds `octopus deployment-target enable|disable [<name> | <id>]`, which flips `IsDisabled` on the machine and reports when the target is already in the requested state. The target is prompted for when no name or ID is supplied, matching the existing `tenant enable|disable` commands. Also adds a shared `--disabled` flag to every deployment-target create command so a target can be created in a disabled state, and includes it in the generated automation command. Fixes #311 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #311
What changed
New commands —
octopus deployment-target enable [<name> | <id>]andoctopus deployment-target disable [<name> | <id>].Machines.GetByIdentifier, flipsIsDisabled, and saves viamachines.Update.selectors.Selectover all targets, the same waydeployment-target deletedoes. Under--no-prompta missing identifier is an error.pkg/cmd/target/shared/disabledstate.go;enable/disableare thin cobra wrappers over it.New create flag —
--disabledon every deployment-targetcreatecommand (azure-web-app,cloud-region,kubernetes,listening-tentacle,ssh), registered from a sharedmachinescommon.CreateTargetDisabledFlagsand included in the generated automation command. It is flag-only: it deliberately does not add a prompt to the interactive create flow.Test support —
testutil.NewRootResource()now publishes theMachineslink so command tests can exercise the machines endpoints.Test evidence
New tests:
pkg/cmd/target/enable/enable_test.go,pkg/cmd/target/disable/disable_test.go— end-to-end through the root command against the mock HTTP server, in the style ofrelease/progression/prevent: named target, already-in-state short circuit, and the interactive prompt path. The PUT body is asserted to carry the flippedIsDisabled.pkg/cmd/target/shared/disabledstate_test.go— prompting behaviour (identifier supplied vs not, and the enable/disable wording).pkg/cmd/target/target_test.go— the enable/disable subcommands are registered and every targetcreatecommand exposes--disabled.Results from the worktree:
go build ./...— clean.go test ./pkg/...— all packages pass, no failures. (gofmt/go vetreport only pre-existing issues in files this PR does not touch.)No live server is required by any of these tests.
Open questions / options
1. Dedicated
enable/disablesubcommands vs a generalupdatecommand. The issue suggests "a new deployment target update command". I implemented the subcommands instead.octopus tenant enable|disable, so the CLI stays internally consistent; each command has exactly one effect, so--no-promptautomation is unambiguous.update --enabled/--disabled: extensible to name, roles, environments, tenants, machine policy, worker pool later — but a much larger surface to get right, and per-target-type (endpoint) fields would force either one giant command or five type-specificupdatecommands mirroringcreate.deployment-target updatecan cover the remaining editable fields, and enable/disable would remain the ergonomic shortcut. Decision needed: is the team happy with this being the answer to Enhancement: Add support for toggling enabled state of deployment targets #311, or should the issue stay open for the broaderupdatecommand?2. Should workers get the same treatment?
machines.Workercarries the sameIsDisabledfield andpkg/cmd/workermirrorspkg/cmd/targetclosely, sooctopus worker enable|disableplus--disabledonworker */createwould be a near-identical change. I scoped this PR to deployment targets because that is what the issue asks for. Decision needed: do it in this PR, a follow-up, or not at all? (If yes, the shared helper would want to move frompkg/cmd/target/sharedintopkg/machinescommonand be generalised over target/worker.)3. Flag naming at creation time. I used
--disabled(bool, default false).--disabled: matches the API field (IsDisabled) and themachine.IsDisabledmodel; a bare--disabledreads naturally andflag.GenerateAutomationCmdalready emits bare bool flags correctly.--enabled=false: reads more positively but requires the=falseform (cobra bools cannot take a separate value argument), which is awkward, and a default-true bool flag is easy to misread in help output.--disable: verb form, closer to the subcommand names, but inconsistent with the resource-state noun used elsewhere.--disabled. Decision needed: confirm, since renaming a shipped flag later is a breaking change.4. Should
deployment-target view/listsurface the disabled state? Neither currently shows it, so after disabling a target there is no CLI way to confirm it other than the web UI. Adding it changes the table columns and the JSON shape, so I left it out of this PR. Worth a follow-up?🤖 Generated with Claude Code