Skip to content

feat(vpn): Add wait handlers for VPN gateway creation, update and deletion#7071

Open
s-inter wants to merge 13 commits into
mainfrom
si/vpn-waiter
Open

feat(vpn): Add wait handlers for VPN gateway creation, update and deletion#7071
s-inter wants to merge 13 commits into
mainfrom
si/vpn-waiter

Conversation

@s-inter
Copy link
Copy Markdown
Contributor

@s-inter s-inter commented May 4, 2026

Description

relates to STACKITTPR-633

Checklist

  • Issue was linked above
  • No generated code was adjusted manually (check comments in file header)
  • Changelogs
    • Changelog in the root directory was adjusted (see here)
    • Changelog(s) of the service(s) were adjusted (see e.g. here)
  • VERSION file(s) of the service(s) were adjusted
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@s-inter s-inter marked this pull request as ready for review May 4, 2026 14:41
@s-inter s-inter requested a review from a team as a code owner May 4, 2026 14:41
@s-inter s-inter changed the title feat: Add wait handlers for VPN gateway creation, update and deletion Feat: Add wait handlers for VPN gateway creation, update and deletion May 4, 2026
@s-inter s-inter changed the title Feat: Add wait handlers for VPN gateway creation, update and deletion feat(vpn): Add wait handlers for VPN gateway creation, update and deletion May 11, 2026
@rubenhoenle

This comment was marked as resolved.

Comment thread services/vpn/v1api/wait/wait.go Outdated
Comment thread services/vpn/v1api/wait/wait.go Outdated
vpn "github.com/stackitcloud/stackit-sdk-go/services/vpn/v1api"
)

func CreateOrUpdateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm no fan of that CreateOrUpdate... wait handlers TBH.

Because - in theory - what should we do if one day there is the Status CREATED and UPDATED?

We can't just remove the CreateOrUpdateGatewayWaitHandler wait handler and add a CreateGatewayWaitHandler and a UpdateGatewayWaitHandler wait handler. That would be a breaking change.

I would propose you do the following instead: Seperate wait handlers for create and update (public visibility) which call an create-or-update wait handler (private visibility). This way we have the full control for the future without having to duplicate waiter logic.

// PRIVATE VISIBILITY - CONTAINS THE COMMON LOGIC FOR CREATE AND UPDATE WAIT HANDLING
func createOrUpdateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] {
	waitConfig := wait.WaiterHelper[vpn.GatewayResponse, vpn.GatewayStatus]{
		FetchInstance: a.GetGateway(ctx, projectId, region, gatewayId).Execute,
		GetState: func(resp *vpn.GatewayResponse) (vpn.GatewayStatus, error) {
			if resp == nil {
				return "", errors.New("could not get gateway status: response is nil")
			}
			if resp.State == nil {
				return "", errors.New("could not get gateway status: state is nil")
			}
			return *resp.State, nil
		},
		ActiveState: []vpn.GatewayStatus{vpn.GATEWAYSTATUS_READY},
		ErrorState:  []vpn.GatewayStatus{vpn.GATEWAYSTATUS_ERROR, vpn.GATEWAYSTATUS_DELETING},
	}

	handler := wait.New(waitConfig.Wait())
	handler.SetTimeout(45 * time.Minute)
	return handler
}

// PUBLIC VISIBILITY
func CreateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] {
    // Killer argument: This internal logic can be changed anytime without creating a breaking change! :-)
    return createOrUpdateGatewayWaitHandler(ctx, a, projectId, region, gatewayId)
}

// PUBLIC VISIBILITY
func UpdateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] {
    // Killer argument: This internal logic can be changed anytime without creating a breaking change! :-)
    return createOrUpdateGatewayWaitHandler(ctx, a, projectId, region, gatewayId)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point and thanks for the write-up - now it seems obvious...

s-inter and others added 3 commits May 12, 2026 17:38
…handlers

- create CreateGatewayWaitHandler and UpdateGatewayWaitHandler
- keep createOrUpdateGatewayWaitHandler as internal helper
- update related tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants