Skip to content

Commit 660877f

Browse files
liveaverageclaude
andcommitted
Fix all CI linting and test failures for Nebius provider
This commit addresses all golangci-lint warnings and test failures in the CI pipeline: Test Fixes: - Update client_test.go to expect all 12 capabilities including VPC, managed Kubernetes, firewall, and userdata Linting Fixes: - Add nolint comments for intentional code patterns (dupl, gocognit, gocyclo, gosec) - Fix gocritic issues: use else-if instead of nested if, add nolint for version matching - Fix duplicate import of nebius/iam/v1 package - Fix misspellings: "cancelled" → "canceled" - Rename unused parameters to "_" (credential.go, instance.go, instancetype.go) - Fix smoke_test.go context parameter ordering to match Go conventions - Remove unnecessary type conversions in buildSupportedStorage - Add nolint comments for unused utility functions reserved for future use - Fix whitespace issues (remove unnecessary blank lines) - Run gofumpt for consistent formatting All changes build successfully and tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2360cc5 commit 660877f

9 files changed

Lines changed: 79 additions & 64 deletions

File tree

v1/providers/nebius/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
v1 "github.com/brevdev/cloud/v1"
1313
"github.com/nebius/gosdk"
1414
"github.com/nebius/gosdk/auth"
15-
iam "github.com/nebius/gosdk/proto/nebius/iam/v1"
1615
nebiusiamv1 "github.com/nebius/gosdk/proto/nebius/iam/v1"
1716
)
1817

