Skip to content

Conversation

@octopus-hideaki
Copy link
Contributor

@octopus-hideaki octopus-hideaki commented Nov 30, 2025

Add support for the new "Strategy" property in Octopus server.
[sc-126260]

This enables runbook retention to be set to:

  • Forever - keep all
  • Count - keep limited number
  • Default - policy is set by the space default retention policy for runbooks

@Rose-Northey
Copy link
Contributor

Rose-Northey commented Dec 1, 2025

Add support for the new "Strategy" property in Octopus server.
[sc-126260]

@Rose-Northey
Copy link
Contributor

Add support for the new "Strategy" property in Octopus server.
Maybe something to at a glance distinguish this from my go client work e.g. "Adds new strategy property to runbooks which enables them to be set as:

  1. Forever - keep all
  2. Count - keep limited number
  3. Default - policy is set by the space default retention policy for runbooks

Copy link
Contributor

@Rose-Northey Rose-Northey Dec 1, 2025

Choose a reason for hiding this comment

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

should we be including omitempty for strategy? I'd thought it was a required field. Is it because of backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean line 64 and line 81 in pkg/runbooks/runbook_retention_policy.go?
Yeah that is a mistake


type RunbookRetentionPolicy struct {
Strategy string `json:"Strategy"`
QuantityToKeep int32 `json:"QuantityToKeep"`
Copy link
Contributor

@Rose-Northey Rose-Northey Dec 1, 2025

Choose a reason for hiding this comment

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

Is QTK better as an "omitempty"?

Copy link
Contributor Author

@octopus-hideaki octopus-hideaki Dec 2, 2025

Choose a reason for hiding this comment

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

I am not marking it as omit empty for backwards compatibility. We want to serialise QTK and the unit for older servers that may not support the strategy field.

Copy link
Contributor

Choose a reason for hiding this comment

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

ooooh this makes sense! very clever

func NewDefaultRunbookRetentionPolicy() *RunbookRetentionPolicy {
return &RunbookRetentionPolicy{
Strategy: RunbookRetentionStrategyDefault,
QuantityToKeep: 100,
Copy link
Contributor

@Rose-Northey Rose-Northey Dec 1, 2025

Choose a reason for hiding this comment

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

If we are setting to a default strategy do we still need to set the QTK and unit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned above, keeping for backwards compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh!

func NewKeepForeverRunbookRetentionPolicy() *RunbookRetentionPolicy {
return &RunbookRetentionPolicy{
Strategy: RunbookRetentionStrategyForever,
QuantityToKeep: 0,
Copy link
Contributor

@Rose-Northey Rose-Northey Dec 1, 2025

Choose a reason for hiding this comment

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

can QTK and Unit be omitted? They will be ignored by the server. Or is it needed for compatibility with the current terraform for runbooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned above, keeping for backwards compatibility.

}

if fields.QuantityToKeep == 100 && r.Unit == RunbookRetentionUnitItems {
r.Strategy = RunbookRetentionStrategyDefault
Copy link
Contributor

Choose a reason for hiding this comment

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

  • If the server is old and doesn't support default but the go client is new, what will happen?
  • If the user changed the default strategy to QTK = 50 could they send an API request with omitted Strategy, QTK = 0 and Unit = Items and have unexpected results?

Copy link
Contributor Author

@octopus-hideaki octopus-hideaki Dec 2, 2025

Choose a reason for hiding this comment

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

If the server is old and doesn't support default but the go client is new, what will happen?

If the server is old and the Go client is new, since the Go client is still sending the old property, the server will receive the system default properties. Then, when the server is upgraded, the values will be correctly migrated to the default value.

If the user changed the default strategy to QTK = 50 could they send an API request with omitted Strategy, QTK = 0 and Unit = Items and have unexpected results?

Not sure if I follow. I think what you mean is: Would the user experience unexpected results if they omit the strategy and send the system default value, but they are on the new server and has set a space-wide default?

If the user sets the policy with the system default (QTK = 100 + Unit = items) and doesn't set the strategy, it will set the policy to the space default.

I think this is fine since the number of users that do this will be small compared to the alternative, where a bunch of runbooks will get custom values when the user is not intending to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's worth noting that they will have to update their policy to deliberately omit the strategy policy. Since the default value for their runbooks will have the new "strategy" property.

Copy link
Contributor

@Rose-Northey Rose-Northey left a comment

Choose a reason for hiding this comment

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

Hey, looking good but I left some questions on the approach. I'd love to discuss

@octopus-hideaki octopus-hideaki changed the title feat: Add support for runbook retention strategy feat: Add support for new runbook retention "Strategy" property Dec 2, 2025
@Rose-Northey Rose-Northey marked this pull request as ready for review December 2, 2025 02:30
Copy link
Contributor

@Rose-Northey Rose-Northey left a comment

Choose a reason for hiding this comment

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

Cheers for the clarifications! Thanks heaps

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.

2 participants