Skip to content

Commit 2921f5e

Browse files
liveaverageclaude
andcommitted
Replace cpu string literal with platformTypeCPU constant
The goconst linter requires string literals used 4+ times to be constants. Created platformTypeCPU constant and replaced all "cpu" string literals in instance.go and instance_test.go. - Add const platformTypeCPU = "cpu" - Replace all "cpu" string literals with platformTypeCPU - Remove unused nolint directive from instance_test.go - Verified with: /tmp/golangci-lint run (0 issues) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1af26a0 commit 2921f5e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

v1/providers/nebius/instance.go

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

17+
const (
18+
platformTypeCPU = "cpu"
19+
)
20+
1721
//nolint:gocyclo,funlen // Complex instance creation with resource management
1822
func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) {
1923
// Track created resources for automatic cleanup on failure
@@ -1389,15 +1393,15 @@ func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID str
13891393
// parts[0]=nebius, parts[1]=eu, parts[2]=north1, parts[3]=l40s, parts[4+]=preset
13901394

13911395
// Find where the preset starts (after region and gpu-type)
1392-
// Region could be multi-part (eu-north1) so we need to find the GPU type or "cpu"
1396+
// Region could be multi-part (eu-north1) so we need to find the GPU type or platformTypeCPU
13931397
var gpuType string
13941398
var presetStartIdx int
13951399

1396-
// Look for GPU type indicators or "cpu"
1400+
// Look for GPU type indicators or platformTypeCPU
13971401
for i := 1; i < len(parts); i++ {
13981402
partLower := strings.ToLower(parts[i])
1399-
// Check if this part is a known GPU type or "cpu"
1400-
if partLower == "cpu" || partLower == "l40s" || partLower == "h100" ||
1403+
// Check if this part is a known GPU type or platformTypeCPU
1404+
if partLower == platformTypeCPU || partLower == "l40s" || partLower == "h100" ||
14011405
partLower == "h200" || partLower == "a100" || partLower == "v100" ||
14021406
partLower == "b200" || partLower == "a10" || partLower == "t4" || partLower == "l4" {
14031407
gpuType = partLower
@@ -1424,8 +1428,8 @@ func (c *NebiusClient) parseInstanceType(ctx context.Context, instanceTypeID str
14241428
platformNameLower := strings.ToLower(p.Metadata.Name)
14251429

14261430
// Match platform by GPU type
1427-
if (gpuType == "cpu" && strings.Contains(platformNameLower, "cpu")) ||
1428-
(gpuType != "cpu" && strings.Contains(platformNameLower, gpuType)) {
1431+
if (gpuType == platformTypeCPU && strings.Contains(platformNameLower, platformTypeCPU)) ||
1432+
(gpuType != platformTypeCPU && strings.Contains(platformNameLower, gpuType)) {
14291433
// Log ALL available presets for this platform for debugging
14301434
availablePresets := make([]string, 0, len(p.Spec.Presets))
14311435
for _, preset := range p.Spec.Presets {

v1/providers/nebius/instance_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ func TestParseInstanceTypeFormat(t *testing.T) {
398398
var presetStartIdx int
399399
for i := 1; i < len(parts); i++ {
400400
partLower := strings.ToLower(parts[i])
401-
//nolint:goconst // GPU type comparison strings used in test
402-
if partLower == "cpu" || partLower == "l40s" || partLower == "h100" ||
401+
if partLower == platformTypeCPU || partLower == "l40s" || partLower == "h100" ||
403402
partLower == "h200" || partLower == "a100" || partLower == "v100" {
404403
gpuType = partLower
405404
presetStartIdx = i + 1

0 commit comments

Comments
 (0)