-
Notifications
You must be signed in to change notification settings - Fork 13
Deprovision a project for an ephemeral environment #563
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
Conversation
416abac to
97712fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds functionality to deprovision projects in ephemeral environments, allowing users to tear down specific project deployments when PRs are closed.
Key changes include:
- Added a shared utility function
GetByNamefor finding ephemeral environments by name with case-insensitive exact matching - Implemented
deprovision-projectcommand to deprovision a specific project in an ephemeral environment - Implemented
deprovision-environmentcommand to deprovision an entire ephemeral environment - Updated dependency to
go-octopusdeploy/v2 v2.88.0to support new deprovisioning APIs
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/ephemeralenvironment/util/util.go | New utility function for finding ephemeral environments by name with case-insensitive matching |
| pkg/cmd/ephemeralenvironment/util/util_test.go | Comprehensive tests for the GetByName utility function |
| pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project.go | Command implementation for deprovisioning a project in an ephemeral environment |
| pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project_test.go | Test coverage for the deprovision-project command |
| pkg/cmd/ephemeralenvironment/deprovision-environment/deprovision_environment.go | Command implementation for deprovisioning an entire ephemeral environment |
| pkg/cmd/ephemeralenvironment/deprovision-environment/deprovision_environment_test.go | Test coverage for the deprovision-environment command |
| pkg/cmd/ephemeralenvironment/ephemeralenvironment.go | Registration of new deprovision commands |
| go.mod | Updated go-octopusdeploy/v2 dependency to v2.88.0 |
| go.sum | Updated checksums for new dependency version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project.go
Outdated
Show resolved
Hide resolved
pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project.go
Outdated
Show resolved
Hide resolved
…roject.go Co-authored-by: Copilot <[email protected]>
c337352 to
112f88f
Compare
| } | ||
|
|
||
| if slices.ContainsFunc(projectChannels, func(channel *channels.Channel) bool { | ||
| return channel.Type == "EphemeralEnvironment" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The go library defines a constant we can use channels.ChannelTypeEphemeral
|
|
||
| environmentId := environmentResource.ID | ||
|
|
||
| cmd.Printf("Deprovisioning ephemeral environment '%s' with id '%s' for project '%s'...\n", opts.Name.Value, environmentId, opts.Project.Value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output function displays a message about deprovisioning. Can either remove this one, or the one in the function. Yours is more specific to the project as well, if it is removed in the function just remember to add one to the deprovision environment command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the one from the util function and added a message to the command
|
|
||
| cmd.Printf("\nSuccessfully deprovisioned ephemeral environment for project '%s' with id '%s'.\n", opts.Project.Value, environmentId) | ||
|
|
||
| util.OutPutDeprovisionResult(opts.Name.Value, cmd, []ephemeralenvironments.DeprovisioningRunbookRun{deprovisionedEnv.DeprovisioningRun}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If deprovisionedEnv.DeprovisioningRun can be nil, this will make a slice containing nil [nil] which will have a count of 1, and the Output function will error because it checks for nil, or length of 0.
As an aside I've also just noticed OutPutDeprovisionResult should probably be OutputDeprovisionResult. Sorry that's my bad 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it receives a null runbookrun it creates one with empty strings rather than having a null. So I just check that
|
LGTM |
Context 🌆
Ephemeral environments are temporary environments that developers can use to test changes. They are expected to come and go with the same cadence as a PR, created when the PR is opened and torn down when it is merged.
Users need to be able to deprovision a specific project in an ephemeral environment
Details 🔍
I have added a command that allows users to deprovision a specific project in an ephemeral environment. The user must provide both a project and an ephemeral environment.

With no deprovisioning runbook
Tasting 🧪
I have added automated tests to provide the behaviour of this new command.
[sc-124014]