feat(vpn): Add wait handlers for VPN gateway creation, update and deletion#7071
Open
s-inter wants to merge 13 commits into
Open
feat(vpn): Add wait handlers for VPN gateway creation, update and deletion#7071s-inter wants to merge 13 commits into
s-inter wants to merge 13 commits into
Conversation
8 tasks
This reverts commit a67637a.
This comment was marked as resolved.
This comment was marked as resolved.
rubenhoenle
reviewed
May 12, 2026
rubenhoenle
reviewed
May 12, 2026
| 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] { |
Member
There was a problem hiding this comment.
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)
}
Contributor
Author
There was a problem hiding this comment.
Good point and thanks for the write-up - now it seems obvious...
…handlers - create CreateGatewayWaitHandler and UpdateGatewayWaitHandler - keep createOrUpdateGatewayWaitHandler as internal helper - update related tests
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.
Description
relates to STACKITTPR-633
Checklist
make fmtexamples/directory)make test(will be checked by CI)make lint(will be checked by CI)