Skip to content

Commit d64a7b7

Browse files
committed
fix(cockpit): remove WaitForAlert and keep only WaitForPreconfiguredAlerts
1 parent 417d470 commit d64a7b7

File tree

3 files changed

+2
-72
lines changed

3 files changed

+2
-72
lines changed

api/cockpit/v1/cockpit_utils.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,6 @@ const (
1313
defaultTimeout = 5 * time.Minute
1414
)
1515

16-
// WaitForAlertRequest is used by WaitForAlert method.
17-
type WaitForAlertRequest struct {
18-
Region scw.Region
19-
AlertID string
20-
Timeout *time.Duration
21-
RetryInterval *time.Duration
22-
}
23-
24-
// WaitForAlert waits for the alert to be in a "terminal state" before returning.
25-
// This function can be used to wait for an alert to be enabled or disabled.
26-
func (s *RegionalAPI) WaitForAlert(req *WaitForAlertRequest, opts ...scw.RequestOption) (*Alert, error) {
27-
timeout := defaultTimeout
28-
if req.Timeout != nil {
29-
timeout = *req.Timeout
30-
}
31-
retryInterval := defaultRetryInterval
32-
if req.RetryInterval != nil {
33-
retryInterval = *req.RetryInterval
34-
}
35-
36-
terminalStatus := map[AlertStatus]struct{}{
37-
AlertStatusEnabled: {},
38-
AlertStatusDisabled: {},
39-
}
40-
41-
alert, err := async.WaitSync(&async.WaitSyncConfig{
42-
Get: func() (any, bool, error) {
43-
// List all alerts and find the one with matching ID
44-
res, err := s.ListAlerts(&RegionalAPIListAlertsRequest{
45-
Region: req.Region,
46-
}, opts...)
47-
if err != nil {
48-
return nil, false, err
49-
}
50-
51-
// Find the alert by ID
52-
for _, alert := range res.Alerts {
53-
if alert.ID == req.AlertID {
54-
_, isTerminal := terminalStatus[alert.RuleStatus]
55-
return alert, isTerminal, nil
56-
}
57-
}
58-
59-
return nil, false, errors.New("alert not found")
60-
},
61-
Timeout: timeout,
62-
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
63-
})
64-
if err != nil {
65-
return nil, errors.Wrap(err, "waiting for alert failed")
66-
}
67-
return alert.(*Alert), nil
68-
}
69-
7016
// WaitForPreconfiguredAlertsRequest is used by WaitForPreconfiguredAlerts method.
7117
type WaitForPreconfiguredAlertsRequest struct {
7218
Region scw.Region
@@ -90,17 +36,14 @@ func (s *RegionalAPI) WaitForPreconfiguredAlerts(req *WaitForPreconfiguredAlerts
9036
retryInterval = *req.RetryInterval
9137
}
9238

93-
// For enabling/disabling, accept transitional states as terminal
9439
var terminalStatus map[AlertStatus]struct{}
9540
switch req.TargetStatus {
9641
case AlertStatusEnabled:
97-
// Accept both enabled and enabling as terminal states
9842
terminalStatus = map[AlertStatus]struct{}{
9943
AlertStatusEnabled: {},
10044
AlertStatusEnabling: {},
10145
}
10246
case AlertStatusDisabled:
103-
// Accept both disabled and disabling as terminal states
10447
terminalStatus = map[AlertStatus]struct{}{
10548
AlertStatusDisabled: {},
10649
AlertStatusDisabling: {},
@@ -113,7 +56,6 @@ func (s *RegionalAPI) WaitForPreconfiguredAlerts(req *WaitForPreconfiguredAlerts
11356

11457
result, err := async.WaitSync(&async.WaitSyncConfig{
11558
Get: func() (any, bool, error) {
116-
// List all preconfigured alerts for the project
11759
res, err := s.ListAlerts(&RegionalAPIListAlertsRequest{
11860
Region: req.Region,
11961
ProjectID: req.ProjectID,
@@ -123,15 +65,13 @@ func (s *RegionalAPI) WaitForPreconfiguredAlerts(req *WaitForPreconfiguredAlerts
12365
return nil, false, err
12466
}
12567

126-
// Create a map of rule ID to alert
12768
alertsByRuleID := make(map[string]*Alert)
12869
for _, alert := range res.Alerts {
12970
if alert.PreconfiguredData != nil && alert.PreconfiguredData.PreconfiguredRuleID != "" {
13071
alertsByRuleID[alert.PreconfiguredData.PreconfiguredRuleID] = alert
13172
}
13273
}
13374

134-
// Check if all requested alerts are in terminal state
13575
var matchedAlerts []*Alert
13676
for _, ruleID := range req.PreconfiguredRules {
13777
alert, found := alertsByRuleID[ruleID]
@@ -141,14 +81,12 @@ func (s *RegionalAPI) WaitForPreconfiguredAlerts(req *WaitForPreconfiguredAlerts
14181

14282
_, isTerminal := terminalStatus[alert.RuleStatus]
14383
if !isTerminal {
144-
// At least one alert is not in terminal state, continue waiting
14584
return nil, false, nil
14685
}
14786

14887
matchedAlerts = append(matchedAlerts, alert)
14988
}
15089

151-
// All alerts are in terminal state
15290
return matchedAlerts, true, nil
15391
},
15492
Timeout: timeout,
@@ -159,4 +97,3 @@ func (s *RegionalAPI) WaitForPreconfiguredAlerts(req *WaitForPreconfiguredAlerts
15997
}
16098
return result.([]*Alert), nil
16199
}
162-

api/cockpit/v1/sweepers/sweepers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func SweepGrafanaUser(scwClient *scw.Client) error {
5757
continue
5858
}
5959

60+
//nolint:staticcheck // Deprecated functions are still functional and needed for sweepers
6061
listGrafanaUsers, err := cockpitAPI.ListGrafanaUsers(&cockpit.GlobalAPIListGrafanaUsersRequest{
6162
ProjectID: project.ID,
6263
}, scw.WithAllPages())
@@ -65,6 +66,7 @@ func SweepGrafanaUser(scwClient *scw.Client) error {
6566
}
6667

6768
for _, grafanaUser := range listGrafanaUsers.GrafanaUsers {
69+
//nolint:staticcheck // Deprecated functions are still functional and needed for sweepers
6870
err = cockpitAPI.DeleteGrafanaUser(&cockpit.GlobalAPIDeleteGrafanaUserRequest{
6971
ProjectID: project.ID,
7072
GrafanaUserID: grafanaUser.ID,

api/domain/v2beta1/domain_utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func (s *API) WaitForDNSZone(
5858
listReq.DNSZone = &req.DNSZone
5959
}
6060

61-
// listing dnsZone zones and take the first one
6261
DNSZones, err := s.ListDNSZones(listReq, opts...)
6362
if err != nil {
6463
return nil, false, err
@@ -108,7 +107,6 @@ func (s *API) WaitForDNSRecordExist(
108107

109108
dns, err := async.WaitSync(&async.WaitSyncConfig{
110109
Get: func() (any, bool, error) {
111-
// listing dns zone records and take the first one
112110
DNSRecords, err := s.ListDNSZoneRecords(&ListDNSZoneRecordsRequest{
113111
Name: req.RecordName,
114112
Type: req.RecordType,
@@ -157,7 +155,6 @@ func (s *RegistrarAPI) WaitForOrderDomain(
157155
retryInterval = *req.RetryInterval
158156
}
159157

160-
// Terminal statuses indicating success or error.
161158
terminalStatuses := map[DomainStatus]struct{}{
162159
DomainStatusActive: {},
163160
DomainStatusExpired: {},
@@ -205,7 +202,6 @@ type WaitForAutoRenewStatusRequest struct {
205202
// WaitForAutoRenewStatus polls the domain until its auto‑renew feature reaches a terminal state
206203
// (either "enabled" or "disabled"). It uses GetDomain() to fetch the current status.
207204
func (s *RegistrarAPI) WaitForAutoRenewStatus(req *WaitForAutoRenewStatusRequest, opts ...scw.RequestOption) (*Domain, error) {
208-
// Use default timeout and retry interval if not provided.
209205
timeout := defaultTimeout
210206
if req.Timeout != nil {
211207
timeout = *req.Timeout
@@ -215,7 +211,6 @@ func (s *RegistrarAPI) WaitForAutoRenewStatus(req *WaitForAutoRenewStatusRequest
215211
retryInterval = *req.RetryInterval
216212
}
217213

218-
// Terminal statuses for auto_renew: enabled or disabled.
219214
terminalStatuses := map[DomainFeatureStatus]struct{}{
220215
DomainFeatureStatusEnabled: {},
221216
DomainFeatureStatusDisabled: {},
@@ -257,7 +252,6 @@ type WaitForDNSSECStatusRequest struct {
257252
// WaitForDNSSECStatus polls the domain until its DNSSEC feature reaches a terminal state
258253
// (either "enabled" or "disabled"). It uses GetDomain() to fetch the current status.
259254
func (s *RegistrarAPI) WaitForDNSSECStatus(req *WaitForDNSSECStatusRequest, opts ...scw.RequestOption) (*Domain, error) {
260-
// Use default timeout and retry interval if not provided.
261255
timeout := defaultTimeout
262256
if req.Timeout != nil {
263257
timeout = *req.Timeout
@@ -267,7 +261,6 @@ func (s *RegistrarAPI) WaitForDNSSECStatus(req *WaitForDNSSECStatusRequest, opts
267261
retryInterval = *req.RetryInterval
268262
}
269263

270-
// Terminal statuses for DNSSEC: enabled or disabled.
271264
terminalStatuses := map[DomainFeatureStatus]struct{}{
272265
DomainFeatureStatusEnabled: {},
273266
DomainFeatureStatusDisabled: {},
@@ -277,15 +270,13 @@ func (s *RegistrarAPI) WaitForDNSSECStatus(req *WaitForDNSSECStatusRequest, opts
277270

278271
domainResult, err := async.WaitSync(&async.WaitSyncConfig{
279272
Get: func() (any, bool, error) {
280-
// Retrieve the domain.
281273
resp, err := s.GetDomain(&RegistrarAPIGetDomainRequest{
282274
Domain: req.Domain,
283275
}, opts...)
284276
if err != nil {
285277
return nil, false, err
286278
}
287279

288-
// Check the current DNSSEC status.
289280
lastStatus = resp.Dnssec.Status
290281
if _, isTerminal := terminalStatuses[resp.Dnssec.Status]; isTerminal {
291282
return resp, true, nil

0 commit comments

Comments
 (0)