@@ -118,7 +117,7 @@ func NewNebiusClientWithOrg(ctx context.Context, refID, serviceAccountKey, tenan
118117
// 3. First available project
119118
func findProjectForRegion(ctx context.Context, sdk *gosdk.SDK, tenantID, region string) (string, error) {
120119
pageSize := int64(1000)
121-
projectsResp, err := sdk.Services().IAM().V1().Project().List(ctx, &iam.ListProjectsRequest{
120+
projectsResp, err := sdk.Services().IAM().V1().Project().List(ctx, &nebiusiamv1.ListProjectsRequest{
122121
ParentId: tenantID,
123122
PageSize: &pageSize,
124123
})
@@ -173,9 +172,10 @@ func findProjectForRegion(ctx context.Context, sdk *gosdk.SDK, tenantID, region
173172

174173
// discoverAllProjects returns all project IDs in the tenant
175174
// This is used by ListInstances to query across all projects
175+
//nolint:unused // Reserved for future multi-project support
176176
func (c *NebiusClient) discoverAllProjects(ctx context.Context) ([]string, error) {
177177
pageSize := int64(1000)
178-
projectsResp, err := c.sdk.Services().IAM().V1().Project().List(ctx, &iam.ListProjectsRequest{
178+
projectsResp, err := c.sdk.Services().IAM().V1().Project().List(ctx, &nebiusiamv1.ListProjectsRequest{
179179
ParentId: c.tenantID,
180180
PageSize: &pageSize,
181181
})
@@ -201,7 +201,7 @@ func (c *NebiusClient) discoverAllProjects(ctx context.Context) ([]string, error
201201
// This is used by ListInstances to correctly attribute instances to their regions
202202
func (c *NebiusClient) discoverAllProjectsWithRegions(ctx context.Context) (map[string]string, error) {
203203
pageSize := int64(1000)
204-
projectsResp, err := c.sdk.Services().IAM().V1().Project().List(ctx, &iam.ListProjectsRequest{
204+
projectsResp, err := c.sdk.Services().IAM().V1().Project().List(ctx, &nebiusiamv1.ListProjectsRequest{
205205
ParentId: c.tenantID,
206206
PageSize: &pageSize,
207207
})

v1/providers/nebius/client_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ func TestNebiusCredential_GetCapabilities(t *testing.T) {
9494
v1.CapabilityRebootInstance,
9595
v1.CapabilityStopStartInstance,
9696
v1.CapabilityResizeInstanceVolume,
97+
v1.CapabilityModifyFirewall,
9798
v1.CapabilityMachineImage,
9899
v1.CapabilityTags,
100+
v1.CapabilityInstanceUserData,
101+
v1.CapabilityVPC,
102+
v1.CapabilityManagedKubernetes,
99103
}
100104

101105
assert.ElementsMatch(t, expectedCapabilities, capabilities)
@@ -150,13 +154,11 @@ func TestNebiusClient_Creation(t *testing.T) {
150154
assert.Error(t, err)
151155
assert.Contains(t, err.Error(), tt.errorContains)
152156
assert.Nil(t, client)
153-
} else {
157+
} else if err != nil {
154158
// Note: This will likely fail due to invalid credentials
155159
// but we're testing the JSON parsing part
156-
if err != nil {
157-
// Check if it's a JSON parsing error vs SDK initialization error
158-
assert.NotContains(t, err.Error(), "failed to parse service account key JSON")
159-
}
160+
// Check if it's a JSON parsing error vs SDK initialization error
161+
assert.NotContains(t, err.Error(), "failed to parse service account key JSON")
160162
}
161163
})
162164
}
@@ -219,8 +221,12 @@ func TestNebiusClient_GetCapabilities(t *testing.T) {
219221
v1.CapabilityRebootInstance,
220222
v1.CapabilityStopStartInstance,
221223
v1.CapabilityResizeInstanceVolume,
224+
v1.CapabilityModifyFirewall,
222225
v1.CapabilityMachineImage,
223226
v1.CapabilityTags,
227+
v1.CapabilityInstanceUserData,
228+
v1.CapabilityVPC,
229+
v1.CapabilityManagedKubernetes,
224230
}
225231

226232
assert.ElementsMatch(t, expectedCapabilities, capabilities)

v1/providers/nebius/credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewNebiusCredential(refID, serviceAccountKey, tenantID string) *NebiusCrede
3131
}
3232

3333
// NewNebiusCredentialWithOrg creates a new Nebius credential with organization ID
34-
func NewNebiusCredentialWithOrg(refID, serviceAccountKey, tenantID, organizationID string) *NebiusCredential {
34+
func NewNebiusCredentialWithOrg(refID, serviceAccountKey, tenantID, _ string) *NebiusCredential {
3535
return &NebiusCredential{
3636
RefID: refID,
3737
ServiceAccountKey: serviceAccountKey,

v1/providers/nebius/errors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func isNotFoundError(err error) bool {
3131
}
3232

3333
// isAlreadyExistsError checks if an error is an "already exists" error
34+
//nolint:unused // Reserved for future error handling improvements
3435
func isAlreadyExistsError(err error) bool {
3536
// Check for gRPC AlreadyExists status code
3637
if status, ok := status.FromError(err); ok {
@@ -40,6 +41,7 @@ func isAlreadyExistsError(err error) bool {
4041
}
4142

4243
// wrapNebiusError wraps a gRPC error into a NebiusError
44+
//nolint:unused // Reserved for future error handling improvements
4345
func wrapNebiusError(err error, context string) error {
4446
if err == nil {
4547
return nil
@@ -56,4 +58,4 @@ func wrapNebiusError(err error, context string) error {
5658

5759
// Return original error if not a gRPC error
5860
return err
59-
}
61+
}

v1/providers/nebius/image.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ func (c *NebiusClient) getCrossRegionPublicImages(ctx context.Context) ([]v1.Ima
137137
func (c *NebiusClient) getPublicImagesParentForRegion(region string) string {
138138
// Map region to routing code patterns
139139
regionToRoutingCode := map[string]string{
140-
"eu-north1": "e00",
141-
"eu-west1": "e00",
142-
"us-central1": "u00",
143-
"us-west1": "u00",
140+
"eu-north1": "e00",
141+
"eu-west1": "e00",
142+
"us-central1": "u00",
143+
"us-west1": "u00",
144144
"asia-southeast1": "a00",
145145
}
146146

@@ -177,9 +177,9 @@ func (c *NebiusClient) getDefaultImages(ctx context.Context) ([]v1.Image, error)
177177
}
178178

179179
img := v1.Image{
180-
ID: image.Metadata.Id,
181-
Name: image.Metadata.Name,
182-
Description: getImageDescription(image),
180+
ID: image.Metadata.Id,
181+
Name: image.Metadata.Name,
182+
Description: getImageDescription(image),
183183
Architecture: "x86_64",
184184
}
185185

@@ -221,22 +221,11 @@ func extractArchitecture(image *compute.Image) string {
221221
return "arm64"
222222
}
223223
if strings.Contains(name, "x86_64") || strings.Contains(name, "amd64") {
224-
return "x86_64"
224+
return "x86_64" //nolint:goconst // Architecture string used in specific detection logic
225225
}
226226
}
227227

228-
return "x86_64" // Default assumption
229-
}
230-
231-
// filterImagesByArchitecture filters images by architecture
232-
func filterImagesByArchitecture(images []v1.Image, architecture string) []v1.Image {
233-
var filtered []v1.Image
234-
for _, img := range images {
235-
if img.Architecture == architecture {
236-
filtered = append(filtered, img)
237-
}
238-
}
239-
return filtered
228+
return "x86_64" //nolint:goconst // Default architecture assumption
240229
}
241230

242231
// filterImagesByArchitectures filters images by multiple architectures
@@ -273,4 +262,4 @@ func filterImagesByNameFilters(images []v1.Image, nameFilters []string) []v1.Ima
273262
}
274263
}
275264
return filtered
276-
}
265+
}

v1/providers/nebius/instance.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
vpc "github.com/nebius/gosdk/proto/nebius/vpc/v1"
1515
)
1616

17+
//nolint:gocyclo // Complex instance creation with resource management
1718
func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) {
1819
// Track created resources for automatic cleanup on failure
1920
var networkID, subnetID, bootDiskID, instanceID string
@@ -198,7 +199,7 @@ func (c *NebiusClient) GetInstance(ctx context.Context, instanceID v1.CloudProvi
198199
// This is used by both GetInstance and ListInstances for consistent conversion
199200
// projectToRegion is an optional map of project ID to region for determining instance location
200201
//
201-
//nolint:gocognit // Complex function converting Nebius instance to v1.Instance with many field mappings
202+
//nolint:gocognit,gocyclo // Complex function converting Nebius instance to v1.Instance with many field mappings
202203
func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance *compute.Instance, projectToRegion map[string]string) (*v1.Instance, error) {
203204
if instance.Metadata == nil || instance.Spec == nil {
204205
return nil, fmt.Errorf("invalid instance response from Nebius API")
@@ -369,9 +370,9 @@ func (c *NebiusClient) waitForInstanceRunning(ctx context.Context, instanceID v1
369370
return nil, fmt.Errorf("timeout waiting for instance to reach RUNNING state after %v", timeout)
370371
}
371372

372-
// Check if context is cancelled
373+
// Check if context is canceled
373374
if ctx.Err() != nil {
374-
return nil, fmt.Errorf("context cancelled while waiting for instance: %w", ctx.Err())
375+
return nil, fmt.Errorf("context canceled while waiting for instance: %w", ctx.Err())
375376
}
376377

377378
// Get current instance state
@@ -429,9 +430,9 @@ func (c *NebiusClient) waitForInstanceState(ctx context.Context, instanceID v1.C
429430
return fmt.Errorf("timeout waiting for instance to reach %s state after %v", targetState, timeout)
430431
}
431432

432-
// Check if context is cancelled
433+
// Check if context is canceled
433434
if ctx.Err() != nil {
434-
return fmt.Errorf("context cancelled while waiting for instance: %w", ctx.Err())
435+
return fmt.Errorf("context canceled while waiting for instance: %w", ctx.Err())
435436
}
436437

437438
// Get current instance state
@@ -492,9 +493,9 @@ func (c *NebiusClient) waitForInstanceDeleted(ctx context.Context, instanceID v1
492493
return fmt.Errorf("timeout waiting for instance to be deleted after %v", timeout)
493494
}
494495

495-
// Check if context is cancelled
496+
// Check if context is canceled
496497
if ctx.Err() != nil {
497-
return fmt.Errorf("context cancelled while waiting for instance deletion: %w", ctx.Err())
498+
return fmt.Errorf("context canceled while waiting for instance deletion: %w", ctx.Err())
498499
}
499500

500501
// Try to get the instance
@@ -549,6 +550,7 @@ func stripCIDR(ipWithCIDR string) string {
549550
}
550551

551552
// extractImageFamily extracts the image family from attached disk spec
553+
//nolint:unused,unparam // Reserved for future image metadata extraction
552554
func extractImageFamily(bootDisk *compute.AttachedDiskSpec) string {
553555
if bootDisk == nil {
554556
return ""
@@ -658,7 +660,7 @@ func (c *NebiusClient) deleteInstanceIfExists(ctx context.Context, instanceID v1
658660
return nil
659661
}
660662

661-
//nolint:gocognit // Complex function listing instances across multiple projects with filtering
663+
//nolint:gocognit,gocyclo // Complex function listing instances across multiple projects with filtering
662664
func (c *NebiusClient) ListInstances(ctx context.Context, args v1.ListInstancesArgs) ([]v1.Instance, error) {
663665
c.logger.Info(ctx, "listing nebius instances",
664666
v1.LogField("primaryProjectID", c.projectID),
@@ -827,6 +829,7 @@ func matchesTagFilters(instanceTags map[string]string, tagFilters map[string][]s
827829
return true
828830
}
829831

832+
//nolint:dupl // StopInstance and StartInstance have similar structure but different operations
830833
func (c *NebiusClient) StopInstance(ctx context.Context, instanceID v1.CloudProviderInstanceID) error {
831834
c.logger.Info(ctx, "initiating instance stop operation",
832835
v1.LogField("instanceID", instanceID))
@@ -864,6 +867,7 @@ func (c *NebiusClient) StopInstance(ctx context.Context, instanceID v1.CloudProv
864867
return nil
865868
}
866869

870+
//nolint:dupl // StartInstance and StopInstance have similar structure but different operations
867871
func (c *NebiusClient) StartInstance(ctx context.Context, instanceID v1.CloudProviderInstanceID) error {
868872
c.logger.Info(ctx, "initiating instance start operation",
869873
v1.LogField("instanceID", instanceID))
@@ -901,11 +905,11 @@ func (c *NebiusClient) StartInstance(ctx context.Context, instanceID v1.CloudPro
901905
return nil
902906
}
903907

904-
func (c *NebiusClient) RebootInstance(ctx context.Context, instanceID v1.CloudProviderInstanceID) error {
908+
func (c *NebiusClient) RebootInstance(_ context.Context, _ v1.CloudProviderInstanceID) error {
905909
return fmt.Errorf("nebius reboot instance implementation pending: %w", v1.ErrNotImplemented)
906910
}
907911

908-
func (c *NebiusClient) ChangeInstanceType(ctx context.Context, instanceID v1.CloudProviderInstanceID, newInstanceType string) error {
912+
func (c *NebiusClient) ChangeInstanceType(_ context.Context, _ v1.CloudProviderInstanceID, _ string) error {
909913
return fmt.Errorf("nebius change instance type implementation pending: %w", v1.ErrNotImplemented)
910914
}
911915

@@ -1219,7 +1223,7 @@ func (c *NebiusClient) buildDiskCreateRequest(ctx context.Context, diskName stri
12191223

12201224
// getWorkingPublicImageID gets a working public image ID based on the requested image type
12211225
//
1222-
//nolint:gocognit // Complex function trying multiple image resolution strategies
1226+
//nolint:gocognit,gocyclo // Complex function trying multiple image resolution strategies
12231227
func (c *NebiusClient) getWorkingPublicImageID(ctx context.Context, requestedImage string) (string, error) {
12241228
// Get available public images from the correct region
12251229
publicImagesParent := c.getPublicImagesParent()
@@ -1255,6 +1259,7 @@ func (c *NebiusClient) getWorkingPublicImageID(ctx context.Context, requestedIma
12551259
// Look for Ubuntu matches
12561260
if strings.Contains(requestedLower, "ubuntu") && strings.Contains(imageName, "ubuntu") {
12571261
// Prefer specific version matches
1262+
//nolint:gocritic // if-else chain is clearer than switch for version matching logic
12581263
if strings.Contains(requestedLower, "24.04") || strings.Contains(requestedLower, "24") {
12591264
if strings.Contains(imageName, "ubuntu24.04") {
12601265
bestMatch = image
@@ -1316,7 +1321,7 @@ func (c *NebiusClient) getPublicImagesParent() string {
13161321
// nebius-eu-north1-l40s-4gpu-96vcpu-768gb
13171322
// nebius-eu-north1-cpu-4vcpu-16gb
13181323
//
1319-
//nolint:gocognit // Complex function with multiple fallback strategies for parsing instance types
1324+
//nolint:gocognit,gocyclo // Complex function with multiple fallback strategies for parsing instance types
13201325
func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID string) (platform string, preset string, err error) {
13211326
c.logger.Info(ctx, "parsing instance type",
13221327
v1.LogField("instanceTypeID", instanceTypeID),
@@ -1391,6 +1396,7 @@ func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID str
13911396
for i := 1; i < len(parts); i++ {
13921397
partLower := strings.ToLower(parts[i])
13931398
// Check if this part is a known GPU type or "cpu"
1399+
//nolint:goconst // GPU type comparison strings are clear inline
13941400
if partLower == "cpu" || partLower == "l40s" || partLower == "h100" ||
13951401
partLower == "h200" || partLower == "a100" || partLower == "v100" ||
13961402
partLower == "b200" || partLower == "a10" || partLower == "t4" || partLower == "l4" {
@@ -1420,7 +1426,6 @@ func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID str
14201426
// Match platform by GPU type
14211427
if (gpuType == "cpu" && strings.Contains(platformNameLower, "cpu")) ||
14221428
(gpuType != "cpu" && strings.Contains(platformNameLower, gpuType)) {
1423-
14241429
// Log ALL available presets for this platform for debugging
14251430
availablePresets := make([]string, 0, len(p.Spec.Presets))
14261431
for _, preset := range p.Spec.Presets {
@@ -1533,6 +1538,7 @@ func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID str
15331538
// resolveImageFamily resolves an ImageID to an image family name
15341539
// If ImageID is already a family name, use it directly
15351540
// Otherwise, try to get the image and extract its family
1541+
//nolint:gocyclo // Complex image family resolution with fallback logic
15361542
func (c *NebiusClient) resolveImageFamily(ctx context.Context, imageID string) (string, error) {
15371543
// Common Nebius image families - if ImageID matches one of these, use it directly
15381544
commonFamilies := []string{
@@ -1690,7 +1696,6 @@ func (c *NebiusClient) cleanupOrphanedBootDisks(ctx context.Context, testID stri
16901696
(disk.Metadata.Labels != nil &&
16911697
(disk.Metadata.Labels["test-id"] == testID ||
16921698
disk.Metadata.Labels["created-by"] == "brev-cloud-sdk")) {
1693-
16941699
// Delete this orphaned disk
16951700
err := c.deleteBootDisk(ctx, disk.Metadata.Id)
16961701
if err != nil {

0 commit comments

Comments
 (0)