Skip to content

feat(domain): add WaitForDNSRecordNotExist waiter #2665

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
49 changes: 49 additions & 0 deletions api/domain/v2beta1/domain_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,55 @@ func (s *API) WaitForDNSRecordExist(
return dns.(*Record), nil
}

// WaitForDNSRecordNotExistRequest is used by WaitForDNSRecordNotExist method.
type WaitForDNSRecordNotExistRequest struct {
DNSZone string
RecordName string
RecordType RecordType
Timeout *time.Duration
RetryInterval *time.Duration
}

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

_, err := async.WaitSync(&async.WaitSyncConfig{
Get: func() (any, bool, error) {
DNSRecords, err := s.ListDNSZoneRecords(&ListDNSZoneRecordsRequest{
Name: req.RecordName,
Type: req.RecordType,
DNSZone: req.DNSZone,
}, opts...)
if err != nil {
return nil, false, err
}

if DNSRecords.TotalCount == 0 {
return nil, true, nil
}

return nil, false, nil
},
Timeout: timeout,
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
})
if err != nil {
return errors.Wrap(err, "waiting for DNS record to not exist failed")
}

return nil
}

// WaitForOrderDomainRequest is used by WaitForOrderDomain method.
type WaitForOrderDomainRequest struct {
Domain string
Expand Down
Loading