Skip to content

Commit d1abe2d

Browse files
Fix linting issues identified in CI
- Remove unused functions: getLocations and isRetryableError - Fix gofumpt formatting issues in errors.go - Add proper response body closing in addSSHKeyIdempotent - Remove unused ctx parameter from handleLLAPIError - Clean up imports to remove unused packages All tests pass locally and linting issues are resolved. Co-Authored-By: Alec Fong <alecsanf@usc.edu>
1 parent 9cdc172 commit d1abe2d

File tree

3 files changed

+12
-40
lines changed

3 files changed

+12
-40
lines changed

internal/lambdalabs/v1/errors.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package v1
22

33
import (
4-
"context"
54
"fmt"
65
"net/http"
76
"strings"
87

98
v1 "github.com/brevdev/compute/pkg/v1"
109
)
1110

12-
func handleLLAPIError(ctx context.Context, resp *http.Response, err error) error {
11+
func handleLLAPIError(resp *http.Response, err error) error {
1312
if err == nil {
1413
return nil
1514
}
@@ -23,50 +22,28 @@ func handleLLErrToCloudErr(err error) error {
2322
}
2423

2524
errStr := err.Error()
26-
25+
2726
if strings.Contains(errStr, "insufficient capacity") ||
2827
strings.Contains(errStr, "no capacity") ||
2928
strings.Contains(errStr, "capacity not available") {
3029
return v1.ErrInsufficientResources
3130
}
32-
31+
3332
if strings.Contains(errStr, "quota") ||
3433
strings.Contains(errStr, "limit exceeded") ||
3534
strings.Contains(errStr, "too many") {
3635
return v1.ErrOutOfQuota
3736
}
38-
37+
3938
if strings.Contains(errStr, "not found") ||
4039
strings.Contains(errStr, "does not exist") {
4140
return v1.ErrInstanceNotFound
4241
}
43-
42+
4443
if strings.Contains(errStr, "service unavailable") ||
4544
strings.Contains(errStr, "temporarily unavailable") {
4645
return v1.ErrServiceUnavailable
4746
}
48-
49-
return fmt.Errorf("lambda labs error: %w", err)
50-
}
5147

52-
func isRetryableError(err error) bool {
53-
if err == nil {
54-
return false
55-
}
56-
57-
errStr := err.Error()
58-
59-
if strings.Contains(errStr, "unauthorized") ||
60-
strings.Contains(errStr, "forbidden") ||
61-
strings.Contains(errStr, "not found") ||
62-
strings.Contains(errStr, "invalid") ||
63-
strings.Contains(errStr, "bad request") {
64-
return false
65-
}
66-
67-
return strings.Contains(errStr, "capacity") ||
68-
strings.Contains(errStr, "timeout") ||
69-
strings.Contains(errStr, "temporary") ||
70-
strings.Contains(errStr, "service unavailable") ||
71-
strings.Contains(errStr, "internal server error")
48+
return fmt.Errorf("lambda labs error: %w", err)
7249
}

internal/lambdalabs/v1/instance.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,21 @@ func (c *LambdaLabsClient) ListInstances(ctx context.Context, _ v1.ListInstances
119119
}
120120

121121
func (c *LambdaLabsClient) addSSHKeyIdempotent(ctx context.Context, keyName, publicKey string) error {
122-
_, _, err := c.client.DefaultAPI.AddSSHKey(c.makeAuthContext(ctx)).AddSSHKeyRequest(openapi.AddSSHKeyRequest{
122+
_, resp, err := c.client.DefaultAPI.AddSSHKey(c.makeAuthContext(ctx)).AddSSHKeyRequest(openapi.AddSSHKeyRequest{
123123
Name: keyName,
124124
PublicKey: &publicKey,
125125
}).Execute()
126-
126+
if resp != nil {
127+
defer func() { _ = resp.Body.Close() }()
128+
}
129+
127130
if err != nil {
128131
if strings.Contains(err.Error(), "name must be unique") {
129132
return nil
130133
}
131134
return handleLLErrToCloudErr(err)
132135
}
133-
136+
134137
return nil
135138
}
136139

internal/lambdalabs/v1/instancetype.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ func (c *LambdaLabsClient) GetLocations(_ context.Context, _ v1.GetLocationsArgs
148148
return locations, nil
149149
}
150150

151-
func getLocations() []LambdaLocation {
152-
var locations []LambdaLocation
153-
err := json.Unmarshal([]byte(lambdaLocationsData), &locations)
154-
if err != nil {
155-
return []LambdaLocation{}
156-
}
157-
return locations
158-
}
159151

160152
func contains(slice []string, item string) bool {
161153
for _, s := range slice {

0 commit comments

Comments
 (0)