Skip to content

Commit

Permalink
feat(apple-silicon): add waiter terminal status ServerPrivateNetworkS…
Browse files Browse the repository at this point in the history
…t… (#2408)
  • Loading branch information
Laure-di authored Feb 6, 2025
1 parent 321fffa commit dd7ae0e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/applesilicon/v1alpha1/apple_silicon_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,39 @@ func (s *PrivateNetworkAPI) WaitForServerPrivateNetworks(req *WaitForServerReque

return serverPrivateNetworks.([]*ServerPrivateNetwork), nil
}

func (s *API) WaitForServerVPCOptionTerminalState(req *WaitForServerRequest, opts ...scw.RequestOption) error {
timeout := defaultTimeout
if req.Timeout != nil {
timeout = *req.Timeout
}
retryInterval := defaultRetryInterval
if req.RetryInterval != nil {
retryInterval = *req.RetryInterval
}

terminalStatus := map[ServerPrivateNetworkStatus]struct{}{
ServerPrivateNetworkStatusVpcEnabled: {},
ServerPrivateNetworkStatusVpcDisabled: {},
}
_, err := async.WaitSync(&async.WaitSyncConfig{
Get: func() (interface{}, bool, error) {
res, err := s.GetServer(&GetServerRequest{
ServerID: req.ServerID,
Zone: req.Zone,
}, opts...)
if err != nil {
return nil, false, err
}
_, isTerminal := terminalStatus[res.VpcStatus]

return res, isTerminal, nil
},
Timeout: timeout,
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
})
if err != nil {
return errors.Wrap(err, "waiting for vpc option terminal state failed")
}
return nil
}

0 comments on commit dd7ae0e

Please sign in to comment.