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

Fairer Task Queue: Add priority to lifecycle phases and deployments #252

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 0 deletions pkg/deployments/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Deployment struct {
FormValues map[string]string `json:"FormValues,omitempty"`
ManifestVariableSetID string `json:"ManifestVariableSetId,omitempty"`
Name string `json:"Name,omitempty"`
Priority string `json:"Priority" binding:"oneof=On Off LifecycleDefault"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is not set? Is it required? Is there a default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it sets it to an empty string. I've changed it to set the default to LifecycleDefault, with the omitempty tag

ProjectID string `json:"ProjectId,omitempty"`
QueueTime *time.Time `json:"QueueTime,omitempty"`
QueueTimeExpiry *time.Time `json:"QueueTimeExpiry,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/lifecycles/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestLifecycleAsJSON(t *testing.T) {
lifecycle.Phases[1].ID = "test-phase-id-2"
lifecycle.Phases[1].ReleaseRetentionPolicy = nil
lifecycle.Phases[1].TentacleRetentionPolicy = nil
lifecycle.Phases[1].IsPriorityPhase = true
lifecycle.TentacleRetentionPolicy.Unit = "Items"

lifecycle.ReleaseRetentionPolicy.QuantityToKeep = 3
Expand All @@ -44,6 +45,7 @@ func TestLifecycleAsJSON(t *testing.T) {
"AutomaticDeploymentTargets": ["test-AutomaticDeploymentTargets-1"],
"Id": "test-phase-id-1",
"IsOptionalPhase": true,
"IsPriorityPhase": false,
"MinimumEnvironmentsBeforePromotion": 123,
"Name": "test-phase-name-1",
"OptionalDeploymentTargets": ["Environments-1"],
Expand All @@ -65,6 +67,7 @@ func TestLifecycleAsJSON(t *testing.T) {
"OptionalDeploymentTargets": [],
"MinimumEnvironmentsBeforePromotion": 0,
"IsOptionalPhase": false,
"IsPriorityPhase": true,
"ReleaseRetentionPolicy": null,
"TentacleRetentionPolicy": null
}
Expand Down Expand Up @@ -206,6 +209,7 @@ func TestLifecycleFromJson(t *testing.T) {
],
"MinimumEnvironmentsBeforePromotion": 1,
"IsOptionalPhase": true,
"IsPriorityPhase": false,
"ReleaseRetentionPolicy": {
"Unit": "Days",
"QuantityToKeep": 1,
Expand Down Expand Up @@ -256,6 +260,7 @@ func TestLifecycleFromJson(t *testing.T) {
require.Equal(t, "A", phase0.Name)
require.Equal(t, int32(1), phase0.MinimumEnvironmentsBeforePromotion)
require.Equal(t, true, phase0.IsOptionalPhase)
require.Equal(t, false, phase0.IsPriorityPhase)
require.Equal(t, 1, len(phase0.AutomaticDeploymentTargets))
require.Equal(t, "Environments-2", phase0.AutomaticDeploymentTargets[0])
require.Equal(t, 1, len(phase0.OptionalDeploymentTargets))
Expand Down
1 change: 1 addition & 0 deletions pkg/lifecycles/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Phase struct {
AutomaticDeploymentTargets []string `json:"AutomaticDeploymentTargets"`
ID string `json:"Id,omitempty"`
IsOptionalPhase bool `json:"IsOptionalPhase"`
IsPriorityPhase bool `json:"IsPriorityPhase"`
MinimumEnvironmentsBeforePromotion int32 `json:"MinimumEnvironmentsBeforePromotion"`
Name string `json:"Name" validate:"required"`
OptionalDeploymentTargets []string `json:"OptionalDeploymentTargets"`
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/lifecycle_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,29 @@ func TestLifecycleAddGetAndDelete_NewClient(t *testing.T) {
assert.Equal(t, lifecycle.Name, getLifecycle.Name)
}

func TestLifecycleAddGetUpdateAndDeleteWithPhases_NewClient(t *testing.T) {
octopusClient := getOctopusClient()
require.NotNil(t, octopusClient)

lifecycle := createTestLifecycle_NewClient(t, octopusClient, internal.GetRandomName())
defer cleanLifecycle_NewClient(t, octopusClient, lifecycle)

priorityPhase := lifecycles.NewPhase(internal.GetRandomName())
priorityPhase.IsPriorityPhase = true

lifecycle.Phases = append(lifecycle.Phases, priorityPhase)
updatedLifecycle, err := lifecycles.Update(octopusClient, lifecycle)

assert.NoError(t, err, "there was an error when updating the lifecycle")
require.NotNil(t, updatedLifecycle)

getLifecycle, err := lifecycles.GetByID(octopusClient, lifecycle.SpaceID, lifecycle.GetID())
assert.NoError(t, err, "there was an error raised getting lifecycle when there should not be")
assert.Equal(t, lifecycle.Name, getLifecycle.Name)

assert.True(t, getLifecycle.Phases[0].IsPriorityPhase)
}

func createTestLifecycle_NewClient(t *testing.T, client *client.Client, lifecycleName string) *lifecycles.Lifecycle {
if client == nil {
client = getOctopusClient()
Expand Down
Loading